falling.py

Created by frattini-fabrice

Created on February 02, 2022

2.08 KB

Un petit jeu où le personnage doit éviter le plus longtemps possible des projectiles qui tombent du ciel.


from ion import *
from kandinsky import *
from random import *

def eff():
  fill_rect(0,0,320,250,(200,255,200))

def perso(x,y):
  fill_rect(x-5,y,5,20,(200,255,200))
  fill_rect(x,y,20,20,(0,0,0))
  fill_rect(x+5,y+5,2,2,(200,255,200))
  fill_rect(x+13,y+5,2,2,(200,255,200))
  fill_rect(x+20,y,5,20,(200,255,200))
  fill_rect(x+7,y+13,6,2,(200,255,200))
  draw_string(str(s),2,2)
  
def m1(x,y,v):
  fill_rect(x,y,20,20,(0,0,100))
  fill_rect(x+3,y+3,14,14,(80,100,200))
  fill_rect(x-3,y-v,24,v,(200,255,200))
  fill_rect(x-3,y-8,3,28,(200,255,200))
  fill_rect(x+20,y-8,3,28,(200,255,200))

def col():
  j=True
  if x>=x1-20 and x<=x1+20:
    if y>=y1-20 and y<=y1+20:
      j=False
  if x>=x2-20 and x<=x2+20:
    if y>=y2-20 and y<=y2+20:
      j=False
  if x>=x3-20 and x<=x3+20:
    if y>=y3-20 and y<=y3+20:
      j=False
  if x>=x4-20 and x<=x4+20:
    if y>=y4-20 and y<=y4+20:
      j=False    
  return j

eff()
s=0

x = 100
y = 205
vit=3
perso(x,y)

x1=100
y1=-50
v1=1

x2=200
y2=-80
v2=1

x3=100
y3=-120
v3=1

x4=150
y4=-200
v4=2



while True:
  
  while col():
    if keydown(KEY_LEFT):
      if x>0:
        x=x-vit
  
    if keydown(KEY_RIGHT):
      if x<300:
        x=x+vit
    y1=y1+v1
    x1=x1+randint(-3,3)    
    if y1>300:
      y1=-10
      x1=randint(0,300)
    y2=y2+v2
    x2=x2+randint(-3,3)    
    if y2>300:
      y2=-50
      x2=randint(0,300)
        
    y3=y3+v3
    x3=x3+randint(-3,3)    
    if y3>300:
      y3=-50
      x3=randint(0,300)
    
    y4=y4+v4
    x4=x4+randint(-3,3)    
    if y4>300:
      y4=-150
      x4=randint(0,300)
      
    s=s+1
    perso(x,y)
    m1(x1,y1,v1)
    m1(x2,y2,v2)
    m1(x3,y3,v3)
    m1(x4,y4,v4)
    col()
  
  while not col():
    draw_string("Game over",120,80)
    draw_string("Votre score "+str(s),90,105)
    if keydown(KEY_OK):
      
      eff()
      s=0
      
      x = 100
      y = 205
      vit=3
      perso(x,y)
      
      x1=100
      y1=-50
      v1=1
      
      x2=200
      y2=-80
      v2=1
      
      x3=100
      y3=-120
      v3=1
      
      x4=150
      y4=-200
      v4=2
      
      col()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.