maze_escape_v4.py

Created by wperez274

Created on August 20, 2022

5.34 KB


from math import *
from kandinsky import *
from kandinsky import fill_rect as F
from kandinsky import draw_string as STR
from ion import *
from ion import keydown as KEY
from ion import KEY_LEFT as LEFT
from ion import KEY_RIGHT as RIGHT
from ion import KEY_UP as UP
from ion import KEY_DOWN as DOWN
from random import *
from random import randint as R
from time import *
H=255
SW=321
SH=222

bg=(0,0,0)
F(0,0,SW,SH,bg)

while not KEY(KEY_OK):
    STR("MAZE ESCAPE",100,10,(R(0,H),R(0,H),R(0,H)),bg)
    STR("KEYs [Arrow] = 8 Directions",6,70,"white",bg)
    STR("KEY [OK] = Slow Motion",6,100,"green",bg)
    STR("KEY [Backspace] = Pause/UnPause",6,130,"gray",bg)
    STR("( Press OK to Start )",40,200,(0,R(100,H),R(100,H)),bg)

board="orange"
F(0,0,SW,36,board)
p_alive=True
move=True
bg=(R(10,H),R(10,H),R(10,H))
world=1
score=0
bonus_points=0
plife=3
px=4
py=200
pw=8
ph=5 
ptravel=0
#leave this 
rect_x=300
rect_y=0
rect_size=0
laser_w=10
clock=0
clock2=9
#player
set_pixel(px,py,"blue")
set_pixel(rect_x,rect_y,"black")
p=(px,py,pw,ph,"blue")

def restart():
  global px,py,pw,ph,bg,plife
  plife-=1
  F(px,py,pw,ph,bg)
  px=3
  py=200
  
  while not KEY(KEY_OK):
    STR("Press [ok]",100,15)
  STR("          ",100,15,"white","white")
  
#generate new_world  
def new_world():
  global clock,bg,world,bonus_points,score
  F(0,39,322,222,"black")
  while bonus_points<=R(100,500):
    sleep(0.03)
    bonus_points+=1
    STR("World:"+str(world),100,80,"cyan","black")
    STR("Score: "+str(score),100,120,"orange","black")
    score+=1    
    
    F(0,50,322,3,"cyan")
    F(0,170,322,3,"cyan")
    
    
  bonus_points=0
        
  bg=(R(10,H),R(10,H),R(10,H))
  
  F(0,38,322,200,bg)
  F(317,38,3,222,"blue")    

  for i in range(10):
    for j in range(6):
      i=R(10,300)
      j=R(35,222)
      F(i,j,randint(3,8),randint(5,12),"black")
  
  clock+=1
  
  if clock>=0 and clock<=27:
#horizontal rect
    F(R(20,280),R(38,218),R(20,60),20,"black")
#parallel rect
    F(R(20,310),R(35,180),20,R(20,65),"black")
F(0,0,322,2,"black")
F(0,38,322,200,bg)
F(317,38,3,222,(R(0,H),R(0,H),R(0,H)))
for i in range(10):
    for j in range(6):
      i=R(10,300)
      j=R(35,222)
      F(i,j,randint(3,8),randint(5,12),"black")

while p_alive:
  F(317,38,3,222,(R(0,H),R(0,H),R(0,H)))

  pw=8
  ph=5 
  set_pixel(px,py,"blue")
  STR("World:"+str(world),120,2,"black",board)
  STR("life "+"\u2248 "+str(round(plife)),4,2,(0,0,100),board)
  STR("time:"+str(int(clock2)),240,2,"white",board)
  
  F(0,36,322,3,"black") 
  F(0,219,322,3,"black") 
  
  if not KEY(LEFT):
    clock2-=0.01

  clock+=1
#laser amount depends on clock
  if clock>=0 and clock<=22:
#horizontal rect
    F(R(20,280),R(38,218),R(20,60),5,"black")
#parallel rect
    F(R(20,310),R(35,180),8,R(20,65),"black")

  F(px,py,pw,ph,"blue")
  F(rect_x,rect_y,rect_size,rect_size,"black")
  
  if KEY(LEFT) and move:
    sleep(0.001)
    score+=R(0,1)
    px-=1
    F(px+pw+1,py,1,ph,bg)
    plife-=0.0001
    clock2=9
    if px>1:
      ptravel+=1
  if px<1:px=1
  
  if KEY(KEY_RIGHT) and move:
    sleep(0.001)
    score+=R(0,1)
    px+=1
    F(px-1,py,1,ph,bg)
    plife-=0.0001
    clock2=9
    if px+pw<321:
      ptravel+=1
  if KEY(KEY_UP) and move:
    sleep(0.001)
    score+=R(0,1)
    py-=1
    F(px,py+ph+1,pw,1,bg)
    plife-=0.0001
    clock2=9
    if py>37:
      ptravel+=1
  if py<38:py=38
  
  if KEY(KEY_DOWN) and move:
    sleep(0.001)
    score+=R(0,1)
    py+=1
    F(px,py-1,pw,1,bg)
    plife-=0.0001
    clock2=9
    if py+ph<222:
      ptravel+=1
  if py+ph>222:
    py=222-ph
  
# player loses energy and restarts
  if get_pixel(px,py)==get_pixel(rect_x,rect_y):
    F(px,py,pw,ph,"red")
    plife-=0.08
    move=False
    sleep(0.1)
    move=True
    #restart()
  if get_pixel(px,py+ph)==get_pixel(rect_x,rect_y) and keydown(KEY_LEFT):
    F(px,py,pw,ph,"red")
    plife-=0.03
    move=False
    sleep(0.1)
    move=True
    #restart()  
  if get_pixel(px+pw,py)==get_pixel(rect_x,rect_y):
    F(px,py,pw,ph,"red")
    plife-=0.03
    move=False
    sleep(0.1)
    move=True
    #restart()
  if get_pixel(px+pw,py+ph)==get_pixel(rect_x,rect_y):
    F(px,py,pw,ph,"red")
    plife-=0.05
    move=False
    sleep(0.1)
    move=True
    #restart()
#player touches laser  
  if get_pixel(px+pw,py)==get_pixel(rect_x+5,rect_y):
    F(px,py,pw,ph,"red")
    move=False
    sleep(0.1)
    move=True
    #restart()
      
    
  if KEY(KEY_OK):
    move=True
    sleep(0.05)
    STR("(slow motion)",2,17,"black",board)
  else:
    STR("             ",2,17,board,board)
      
    
  if KEY(KEY_BACKSPACE):
    STR("(PAUSED)",70,17,"black",board)
    while KEY(KEY_BACKSPACE):
      pass
    while not KEY(KEY_BACKSPACE):
      pass
    while KEY(KEY_BACKSPACE):
      STR("        ",70,17,board,board)
      pass
    
  if px+pw>318:
    plife+=1
    px=4
    py=200
    clock=0
    world+=1
    new_world()
    clock2=9
  
  if clock2<1:
    px=4
    py=200
    clock=0
    new_world()
    score-=500
    
    clock2=9
    plife-=1

  if plife<1:
    p_alive=False

    
  if KEY(KEY_TOOLBOX):
    sleep(0.05)
    F(px,py,pw,ph,bg)
    pw=4
    ph=7
  else:
    pw=7
    ph=4


  F(px+3,py+1,5,3,(R(0,H),R(0,H),R(0,H)))    
  
sleep(1)
F(0,0,322,222,(0,0,0))

sleep(0.8)  
STR("GAME OVER",100,70,(255,0,0),(0,0,0))      
sleep(1.5)
STR("Pixels Traveled: "+str(ptravel),45,120,"gray",(0,0,0))  
sleep(2)
STR("Score: "+str(ptravel),100,170,"orange",(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.