yumfish_.py

Created by alexandre-merle

Created on June 20, 2023

2.94 KB

jeu ou il faut déplacer un poisson et manger des poissons plus petit que soi


from math import *
from random import *
from kandinsky import *
from ion import *
from time import *
#Def
fish=[
1,0,0,0,1,1,1,1,0,
1,1,0,1,1,1,0,1,1,
1,1,1,1,1,1,1,1,1,
1,1,0,1,1,1,0,0,0,
1,0,0,0,1,1,1,1,0]
fishfood=[
0,1,1,1,1,0,0,0,1,
1,1,0,1,1,1,0,1,1,
1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,0,1,1,
0,1,1,1,1,0,0,0,1]
colors=[
(255,255,0),(255,0,255),(0,255,255),(0,255,0),(0,0,255),(255,180,0),(255,255,0),(255,0,255),(0,255,255),(0,255,0),(0,0,255),(255,180,0)]
def draw_fish(x,y,t):
  a=0
  for b in range(y,y+(5*t),t):
    for c in range(x,x+(9*t),t):
      if fish[a]==1:
        fill_rect(c,b,t,t,(255,0,0))
      a+=1
def draw_fishfood(x,y,t,color):
  a=0
  for b in range(y,y+(5*t),t):
    for c in range(x,x+(9*t),t):
      if fishfood[a]==1:
        fill_rect(c,b,t,t,color)
      a+=1
bg_color=(0,200,255)
x_=0
y_=111
x_fishes=[400,500,300,600,800,400,500,300,600,800]
y_fishes=[200,150,100,50,170,130,110,80,30,210]
taille_fishes=[1,1,2,4,5,10,1,1,2,2,3]
taille=2
score=0
stop=0
v=3
kill=0
t=monotonic()
#Logo
fill_rect(0,0,320,222,bg_color)
draw_fish(0,111,5)
draw_fishfood(200,100,3,(0,255,0))
draw_fishfood(50,75,7,(255,180,0))
draw_string("Play => OK",100,200,(0,0,255),bg_color)
draw_string("YUMFISH",120,20,(0,0,255),bg_color)
while not keydown(KEY_OK):
  pass
#Jeu
fill_rect(0,0,320,222,bg_color)
while stop==0:
  if monotonic()-t>30:
    t=monotonic()
    v+=1
  draw_fish(x_,y_,taille)
  for i in range(0,10):
    fill_rect(x_fishes[i]+taille_fishes[i],y_fishes[i],taille_fishes[i]*15,taille_fishes[i]*5,bg_color)
    draw_fishfood(x_fishes[i],y_fishes[i],taille_fishes[i],colors[i])
    x_fishes[i]-=v
    if x_fishes[i]<0-(taille_fishes[i]*5):
      fill_rect(x_fishes[i]+taille_fishes[i],y_fishes[i],taille_fishes[i]*10,taille_fishes[i]*5,bg_color)
      x_fishes[i]=randint(400,700)
      y_fishes[i]=randint(0,190)
    if y_fishes[i]>y_ and y_fishes[i]-(taille*5)<y_ and taille_fishes[i]<taille and x_fishes[i]<taille*9:
      score+=taille_fishes[i]*5
      kill+=1
      fill_rect(x_fishes[i]+taille_fishes[i],y_fishes[i],taille_fishes[i]*10,taille_fishes[i]*5,bg_color)
      x_fishes[i]=randint(400,700)
      y_fishes[i]=randint(0,190)
    if y_fishes[i]>=y_ and y_fishes[i]-(taille*5)<=y_ and taille_fishes[i]>=taille and x_fishes[i]<=taille*9:
      stop=1
      draw_string("Game Over",100,105,(0,0,255),bg_color)
  if score>=50:
    score-=50
    taille+=1
  if keydown(KEY_UP)and y_>0:
    fill_rect(x_,y_,taille*9,taille*5,bg_color)
    y_-=v
  if keydown(KEY_DOWN)and y_<200-(taille*5):
    fill_rect(x_,y_,taille*9,taille*5,bg_color)
    y_+=v
  if keydown(KEY_BACKSPACE):
    while not keydown(KEY_SHIFT):
      pass
  if taille>25:
    stop=1
    draw_string("You won!!",100,105,(0,0,255),bg_color)
  draw_string("You ate "+str(kill)+" fishes",0,200,(0,0,255),bg_color)
  fill_rect(183,203,104,12,(100,)*3)
  fill_rect(185,205,score*2,8,(0,255,0))
  fill_rect(185+(score*2),205,100-(score*2),8,(0,220,0))
  draw_string(str(taille-1),295,200,(0,0,255),bg_color)

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.