a_void_v4.py

Created by mathieu-croslacoste

Created on January 03, 2025

6.07 KB

Amélioration (j’espère) du script “a-void” par squarepoint (https://my.numworks.com/python/squarepoint)

EXE ou OK pour commencer (Entrée avec l’emulateur). Évitez les projectiles en vous déplaçant avec les flèches. Simple mais addictif.


from math import sin,cos,pi
from kandinsky import draw_string as txt,fill_rect as f_r,get_pixel as gp,color as C
from ion import keydown as key
from time import sleep
from random import randint as rint
blue=C(200,230,255)
red=C(255,0,0)
gray=C(150,150,150)
def laser():
 x,y,obj,score=155,105,[],0
 while 1:
  if score%25==0:a=rint(1,4)
  else:a=0
  if a==1:obj.append([315,rint(y-20,y+20),1])
  elif a==2:obj.append([0,rint(y-20,y+20),2])
  elif a==3:obj.append([rint(x-20,x+20),217,3])
  elif a==4:obj.append([rint(x-20,x+20),0,4])
  obj2=[]
  for i in range(len(obj)):
   if obj[i][2]==1:a=1+(obj[i][0]<=0);obj2.append([obj[i][0]-5,obj[i][1],a])
   elif obj[i][2]==2:a=2-(obj[i][0]>=310);obj2.append([obj[i][0]+5,obj[i][1],a])
   elif obj[i][2]==3:a=3+(obj[i][1]<=0);obj2.append([obj[i][0],obj[i][1]-5,a])
   else:a=4-(obj[i][1]>=210);obj2.append([obj[i][0],obj[i][1]+5,a])
  obj=obj2;x,y,score=move(x,y,score)
  for i in range(len(obj)):f_r(obj[i][0],obj[i][1],5,5,red)
  x,y,score,a=collide(x,y,score)
  if a==1:return score
  pause()
def bombs():
 x,y,obj,score=155,105,[],0
 while 1:
  if score%50==0 or (score>750 and score%75==0):obj.append([rint(0,310),0,2,0])
  if score%25==0:obj.append([rint(0,310),0,1,0])
  obj2=[]
  for i in range(len(obj)):
   if obj[i][2]==1 or obj[i][2]==2:
    if rint(1,40)==1 or obj[i][1]>=200 or obj[i][3]>0:
     if obj[i][2]==1:
      for j in range(12):obj2.append([obj[i][0],obj[i][1],0,30*j,0])
      f_r(obj[i][0]-25,obj[i][1]-25,50,50,(255,180,50))
     elif obj[i][3]<24:obj2.append([obj[i][0],obj[i][1],obj[i][2],obj[i][3]+1]);obj2.append([obj[i][0],obj[i][1],0,25*obj[i][3],0])
    else:obj2.append([obj[i][0],obj[i][1]+5,obj[i][2],obj[i][3]])
   elif obj[i][4]<=30:obj2.append([obj[i][0]+int((cos((2*pi*obj[i][3])/360))*7),obj[i][1]+int((sin((2*pi*obj[i][3])/360))*7),0,obj[i][3],obj[i][4]+1])
  obj=obj2;x,y,score=move(x,y,score)
  for i in range(len(obj)):
   if obj[i][2]==0:f_r(obj[i][0],obj[i][1],5,5,gray)
   elif obj[i][2]==1:f_r(obj[i][0],obj[i][1],10,10,(0,255,0))
   elif obj[i][2]==2:f_r(obj[i][0],obj[i][1],10,10,(255,255,0))
  x,y,score,a=collide(x,y,score)
  if a==1:return score
  pause()
def asteroid():
 x,y,obj,score=155,105,[],0
 while 1:
  if score%50==0 or (score>325 and score%40==0) or (score>650 and score%25==0) or (score>1050 and score%15==0):
   side=rint(1,4)
   if side==1:objX,objY=rint(0,300),0
   elif side==2:objX,objY=300,rint(0,202)
   elif side==3:objX,objY=rint(0,300),202
   elif side==4:objX,objY=0,rint(0,202)
   obj.append([objX,objY,2,rint(1,360),0])
  obj2=[]
  for i in range(len(obj)):
   if obj[i][4]<=20:obj2.append([obj[i][0]+int((cos((2*pi*obj[i][3])/360))*7),obj[i][1]+int((sin((2*pi*obj[i][3])/360))*7),obj[i][2],obj[i][3],obj[i][4]+1])
   elif obj[i][2]!=0:obj2.append([obj[i][0],obj[i][1],obj[i][2]-1,obj[i][3],0]);obj2.append([obj[i][0],obj[i][1],obj[i][2]-1,obj[i][3]+180,0])
  for i in range(len(obj2)):
   if obj2[i][0]<0:obj2[i][0]=300
   elif obj2[i][0]>300:obj2[i][0]=0
   elif obj2[i][1]<0:obj2[i][1]=202
   elif obj2[i][1]>202:obj2[i][1]=0
  obj=obj2;x,y,score=move(x,y,score)
  for i in range(len(obj)):f_r(obj[i][0],obj[i][1],5+5*(obj[i][2]==1)+15*(obj[i][2]),5+5*(obj[i][2]==1)+15*(obj[i][2]),gray)
  x,y,score,a=collide(x,y,score)
  if a==1:return score
  pause()
def raid():
 x,y,obj,score=155,105,[],0
 while 1:
  if score%40==0 or(score>250 and score%50==0)or(score>500 and score%30==0)or(score>750 and score%20==0):side=rint(1,4);objX,objY=rint(0,305)*((side+1)%2==0),rint(0,207)*(side%2==0);obj.append([objX,objY,side*2,1,rint(20,80)])
  obj2=[]
  for i in obj:
   if i[2]==1:obj2.append([i[0]-5,i[1]-5,1,i[3],i[4]-1])
   elif i[2]==2:obj2.append([i[0],i[1]-5,2,i[3],i[4]-1])
   elif i[2]==3:obj2.append([i[0]+5,i[1]-5,3,i[3],i[4]-1])
   elif i[2]==4:obj2.append([i[0]+5,i[1],4,i[3],i[4]-1])
   elif i[2]==5:obj2.append([i[0]+5,i[1]+5,5,i[3],i[4]-1])
   elif i[2]==6:obj2.append([i[0],i[1]+5,6,i[3],i[4]-1])
   elif i[2]==7:obj2.append([i[0]-5,i[1]+5,7,i[3],i[4]-1])
   elif i[2]==8:obj2.append([i[0]-5,i[1],8,i[3],i[4]-1])
  obj=obj2
  for i in obj:
   if i[4]<=0:
    obj2.remove(i)
    if i[3]==1:
     dist=rint(20,30)
     for j in range(4):obj2.append([i[0],i[1],1+2*j,0,dist])
  obj=obj2;x,y,score=move(x,y,score)
  for i in obj:
   if i[0]<0:i[0]=315-10*(i[3]==1)
   elif i[0]>315-10*(i[3]==1):i[0]=0
   if i[1]<0:i[1]=217-10*(i[3]==1)
   elif i[1]>217-10*(i[3]==1):i[1]=0
   f_r(i[0],i[1],5+10*(i[3]==1),5+10*(i[3]==1),red*(i[3]==1)+gray*(i[3]==0))
  x,y,score,a=collide(x,y,score)
  if a==1:return score
  pause()
def pause():
 if key(17):
  while key(17):txt("P A U S E D",105,103,red,(0,)*3)
  while 1-key(17):0
  while key(17):txt("           ",105,103,(0,)*3,(0,)*3)
def collide(x,y,score):
 b=0
 for i in range(10):
  if score>=1000+500*((a%4==2)or(a%4==3))or gp(x+i,y-1)==red or gp(x+i,y-1)==gray or gp(x+i,y+11)==red or gp(x+i,y+11)==gray or gp(x-1,y+i)==red or gp(x-1,y+i)==gray or gp(x+11,y+i)==red or gp(x+11,y+i)==gray:b=1
 return x,y,score,b
def move(x,y,score):
 if key(0)and x>0:x-=5
 elif key(3)and x<310:x+=5
 if key(1)and y>0:y-=5
 elif key(2)and y<212:y+=5
 sleep(.05);f_r(0,0,320,222,(0,)*3);score+=1;txt("Score: "+str(score),0,0,(255,)*3,(0,)*3);f_r(x,y,10,10,blue);return x,y,score
a=0
def menu():
 f_r(0,0,320,225,(0,)*3);txt("a-VOID",130,20,(255,)*3,(0,)*3)
 if a%4==0:txt("Bouncy Laser →",100,80,red,(0,)*3)
 else:txt("Bouncy Laser  ",100,80,(255,)*3,(0,)*3)
 if a%4==1:txt("Bomby Party →",105,100,red,(0,)*3)
 else:txt("Bomby Party  ",105,100,(255,)*3,(0,)*3)
 if a%4==2:txt("Asteroid Brawl →",90,120,red,(0,)*3)
 else:txt("Asteroid Brawl  ",90,120,(255,)*3,(0,)*3)
 if a%4==3:txt("Raider 51 →",115,140,red,(0,)*3)
 else:txt("Raider 51  ",115,140,(255,)*3,(0,)*3)
menu()
while(key(4)|key(52)):0
while 1:
 if key(1):a-=1;menu();sleep(.2)
 elif key(2):a+=1;menu();sleep(.2)
 if(key(4)|key(52)):
  if a%4==0:score=laser()
  elif a%4==1:score=bombs()
  elif a%4==2:score=asteroid()
  elif a%4==3:score=raid()
  if score>=1000+500*((a%4==2)or(a%4==3)):txt("You won",125,100,(255,)*3,(0,)*3)
  else:txt("You died",120,100,(255,)*3,(0,)*3)
  txt("Press <OK>",115,118,(255,)*3,(0,)*3)
  while(key(4)|key(52))^1:0
  while(key(4)|key(52)):0
  menu()

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.