a_void.py

Created by squarepoint

Created on November 29, 2022

5.93 KB

Move you square and avoid everything! The last level isn’t done yet.


from math import sin,cos,pi
from kandinsky import *
from ion import *
from time import sleep
from random import randint
black=color(0,0,0)
white=color(255,255,255)
blue=color(200,230,255)
red=color(255,0,0)
gray=color(150,150,150)
def laser(black,white,blue,red):
  x=155
  y=105
  objects=[]
  objects2=[]
  score=0
  while True:
    if score%25==0: a=randint(1,4)
    else: a=0
    if a==1: objects.append([315,randint(y-20,y+20),1])
    elif a==2: objects.append([0,randint(y-20,y+20),2])
    elif a==3: objects.append([randint(x-20,x+20),217,3])
    elif a==4: objects.append([randint(x-20,x+20),0,4])
    objects2=[]
    for i in range(len(objects)):
      if objects[i][2]==1:
        if objects[i][0]<=0: a=2
        else: a=1
        objects2.append([objects[i][0]-5,objects[i][1],a])
      elif objects[i][2]==2:
        if objects[i][0]>=310: a=1
        else: a=2
        objects2.append([objects[i][0]+5,objects[i][1],a])
      elif objects[i][2]==3:
        if objects[i][1]<=0: a=4
        else: a=3
        objects2.append([objects[i][0],objects[i][1]-5,a])
      else:
        if objects[i][1]>=210: a=3
        else: a=4
        objects2.append([objects[i][0],objects[i][1]+5,a]) 
    objects=objects2
    x,y,score=move(x,y,score)
    for i in range(len(objects)):
      fill_rect(objects[i][0],objects[i][1],5,5,red)
    x,y,score,a=collide(x,y,score)
    if a==1:
      return score
def bombs(black,white,blue,red,gray):
  x=155
  y=105
  objects=[]
  objects2=[]
  score=0
  while True:
    if score%50==0:
      objects.append([randint(0,310),0,2,0])
    if score%25==0:
      objects.append([randint(0,310),0,1,0])
    objects2=[]
    for i in range(len(objects)):
      if objects[i][2]==1 or objects[i][2]==2:
        if randint(1,40)==1 or objects[i][1]>=200 or objects[i][3]>0:
          if objects[i][2]==1:
            for j in range(12):
              objects2.append([objects[i][0],objects[i][1],0,30*j,0])
            fill_rect(objects[i][0]-25,objects[i][1]-25,50,50,color(255,180,50))
          elif objects[i][3]<24:
            objects2.append([objects[i][0],objects[i][1],objects[i][2],objects[i][3]+1])
            objects2.append([objects[i][0],objects[i][1],0,25*objects[i][3],0])
        else:
          objects2.append([objects[i][0],objects[i][1]+5,objects[i][2],objects[i][3]])
      elif objects[i][4]<=30:
        objects2.append([objects[i][0]+int((cos((2*pi*objects[i][3])/360))*7),objects[i][1]+int((sin((2*pi*objects[i][3])/360))*7),0,objects[i][3],objects[i][4]+1])
    objects=objects2
    x,y,score=move(x,y,score)
    for i in range(len(objects)):
      if objects[i][2]==0:
        fill_rect(objects[i][0],objects[i][1],5,5,gray)
      elif objects[i][2]==1:
        fill_rect(objects[i][0],objects[i][1],10,10,color(0,255,0))
      elif objects[i][2]==2:
        fill_rect(objects[i][0],objects[i][1],10,10,color(255,255,0))
    x,y,score,a=collide(x,y,score)
    if a==1:
      return score
def asteroid(black,white,blue,red,gray):
  x=155
  y=105
  objects=[]
  objects2=[]
  score=0
  while True:
    if score%50==0:
      objects.append([300,randint(0,202),2,randint(0,360),0])
    objects2=[]
    for i in range(len(objects)):
      if objects[i][0]<=0:
        filler=filler
      elif objects[i][0]>=315:
        filler=filler
      elif objects[i][1]<=0:
        filler=filler
      elif objects[i][1]>=217:
        filler=filler
      if objects[i][4]<=20:
        objects2.append([objects[i][0]+int((cos((2*pi*objects[i][3])/360))*7),objects[i][1]+int((sin((2*pi*objects[i][3])/360))*7),objects[i][2],objects[i][3],objects[i][4]+1])
      elif objects[i][2]!=0:
          objects2.append([objects[i][0],objects[i][1],objects[i][2]-1,objects[i][3],0])
          objects2.append([objects[i][0],objects[i][1],objects[i][2]-1,objects[i][3]+180,0])
    objects=objects2
    x,y,score=move(x,y,score)
    for i in range(len(objects)):
      if objects[i][2]==0:
        fill_rect(objects[i][0],objects[i][1],5,5,gray)
      elif objects[i][2]==1:
        fill_rect(objects[i][0],objects[i][1],10,10,gray)
      elif objects[i][2]==2:
        fill_rect(objects[i][0],objects[i][1],20,20,gray) 
    x,y,score,a=collide(x,y,score)
    if a==1:
      return score
def raid(black,white,blue,red):
  a=1
def collide(x,y,score):
  a=0
  for i in range(10):
    if score>=1000 or get_pixel(x+i,y-1)==red or get_pixel(x+i,y-1)==gray or get_pixel(x+i,y+11)==red or get_pixel(x+i,y+11)==gray or get_pixel(x-1,y+i)==red or get_pixel(x-1,y+i)==gray or get_pixel(x+11,y+i)==red or get_pixel(x+11,y+i)==gray:
      a=1
  return x,y,score,a
def move(x,y,score):
  if keydown(KEY_LEFT)and x>0: x-=5
  elif keydown(KEY_RIGHT)and x<310: x+=5
  if keydown(KEY_UP)and y>0: y-=5
  elif keydown(KEY_DOWN)and y<212: y+=5
  sleep(0.05)
  fill_rect(0,0,320,222,black)
  score+=1
  draw_string("Score: "+str(score),0,0,white,black)
  fill_rect(x,y,10,10,blue)
  return x,y,score
a=0
while True:
  fill_rect(0,0,320,225,color(0,0,0))
  draw_string("a-VOID",130,20,white,black)
  if a%4==0: draw_string("Bouncy Laser →",100,80,red,black)
  else: draw_string("Bouncy Laser",100,80,white,black)
  if a%4==1: draw_string("Bomby Party →",105,100,red,black)
  else: draw_string("Bomby Party",105,100,white,black)
  if a%4==2: draw_string("Asteroid Brawl →",90,120,red,black)
  else: draw_string("Asteroid Brawl",90,120,white,black)
  if a%4==3: draw_string("Raider 51 →",115,140,red,black)
  else: draw_string("Raider 51",115,140,white,black)
  if keydown(KEY_UP):
    a-=1
    sleep(0.1)
  elif keydown(KEY_DOWN):
    a+=1
    sleep(0.1)
  if keydown(KEY_OK):
    if a%4==0:
      score=laser(black,white,blue,red)
    elif a%4==1:
      score=bombs(black,white,blue,red,gray)
    elif a%4==2:
      score=asteroid(black,white,blue,red,gray)
    elif a%4==3:
      score=raid(black,white,blue,red)
    if score>=1000:
      draw_string("You won",125,100,white,black)
    else:
      draw_string("You died",120,100,white,black)
    draw_string("Press <OK>",115,118,white,black)
    while not keydown(KEY_OK): sleep(0.1)
  sleep(0.1)

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.