I better post before anyone else does
Type box
Field x#,y#,w,h
End Type
Type coin
Field x#,y#,frame#
End Type
Type Player
Field x#,y#,frame#
Field xd#,yd#,angle#
Field Width, Height
Field lives
Field Thrust#
Field Thrusting
Field ThrustFrame
Field ThrustFrameDir
Field shieldtime
Field dying
End Type
Type Message
Field x,y#,life,txt$
End Type
Type rock
Field x#,y#
Field speed#
End Type
Type poof
Field x#,y#,sx#,sy#
Field count
End Type
Type dust
Field x#,y#,sx#,sy#
End Type
Type monster
Field t
Field x#,y#,frame#
Field xd#,yd#
Field box.box
Field dead
End Type
Type bird
Field x#,y#,frame#
Field vx#,vy#
End Type
Graphics 640,480,0,2
HidePointer
power#=0
Dim CreditsArray$(10)
CreditsArray(0) = "A BlitzBasic Community Project"
CreditsArray(1) = "Created by the following people"
CreditsArray(2) = "In order they appeared in the thread:"
CreditsArray(3) = "Rob Farley (original codebase)"
CreditsArray(4) = "Kris Kelly"
CreditsArray(5) = "Mikkel Fredborg"
CreditsArray(6) = "RetroBooster"
CreditsArray(7) = "Marcus Matt"
CreditsArray(8) = "Jeppe Nielsen"
CreditsArray(9) = "Yan"
CreditsArray(10)= "eBusiness"
Dim instructionsArray$(8)
instructionsArray(0) = "Jump from platform to platform"
instructionsArray(1) = "Blah blah blah blah"
instructionsArray(2) = ""
instructionsArray(3) = "Keys:"
instructionsArray(4) = "Left: Angle left"
instructionsArray(5) = "Right: Angle right"
instructionsArray(6) = "Down: Jump (hold to increase power)"
instructionsArray(7) = "Up: Thrust (if you have any thurst)"
instructionsArray(8) = "Shift: Fine tune angle"
Const keyleft=203
Const keyright=205
Const keyjump=200
Const keyUp = 57
;Const keyFineAngle = 54
Const THRUST_MAX = 50
Const keySkip=208
Const angleMod=2
Global gotr=0
Global gotg=0
Global gotb=0
;Global angleMod = 5
Global Player.Player = New Player
Global jump
Global Score
Global Scrollspeed#
Global highscore
Global oldtime, newtime
highfile=OpenFile("HighScore")
If highfile
highscore=ReadLine(highfile)
CloseFile highfile
Else
highscore=200
highfile=WriteFile("HighScore")
WriteLine highfile,highscore
CloseFile highfile
EndIf
Global gameover = True
SetBuffer BackBuffer()
Reset()
; Load Sounds
Global getcoin = LoadSound("sounds/coin.ogg")
Global die = LoadSound("sounds/die.ogg")
Global dieplayed = False
Global bg = LoadSound("sounds/bg.ogg")
LoopSound bg
Global bgchannel = PlaySound(bg)
Global boom = LoadSound("sounds/boom.ogg")
; Load images
Global backdrop = LoadImage("images/Background00.png")
Global arrow = LoadImage("images/arrow00.png")
Global rockimage = LoadImage("images/Fall00.png")
Global poofimage = LoadImage("images/poof00.png")
Global tiles = LoadAnimImage("images/Tiles00.png",32,32,0,3)
Global coins = LoadAnimImage("images/Coins00.png",16,16,0,8)
Global character = createcharacter("images/CharacterBW.png",100,255,100)
HandleImage character, Player\Width/2,Player\Height-2
Global thruster = LoadAnimImage("images/thrust00.png", 16,16,0,3)
HandleImage thruster, 8, 0
Global birds = LoadAnimImage("images/Bird00.png",16,16,0,4)
Global logo = LoadImage("images/Logo00.png")
MidHandle logo
Dim monsters(1)
For n=0 To 1
monsters(n) = LoadAnimImage("images/Monster0"+Str(n)+".png",16,16,0,4)
Next
backscroll# = GraphicsHeight()-ImageHeight(backdrop)
ClsColor 154,198,237
SetFont LoadFont("tahoma",15,True)
Repeat
Cls
backscroll = backscroll + (scrollspeed*0.025)
DrawImage backdrop,0,backscroll
If player\dying = 0
If jump = False
; If KeyDown(keyFineAngle) Then angleMod = 1 Else angleMod = 1
If KeyDown(keyright) And Player\angle<270 Then Player\angle=Player\angle+angleMod
If KeyDown(keyleft) And Player\angle>90 Then Player\angle=Player\angle-angleMod
If KeyDown(keyright) And Player\angle=270 Then Player\x=Player\x+.4
If KeyDown(keyleft) And Player\angle=90 Then Player\x=Player\x-.4
If KeyDown(keySkip) Then
Player\y=Player\y+5
jump = True
End If
Else
If KeyDown(keyright) Then player\xd = player\xd+0.05
If KeyDown(keyleft) Then player\xd = player\xd-0.05
End If
If KeyDown(keyUp) And Player\Thrust > 0 Then
Player\yd = Player\yd-0.2
Player\Thrust = Player\Thrust - 0.1
Player\Thrusting = True
jump = True
DebugLog Player\Thrust
Else
Player\Thrusting = False
EndIf
; Down grade shield time
If player\shieldtime>0
player\shieldtime = player\shieldtime - 1
End If
If KeyDown(keyjump) And jump=False And Int(xd+yd)=0 Then power=power+20
If power>1000 Then power=1000
; jump
If KeyDown(keyjump)=False And power>0
power=power/10
Player\xd=Sin(-Player\angle)*Sqr(power)
Player\yd=Cos(-Player\angle)*Sqr(power)
power=0
jump = True
deck=False
EndIf
If jump
Player\yd = Player\yd+.1
Player\xd = Player\xd*.99
Player\yd = Player\yd*.99
Else
player\yd = 0
player\xd = 0
End If
oldx#=Player\x
oldy#=Player\y
Else
player\yd = player\yd + 0.1
player\frame = Int(player\frame + 1) Mod 55
EndIf
Player\x=Player\x+Player\xd
Player\y=Player\y+Player\yd+scrollspeed
For bird.bird=Each bird
DrawImage birds,bird\x,bird\y,bird\frame
bird\x=bird\x+bird\vx
bird\y=bird\y+bird\vy+ScrollSpeed
bird\frame = (bird\frame + 0.05) Mod 3
If bird\x<0
bird\x=GraphicsWidth()
EndIf
If bird\y<0
bird\y=GraphicsHeight()
EndIf
If bird\x>GraphicsWidth()
bird\x=0
EndIf
If bird\y>GraphicsHeight()
bird\y=0
EndIf
Next
; draw level
For box.box = Each box
For sx = 0 To box\w-32 Step 32
frame = 1
If sx = 0 Then frame = 0
If sx = box\w-32 Then frame = 2
DrawImage tiles,box\x+sx,box\y,frame
Next
box\y = box\y + ScrollSpeed
If box\y > GraphicsHeight()
box\x = Rand(0,(GraphicsWidth()-64)/32)*32
box\y = -32
box\w = Rand(2,5)*32
If box\x+box\w>GraphicsWidth()
box\w = 64
End If
If Rand(0,2) = 1
coin.coin = New coin
coin\x = Rand(box\x,box\x+box\w)
;prevent a coin appearing too far to the right where the player can't reach it
If coin\x > GraphicsWidth()-10 Then coin\x = GraphicsWidth()-10
coin\y = box\y-16
End If
If Rand(0,3)=1
monster.monster=New monster
monster\x=Rand(box\x,box\x+box\w)
monster\y=box\y-16
monster\box=box
monster\t=Rand(0,1)
If Rand(0,1)=0
monster\xd=-Rnd(0.1+0.2*monster\t,0.5+0.2*monster\t)
Else
monster\xd=Rnd(0.1+0.2*monster\t,0.5+0.2*monster\t)
EndIf
EndIf
End If
Next
For coin.coin = Each coin
DrawImage coins,coin\x,coin\y,coin\frame
coin\y = coin\y + ScrollSpeed
coin\frame = (coin\frame + 0.1) Mod 7
If player\dying = 0
If RectsOverlap(Player\x-2,Player\y-2,5,5,coin\x,coin\y,16,16)
score = score + 100
If score>highscore
highscore=score
highfile=WriteFile("HighScore")
WriteLine highfile,highscore
CloseFile highfile
EndIf
m.message = New message
m\x = coin\x
m\y = coin\y-10
m\life = 100
m\txt = "100"
PlaySound(getcoin)
Delete coin
If (Score Mod 500) = 0
Player\Thrust=Player\Thrust+10
m\txt$ = "EXTRA THRUST"
End If
If Player\Thrust > THRUST_MAX Then Player\Thrust = THRUST_MAX
If (Score Mod 5000) = 0
Player\Lives = Player\Lives + 1
m\txt$ = "EXTRA LIFE"
End If
ElseIf coin\y > GraphicsHeight()
Delete coin
End If
EndIf
Next
For monster.monster=Each monster
DrawImage monsters(monster\t),monster\x,monster\y,monster\frame
If monster\dead
monster\x = monster\x + monster\xd
monster\y = monster\y + monster\yd
monster\yd = monster\yd * 0.99 + 0.1
monster\xd = monster\xd * 0.99
Else
monster\y=monster\y+ScrollSpeed
monster\frame = (monster\frame + 0.1) Mod 3
monster\x=monster\x+monster\xd
If monster\x+16>monster\box\x+monster\box\w
monster\xd=-Rnd(0.1,0.5)
ElseIf monster\x<monster\box\x
monster\xd=Rnd(0.1,0.5)
EndIf
If player\dying = 0
dx#=((monster\x+8)-player\x)
dy#=(monster\y+8-player\y)
If (dx*dx+dy*dy)<32*32
If Sin(MilliSecs())>0
Outline_text player\x,player\y-30,"Watch out!",1,1
EndIf
EndIf
If RectsOverlap(Player\x-2,Player\y-2,5,5,monster\x,monster\y,16,16)
If player\shieldtime = 0
;LoseLife(player)
player\dying = 1
player\yd = -3
player\xd = 0
m.message = New message
m\x = player\x
m\y = player\y
m\life = 100
m\txt = "EEK!"
End If
ElseIf monster\y > GraphicsHeight()
Delete monster
End If
EndIf
End If
Next
For rock.rock = Each rock
For monster.monster = Each monster
If monster\dead = False
If ImagesOverlap(monsters(monster\t),monster\x,monster\y,rockImage,rock\x,rock\y)
monster\dead = True
monster\xd = Rnd(-2.5,2.5)
monster\yd = Rnd(-5.0,-3.0)
End If
End If
Next
Next
If player\dying = 0
; Player frame
temp = Abs(Int(player\yd))*11
If temp>22 Then temp = 22
Player\frame = 27 + (((player\angle-180)/90.0)*5) - (Int(power/500)*11) + temp
; Sides of screen
If Player\x<10 Or Player\x>GraphicsWidth()-10
Player\x = oldx
Player\xd = -Player\xd/2
End If
; Top of screen
If player\y<0
player\y = oldy
player\yd = 0
End If
For box.box = Each box
; Y Collision
If Player\yd>0
collisionA = PointInBox(Player\x,Player\y+1,box)
collisionB = PointInBox(Player\x,Player\y-5,box)
If collisionA = True And collisionB = False
deck = True
Player\y = oldy
Player\xd=Player\xd*.9
Player\yd=-Player\yd/3
Player\Angle = 180
If Abs(player\xd)<0.2 And Abs(player\yd)<0.2
jump = False
End If
EndIf
EndIf
Next
EndIf
; Bottom of screen
If Player\y>GraphicsHeight()+40
LoseLife(player)
End If
; rocks!
If Rand(0,400) = 0
rock.rock = New rock
rock\x = Rand(16,GraphicsWidth()-16)
rock\y = -600
rock\speed = Rnd(2,4)
EndIf
For rock.Rock = Each rock
kill =False
rock\y = rock\y + rock\speed
If rock\y<-32
If Rand(-600,-100)<rock\y
DrawImage arrow,rock\x,0
End If
Else
DrawImage rockImage, rock\x,rock\y
End If
If rock\y > GraphicsHeight()
kill = True
EndIf
For box.box = Each box
If ImageRectCollide(rockimage,rock\x,rock\y,0,box\x,box\y,box\w,box\h)
For i = 0 To 10
poof.poof = New poof
poof\x = rock\x
poof\y = rock\y
a# = Rnd(0,360)
ms# = Rnd(1.5,5.0)
poof\sx = Sin(a)*ms
poof\sy = Cos(a)*ms
Next
Dustify(rock\x+16,rock\y,120,100,80)
kill = True
EndIf
Next
If player\dying = 0
If ImagesOverlap(character,player\x,player\y,rockImage,rock\x,rock\y)
For i = 0 To 10
poof.poof = New poof
poof\x = rock\x
poof\y = rock\y
a# = Rnd(0,360)
ms# = Rnd(1.5,5.0)
poof\sx = Sin(a)*ms
poof\sy = Cos(a)*ms
Next
Dustify(rock\x+16,rock\y,120,180,140)
kill = True
If player\shieldtime = 0
;LoseLife(player)
player\dying = 1
player\yd = -3
player\xd = 0
m.message = New message
m\x = player\x
m\y = player\y
m\life = 100
m\txt = "SQUISH!"
End If
EndIf
EndIf
If kill
SoundVolume boom,.1
PlaySound(boom)
Delete rock
End If
Next
; Poof clouds
drawpoof = Not drawpoof
If drawpoof
For poof.poof = Each poof
poof\x = poof\x + poof\sx
poof\y = poof\y + poof\sy
poof\sx = poof\sx * 0.9
poof\sy = poof\sy * 0.9
If Rand(10,20)>poof\count
DrawImage poofImage, poof\x,poof\y
End If
poof\count = poof\count + 1
If poof\count > 20 Then Delete poof
Next
End If
; dust/rubble
Color 120,100,80
For dust.dust = Each dust
dust\x = dust\x + dust\sx
dust\y = dust\y + dust\sy
dust\sx = dust\sx * Rnd(0.95,0.999)
dust\sy = (dust\sy * Rnd(0.95,0.999)) + 0.1
Rect dust\x,dust\y,2,2
If dust\y > GraphicsHeight() Then Delete dust
Next
If gameover
player\x = -100
player\y = -100
player\xd = 0
player\yd = 0
frontend()
If KeyDown(57)
gameover=False
backscroll# = GraphicsHeight()-ImageHeight(backdrop)
Reset()
EndIf
Else
; draw player
If player\dying
If (MilliSecs() And 1)
DrawImage character, Player\X,Player\Y,Player\frame
EndIf
Else
If jump = False
Color 255,0,0
Line Player\x+(Sin(-Player\angle)*16),Player\y-4+(Cos(-Player\angle)*16),Player\x+(Sin(-Player\angle)*32),Player\y-4+(Cos(-Player\angle)*32)
Line Player\x+(Sin(-Player\angle+5)*27),Player\y-4+(Cos(-Player\angle+5)*27),Player\x+(Sin(-Player\angle)*32),Player\y-4+(Cos(-Player\angle)*32)
Line Player\x+(Sin(-Player\angle-5)*27),Player\y-4+(Cos(-Player\angle-5)*27),Player\x+(Sin(-Player\angle)*32),Player\y-4+(Cos(-Player\angle)*32)
End If
DrawImage character, Player\X,Player\Y,Player\frame
EndIf
If Player\Thrusting Then
DrawImage thruster, Player\X,Player\Y+2,Player\ThrustFrame
If Player\ThrustFrame = 0 Then Player\ThrustFrameDir = 1 ElseIf Player\ThrustFrame = 2 Then Player\ThrustFrameDir = -1
Player\ThrustFrame = Player\ThrustFrame + Player\ThrustFrameDir
EndIf
If player\shieldtime>0
If Rand(0,100)<player\shieldtime
Color 255,255,255
Oval player\x-10,player\y-14,20,20,False
End If
End If
End If
; Draw Power bar
DrawBar(8,GraphicsHeight(),power,100,"POWER")
; Draw Thrust bar
DrawBar(GraphicsWidth()-24,GraphicsHeight(),player\thrust,THRUST_MAX,"THRUST",True)
Outline_Text GraphicsWidth()-120,10,"SCORE "+Replace(RSet(score,8)," ","0")
Outline_Text GraphicsWidth()/2,10,"HIGHSCORE "+Replace(RSet(highscore,8)," ","0"),True
For i = 1 To player\lives
DrawImage character,((i-1)*16)+16,20,27
Next
For m.message = Each message
m\y = m\y - 0.5
m\life = m\life - 1
If Rand(0,50)<m\life
Outline_Text m\x,m\y,m\txt,True,True
End If
If m\life <= 0
Delete m
End If
Next
Flip
ScrollSpeed = ScrollSpeed + 0.00001
Until KeyHit(1)
End
Function Reset(seed=1014)
Delete Each box
Delete Each coin
Delete Each monster
Delete Each Message
Delete Each rock
Delete Each poof
Delete Each dust
Delete Each bird
Player\x#=GraphicsWidth()/2
Player\y#=GraphicsHeight()/2
Player\frame = 5
Player\xd# = 0
Player\yd# = 0
Player\angle# = 180
Player\Width = 16
Player\Height = 16
Player\lives=3
player\shieldtime = 500
player\dying = 0
SeedRnd seed
box.box=New box
box\x=0
box\y=GraphicsHeight()-128
box\w=GraphicsWidth()
box\h=32
For n=1 To 20
box.box = New box
box\x = Rand(0,(GraphicsWidth()-64)/32)*32
box\y = Rand(0,(GraphicsHeight()-160)/32)*32
box\w = Rand(2,5)*32
If box\x+box\w>GraphicsWidth()
box\w = 64
End If
box\h = 32
Next
For box.box = Each box
If Rand(0,2) = 1
coin.coin = New coin
coin\x = Rand(box\x,box\x+box\w)
coin\y = box\y-16
End If
If Rand(0,3)=1
monster.monster=New monster
monster\x=Rand(box\x,box\x+box\w)
monster\y=box\y-16
monster\box=box
monster\t=Rand(0,1)
If Rand(0,1)=0
monster\xd=-Rnd(0.1+0.2*monster\t,0.5+0.2*monster\t)
Else
monster\xd=Rnd(0.1+0.2*monster\t,0.5+0.2*monster\t)
EndIf
EndIf
Next
For n=1 To 20
bird.bird=New bird
bird\x = Rand(0,GraphicsWidth())
bird\y = Rand(0,GraphicsHeight())
If Rand(0,1)=0
bird\vx=Rnd(0.1,1)
Else
bird\vx=-Rnd(0.1,1)
EndIf
If Rand(0,1)=0
bird\vy=Rnd(0.01,0.5)
Else
bird\vy=-Rnd(0.1,1)
EndIf
Next
jump = True
scrollspeed# = 0.1
Score = 0
End Function
Function DrawBar(x,y,val#,max#,txt$,lf=False)
val = val/(max/100.0)/10
Color val*2.55,255-(val*1.28),0
Rect x,y-val-24,12,val
Color 0,0,0
Rect x ,y-100-24,14,100,False
Rect x+2,y-100-22,10,96,False
Color 255,255,255
Rect x+1,y-100-23,12,98,False
If lf
Outline_Text x+14-StringWidth(txt),y-18,txt$
Else
Outline_Text x,y-18,txt$
End If
End Function
Function Dustify(x,y,r,g,b)
For i = 0 To 30
d.dust = New dust
d\x = x
d\y = y
d\sx = Rnd(-2.0,2.0)
d\sy = Rnd(-5.0,2.0)
Next
End Function
Function LoseLife(player.player)
player\lives = player\lives-1
player\thrust = 10
player\angle = 180
player\shieldtime = 500
player\dying = 0
If player\lives < 0
gameover = True
player\x=-100
;Return
Else
; reposition player
For box.box = Each box
If box\y<GraphicsHeight()-100 And box\y>100
If box\x>0 And box\x+box\w<GraphicsWidth()
player\y = box\y-32
player\x = Rand(box\x,box\x+box\w)
player\xd = 0
player\yd = 0
Exit
End If
End If
Next
End If
channel = PlaySound(die)
End Function
Function Outline_Text(x,y,t$,cx=False,cy=False,r=255,g=255,b=255)
Color 0,0,0
For i = -1 To 1
For j = -1 To 1
Text x+i,y+j,t,cx,cy
Next
Next
If r<0 Then r = 0
If g<0 Then g = 0
If b<0 Then b = 0
If r>255 Then r = 255
If g>255 Then g = 255
If b>255 Then b = 255
Color r,g,b
Text x,y,t,cx,cy
End Function
Function PointInBox(x,y,box.box)
If x=>box\x And x<=box\x+box\w
If y=>box\y And y<=box\y+box\h
Return True
End If
End If
Return False
End Function
Function DisplayCredits(t#,period#)
gwid=GraphicsWidth()/2
g10th=GraphicsHeight()/10
If t<(period/10)
x = t-(period/10)
ElseIf t>period-(period/10)
x = t-(period-(period/10))
End If
For i = 0 To 10
j = ((i Mod 2)*2)-1
shiftA = Sin((MilliSecs()/5)+i*20)*64
shiftB = Cos((MilliSecs()/8)+i*20)*64
shiftC = Sin((MilliSecs()/10)+i*20)*64
Outline_Text(gwid-x*j, (g10th*4.5)+(i*15),CreditsArray(i),True,True,192+shiftA,192+shiftB,192+shiftC)
Next
End Function
Function displayinstructions(t#,period#)
gwid=GraphicsWidth()/2
g10th=GraphicsHeight()/10
If t<(period/10)
x = t-(period/10)
ElseIf t>period-(period/10)
x = t-(period-(period/10))
End If
For i = 0 To 8
j = ((i Mod 2)*2)-1
shiftA = Sin((MilliSecs()/5)+i*20)*64
shiftB = Cos((MilliSecs()/8)+i*20)*64
shiftC = Sin((MilliSecs()/10)+i*20)*64
Outline_Text(gwid-x*j, (g10th*4.5)+(i*15),instructionsArray(i),True,True,192+shiftA,192+shiftB,192+shiftC)
Next
End Function
Function frontend()
DrawImage logo,GraphicsWidth()/2,(GraphicsHeight()/2)-100+(Sin(MilliSecs()/5)*20)
gwid=GraphicsWidth()/2
ghie=GraphicsHeight()/2
g10th=GraphicsHeight()/10
t=MilliSecs() Mod 10000
If Sin(MilliSecs()/2)>0
Outline_Text gwid,GraphicsHeight()-12,"INSERT COIN",True,True
EndIf
If t<5000
displaycredits(t,5000)
Else
displayinstructions(t-5000,5000)
End If
End Function
Function createcharacter(file$,r#,g#,b#)
temp=LoadAnimImage(file$,16,16,0,11*5)
char=CreateImage(16,16,11*5)
r=r/255
g=g/255
b=b/255
For frame = 0 To (11*5)-1
LockBuffer ImageBuffer(temp,frame)
LockBuffer ImageBuffer(char,frame)
For x=0 To ImageWidth(temp)
For y=0 To ImageHeight(temp)
val#=getr(ImageBuffer(temp,frame),x,y)
If val>0
If val>240
writergb(ImageBuffer(char,frame),x,y,val,val,val)
Else
writergb(ImageBuffer(char,frame),x,y,r*val,g*val,b*val)
EndIf
EndIf
Next
Next
UnlockBuffer ImageBuffer(temp,frame)
UnlockBuffer ImageBuffer(char,frame)
Next
FreeImage temp
Return char
End Function
Function getr(buffer,x,y)
argb=ReadPixelFast(x,y,buffer)
Return (ARGB Shr 16) And $ff
End Function
Function writergb(buffer,x,y,red,green,blue)
argb=(blue Or (green Shl 8) Or (red Shl 16) Or ($ff000000))
WritePixelFast x,y,argb,buffer
End FunctionAtered the keys and stuff