PDA

View Full Version : Sdl Demo



peter
12-05-2013, 23:15
Sdl Demo


#INCLUDE "sdl.inc"

SDL_Window 640,480,1

Long bild,x,y,mouse,fo,tree,weed
Long dir,x1,y1,zr,zl,zu,zd
Single v1,v2,v3,v4

dir=1 : y1=480-64 : zr=12 : zl=8 : zu=4

fo = SDL_LoadFont "fonts/font1.ttf",38

tree = SDL_LoadImage "png/tree.png",1
weed = SDL_LoadImage "png/weed.png",1
mouse= SDL_LoadTile "png/bitmap.png",16,4

While SDL_Key(27)=0
SDL_Cls SDL_RGB(20,200,255)
SDL_Text fo,180,0,"HELLO IS A SDL DEMO", SDL_RGB(255,255,0)
SDL_Sprite tree,200,150,0
SDL_Sprite weed,0,432,0
If dir=1 Then
SDL_Tile mouse,x1,y1,zr,0
v1 +=.1
If v1 >=1 Then
v1=0
zr +=1
iF zr=16 then zr=12
EndIf
x1 +=1
If x1 >= 640-64 Then
dir=2
zr=12
EndIf
EndIf
If dir=2 Then
SDL_Tile mouse,x1,y1,zu,0
v2 +=.1
If v2 >=1 Then
v2 =0
zu +=1
iF zu=8 then zu=4
EndIf
y1 -=1
If y1 <=0 Then
dir=3
zu=4
EndIf
EndIf
If dir=3 Then
SDL_Tile mouse,x1,y1,zl,0
v3 +=.1
If v3 >=1 Then
v3=0
zl +=1
iF zl=12 then zl=8
EndIf
x1 -=1
If x1 <=0 Then
dir=4
zl=8
EndIf
EndIf
If dir=4 Then
SDL_Tile mouse,x1,y1,zd,0
v4 +=.1
If v4 >=1 Then
v4=0
zd +=1
iF zd=4 then zd=0
EndIf
y1 +=1
If y1 >= 480-64 Then
dir=1
zd=0
EndIf
EndIf
SDL_Sync
Wend

SDL_Quit

Billbo
13-05-2013, 10:58
Peter,

It sure would help if you would explain what it demonstrates.
Plus, put the script in your download zip.

Bill

peter
13-05-2013, 13:21
Billbo,

Shows some sdl_sprites, so you can see how it goes.

peter
13-05-2013, 15:53
Magic game.


just click on a number.

The contruction: 123
456
78
Wins.


#INCLUDE "sdl.inc"
#DEFAULT BOUNDCHECK Off

SDL_Window 192,240,1

Long fo= SDL_LoadFont("fonts/font2.ttf",18)
Long xPos,yPos,x,y,j,m,n,num,a,i,jx,moves,clic,won
String win,klic

Dim Map(100) As Long
Dim Buf(20) As Long

For j=0 To 25
Map(j) =255
Next

num = SDL_LoadImage "mmedia/number.png",8
win = "mmedia/won.wav"
klic= "mmedia/klic.wav"

Sub CheckWon()
iF Won =1 Then
Exit Sub
EndIf
For y=0 To 2
For x=0 To 2
j= (y*3+x)+1
jx = jx+1
iF jx =9 Then
jx =0
EndIf
If Map(j) <> jx Then
Exit Sub
EndIf
Next
Next
PlayWav win,0,1
SDL_SetCaption "WON!"
won =1
End Sub

Sub PushNumber()
If SDL_mButton=1 And clic=0 And won=0 Then
xPos = Int(SDL_xMouse() /64)
yPos = Int(SDL_yMouse() /64)
j = (yPos*3+xPos)+1
If Map(j) =0 Or yPos >2 Then
Exit Sub
EndIf
If Map(j+1) =0 And clic=0 Then
Map(j+1) = Map(j)
Map(j)=0
moves = moves +1
clic =1
PlayWav klic,0,1
ElseIf xPos >0 And Map(j-1) =0 And clic=0 Then
Map(j-1) = Map(j)
Map(j)=0
moves = moves +1
clic =1
PlayWav klic,0,1
ElseIf yPos >0 And Map(j-3) =0 And clic=0 Then
Map(j-3) = Map(j)
Map(j)=0
moves = moves +1
clic =1
PlayWav klic,0,1
ElseIf Map(j+3) =0 And clic=0 Then
Map(j+3) = Map(j)
Map(j)=0
moves = moves +1
clic =1
PlayWav klic,0,1
EndIf
End iF
End Sub

Sub ShowMap()
For y=0 To 2
For x=0 To 2
j=(y*3+x)+1
If Map(j) =9 Then
Map(j) =0
ElseIf Map(j) >=1 And Map(j) <=8 Then
SDL_Sprite num,x*64,y*64,Map(j)-1
EndIf
Next
Next
End Sub

Sub CheckBuffer()
a = SDL_Rnd(1,9)
For m=1 To 9
If Buf(m)=a Then
Exit Sub
EndIf
Next
Buf(n)=a
n +=1
End Sub

Sub SetNumber()
n=1
While n <10
CheckBuffer
Wend
For y=0 To 2
For x=0 To 2
j=(y*3+x)+1
Map(j) = Buf(j)
Next
Next
End Sub

Sub NewGame()
If SDL_mButton()=1 And clic=0 Then
If Int(SDL_xMouse() /18) >=3 And Int(SDL_xMouse() /18) <=5 And Int(SDL_yMouse() /18) =11 Then
moves =0
won =0
clic =1
For i=1 To 9
Buf(i) =0
Next
For y=1 To 2
For x=1 To 2
j=(y*3+x)+1
Map(j) =0
Next
Next
SetNumber
SDL_SetCaption "SDL_app"
EndIf
EndIf
End Sub

SetNumber
While SDL_Key(27)=0
SDL_Cls SDL_RGB(0,0,255)
ShowMap
NewGame
PushNumber
CheckWon
SDL_Text fo,62,198,"NEW",SDL_RGB(255,255,255)
SDL_Text fo,16,218,"MOVES " & moves,SDL_RGB(255,255,255)
SDL_Sync
If SDL_mbutton()=0 Then clic=0
Wend

SDL_Quit

Billbo
13-05-2013, 16:36
Peter,

There is no "fonts/font2.ttf" in the Magic game zip.

You had a fonts/font1.ttf in the SDL Demo, but no font2.ttf
in Magic.

Bill

peter
13-05-2013, 16:40
Here are you.

Billbo
13-05-2013, 16:54
Thanks, Peter.

Bill