gamey.py

Created by wperez274

Created on February 17, 2022

3.27 KB

Avoid crashing into rectangular objects. key [OK] = Start Game key [Backspace} = Pause

good luck.

Sincerely,

Wilson


from math import *
from kandinsky import *
from random import *
from ion import *
from time import *

detected=False

fill_rect(0,0,322,222,(6,155,255))
clock=0
while not keydown(KEY_OK):
  clock+=0.40
  
  if clock<1:
    for i in range(20):
      for j in range(20):
      
        i=randint(0,321)
        j=randint(0,20)
        k=randint(0,321)
        l=randint(150,222)
        fill_rect(i,j,randint(20,50),randint(20,70),choice(["cyan","black"]))
        fill_rect(k,l,randint(20,50),randint(20,70),choice(["cyan","black"]))


      

    draw_string("GAME Y",120,110,"black","white")




x=y=[10,30,60,90,120,150,180,
210,240,270,300]

#rect speed
e_accel=0
ex=randint(275,322)
ey=randint(24,200)

ew=randint(10,80)
eh=randint(10,80)

ec=(randint(150,255),randint(150,255),randint(150,255))

r=0
g=0
b=100

bg=(0,0,0)

clock1=0
dark_r=(100,0,0)

R1=(randint(0,100),randint(0,100),randint(0,100))
R2=(randint(140,255),randint(140,255),randint(140,255))
R3=(randint(50,255),randint(50,255),randint(50,255))
R4=choice(["pink","cyan","gray","white","yellow","orange",(100,0,0),(6,155,255),(0,0,150),"gray"])



k=0

energy=50
score=0
px=20
py=120

pw=5+12+10
ph=py-(12+8+5)

# player shuttle
rects=[(10,py,5,-12,"cyan"),
(15,py,12,-8,"gray"),
(25,py,10,-5,"green")
]

fill_rect(0,0,322,222,bg)
fill_rect(0,22,322,2,"gray")

x=y=[10,30,60,90,120,150,180,
210,240,270,300]

for i in x:
  fill_rect(i,0,randint(40,60),randint(0,100),R2)

while energy>=0:
# Of corse, you can use
# e_accel+=3*10**-4
  e_accel+=0.0003
  
  draw_string("SCORE:"+str(score),228,2,"blue",R2)  
  fill_rect(ex,ey,ew,eh,ec)
  fill_rect(ex+ew,ey,2,eh,bg)
  draw_string("Health:",2,2,"cyan","black")
  fill_rect(0,22,322,2,"gray")

  if e_accel>4:
    e_accel=4
    
  for i in range(e_accel):
    ex-=1

  if ex<-100-ew:
    score+=5
    fill_rect(0,0,322,222,bg)

    x=y=[10,30,60,90,120,150,180,
    210,240,270,300]
    
    R2=(randint(140,255),randint(140,255),randint(140,255))

    for i in x:
      fill_rect(i,0,randint(40,60),randint(0,100),R2)

    ec=(randint(50,255),randint(50,255),randint(50,255))
    ex=randint(100,340)
    ey=randint(10,155)
    ew=randint(20,160)
    eh=randint(20,200)
    energy+=2
  
  
  
  
    
  fill_rect(ex,ey,ew,eh,ec)
  fill_rect(ex+ew,ey,2,eh,bg)
  draw_string("Health:",2,2,"white",bg)
# health bar
  for i in range(5,energy,8):
    fill_rect(70+i,5,6,12,"red")

  for i in rects:
    fill_rect(*i)
    
     
  if keydown(KEY_UP):
    ey+=1
    fill_rect(ex,ey-1,ew,1,bg)
  
  if keydown(KEY_DOWN):
    ey-=1
    fill_rect(ex,ey+eh,ew,1,bg)
  
  if px+17 >= ex and px+17 <=ex+ew and py-5 >= ey and py <= ey+eh:
    fill_rect(px+5,py-5,10,5,"red")
    energy-=0.1
    fill_rect(70+int(energy),5,int(energy),12,R2)
  
  if keydown(KEY_BACKSPACE):
    draw_string("(PAUSED)",110,100,"white",bg)
    while keydown(KEY_BACKSPACE):
      pass
    while not keydown(KEY_BACKSPACE):
      pass
    while keydown(KEY_BACKSPACE):
      draw_string("        ",110,100,bg,bg)
      pass


    
    
    
  if energy>180:
    energy=180
  
  
for i in range(100):
  for j in range(100):
    i=randint(0,321)
    j=randint(0,222)
    fill_rect(i,j,randint(5,20),randint(5,20),(randint(50,150),0,randint(0,50)))

draw_string("GAME OVER",100,100,"white",(0,0,0))
draw_string("SCORE:"+str(score),100,140,"cyan",(0,0,0))

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.