Fun Game
key Arrows [Left/Right] = move left/right key [OK] = Pause/Resume key [Backspace] = Jump Key [Toolbox] = Shoot key [Up] = Shoot Laser Upward ——————————————————-
Good luck!
Sincerely,
Wilson ************
from math import * from random import * from kandinsky import * from ion import * from time import * from kandinsky import fill_rect as F from kandinsky import draw_string as STR from random import randint as R from ion import keydown as K #just plug in the RGB Tuples to save space H=255 r=R(0,H) g=R(0,H) b=R(0,H) #random tuple RAND=(R(0,H),R(0,H),R(0,H)) CYAN=(0,H,H) RED=(H,0,0) DARKRED=(135,0,0) DARKGREEN=(0,135,0) WHITE=(H,H,H) BLACK=(0,0,0) GREEN=(0,H,0) BLUE=(0,0,H) SCRW=322 SCRH=222 world_count=0 world=1 game=True bg=(R(0,H),R(0,H),R(0,H)) #player pdir=0 psc=0 pe=9 pl=3 pc=BLUE #enemy ee=R(6,15) edash=False et=0 echase=False edir=0 jump,count,L_jump=False,0,[int(-0.4*(x/4)**2+70) for x in range(-52,52)]+[0] #player the size or width side=17 #player x x=15 #grd height y_floor=R(120,180) eh=R(20,40) ec=(R(0,H),R(0,H),R(0,H)) ex=R(300,400) ey=y_floor-eh ew=R(15,30) y=y_floor-side dr=False drx=280 dry=y_floor-28 drw=22 drh=28 score=0 L_bullets=[] #width and height of bullets w_bullet=8 h_bullet=6 #velocity of bullets v_bullet=4 offset=0 cherbe=(R(0,H),R(0,H),R(0,H)) cgrd1=(R(50,H),R(50,H),R(50,H)) cgrd2=(R(0,H),R(0,H),R(0,H)) #ground ccarre=BLUE def pause(): STR("(PAUSED)",110,40,(R(0,H),R(0,H),R(0,H)),bg) while K(KEY_OK): pass while not K(KEY_OK): pass while K(KEY_OK): STR(" ",110,40,bg,bg) pass F(0,0,322,222,bg) #grd random pattern grass ccarre=BLACK #right Direction=1 shoot=True #main loop F(0,y_floor,322,80,BLACK) #ceiling for i in range(0,322): i+=1 fill_rect(i,randint(20,25),randint(2,5),randint(5,15),choice([(125,0,0),(0,0,0),"red"])) fill_rect(i,randint(16,20),randint(5,15),randint(5,25),choice([(125,0,0),(0,0,0),"red"])) while game: F(x,y,side,side,pc) et+=0.1 STR("Lives:"+str(round(pl)),4,0,CYAN,bg) STR("World:"+str(world),105,0,BLACK,bg) STR("Score:"+str(psc),210,0,WHITE,bg) F(ex,ey,ew,eh,ec) #enemy moves if edir==1: ex-=1 F(ex+ew,ey,1,eh,bg) if edir==2: ex+=1 F(ex-1,ey,1,eh,bg) if edir==3: ey-=1 F(ex,ey+eh,ew,1,bg) if edir==4: ey+=1 F(ex,ey-1,ew,1,bg) if ey+eh>y_floor: ey=y_floor-eh #player energy loss if x+side>=ex and x<=ex+ew and y+side>=ey and y<=ey+eh: F(x,y,side,side,RED) F(0,0,322,20,bg) sleep(0.001) pe-=0.3 if pl<2: F(x,y,side,side,bg) if pe<1: pe=9 pl-=1 F(0,0,322,20,bg) if pe>9: pe=1 pl+=1 F(0,0,322,20,bg) #game is over when plife < 1 if pl<1: game=False for i in range(100): for j in range(100): i=R(x,x+side) j=R(y,y+side) F(i,j,R(2,5),R(2,5),choice([BLACK,DARKRED,RED])) if K(KEY_OK): pause() precedent_y=y if K(KEY_LEFT): pdir=1 Direction=-1 if x>0: F(x+side-2,y,2,side,bg) x-=2 elif K(KEY_RIGHT): pdir=2 Direction=1 if x+side<=320: F(x,y,2,side,bg) x+=2 #jump if K(KEY_BACKSPACE): if y==y_floor-side: jump=True #player shoots if K(KEY_TOOLBOX): if shoot: shoot=False # 1 = right if len(L_bullets)<15: if Direction==1: L_bullets.append([x+side+3, y+4, 1,side//3,side//4]) else: L_bullets.append([x-3-w_bullet, y+4, -1,side//3,side//4]) elif not(K(KEY_TOOLBOX)): shoot=True #bullets fired (L_bullets) if len(L_bullets)!=0: for i in L_bullets: #bullets reach left or right if i[0]>320 or i[0]<0-i[3]: L_bullets.remove(i) else: if i[2]==1: x_eff_bullet=i[0] else: x_eff_bullet=i[0]+i[3]-v_bullet F(x_eff_bullet,i[1],v_bullet,i[4],bg) i[0]+=v_bullet*i[2] #player bullets color F(i[0],i[1],i[3], i[4], (R(0,255),R(0,255),R(0,255))) F(i[0]+(i[3]//6)+1,i[1]+(i[4]//6)+1,i[3]-(i[3]//6)*2-2,i[4]-(i[4]//6)*2-2, ccarre) if jump: y=y_floor-side-L_jump[count] count+=1 if count==len(L_jump): count=0 jump=False if precedent_y<y: F(x-2,y-4,side+4,4,bg) else: F(x-2,y+side,side+4,precedent_y-y,bg) F(x,y,side,side,pc) if ey<22: ey=22 if ey+eh>200: ey=200-eh if y<ey: edir=choice([3,4]) if y>ey: edir=choice([3,4]) if ex+ew<-R(10,20): ee+=R(1,3) ew=R(15,60) eh=R(15,60) ex=R(250,400) ey=R(20,y_floor-eh) ec=(R(0,100),R(0,100),R(0,100)) pl-=1 echase=False F(ex,ey,ew,eh,ec) F(x,y,side,side,RED) #enemy defeated if ee<1 and x+side>=300 and y+side>=y_floor-30: ee=R(12,35) F(0,y_floor,322,120,(R(0,255),R(0,255),R(0,255))) psc+=R(25,100) pe+=2 ew=R(15,60) eh=R(15,60) ex=R(220,400) ey=R(20,y_floor-ey+eh) ec=(R(0,H),R(0,H),R(0,H)) pe+=2 echase=False world+=1 bg=(R(0,H),R(0,H),R(0,H)) y_floor=R(120,180) x=10 y=y_floor-side F(0,0,322,222,bg) r=R(0,H) g=R(0,H) b=R(0,H) F(0,y_floor,322,120,(r,g,b)) #enemy destroyed if ee<1: ex+=R(1,3) for i in range(10): for j in range(10): i=R(ex,ex+ew) j=R(ey,ey+eh) F(i,j,R(2,5),R(2,5),choice([BLACK,bg])) #door pops up F(300,y_floor-30,16,30,(R(0,H),R(0,H),R(0,H))) for i in range(0,10): i+=1 lavay=R(200,220) F(i,lavay,4,40,(R(0,50),R(0,50),R(0,50))) ex-=1 F(ex+ew,ey,1,eh,bg) if K(KEY_TOOLBOX) and y+4>=ey and y+4<=ey+eh and x>ex and pdir==1 and ee>=1: F(ex,ey,ew,eh,RED) F(0,0,322,20,bg) psc+=1 pe+=0.04 ee-=0.1 if K(KEY_TOOLBOX) and y+4>=ey and y+4<=ey+eh and x<ex and pdir==2 and ee>=1: F(ex,ey,ew,eh,RED) F(0,0,322,20,bg) psc+=1 pe+=0.04 ee-=0.1 if K(KEY_UP): F(x+7,25,3,y-25,RED) sleep(0.01) F(x+7,25,3,y-25,bg) if K(KEY_UP) and x+9>=ex and x+7<=ex+ew and ee>=1: F(ex,ey,ew,eh,RED) F(0,0,322,20,bg) psc+=1 pe+=0.04 ee-=0.2 dash=R(0,2) if dash: for i in range(2): ex-=R(0,1) F(ex+ew-1,ey,2,eh,bg) #player pc=(0,R(150,H),R(150,H)) #enemy leaves cloud F(ex+ew,ey+R(1,eh),R(2,4),R(1,3),(R(0,40),R(0,40),R(0,40))) #grass and flowers if y+side>=y_floor: y=y_floor-side for i in range(0.0001): i=R(0,322) F(i,y_floor+R(0,4),R(1,2),R(1,2),choice([GREEN,BLACK,RED])) STR("GAME OVER",100,90,BLACK,bg) STR("SCORE:"+str(psc),100,120,CYAN,bg)