Hi everyone,
Thought I would include a very basic flappy bird type game here on the forums.
I am no expert in programming but thought this may be useful for others and provide an opportunity to learn from each other and adapted code from elsewhere.
* Please note there are only pipes on the bottom of the screen but should not be hard to adapt it to add pipes to the top of the screen.
setvirtualresolution(640,480)
setdefaultwrapu(1)
rem set up global variables
global ypipe
global xpipe
global playery
global playerx
global playersprite
global score
global score$
global backdropim
global greenpipe
global xscroll#
xpipe=800
ypipe=400
backdropim=loadimage("backgroundday.png")
createsprite(backdropim)
playersprite=loadimage("flappybird.png")
createsprite(playersprite)
greenpipe=loadimage("greenpipe.png")
createsprite(greenpipe)
setspritesize(backdropim,640,480)
setspritesize(playersprite,50,50)
setspritephysicson(playersprite,2)
SetSpriteShape(playersprite,3)
setphysicsgravity(0,200)
setspriteposition(playersprite,300,140)
SetSpritePhysicsCanRotate(playersprite,1)
setspriteposition(greenpipe,xpipe,ypipe)
score$="score:"
rem starts the game
resetvariables()
function resetvariables()
setspritephysicson(playersprite,2)
score=0
xpipe=800
ypipe=400
playerx=300
playery=140
setspriteposition(playersprite,playerx,playery)
startgame()
endfunction
function startgame()
do
backdropscrolling()
checkforpipecollision()
checkforgroundcollision()
checkformouseclick()
printc(score$);
print(score)
sync()
loop
endfunction
rem checks for pipe collision between player and pipe
function checkforpipecollision
if GetSpriteCollision(playersprite,greenpipe)
playery=getspritey(playersprite)
setspritephysicsoff(playersprite)
repeat
printc(score$);
print(score)
playery=playery+1
setspriteposition(playersprite,300,playery)
sync()
until playery>=325
gameover()
Endif
endfunction
rem scrolls the backdrop and the pipe
function backdropscrolling
xscroll#=xscroll#+0.005
setspriteuvoffset(backdropim,xscroll#,0)
setspriteposition(greenpipe,xpipe,ypipe)
xpipe=xpipe-5
if xpipe<-70
score=score+1
randomisepipeplacement()
endif
endfunction
rem randomly places the pipe at variable heights
function randomisepipeplacement
xpipe=800
ypipe=random(100,400)
endfunction
rem checks for mouse click to flap wings
function checkformouseclick
if GetRawMouseLeftPressed()
setspriteposition(playersprite,300,playery-15)
SetSpriteAngle(playersprite,-35)
endif
endfunction
rem checks for collision with ground
function checkforgroundcollision
playery=getspritey(playersprite)
if playery>=325
gameover()
endif
endfunction
rem game over function
function gameover()
gameover$="game over"
message$="click to start again"
do
printc(score$)
print(score)
print (gameover$)
print (message$)
setspritephysicsoff(playersprite)
if getrawmouseleftpressed()=1
exit
endif
sync()
loop
resetvariables()
endfunction
Anyway have fun with it all and perhaps we could all share code to make it better as no doubt there is heaps of opportunity for improvement here and we can learn from each other.
DBPro is the new Amos (I hope)