game_x_v2.py

Created by wperez274

Created on January 29, 2022

5.54 KB


# BY:
#  WILSON  
from math import *
from kandinsky import *
from kandinsky import fill_rect as FILL
from kandinsky import draw_string as STR

from random import *
from ion import *
from time import *

bg=(0,0,0)
FILL(0,0,322,222,bg)


#home menu
FILL(0,10,322,5,"orange")
FILL(0,60,322,5,"orange")
FILL(0,180,322,3,"white")  
while not keydown(KEY_OK):
  STR("GAME X Reloaded",80,30,"white",bg)
  STR("Key [OK] = SHOOT",50,80,"orange","black")
  STR("Key [Backspace] = Pause/Unpause",2,110,"green",bg)
  STR("Use [ARROWS] to Avoid Rects",15,140,"cyan",bg)
  
  sleep(0.1)
  STR("( Press [OK] to START )",25,190,"white",bg)

#beginning
game=True
#speed of oncoming rectangles
rectspeed=0.5
#slow speed
G=1*10**-2
#medium speed
G2=1*10**-3
#fast speed
G3=1*10**-8

#background
bg=(randint(0,50),randint(0,50),randint(0,50))

back_x=0
back_y=0

# player
pe=40
px=40
py=round(222/2)
ps=0
pc="cyan"
pw=12
ph=5

fire=False

ammo_timer=0
ammo_x=randint(600,900)
ammo_y=randint(20,200)
ammo_w=6
ammo_h=6
ammo_c=(randint(180,255),randint(180,255),randint(180,255))

bullets=35

bx=px
by=py+2
bw=8
bh=5
bc="red"

rect_x=back_x+randint(160,300)
rect_y=back_y+randint(80,200)
rect_w=randint(20,200)
rect_h=randint(20,200)
#just a tuple used for 
#randomizing medium to light 
#colors.
R=(randint(50,200),randint(50,200),randint(50,250))

#rectangle color
rect_c=(randint(50,200),randint(50,200),randint(50,250))

#screen 
FILL(back_x,back_y,500,222,bg)
#screen color
FILL(0,0,322,222,bg)
#rectangle location, abstract think.   
x=y=[10,30,60,90,120,150,180,
210,240,270,300]

#not sure if i need this
rw=randint(20,70)
#not sure why this
for i in x:
    FILL(back_x+i,back_y,randint(40,60),randint(0,100),R)

# MAIN GAME LOOP
#pe is player energy
while pe > 0:
  
  FILL(ammo_x,ammo_y,ammo_w,ammo_h,ammo_c)
  
  FILL(px,py,pw,ph,pc)
  FILL(px,py,3,2,(0,0,80))
  
  
  FILL(rect_x,rect_y,rect_w,rect_h,rect_c)

  STR("SCORE:"+str(int(ps)),90,0,"white",R)  
  STR("E:"+str(int(pe)),2,0,"cyan",R)  
  

  
  if keydown(KEY_LEFT):
    FILL(px+pw,py,1,ph,bg)
    px-=1
    FILL(rect_x,rect_y,1,rect_h,bg)

    #dont put this in the 
    #main loop because then 
    #the rect will not be able
    #to push player back less 
    #than 20
    if px<10:
      px=20
 
    
  if px+9<0:
    px=321
  if keydown(KEY_RIGHT):
    FILL(px-1,py,1,ph,bg)
    px+=1
  if px>60:
    px=60
 
    FILL(px-1,py,1,18,bg)
    
    FILL(rect_x+rect_w,rect_y,2,rect_h,bg)
  if px-9>321:
    px=0

  if keydown(KEY_UP):
    

    FILL(px,py+18,10,1,bg)
    rect_y+=1
    FILL(rect_x,rect_y-1,rect_w,1,bg)
  if keydown(KEY_DOWN):
    
#    py+=1
    FILL(px,py-1,10,1,bg)
    rect_y-=1
    FILL(rect_x,rect_y+rect_h,rect_w,1,bg)
   
  if py<-18:
    py=222
  if py>222:
    py=0
  

  FILL(rect_x+rect_w,rect_y,2,rect_h,bg)
  
  if rect_x+rect_w < -randint(10,40):
    pc=(randint(100,255),randint(100,255),randint(100,255))

    FILL(0,0,322,222,bg)
    bg=(randint(0,50),randint(0,50),randint(0,50))

    pe+=2
    ps+=randint(5,25)
    rect_x=back_x+randint(180,300)
    rect_y=randint(-10,190)
    rect_w=randint(10,200)
    rect_h=randint(10,200)
    rect_c=(randint(100,250),randint(100,250),randint(100,250))
    
    x=y=[10,30,60,90,120,150,180,
    210,240,270,300]
    rw=randint(20,70)
    
    FILL(0,0,322,222,bg)
    

    R=(randint(50,200),randint(50,200),randint(50,250))

    for i in x:
      FILL(back_x+i,back_y,randint(40,60),randint(0,100),R)
      
#player collision
#player gets hit and losses 
#energy
  if px+pw >= rect_x and px <= rect_x+rect_w and py+ph >= rect_y and py <= rect_y+rect_h:
    FILL(px,py,pw,ph,"red")
    pe-=0.5
    px-=1
  if px<0:
    px=40
    py=round(222/2)

  # rects gets shot
  if keydown(KEY_OK) and fire==True and py >= rect_y and py+ph <= rect_y+rect_h:
    FILL(px,py,pw,ph,"green")
    pe+=1
    ps+=randint(10,20)
    fill_rect(rect_x,rect_y,rect_w,rect_h,"red")
    fill_rect(rect_x,rect_y,rect_w,rect_h,bg)
    
    for i in range(randint(5,20)):
      for j in range(randint(5,20)):
        i=rect_x+randint(0,rect_w)
        j=rect_y+randint(0,rect_h)
        FILL(i,j,randint(2,5),randint(2,5),choice([rect_c,bg]))

    rect_x=randint(322,500)
    rect_y=randint(20,200)
    rect_c=(randint(50,200),randint(50,200),randint(50,250))
    rect_w=randint(20,200)
    rect_h=randint(20,200)

    
  
  if keydown(KEY_BACKSPACE):
    STR("( PAUSED )",110,100,"white",bg)
    while keydown(KEY_BACKSPACE):
      pass
    while not keydown(KEY_BACKSPACE):
      pass
    while keydown(KEY_BACKSPACE):
      STR("          ",110,100,bg,bg)
  #time acceleration
  accel=2*10**-4
  
  rectspeed+=accel
  for i in range(rectspeed):
    rect_x-=1
    
  if bullets>0:
    fire=True
  else:
    fire=False  
    
  if keydown(KEY_OK) and bullets>0:
    bullets-=0.2
    
    fill_rect(px+3,py,322,5,"cyan")
    fill_rect(px+3,py,322,5,bg)
    
   
   #player gets more ammo
  if px+pw >= ammo_x and px <= ammo_x+ammo_w and py+ph >= ammo_y and py <= ammo_y+ammo_h:
    pe+=2
    bullets+=40
    FILL(ammo_x,ammo_y,ammo_w,ammo_h,bg)
    ammo_x=randint(2000,5000)
    ammo_y=randint(20,200)
    FILL(px,py,pw,ph,(80,0,0))
    
    
    
  FILL(ammo_x,ammo_y,ammo_w,ammo_h,bg)
  ammo_x-=1
  
  #ammo package gravitates
  #to player
  if ammo_y<py:
    ammo_y+=1
  if ammo_y>py:
    ammo_y-=1 
     
  STR("Ammo:"+str(bullets),250,0,"white",R)      
        
#game over    
for i in range(100):
    for j in range(90):
      i=randint(0,321)
      j=randint(0,222)
      FILL(i,j,randint(3,9),randint(3,9),(choice([100,150,200]),0,randint(0,50)))
  
STR("GAME OVER",100,90,(255,)*3,(0,)*3)      
STR("SCORE: "+str(ps),100,120,"cyan",(0,)*3)

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.