nyan_cat.py

Created by marius-layan

Created on April 18, 2024

6.1 KB

Nyan-cat est un memes bien connu que j’ai ici retranscrit sous forme de petit jeu ou il faut éviter les planètes et astéroïdes qui travers l’espace.

pour boucher: [UP] and [DOWN]

BON JEU !


from random import *
from kandinsky import *
from ion import *
from time import *
FONT=(30,30,80);fill_rect(0,0,320,222,FONT)
def cat():
  # PAWS-TAIL
  fill_rect(46+h+e*2,a+30+g,6,6,'black')
  fill_rect(48+h+e*2,a+28+g,6,6,'black')
  fill_rect(48+h+e*2,a+30+g,4,4,'gray')
  for i in [0,18,28]:
    fill_rect(56+e+h+i,a+30+g,8,4,'black')
    fill_rect(58+e+h+i,a+32+g,6,4,'black')
  fill_rect(58+e+h,a+30+g,4,4,'gray')
  fill_rect(76+e+h,a+30+g,4,4,'gray')
  fill_rect(86+e+h,a+30+g,4,4,'gray')
  # BODY
  fill_rect(52,a-2+g,34,34,'black');fill_rect(50,a+g,38,30,'black');fill_rect(48,a+2+g,42,26,'black')
  fill_rect(52,a+g,34,30,(255,235,198));fill_rect(50,a+2+g,38,26,(255,235,198));fill_rect(56,a+2+g,26,26,'pink');fill_rect(54,a+4+g,30,22,'pink');fill_rect(52,a+6+g,34,18,'pink')
  p_cat=[[56,6],[66,4],[72,4],[80,8],[54,18],[58,14],[56,24],[62,22],[66,16],[64,10]]
  for i in range(len(p_cat)):fill_rect(p_cat[i][0],a+g+p_cat[i][1],2,2,(255,100,100))
  # HEAD
  fill_rect(68+e,a+16+f,32,10,'black');fill_rect(70+e,a+12+f,28,4,'black')
  for i in range(0,4,2):
    fill_rect(70+e,a+10+f-i,10-i,2,'black');fill_rect(88+e+i,a+10+f-i,10-i,2,'black')
  fill_rect(92+e,a+6+f,4,2,'black');fill_rect(72+e,a+6+f,4,2,'black');fill_rect(70+e,a+26+f,28,2,'black');fill_rect(72+e,a+28+f,24,2,'black');fill_rect(74+e,a+30+f,20,2,'black');c=0
  for i in range(0,8,2):fill_rect(72+e,a+14+f-i,10-i,2,'gray')
  for i in range(0,8,2):fill_rect(86+e+i,a+14+f-i,10-i,2,'gray')
  fill_rect(72+e,a+14+f,24,2,'gray');fill_rect(70+e,a+16+f,28,10,'gray');fill_rect(72+e,a+26+f,24,2,'gray');fill_rect(74+e,a+28+f,20,2,'gray')
  fill_rect(76+e,a+18+f,4,4,'black');fill_rect(90+e,a+18+f,4,4,'black');fill_rect(76+e,a+18+f,2,2,'white');fill_rect(90+e,a+18+f,2,2,'white');fill_rect(72+e,a+22+f,4,4,(255,150,160));fill_rect(94+e,a+22+f,4,4,(255,150,160))
  fill_rect(78+e,a+26+f,14,2,'black');fill_rect(78+e,a+24+f,2,2,'black');fill_rect(90+e,a+24+f,2,2,'black');fill_rect(84+e,a+24+f,2,2,'black');fill_rect(86+e,a+20+f,2,2,'black')
def sup():
  fill_rect(0,a-4,54,40,FONT);fill_rect(48,a-4+g,42,10,FONT);fill_rect(42+e*2,a+28+f,56,10-f+g,FONT);fill_rect(80+e,a+4+f,22,26,FONT)
def rainbow():
  for i in range(4):fill_rect(38-i*16,a-2+g-((i%2)*2)*k,16,6,'red');fill_rect(38-i*16,a+4+g-((i%2)*2)*k,16,6,'orange');fill_rect(38-i*16,a+10+g-((i%2)*2)*k,16,6,'yellow');fill_rect(38-i*16,a+16+g-((i%2)*2)*k,16,6,'green');fill_rect(38-i*16,a+22+g-((i%2)*2)*k,16,6,'blue');fill_rect(38-i*16,a+28+g-((i%2)*2)*k,16,6,'purple')
def c1():
  fill_rect(46,a+28,2,2,'gray');fill_rect(44,a+12,4,8,'black');fill_rect(38,a+10,6,8,'black');fill_rect(36,a+8,6,6,'black');fill_rect(44,a+16,4,2,'gray');fill_rect(40,a+14,8,2,'gray');fill_rect(38,a+10,4,4,'gray')
def F1():
  global e
  cat();fill_rect(44,a+18,4,8,'black');fill_rect(38,a+20,6,8,'black');fill_rect(36,a+24,6,6,'black');fill_rect(44,a+20,4,4,'gray');fill_rect(40,a+22,4,6,'gray');fill_rect(38,a+24,2,4,'gray');e-=2
def F2():
  global f
  fill_rect(50,a+30,2,4,'black');fill_rect(48,a+34,2,2,'black');cat();fill_rect(48,a+30,2,2,'gray');fill_rect(44,a+14,4,6,'black');fill_rect(38,a+12,10,6,'black');fill_rect(34,a+10,10,6,'black');fill_rect(46,a+16,2,2,'gray');fill_rect(38,a+14,8,2,'gray');fill_rect(36,a+12,6,2,'gray');f-=2
def F3():
  global g
  fill_rect(50,a+30,2,4,'black');fill_rect(48,a+34,2,2,'black');fill_rect(46,a+26,2,2,'black');cat();fill_rect(48,a+30,2,2,'gray');c1();g-=2
def F4():
  global e
  fill_rect(50,a+28,2,4,'black');fill_rect(48,a+32,2,2,'black');cat();fill_rect(48,a+28,2,2,'gray')
  for i in range(0,7,2):fill_rect(44-i,a+12-i,4,6,'black')
  for i in range(0,7,2):fill_rect(44-i,a+14-i,4,2,'gray')
  fill_rect(36,a+6,2,6,'black');e+=2
def F5():
  global h,f,g
  cat();h+=2;f+=2;g+=2;c1()
def F6():
  cat()
  for i in range(0,7,2):fill_rect(44-i,a+12+i,4,6,'black')
  for i in range(0,7,2):fill_rect(44-i,a+14+i,4,2,'gray')
  fill_rect(36,a+18,2,6,'black')
a,d,e,f,g,h,k,l,l1,m,n,j,p,q=91,0,0,0,0,0,1,[],[],0,28,0,28,0
while True:
  while l!=[]:
    for i in range(len(l)):  
      j=i
      if l[i][2]==6:fill_rect(l[i][0]-6,l[i][1]-6,14,14,FONT);del l[i];break
      elif l[i][2]==0:fill_rect(l[i][0]-2,l[i][1],6,2,'white');fill_rect(l[i][0],l[i][1]-2,2,6,'white')
      elif l[i][2]==2:fill_rect(l[i][0]-2,l[i][1],6,2,FONT);fill_rect(l[i][0],l[i][1]-2,2,6,FONT);fill_rect(l[i][0]-6,l[i][1],14,2,'white');fill_rect(l[i][0],l[i][1]-6,2,14,'white');fill_rect(l[i][0],l[i][1],2,2,FONT)
      elif l[i][2]==4:fill_rect(l[i][0]-4,l[i][1],10,2,FONT);fill_rect(l[i][0],l[i][1]-4,2,10,FONT)
    if j==len(l)-1:
      for i in range(len(l)):l[i][2]+=1
      break
  l.append([randint(4,316),randint(4,218),0])
  if keydown(KEY_UP) and a>12:sup();a-=8
  if keydown(KEY_DOWN) and a<178:sup();a+=8
  if d==0:e,f,g,h,k=0,0,0,0,1;sup();F1();d+=1
  elif d==1:sup();rainbow();F2();d+=1
  elif d==2:sup();rainbow();F3();d+=1
  elif d==3:sup();k=-1;rainbow();F4();d+=1
  elif d==4:sup();rainbow();F5();d+=1
  elif d==5:sup();rainbow();F6();d=0
  if m==0:l1.append([320,randint(4,188)])
  if m==n and n>10:m=0;n-=4
  elif 40<m<94:draw_string("METEORITE",160,100,'white',FONT);m+=1
  elif m==94:draw_string("METEORITE",160,100,FONT,FONT);m+=1
  elif m==99:l1.append([320,randint(4,188)]);m=95
  else:m+=1
  while l1!=[]:
    for i in range(len(l1)):
      if m<80:fill_rect(l1[i][0],l1[i][1],30,30,FONT);l1[i][0]-=6;fill_rect(l1[i][0]+2,l1[i][1],26,30,(50,50,255));fill_rect(l1[i][0],l1[i][1]+2,30,26,(50,50,255));fill_rect(l1[i][0]+6,l1[i][1]+4,8,10,'green');fill_rect(l1[i][0]+12,l1[i][1]+12,6,10,'green');fill_rect(l1[i][0]+14,l1[i][1]+22,2,4,'green');fill_rect(l1[i][0]+24,l1[i][1]+8,6,8,'green');o=i
      else:fill_rect(l1[i][0],l1[i][1],14,14,FONT);l1[i][0]-=10;fill_rect(l1[i][0],l1[i][1],14,14,'gray');o=i
      if l1[i][0]<-30:del l1[i];break
    if o==len(l1)-1:break
  if m>94:p=14
  for i in range(len(l1)):
    if (48<l1[i][0]<96 and a-2+g<l1[i][1]<a+38+g) or (48<l1[i][0]+p<96 and a-2+g<l1[i][1]<a+38+g) or (48<l1[i][0]<96 and a-2+g<l1[i][1]+p<a+38+g) or (48<l1[i][0]+p<96 and a-2+g<l1[i][1]+p<a+38+g):j=-1;break
  if j==-1:break
  sleep(0.05);q+=1
fill_rect(0,0,320,222,'black');draw_string("GAME OVER",110,60,'red','black');draw_string("SCORE : "+str(int(q/10)),110,110,'yellow','black')

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.