Marek Mansell
Obrázky prevzaté z www.fablab.sk
Obrázky prevzaté z robocoop.eu
python.sk/navody/flappy/
Flappy
Pozadie
(nehýbe sa)
Pipe
(hýbe sa)
Pipe
(hýbe sa)
Stlačenie medzerníka - Flappy ide hore
python.sk/navody/flappy/
Zmena
módu
Súčasný
mód
python.sk/navody/flappy/
Otvor
súbor
python.sk/navody/flappy/
HEIGHT = 500
WIDTH = 500
TITLE = "My Flappy Game"
Spustenie hry
Ukončenie hry
python.sk/navody/flappy/
Spracuj vstupy
(napr. klávesnica)
"Update" hry (pozícia postáv)
"Render" hry
(zmeny sa zobrazia)
python.sk/navody/flappy/
HEIGHT = 500
WIDTH = 500
TITLE = "My Flappy Game"
def update():
pass
def draw():
pass
python.sk/navody/flappy/
python.sk/navody/flappy/
HEIGHT = 500
WIDTH = 500
TITLE = "My Flappy Game"
flappy = Actor("flappy")
flappy.x = WIDTH / 2
flappy.y = HEIGHT / 2
flappy.dy = 0
def update():
pass
def draw():
flappy.draw()
python.sk/navody/flappy/
0, 0
X
Y
500, 500
python.sk/navody/flappy/
HEIGHT = 500
WIDTH = 500
TITLE = "My Flappy Game"
GRAVITY = 0.3
flappy = Actor("flappy")
flappy.x = WIDTH / 2
flappy.y = HEIGHT / 2
flappy.dy = 0
def update():
flappy.y += GRAVITY
def draw():
flappy.draw()
python.sk/navody/flappy/
HEIGHT = 500
WIDTH = 500
TITLE = "My Flappy Game"
GRAVITY = 0.3
flappy = Actor("flappy")
flappy.x = WIDTH / 2
flappy.y = HEIGHT / 2
flappy.dy = 0
def update():
flappy.y += flappy.dy
flappy.dy += GRAVITY
def draw():
flappy.draw()
python.sk/navody/flappy/
HEIGHT = 640
WIDTH = 360
TITLE = "My Flappy Game"
GRAVITY = 0.3
flappy = Actor("flappy")
flappy.x = WIDTH / 2
flappy.y = HEIGHT / 2
flappy.dy = 0
def update():
flappy.y += flappy.dy
flappy.dy += GRAVITY
def draw():
screen.blit("bg", (0, 0))
flappy.draw()
HEIGHT = 640
WIDTH = 360
TITLE = "My Flappy Game"
GRAVITY = 0.3
FLAP_SPEED = 6.5
def on_key_down(key):
if key == keys.SPACE:
flappy.dy = -FLAP_SPEED
python.sk/navody/flappy/
def update():
flappy.y += flappy.dy
flappy.dy += GRAVITY
if flappy.top > HEIGHT:
quit()
if flappy.bottom < 0:
quit()
python.sk/navody/flappy/
GRAVITY = 0.3
FLAP_SPEED = 6.5
SPEED = 3
pipe_upper = Actor("pipe_upper")
pipe_upper.left = WIDTH
pipe_upper.top = 0
def update():
flappy.y += flappy.dy
flappy.dy += GRAVITY
pipe_upper.left -= SPEED
def draw():
screen.blit("bg", (0, 0))
flappy.draw()
pipe_upper.draw()
def update():
flappy.y += flappy.dy
flappy.dy += GRAVITY
pipe_upper.left -= SPEED
if flappy.top > HEIGHT:
quit()
if flappy.bottom < 0:
quit()
if pipe_upper.colliderect(flappy):
quit()
python.sk/navody/flappy/
pipe_lower = Actor("pipe_lower")
pipe_lower.left = 1.5 * WIDTH
pipe_lower.bottom = HEIGHT
pipe_upper.left -= SPEED
pipe_lower.left -= SPEED
if pipe_lower.colliderect(flappy):
quit()
pipe_lower.draw()
update
update
draw
python.sk/navody/flappy/
if pipe_upper.right < 0:
pipe_upper.left = WIDTH
if pipe_lower.right < 0:
pipe_lower.left = WIDTH
update
python.sk/navody/flappy/
python.sk/navody/flappy/
python.sk/navody/flappy/
python.sk/navody/flappy/
python.sk/navody/flappy/
Prezentácia:
slides.com/marekmansell/pygame-zero-flappy