fruit_ninja.py

Created by dkfe123

Created on September 02, 2025

2.79 KB

Ok pour commencer. Flèches pour se déplacer. Attrapez les fruits bleus, évitez les rouges (bombes). Ne pas attraper un bleu fait perdre une vie. Toucher une bombe fait perdre.


from math import *
from kandinsky import *
from ion import *
import random as r
import time as t
fill_rect(0,0,320,222,(0,0,0))
draw_string("Fruit Ninja",100,80,(255,255,255),(0,0,0))
draw_string("Press OK to start",90,170,(255,255,255),(0,0,0))
while not keydown(KEY_OK):
  pass
fill_rect(0,0,320,222,(255,255,255))
x,y,l=155,5,7
fill_rect(80,0,160,222,(0,0,0))
fill_rect(0,0,60,222,(0,0,0))
fill_rect(260,0,60,222,(0,0,0))
v,score=2,0
pt=[0]
ex,ey=0,0
f=0.8
fr=[0]
vie=3
#type,x,y,elanx,elany
mort=0
fond,df=0,0
while True:
  vit=0.001+score/350000
  df-=0.1
  if df<0:
    fond=0
  cf=(255,255,255)
  if fond==1:
    cf=(255,0,0)
  elif fond==2:
    cf=(0,0,125)
  fill_rect(60,0,20,222,cf)
  fill_rect(240,0,20,222,cf)
  dx,dy=v*(keydown(KEY_RIGHT)-keydown(KEY_LEFT)),v*(keydown(KEY_DOWN)-keydown(KEY_UP))
  ex,ey=dx,dy
  #ex,ey=f*(ex+dx),f*(ey+dy)
  if ex!=0 or ey!=0:
    fill_rect(floor(x),floor(y),l,l,(0,0,0))
  x+=ex
  y+=ey
  if x<80:
    x=80
  if x>240-l:
    x=240-l
  if y<25:
    y=25
  if y>200-l:
    y=200-l
  fill_rect(floor(x),floor(y),l,l,cf)
  if len(fr)<9:
    if r.randint(0,15)==0:
      fr.append(0)
    else:
      fr.append(1)
    fr.append(r.randint(80,225))
    fr.append(200)
    fr.append(r.uniform(-300*vit,-500*vit))
  for i in range(1,len(fr),4):
    if i<len(fr)-3:
      if fr[i+2]<40:
        fr[i+2]=40
        fr[i+3]=0
      fill_rect(floor(fr[i+1]),floor(fr[i+2]),15,15,(0,0,0))
      fr[i+2]+=fr[i+3]
      fr[i+3]+=vit
      if x<fr[i+1]+15 and x+l>fr[i+1] and y<fr[i+2]+15 and y+l>fr[i+2]:
        if fr[i]==0:
          mort=1
        else:
          bon=r.randint(6,12)
          pt.append(bon)
          pt.append(0)
          pt.append(r.randint(260,290))
          pt.append(80+r.randint(20,40)*(2*r.randint(0,1)-1))
          score+=bon
          if fond==0:
            fond,df=2,1
        for w in range(4):
          fr.pop(i)
      elif fr[i+2]>230:
        if fr[i]>0:
          vie-=1
          fond,df=1,20
        if vie<0:
          mort=1
        for w in range(4):
          fr.pop(i)
      else:
        c=(0,0,255)
        if fr[i]==0:
          c=(255,0,0)
        fill_rect(floor(fr[i+1]),floor(fr[i+2]),15,15,c)
  if mort==1:
    break
  for i in range(3):
    c=(255*(i<vie),0,0)
    fill_rect(5+16*i,10,8,8,c)
  for i in range(1,len(pt),4):
    if i<len(pt)-3:
      pt[i+1]+=1
      bon=255-pt[i+1]
      draw_string(str("+"+str(pt[i])),pt[i+2],pt[i+3],(bon,bon,bon),(0,0,0))
      if pt[i+1]==255:
        for w in range(4):
          pt.pop(i)
  draw_string("FRUIT NINJA",120,0,(255,255,255),(0,0,0))
#  draw_string(str(vie),0,0)
  draw_string(str(score),260,80,(0,0,255),(0,0,0))
fill_rect(0,0,320,222,(0,0,0))
draw_string("Perdu !",120,40,(255,255,255),(0,0,0))
draw_string("Score :",120,100,(255,255,255),(0,0,0))
draw_string(str(score),180,100,(255,255,255),(0,0,0))

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.