gamex.py

Created by wperez274

Created on December 29, 2021

3.88 KB

adigital frontier


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 *

FILL(0,0,322,222,"black")

#home menu
while not keydown(KEY_OK):
  STR("≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈",0,40,"cyan","black")
  STR("GAME X",100,80,"cyan","blue")
  STR("≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈",0,120,"cyan","black")
  STR("Key [Backspack] = Pause/Unpause",2,160)
  sleep(0.1)
  STR("( Press [OK] to START )",25,190)

#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=10
ph=4

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,500000,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(px,py,pw,ph,pc)
  FILL(rect_x,rect_y,rect_w,rect_h,rect_c)
  STR("Energy:"+str(int(pe)),0,0,"red","white")  
  STR("SCORE:"+str(int(ps)),110,0)  
  STR("Speed:"+str(int(rectspeed)),225,0,"blue","white")

  
  if keydown(KEY_LEFT):
    FILL(px+pw,py,1,ph,bg)
    px-=1
    FILL(rect_x-2,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):
    
#    py-=1
    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<0:
    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)

  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)
  #acceleration
  accel=0.0002
  
  rectspeed+=accel
  for i in range(rectspeed):
    rect_x-=1
        
#game over    
for i in range(150):
    for j in range(110):
      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.