random_land.py

Created by wperez274

Created on January 12, 2022

1.65 KB

Game potential.


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

game=True

x=[0,10,20,30,40,60,80,90,100,
110,120,130,140,150,160,170,
180,190,200,210,220,230,240,250,
260,270,280,290,300,310,320
]

colors=[
'blue',
'red',
'green',
'yellow',
'white',
'brown',
'pink',
'orange',
'purple',
'gray'

]







speed=0.005
bg="white"
pscore=0
penergy=40

px=10
py=140
pw=10
ph=4
pc="blue"

def pause():
  draw_string("(PAUSED)",110,30,"white","black")
  while keydown(KEY_BACKSPACE):
    pass
  while not keydown(KEY_BACKSPACE):
    pass
  while keydown(KEY_BACKSPACE):
    draw_string("        ",110,30,"black","black")
    pass

def up():
  global px,py,pw,ph,bg
  py-=1
  fill_rect(px,py+ph,pw,1,bg)
  sleep(0.005)
  if py<1:py=1
def down():
  global px,py,pw,ph,bg
  py+=1
  fill_rect(px,py-1,pw,1,bg)
  sleep(0.005)
  if py+ph>222:py=222-ph


 
rect_x=0
rect_y=0

rect_w_,rect_h=randint(12,25),randint(-30,-2)

rect_c1="black"
rect_c2="blue"


def random_land():
  global w,h
  for i in x:
    fill_rect(i,0,randint(20,30),randint(60,120),"black")
    fill_rect(i,222,randint(20,30),randint(-100,-30),"black")
    

    
  
for i in x:
    fill_rect(i,0,20,randint(40,110),"black")
    fill_rect(i,222,20,randint(-90,-10),"black")
    
while game:
  sleep(speed)
  px+=1
  fill_rect(px-1,py,1,ph,"white")
  if keydown(KEY_UP):
    up()
  if keydown(KEY_DOWN):
    down()
    
  fill_rect(px,py,pw,ph,pc)
  if px>=322:
    px=0
    fill_rect(0,0,322,222,"white")
    random_land()
    sleep(0.2)
    
  
  if keydown(KEY_BACKSPACE):
    pause()
  if keydown(KEY_OK):
    speed=0.0005
  else:
    speed=0.005

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.