Skip to content
Snippets Groups Projects
Commit c87a7c70 authored by Vincent N's avatar Vincent N
Browse files

Première version de Flappy Bird

parent b8c77e4c
Branches
No related tags found
No related merge requests found
import turtle
import time
from PIL import Image
import io
img = LTurtle = HTurtle = LImg = HImg = None
def get_background():
global img, LTurtle, HTurtle , LImg , HImg
turtle.hideturtle()
screen = turtle.Screen()
LTurtle = screen.window_width()
HTurtle = screen.window_height()
screen_image = screen.getcanvas().postscript(colormode="color")
img = Image.open(io.BytesIO(screen_image.encode('utf-8')))
LImg = img.size[0]
HImg = img.size[1]
turtle.showturtle()
def get_pixel_color(x, y):
X = (x+LTurtle//2)*LImg/LTurtle
Y = HImg-(y+HTurtle//2)*HImg/HTurtle
if 0<X<LImg and 0<Y<HImg:
color = img.getpixel((int(X), int(Y)))
return color
else:
return (0,0,0)
if __name__ == "__main__":
# Créer une tortue
t = turtle.Turtle()
def rectangle(h, l):
t.begin_fill()
for _ in range(2):
t.fd(l)
t.left(90)
t.fd(h)
t.left(90)
t.end_fill()
rectangle(200,200)
t.fd(100)
t.left(90)
t.fd(100)
# Capturer l'écran à la position de la tortue
get_background()
t0 = time.time()
print(get_pixel(-10,-10))
print(get_pixel(10,10))
print(get_pixel(210,210))
print(time.time()-t0)
from turtle import *
from random import randint
from color_pixel import *
### Constantes
LWorld = 1000
HWorld = 300
lObstacle = 10
ratioObstacleEspacement = 15
nObstacles = LWorld // (lObstacle*ratioObstacleEspacement)
hFenetre = lObstacle*5
### Background
def rectangle(h, l):
begin_fill()
for _ in range(2):
fd(l)
left(90)
fd(h)
left(90)
end_fill()
def dessiner_obstacles():
up();goto(-LWorld//2 + lObstacle*10, -HWorld//2);down() # Aller en bas à gauche
speed(0)
for _ in range(nObstacles):
hObstacle = randint(HWorld//5,(4*HWorld)//5)
rectangle(hObstacle, lObstacle)
up()
left(90)
fd(hObstacle+hFenetre)
right(90)
down()
rectangle(HWorld- (hObstacle+hFenetre), lObstacle)
up()
right(90)
fd(hObstacle+hFenetre)
left(90)
fd(lObstacle*ratioObstacleEspacement)
down()
#### Dessin
# Background
Screen().setup(width=LWorld, height=HWorld)
dessiner_obstacles()
up();goto(-LWorld//2 , 0); left(90) # Aller au début
# Init
shape('circle')
get_background()
onkey(lambda: fd(20), 'space')
listen()
# Boucle principale du jeu
while True:
update()
setx(xcor() + 1)
backward(1)
if get_pixel_color(xcor(),ycor()) != (255,255,255):
break;
print("Perdu")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment