__Planet Z______
================================== key [Arrows Left/Right] = move left / right key [OK] = Pause Resume key [Backspace] = Jump key [Toolbox] = Shoot =====================================
Good luck!
Sincerely,
Wilson
from math import * from random import * from kandinsky import * from ion import * from time import * # this saves space and limited storage from kandinsky import fill_rect as F from random import randint as R from ion import keydown as K # random color range C1=(R(0,255),R(0,255),R(0,255)) C2=(R(0,255),R(0,255),R(0,255)) C3=(R(0,255),R(0,255),R(0,255)) CYAN=(0,255,255) YELLOW=(255,255,0) RED=(255,0,0) DARK_RED=(135,0,0) WHITE=(255,255,255) BLUE=(0,0,255) DARK_BLUE=(0,0,135) MAGENTA=(2550,0,255) BLACK=(0,0,0) GREEN=(0,255,0) DARK_GREEN=(0,125,0) #screen width and height SCR_W=322 SCR_H=222 SCR_A=SCR_W*SCR_H GX=0 GY=R(50,140) GW=R(60,110) GH=300 GC=C1 GX2=R(80,180) GY2=R(90,160) GW2=R(60,100) GH2=300 GC2=C2 GX3=R(200,290) GY3=R(70,190) GW3=R(80,120) GH3=300 GC3=C3 game=True bg=BLACK #player psc=0 pe=9 plife=3 px=GX+10 py=10 pw=10 ph=15 pc=BLUE e_attacks=False e_runs=False e_defeated=False door_open=False e_timer=0 e_chase=False e_dir=R(1,4) #enemys energy e_e=R(100,300) e_x=R(180,280) e_y=R(40,100) e_w=12 e_h=18 e_c=(R(0,100),R(0,100),R(0,100)) #lava lava_x=0 lava_y=200 lava_w=322 lava_h=100 lava_c=RED #player faces left or right facing_left=False facing_right=True facing_up=False door_x=R(100,280) door_y=R(10,80) door_w=15 door_h=20 door_c=(35,20,0) vel=1 xVel=0 jumping=False jumpCount=0 maxJump=30 falling=True def pause(): draw_string("(PAUSED)",110,100,"white",bg) while K(KEY_OK): pass while not K(KEY_OK): pass while K(KEY_OK): draw_string(" ",110,100,bg,bg) pass F(0,0,322,222,bg) F(lava_x,lava_y,lava_w,lava_h,lava_c) #lava below for i in range(0,322): i+=1 lava_y=R(180,200) F(i,lava_y,4,100,choice([RED,DARK_RED])) #ceiling for i in range(0,322): i+=1 F(i,R(0,5),5,R(2,8),choice([DARK_RED,bg])) #main while game: e_timer+=0.1 if e_timer>R(8,10): e_timer=0 e_dir=R(0,4) e_chase=choice([False,True,True]) #enemy chases player if e_chase: if e_x<px: e_dir=2 if e_x>px: e_dir=1 if e_y<py: e_dir=4 if e_y>py: e_dir=3 draw_string("Life:"+str(plife),10,0,CYAN,bg) draw_string("Enemy:",140,0,WHITE,bg) F(205,5,int(e_e/4),12,e_c) if door_open: F(door_x,door_y,door_w,door_h,door_c) F(door_x,door_y+door_h,door_w,2,WHITE) # platforms F(GX,GY,GW,GH,GC) F(GX2,GY2,GW2,GH2,GC2) F(GX3,GY3,GW3,GH3,GC3) F(px,py,pw,ph,pc) F(px+2,py+2,7,5,CYAN) F(e_x,e_y,e_w,e_h,e_c) F(e_x+2,e_y+4,8,4,choice([BLACK,WHITE,DARK_GREEN])) if K(KEY_LEFT): px += -vel F(px+pw,py,1,ph,bg) facing_left=True facing_right=False if K(KEY_RIGHT): px += vel F(px-1,py,1,ph,bg) facing_right=True facing_left=False if K(KEY_BACKSPACE) and jumping==False and falling==False: jumping=True jumpCount=1 if jumping: jumpCount+=1 py-=3 F(px,py+ph+1,pw,3,bg) #leave this in jumping scope if jumpCount==maxJump: jumping=False falling=True elif falling: if py+ph<=GY and py+ph>=GY: falling=False else: falling=True #careful with code here! #Do not add any more else: if px+pw>=GX and px<=GX+GW and py+ph>=GY: falling=False else: falling=True if py+ph>=GY+GH: falling=True if px+pw>=GX2 and px<=GX2+GW2 and py+ph>=GY2: falling=False if py+ph>=GY2+GH2: falling=True if px+pw>=GX3 and px<=GX3+GW3 and py+ph>=GY3: falling=False if py+ph>=GY3+GH3: falling=True if falling: sleep(0.001) py+=vel F(px,py-1,pw,1,bg) if py+ph>=lava_y: sleep(0.3) F(0,0,322,222,bg) F(lava_x,lava_y,lava_w,lava_h,lava_c) for i in range(0,322): i+=1 F(i,R(0,5),5,R(2,8),choice([DARK_RED,bg])) #lava below for i in range(0,322): i+=1 lava_y=R(180,200) F(i,lava_y,4,100,choice([RED,DARK_RED])) px=GX+10 py=GY-20 plife-=1 F(px,py,pw,ph,bg) GX=R(0,10) GY=R(50,140) GW=R(60,110) GH=300 GC=(R(0,255),R(0,255),R(0,255)) GX2=R(80,180) GY2=R(90,160) GW2=R(60,80) GH2=300 GC2=(R(0,255),R(0,255),R(0,255)) GX3=R(180,180) GY3=R(90,160) GW3=R(60,80) GH3=300 GC3=(R(0,255),R(0,255),R(0,255)) door_x=R(150,310) door_y=R(50,150) if px+pw>door_x and px<=door_x+door_w and py+ph>=door_y and py<=door_y+door_h and door_open: bg=(R(0,255),R(0,255),R(0,255)) px=GX+10 py=GY-20 e_e=R(200,400) e_c=(R(0,255),R(0,255),R(0,255)) door_open=False plife+=1 pe=9 psc+=R(100,500) F(0,0,322,222,bg) F(px,py,pw,ph,"gray") F(px,py,pw,ph,bg) # F(lava_x,lava_y,lava_w,lava_h,lava_c) for i in range(0,322): i+=1 F(i,R(0,5),5,R(2,8),choice([DARK_RED,bg])) #lava below for i in range(0,322): i+=1 lava_y=R(180,200) F(i,lava_y,4,100,choice([RED,DARK_RED])) px=GX+10 py=GY-py+ph-2 GX=R(0,10) GY=R(100,200) GW=R(60,110) GH=300 GC=(R(0,255),R(0,255),R(0,255)) GX2=R(80,180) GY2=R(90,160) GW2=R(60,80) GH2=300 GC2=(R(0,255),R(0,255),R(0,255)) GX3=R(200,280) GY3=R(90,160) GW3=R(30,120) GH3=300 GC3=(R(0,255),R(0,255),R(0,255)) door_x=R(200,310) door_y=R(50,180) door_c=(R(0,100),R(0,100),R(0,100)) lava_y=R(180,210) lava_c=(R(80,200),0,0) F(door_x,door_y,door_w,door_h,door_c) if K(KEY_OK): pause() if K(KEY_TOOLBOX) and facing_left: F(0,py+4,px,3,"cyan") F(0,py+4,px,3,bg) if K(KEY_TOOLBOX) and facing_right: F(px+pw,py+4,322-px,3,"cyan") F(px+pw,py+4,322-px,3,bg) if K(KEY_UP): facing_up=True facing_left=False facing_right=False if facing_left: F(px+1,py+7,1,3,WHITE) facing_right=False if facing_right: F(px+pw-3,py+7,1,3,WHITE) facing_left=False #enemy gets shot if K(KEY_TOOLBOX) and facing_left and e_x<=px and py+4>=e_y and py+4<=e_y+e_h: F(e_x,e_y,e_w,e_h,RED) F(205+int(e_e/4),5,2,12,bg) e_e-=0.2 psc+=1 pe+=0.01 if K(KEY_TOOLBOX) and facing_right and e_x>=px and py+4>=e_y and py+4<=e_y+e_h: F(e_x,e_y,e_w,e_h,RED) F(205+int(e_e/4),5,2,12,bg) e_e-=0.2 psc+=1 pe+=0.01 #enemy destroyed if e_e<1: e_e=0 door_y=GY3-door_h-1 door_x=GX3+R(2,8) door_open=True for i in range(5): for j in range(5): i=R(e_x,e_x+e_w) j=R(e_y,e_y+e_h) F(i,j,R(2,5),R(2,5),choice([BLACK,DARK_RED,RED])) door_open=True if door_open: e_attacks=False e_chase=False e_timer=0 e_dir=0 if e_x<1: e_x=1 e_dir=choice([2,3,4]) if e_x+e_w>322: e_x=322-e_w e_dir=choice([1,3,4]) if e_y<10: e_dir=choice([1,2,4]) e_y=10 if e_y+e_h>222: e_y=222-e_h e_dir=choice([1,2,3]) #enemy moves if e_dir==1: e_x-=1 F(e_x+e_w,e_y,1,e_h,bg) if e_dir==2: e_x+=1 F(e_x-1,e_y,1,e_h,bg) if e_dir==3: e_y-=1 F(e_x,e_y+e_h,e_w,1,bg) if e_dir==4: e_y+=1 F(e_x,e_y-1,e_w,1,bg) if e_y+e_h>lava_y: e_y=lava_y-e_h e_dir=choice([1,2,3]) if px<1: px=1 if px+pw>322: px=322-pw if py<5: F(px,py,pw,ph,choice([BLACK,RED])) py=5 pe-=0.2 #player energy loss if px+pw>=e_x and px<=e_x+e_w and py+ph>=e_y and py<=e_y+e_h: F(px,py,pw,ph,RED) pe-=0.1 e_dir=R(1,4) if K(KEY_UP) and K(KEY_TOOLBOX): facing_left=False facing_right=False for i in range(0,py): F(px+4,0,3,i,CYAN) F(px+4,0,3,i,bg) if pe<1: pe=9 plife-=1 if pe>9: pe=1 plife+=1 #game is over when plife < 1 if plife<1: game=False for i in range(100): for j in range(100): i=R(px,px+pw) j=R(py,py+ph) F(i,j,R(2,5),R(2,5),choice([BLACK,DARK_RED,RED])) for i in range(100): for j in range(100): i=R(px,px+pw) j=R(py,py+ph) F(i,j,R(2,5),R(2,5),choice([BLACK,DARK_RED,RED])) draw_string("GAME OVER",100,100,WHITE,bg) draw_string("SCORE:"+str(psc),100,140,CYAN,bg)