snak.py

Created by systeme-eratz

Created on June 26, 2023

1.48 KB

Petit jeu amusant, le but étant de ramasser les “pommes” en rouge, tout en évitant les trous noirs !

Kojiverse Productions


from math import *
from math import *
from ion import *
from kandinsky import *
from random import *
from time import *
nb_obstacle=10
timer=float(input("vitesse : \n(entre 0.1 et 0.001) :"))
x=140
y=100
d=0
g="Game Over"
score=0
pomme=0
x_pomme=None
y_pomme=None
run=True
l=[]
y_obstacle=[]
x_obstacle=[]
for i in range(nb_obstacle):
  x_obstacle.append(randint(0,32)*10)
  y_obstacle.append(randint(0,32)*10)

while run==True:

  if keydown(KEY_RIGHT)==True:d=1
  elif keydown(KEY_LEFT)==True:d=2
  elif keydown(KEY_UP)==True:d=3
  elif keydown(KEY_DOWN)==True:d=4

  if d==1:x+=10
  elif d==2:x-=10
  elif d==3:y-=10
  elif d==4:y+=10

  fill_rect(0,0,333,222,(255,255,255))
  draw_string("score : {}".format(score),0,0)

  #for i in range(score+1):


  fill_rect(x,y,10,10,(0,255,0))
  for i in range(nb_obstacle):
    fill_rect(x_obstacle[i],y_obstacle[i],10,10,(0,0,0))

  if pomme==1:
    fill_rect(x_pomme,y_pomme,10,10,(255,0,0))
    if x_pomme==x and y_pomme==y:
      score+=1
      pomme=0
      timer-=0.005
      nb_obstacle+=1
      for i in range(nb_obstacle):
        x_obstacle.append(randint(0,32)*10)
        y_obstacle.append(randint(1,22)*10)
  for i in range(nb_obstacle):
    if x_pomme == x_obstacle[i] and y_pomme == y_obstacle[i]:
      y_pomme-=10
  sleep(timer)
  if x<=0 or x>=320 or y<=0 or y>=220 or get_pixel(x,y)==color(0,0,0):
    print(g)
    run=False
    break
  if pomme==0:
    x_pomme=randint(1,31)*10
    y_pomme=randint(1,21)*10
    pomme=1




input("[press OK]")

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.