PDA

View Full Version : SDL Heaven



peter
10-05-2013, 20:25
Hi,

New SDL series now.

Demo 1


#INCLUDE "sdl.inc"

SDL_LoadWinIcon "acorn.bmp"
SDL_Window 640,480,1

Long x, fnt, toy, ses
Single a

Fnt = SDL_LoadFont "fonts/font1.ttf",38
toy = SDL_LoadImage "img/toy.gif",1
ses = SDL_LoadTile "img/lady.png",4,4

While SDL_Key(27)=0
SDL_CLS SDL_RGB 100,100,100

SDL_Text fnt,20,0,"Hello, my name is Peter.",SDL_RGB(255,255,255)
SDL_Text fnt,460,0,"Tiles",SDL_RGB(255,255,255)

SDL_Sprite toy,100,60,0

SDL_Tile ses,450, 32,0,0
SDL_Tile ses,450,132,0,1
SDL_Tile ses,450,232,0,2
SDL_Tile ses,450,332,0,3

For x=0 To 639
SDL_SetPoint x,428,1,4, SDL_RGB(0,255,0)
Next
For x=20 To 640 Step 40
For a=0 To 360
SDL_SetPoint x+Sin(a)*20,456+Cos(a)*20,2,2,SDL_RGB(SDL_Rnd(64,255),SDL_Rnd(64,255),SDL_Rnd(64,255))
Next
Next
SDL_Sync
Wend
SDL_Quit


Demo 2


#INCLUDE "sdl.inc"
#DEFAULT BOUNDCHECK Off

SDL_Window 768,708,1

'variables
Long xBoy,yBoy,zBoy,rBoy,xExit,yExit,zExit,aExit,xShrink,yShrink,zShrink
Long ras,pills,yPill,xPill,zPill,x,y,z,zAtom,yStar,xStar,zStar,fo
Long s1,s2,s3,s4,s5,s6,s7,s8,s9,sa,sb
Single vAtom,vBoy,vPill,vExit,vShrink,vStar
String w1,w2,w3,w4

Dim Map1(1200) As Byte
Dim Map2(1200) As Byte
Dim Map3(1200) As Byte

'load font
fo = SDL_LoadFont "fonts/font3.ttf",48

'loadbitmaps
s1= SDL_LoadImage "gfx/char.bmp",60
s2= SDL_LoadImage "gfx/atom.bmp",16
s3= SDL_LoadImage "gfx/boyd.bmp",16
s4= SDL_LoadImage "gfx/boyu.bmp",16
s5= SDL_LoadImage "gfx/boyr.bmp",16
s6= SDL_LoadImage "gfx/boyl.bmp",16
s7= SDL_LoadImage "gfx/exitani.bmp",16
s8= SDL_LoadImage "gfx/pillani.bmp",16
s9= SDL_LoadImage "gfx/bummani.bmp",16
sa= SDL_LoadImage "gfx/starani.bmp",16
sb= SDL_LoadImage "gfx/shrani.bmp",16

'loadwavs
w1= "gfx/eat.wav"
w2= "gfx/grab.wav"
w3= "gfx/hit.wav"
w4= "gfx/success.wav"

'loadmaps
SDL_LoadBytes("maps/map1-1.txt",map1)
SDL_LoadBytes("maps/map1-2.txt",map2)
SDL_LoadBytes("maps/map1-3.txt",map3)

'game routines
Sub ShowMaps()
For y=0 To 29
For x=0 To 39
z=(y*40+x)+1
If map1(z)=34 Then SDL_Sprite s1,x*64,y*64,1
If map1(z)=41 Then SDL_Sprite s1,x*64,y*64,2
If map2(z)=91 Then SDL_Sprite s2,x*64,y*64,zAtom
If map2(z)=121 Then SDL_Sprite s7,x*64,y*64,0
If map2(z)=81 Then SDL_Sprite sa,x*64,y*64,zAtom
Next
Next
vAtom +=.4
If vAtom >=1 Then
vAtom=0
zAtom +=1
If zAtom=16 Then zAtom=0
End If
End Sub

Sub InitBoy()
For y=0 To 29
For x=0 To 39
z=(y*40+x)+1
If map3(z)=111 Then
xBoy=x*64
yBoy=y*64
End If
If map2(z)=91 Or map2(z)=81 Then
pills +=1
End If
If map2(z)=121 Then
xExit=x*64
yExit=y*64
End If
Next
Next
End Sub

Sub CheckBoy()
If ras >0 Or rBoy=5 Then Exit Sub
Long xb,yb
xb = xBoy/64
yb = yBoy/64
z=(yb*40+xb)+1
If map2(z)=121 And aExit=1 Then
xShrink=xBoy
yShrink=yBoy
map3(z)=32
rBoy=5
ElseIf map2(z)=91 Then
xPill=xBoy
yPill=yBoy
Pills -= 1
map2(z)=32
map3(z)=32
rBoy=0
PlayWav w1,0,1
ElseIf map2(z)=81 Then
xStar=xBoy
yStar=yBoy
Pills -= 1
map2(z)=32
map3(z)=32
rBoy=0
PlayWav w2,0,1
ElseIf SDL_Key(275) And map3(z+1)=32 Then
map3(z)=32
map3(z+1)=111
rBoy=1
ElseIf SDL_Key(276) And map3(z-1)=32 Then
map3(z)=32
map3(z-1)=111
rBoy=2
ElseIf SDL_Key(273) And map3(z-40)=32 Then
map3(z)=32
map3(z-40)=111
rBoy=3
ElseIf SDL_Key(274) And map3(z+40)=32 Then
map3(z)=32
map3(z+40)=111
rBoy=4
else
rBoy=0
End If
End Sub

Sub DrawBoy()
If rBoy=0 Then
SDL_Sprite s3,xBoy,yBoy,0
ElseIf rBoy=1 Then
xBoy +=2
SDL_Sprite s5,xBoy,yBoy,zBoy
vBoy +=.4
If vBoy >=1 Then
vBoy=0
zBoy +=1
if zBoy=16 then zBoy=0
end if
ras +=2
if ras=64 Then ras=0
ElseIf rBoy=2 Then
xBoy -=2
SDL_Sprite s6,xBoy,yBoy,zBoy
vBoy +=.4
If vBoy >=1 Then
vBoy=0
zBoy +=1
If zBoy=16 Then zBoy=0
End If
ras +=2
if ras=64 Then ras=0
ElseIf rBoy=3 Then
yBoy -=2
SDL_Sprite s4,xBoy,yBoy,zBoy
vBoy +=.4
If vBoy >=1 Then
vBoy=0
zBoy +=1
if zBoy=16 then zBoy=0
end if
ras +=2
if ras=64 Then ras=0
ElseIf rBoy=4 Then
yBoy +=2
SDL_Sprite s3,xBoy,yBoy,zBoy
vBoy +=.4
If vBoy >=1 Then
vBoy=0
zBoy +=1
if zBoy=16 then zBoy=0
End If
ras +=2
if ras=64 Then ras=0
End If
End Sub

Sub PillsAni()
If ypill >0 Then
SDL_Sprite s8,xpill,yPill,zPill
vPill +=.2
If vPill >=1 Then
vPill=0
zPill +=1
If zPill=8 Then
zPill=0
yPill=0
End If
End If
End If
End sub

Sub NoPills()
If Pills=0 Then
If pills=0 And aExit=0 Then PlayWav w4,0,1
aExit=1
End If
End Sub

Sub ExitActiv()
If aExit=1 Then
SDL_Sprite s7,xExit,yExit,zExit
vExit +=.2
If vExit >=1 Then
vExit=0
zExit +=1
If zExit=16 Then zExit=0
End If
End If
End Sub

Sub BoyShrink()
If yShrink >0 Then
SDL_Sprite s9,xShrink,yShrink,zShrink
vShrink +=.2
If vShrink >=1 Then
vShrink=0
zShrink +=1
If zShrink=16 Then
yShrink=0
PlayWav w3,0,1
End If
end if
end if
End Sub

Sub StarShrink()
If yStar >0 Then
SDL_Sprite sb,xStar,yStar,zStar
vStar +=.4
If vStar >=1 Then
vStar=0
zStar +=1
If zStar=16 Then
zStar=0
yStar=0
End If
End If
End If
End Sub

InitBoy
While SDL_Key(27)=0
SDL_SetCaption "FRAMES " & SDL_GetFps
ShowMaps
ExitActiv
BoyShrink
CheckBoy
DrawBoy
PillsAni
NoPills
Starshrink
If rBoy=5 Then
SDL_Text Fo,160,340,"IS OVER NOW", SDL_RGB(255,255,255)
end if
SDL_Redraw
SDL_SetFps (120)
wend
SDL_Quit