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=(40,0,60) F(0,0,SW,SH,bg) #left line F(0,0,2,222,"cyan") #right line F(319,0,2,222,"cyan") #top line F(0,0,322,3,"cyan") #bottom line F(0,219,322,3,"cyan") while not KEY(KEY_OK) and not KEY(KEY_EXE): F(0,35,322,3,"cyan") STR("MAZE ESCAPE",100,10,"white",bg) STR("KEYs [Arrow] = 8 Directions",6,70,"white",bg) STR("KEY [OK] = Slow Motion",20,100,"yellow",bg) STR("KEY [Backspace] = Pause/UnPause",6,130,"gray",bg) STR("KEY [Toolbox] = fire laser",20,170,"green",bg) STR("( Press [OK],[EXE] to Start )",20,200,"white",bg) board="cyan" F(0,0,SW,36,board) p_alive=True move=True bg=(R(0,H),R(0,H),R(0,H)) world=1 score=0 bonus_points=0 plife=3 px=2 py=180 pw=7 ph=6 ptravel=0 #leave this rect_x=300 rect_y=0 rect_size=0 laser_w=10 clock=R(2,5) clock2=9 #player set_pixel(px,py,"blue") #rects set_pixel(rect_x,rect_y,"black") p=(px,py,pw,ph,"blue") #generate new_world def new_world(): global bg,clock,fuel_x,fuel_y fuel_x=R(5,300) fuel_y=R(40,200) ammo_x=R(5,300) ammo_y=R(40,200) F(0,39,322,222,(50,20,70)) sleep(0.2) while not keydown(KEY_OK): STR("Maze Escaped!",100,80,"cyan",(50,20,70)) STR("( Press [OK] to continue )",50,140,"white",(50,20,70)) F(0,60,322,2,"red") F(0,180,322,2,"red") 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) #this may be width of parallel rects F(i,j,randint(4,7),randint(9,25),"black") clock+=1 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") ammo_amount=3 ammo_x=R(5,300) ammo_y=R(40,200) ammo_w=5 ammo_h=8 ammo_c="red" fuel_clock=0 fuel_x=R(5,300) fuel_y=R(40,200) fuel_w=6 fuel_h=6 fuel_c="white" #main loop while p_alive: clock+=1 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("Ammo:"+str(round(ammo_amount)),240,2,(0,0,80),board) F(0,36,322,3,"black") F(0,219,322,3,"black") if not KEY(LEFT): clock2-=0.01 #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(px,py,1,ph,"cyan") F(px+pw-1,py,1,ph,"cyan") F(px,py,pw,1,"cyan") F(px,py+ph-1,pw,1,"cyan") 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 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 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 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 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 #/////////////////////////// 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=2 py=180 #clock fr rect amount clock=R(1,3) world+=1 new_world() clock2=9 if clock2<1: clock2=9 # amount of rects are # added based # on clock value # the higher the range in # clock (below), the less # rects are added. clock=R(6,17) F(px,py,pw,ph,"red") sleep(0.4) F(px,py,pw,ph,bg) sleep(0.4) if plife<=0: p_alive=False F(px,py,pw,ph,"red") F(px+3,py+1,5,3,(R(0,H),R(0,H),R(0,H))) #fuel box F(fuel_x,fuel_y,fuel_w,fuel_h,fuel_c) #outline just for looks F(fuel_x,fuel_y,1,fuel_h,"blue") F(fuel_x+fuel_w-1,fuel_y,1,fuel_h,"blue") F(fuel_x,fuel_y,fuel_w,1,"blue") F(fuel_x,fuel_y+fuel_h-1,fuel_w,1,"blue") #ammo box F(ammo_x,ammo_y,ammo_w,ammo_h,ammo_c) #outline just for looks F(ammo_x,ammo_y,1,ammo_h,"blue") F(ammo_x+ammo_w-1,ammo_y,1,ammo_h,"blue") F(ammo_x,ammo_y,ammo_w,1,"blue") F(ammo_x,ammo_y+ammo_h-1,ammo_w,1,"blue") #player gets ammo if px+pw>=ammo_x and px<=ammo_x+ammo_w and py+ph>=ammo_y and py<=ammo_y+ammo_h: F(ammo_x,ammo_y,ammo_w,ammo_h,bg) sleep(0.4) F(px,py,pw,ph,"purple") ammo_x=R(5,300) ammo_y=R(40,200) ammo_amount+=7 if ammo_amount>20: ammo_amount=20 #player gets energy if px+pw>=fuel_x and px<=fuel_x+fuel_w and py+ph>=fuel_y and py<=fuel_y+fuel_h: F(fuel_x,fuel_y,fuel_w,fuel_h,bg) sleep(0.4) F(px,py,pw,ph,"cyan") fuel_x=R(5,300) fuel_y=R(40,200) plife+=1 if keydown(KEY_TOOLBOX): ammo_amount-=0.6 F(220,2,95,22,"cyan") if ammo_amount<0: ammo_amount=0 if ammo_amount>0: F(px+pw+5,py+1,32,2,choice(["white","cyan"])) sleep(0.03) F(px+pw+5,py+1,32,2,bg) F(px,py,pw,ph,"red") sleep(2) #game over sx=450 F(0,0,322,222,(0,0,0)) draw_string("Written by: Wilson",11,7,"white","black") while plife<0 and not keydown(KEY_OK): F(0,1,322,5,"cyan") F(0,217,322,5,"cyan") F(0,0,5,222,"cyan") F(316,0,5,222,"cyan") sleep(0.05) sx-=8 if sx<170: sx=170 draw_string("GAME OVER",100,80,(randint(100,255),0,randint(0,55)),"black") draw_string("SCORE:",100,120,"orange","black") draw_string(str(score)+" ",sx,120,"cyan","black") if world>1: draw_string("Worlds Survived: "+str(world-1),60,160,"gray","black") else: draw_string("Worlds Survived: "+str(0),60,160,"gray","black") draw_string("You need more practice",40,190,"white","black")