Code : Tout sélectionner
EnableExplicit
InitSprite()
InitKeyboard()
Enumeration
#Flapping
#Kabooming
#Attending
EndEnumeration
Structure wall
x.i
y1.i
y2.i
pt.i
EndStructure
Global A = 10, B = 24, x = 18, framerate, pushed, window, wall, flappy, rnd, flappyY, event, lasty, GameStep = #Attending, y , score
Global cloud, white, black, cloudloop
Global Dim cloud(2,1)
Global NewList wall.wall()
Declare init()
Declare Kaboom()
cloud(0,0) = 80 : cloud(1,0) = 480 : cloud(2,0) = 880
cloud(0,1) = Random(50) : cloud(1,1) = Random(50) : cloud(2,1) = Random(50)
window = OpenWindow(#PB_Any,0,0,900,500,"Flappy",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(window),0,0,900,500)
flappy = CreateSprite(#PB_Any,50,50, #PB_Sprite_PixelCollision)
wall = CreateSprite(#PB_Any,50,400, #PB_Sprite_PixelCollision)
cloud = CreateSprite(#PB_Any,200,130)
white = CreateSprite(#PB_Any,50,50)
black = CreateSprite(#PB_Any,50,50)
StartDrawing(SpriteOutput(flappy))
Circle(25,25,25,$0033CC)
Circle(35,25,5 ,$8899CC)
Circle(45,25,5 ,$8899CC)
StopDrawing()
StartDrawing(SpriteOutput(wall)) : Box(0,0,50,400,$006600) : StopDrawing()
StartDrawing(SpriteOutput(white)) : Circle(25,25,25,$FFFFFF) : StopDrawing()
StartDrawing(SpriteOutput(black)) : Circle(25,25,25,$100000) : StopDrawing()
StartDrawing(SpriteOutput(cloud))
Circle(35,65,35,$FFCCFF)
Circle(80,40,40,$FFCCFF)
Circle(75,95,30,$FFCCFF)
Circle(110,30,30,$FFCCFF)
Circle(130,70,50,$FFCCFF)
Circle(175,80,20,$FFCCFF)
StopDrawing()
init()
framerate = ElapsedMilliseconds()
Repeat
event = WindowEvent()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Space) And pushed = 0 : pushed = 1 : EndIf
Select GameStep
Case #Flapping
If pushed = 1 : x = 12 : EndIf
If ElapsedMilliseconds() >= framerate + 16
ClearScreen($CC3C3C)
If x < 25
x + 1
EndIf
y = A * Sin(2 * #PI / B * x)
flappyY + y
For cloudloop = 0 To 2
cloud(cloudloop,0) - 1
If cloud(cloudloop,0) < -200
cloud(cloudloop,0) = 980
cloud(cloudloop,1) = Random(50)
EndIf
Next cloudloop
DisplayTransparentSprite(cloud,cloud(0,0),cloud(0,1))
RotateSprite(cloud,180,#PB_Absolute)
DisplayTransparentSprite(cloud,cloud(1,0),cloud(1,1))
RotateSprite(cloud,0,#PB_Absolute)
DisplayTransparentSprite(cloud,cloud(2,0),cloud(2,1))
ForEach wall()
wall()\x = wall()\x - 7
If wall()\x < 150 And wall()\pt = 0 : wall()\pt = 1: score + 1 : EndIf
If wall()\x < -50
wall()\x = 950
rnd = -Random(390,110)
If lasty - rnd < -200 : rnd = lasty + 200 : EndIf
lasty = rnd
wall()\y1 = rnd
wall()\y2 = rnd +550
wall()\pt = 0
EndIf
DisplaySprite(wall,wall()\x,wall()\y1)
DisplaySprite(wall,wall()\x,wall()\y2)
DisplayTransparentSprite(flappy,150,flappyY)
If SpritePixelCollision(flappy,150,flappyY,wall,wall()\x,wall()\y1) Or SpritePixelCollision(flappy,150,flappyY,wall,wall()\x,wall()\y2)
GameStep = #Kabooming
EndIf
Next
StartDrawing(ScreenOutput()) : DrawingMode(#PB_2DDrawing_Transparent ) : DrawText(10,10,Str(score),$000000) : StopDrawing()
EndIf
StartDrawing(ScreenOutput())
Box(0,480,900,20,$006633)
Box(0,475,900,5,$006699)
StopDrawing()
FlipBuffers()
Case #Kabooming
If ElapsedMilliseconds() >= framerate + 32
Kaboom() : framerate = ElapsedMilliseconds()
EndIf
Case #Attending
If pushed : GameStep = #Flapping: pushed = 0: score = 0 : EndIf
EndSelect
If pushed : pushed = 2 : EndIf
If KeyboardReleased(#PB_Key_Space) : pushed = 0 : EndIf
Delay(1)
Until event = #PB_Event_CloseWindow
Procedure init()
ClearScreen($CC3C3C)
ClearList(wall())
AddElement(wall())
wall()\x = 500
wall()\y1 = -300
wall()\y2 = 250
AddElement(wall())
wall()\x = 1000
rnd = -Random(390,110)
wall()\y1 = rnd
wall()\y2 = rnd +550
lasty = rnd
FlappyY = 250
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(WindowWidth(window)/2 - TextWidth("Space to Flapp !")/2,250,"Space to Flapp !",$000000)
DrawText(WindowWidth(window)/2 - TextWidth(" Score : "+Str(score))/2,270," Score : "+Str(score),$000000)
StopDrawing()
DisplayTransparentSprite(cloud,cloud(0,0),cloud(0,1))
RotateSprite(cloud,180,#PB_Absolute)
DisplayTransparentSprite(cloud,cloud(1,0),cloud(1,1))
RotateSprite(cloud,0,#PB_Absolute)
DisplayTransparentSprite(cloud,cloud(2,0),cloud(2,1))
StartDrawing(ScreenOutput())
Box(0,480,900,20,$006633)
Box(0,475,900,5,$006699)
StopDrawing()
FlipBuffers()
EndProcedure
Procedure Kaboom()
Static Kaboom = 15, kaboomstat, flapX = 150
Protected rnd
Kaboom - 1
rnd = Random(20)
ClearScreen($CC3C3C)
DisplayTransparentSprite(cloud,cloud(0,0),cloud(0,1))
RotateSprite(cloud,180,#PB_Absolute)
DisplayTransparentSprite(cloud,cloud(1,0),cloud(1,1))
RotateSprite(cloud,0,#PB_Absolute)
DisplayTransparentSprite(cloud,cloud(2,0),cloud(2,1))
If kaboomstat
flapX + rnd
flappyY - rnd
DisplayTransparentSprite(black,flapX,flappyY)
ForEach wall()
DisplaySprite(wall,wall()\x+rnd/2,wall()\y1)
DisplaySprite(wall,wall()\x+rnd/2,wall()\y2)
Next
DisplayTransparentSprite(black,flapX,flappyY)
kaboomstat = 0
Else
flapX - rnd
flappyY + rnd
ForEach wall()
DisplaySprite(wall,wall()\x-rnd/2,wall()\y1)
DisplaySprite(wall,wall()\x-rnd/2,wall()\y2)
Next
DisplayTransparentSprite(white,flapX,flappyY)
kaboomstat = 1
EndIf
StartDrawing(ScreenOutput()) : DrawingMode(#PB_2DDrawing_Transparent ) : DrawText(10,10,Str(score),$000000) : StopDrawing()
StartDrawing(ScreenOutput())
Box(0,480,900,20,$006633)
Box(0,475,900,5,$006699)
StopDrawing()
FlipBuffers()
If Kaboom = 0
Kaboom = 15
flapX = 150
init()
GameStep = #Attending
EndIf
EndProcedure