# Edited by: Wilson.
fromkandinskyimport*fromkandinskyimportfill_rectasFfromkandinskyimportdraw_stringasSTRfromionimport*fromtimeimport*fromrandomimport*fromrandomimportrandintasRlaser_force_x=250key_x=R(0,300)key_y=R(-20,0)key_w=4key_h=18key_c="cyan"defdraw_ground():bg=(0,0,0)gx=300gy=5gw=5gh=5foriinrange(0,322,5):forjinrange(210,222):gc=choice([(150,0,0),(100,0,0),(250,0,0)])i+=randint(0,1)j+=randint(-4,2)F(i,j,gw,gh,gc)F(i+gw,j,2,gh,bg)F(i,j-2,gw,2,bg)sleep(0.2)defdraw_home_screen():clone_x=R(10,35)clone_y=170bg=(45,5,79)F(0,0,322,222,bg)whilenotkeydown(KEY_OK):F(0,25,322,2,"cyan")F(0,55,322,2,"cyan")F(10,200,300,10,"gray")F(280,192,22,8,"cyan")F(0,210,322,25,"red")F(clone_x,clone_y,14,26,(0,120,0))F(clone_x+5,clone_y+5,12,8,"cyan")STR("Chute 2.0",100,34,"black","cyan")STR("keys [left]/[Right] = Move",25,70,"white",bg)STR("key [Backspace] = Jump",30,90,"yellow",bg)STR("key [Toolbox] = Shoot",40,110,"gray",bg)STR("key [VAR] = Pause",60,130,"cyan",bg)STR("(Press [OK] to Start)",90,160,(R(200,255),0,0),bg)defprint_intro():text=["In a peaceful planet, chaos","erupted! Visitors from unknown","origin and unknown species","appeared on a quiet morning.","They took over all resources.","HELP!! Who will save us??!"]F(0,0,322,222,"white")sleep(0.7)STR(text[0],10,30,"blue")sleep(0.7)STR(text[1],10,50,"blue")sleep(0.7)STR(text[2],10,70,"blue")sleep(0.7)STR(text[3],10,90,"blue")sleep(0.7)STR(text[4],10,110,"blue")sleep(0.7)STR(text[5],10,130,"blue")sleep(0.5)whilenotkeydown(KEY_OK):STR("Press [OK] to Start",50,180)draw_home_screen()sleep(0.2)print_intro()time=9time_2=1lives=3score=0energy=30shield_on=Falseshield_time=5shield_x=R(2,310)shield_y=R(-20,0)shield_w=16shield_h=16shield_c=(R(0,255),R(0,255),R(0,255))food_x=R(2,315)food_y=R(-100,-50)food_w=11food_h=18food_c=(R(0,255),R(0,255),R(0,255))lava_y=210#dark red
lava_c=(150,0,0)rect_x=300rect_y=R(20,60)rect_w=R(20,50)rect_h=R(10,30)rect_c=(R(0,255),R(0,255),R(0,255))#background
backColor=choice(["black","pink",(randint(0,105),R(0,105),randint(0,255))])defgame_over_draw():F(0,0,322,222,"black")forxinrange(0,322,14):foryinrange(0,222,18):sleep(0.0025)F(x,y,13,17,choice(["grey","white",(150,140,135),(201,205,200)]))F(0,70,322,110,"black")whilenotkeydown(KEY_OK):STR("GAME OVER",100,100,"white","black")STR("SCORE: "+str(round(score)),100,130,"cyan","black")F(0,0,322,222,"black")#platforms to jump on
plateforms_color=(randint(0,255),randint(0,255),randint(0,255))shoot_color=(randint(150,255),randint(150,255),randint(150,255))trainee=Falselevel=0classEntity():def__init__(self,x,y,width,height,speed,ma=True):self.x=xself.y=yself.width=widthself.height=heightself.speed=speedself.move_alone=maself.chute=0self.gx=self.x+int(self.width/2)self.gy=self.y+self.heightself.dead=Falseself.drawing=[]self.shooting=Nonedefset_drawing_inverse(self):self.drawing_inverse=[None,]*len(self.drawing)foriinrange(len(self.drawing)):j=self.drawing[i]self.drawing_inverse[i]=[self.width-j[0]-j[2],j[1],j[2],j[3],j[4]]defcontact(self,x1,y1,x2,y2):ifself.x<=x1<=self.x+self.widthorself.x<=x2<=self.x+self.width:ifself.y<=y1<=self.y+self.heightorself.y<=y2<=self.y+self.height:returnTruereturnFalsedefstep(self):x=self.xy=self.yself.move()ifself.x!=xorself.y!=yorlen(shoot):F(x,y,20,30,backColor)self.draw()ifis_shooting:draw_shoot((0,)*3)#assign global variables..
defmove(self):globallevel,energy,livesifis_shooting:draw_shoot(backColor)ifself.chute:ifself.chute>0:ifself.tomber():self.y+=self.chuteself.chute+=1else:self.y=plateforms[self.get_plateform()][1]-self.height#player dies
ifself.y+self.height>lava_y+4ortime_2<=0:self.dead=Truelives-=1#6 spaces for this else
else:self.y+=self.chuteself.chute+=1ifself.move_alone:self.x+=self.speedifself.tomber():self.speed*=-1self.x+=self.speedelse:x=(keydown(3)-keydown(0))ifx:self.speed=abs(self.speed)*xself.x+=self.speed# Jump
ifkeydown(KEY_BACKSPACE)andnotself.tomber():self.y=plateforms[self.get_plateform()][1]-self.height# and height of jump..
self.chute=-10if (notself.tomber()):ifself.contact(points[1][0],points[1][1],points[1][0]+20,points[0][1]+5):level+=1self.dead=Trueifself.tomber()andself.chute==0:self.chute=1deftomber(self):self.gx=self.x+int(self.width/2)self.gy=self.y+self.heightforiinplateforms:ifself.gy<=i[1]<=self.gy+self.chute:ifi[0]<=self.gx<=i[0]+i[2]:returnFalsereturnTruedefget_plateform(self):ifnotself.tomber():foriinplateforms:ifself.gy<=i[1]<=self.gy+self.chute:ifi[0]<=self.gx<=i[0]+i[2]:returnplateforms.index(i)defdraw(self):ifself.speed<=0:foriinself.drawing:F(self.x+i[0],self.y+i[1],i[2],i[3],i[4])else:foriinself.drawing_inverse:F(self.x+i[0],self.y+i[1],i[2],i[3],i[4])#Plateforms
defdraw_all_plateforms(color):foriinplateforms:F(i[0],i[1],i[2],i[3],color)#Entites
defdraw_all_entities():foriinentities:i.move()i.draw()#Shoot
is_shooting=Noneshooting_direction=1shoot=[]shooting_list=[]foriinrange(20):shooting_list+=[[int((15**2-(i-10)**2)**0.5),i-10],]defget_shoot(e,shooting):return[e.gx,e.y+8+10,shooting_list[shooting][0]*((e.speed>0)*2-1),shooting_list[shooting][1],0]#shoot aim moves in curve..
defdraw_shoot(color):shoot_color="cyan"c=get_shoot(avatar,is_shooting)F(c[0]+c[2]*2-5,c[1]+c[3]*2-2,9,9,color)#Screen when died or when complete level
defnew_area_screen():F(0,0,322,222,"black")whilenotkeydown(KEY_OK):STR("Life: "+str(round(lives)),60,60,"gray","black")STR("Press [OK] to conitue",70,120,"white","black")#player loss 1 chance (life)
defdeath_animation():F(0,0,322,222,"black")forxinrange(0,322,16):foryinrange(0,222,5):sleep(0.0006)F(x,y,15,4,choice(["white","black"]))F(0,70,322,110,"black")whilenotkeydown(KEY_OK):STR("Life: "+str(round(lives)),100,90,"cyan","black")STR("Press [OK] to conitue",70,120,"black","cyan")# portals on left and right
# 2 teleport stations
points=[]defdraw_all_points():#start
F(points[0][0],points[0][1]-5,20,5,"cyan")#goal
F(points[1][0],points[1][1]-5,20,5,(R(0,50),R(200,250),R(200,250)))maps=[#[spawn/end,monsters,plateforms(,txt)]
[#[x,y] coordinate of:
#platform and portal.
[[10,200],[280,200]],[],[#[x,y,w,h] values of: plateforms
[0,200,322,10],],],[[[10,200],[10,100]],[],[[10,200,100,10],[140,200,100,10],[170,150,100,10],[10,100,100,10],],],[[[10,160],[280,80]],[[100,100,20,30,5],],[[10,160,50,10],[100,130,100,10],[200,80,100,10],],],[[[0,120],[280,80]],[[130,100,20,30,5],[160,100,20,30,5],[190,100,20,30,5],],[[0,120,50,10],[100,130,140,10],[200,80,100,10],],],[[[10,190],[270,90]],[[180,100,20,30,5]],[[10,190,130,10],[140,140,100,10],[240,90,50,10]]],[[[10,170],[270,170]],[[90,140,20,30,5]],[[10,170,100,10],[170,170,120,10]]],[[[20,40],[270,200]],[[270,100,20,30,5],[100,80,20,30,5],[180,130,20,30,5],[160,10,20,30,5],[50,50,20,30,5],[230,170,20,30,5]],[[220,200,70,10],[220,130,70,10],[160,160,60,10],[90,110,40,10],[140,40,60,10],[40,80,40,10],[20,40,50,10]]],[[[120,200],[290,50]],[[190,120,20,30,5],[110,120,20,30,5],[100,70,20,30,5],[200,70,20,30,5],[150,70,20,30,5],[80,20,20,30,5],[120,20,20,30,5],[180,20,20,30,5],[220,20,20,30,5]],[[100,150,120,10],[90,100,140,10],[70,50,180,10],[120,200,80,10],[280,50,30,10]]],[[[40,130],[240,130]],[[70,0,20,30,5],[90,10,20,30,5],[110,20,20,30,5],[130,30,20,30,5],[150,40,20,30,5],[170,50,20,30,5],[190,60,20,30,5],[210,70,20,30,5],[230,80,20,30,5]],[[40,130,220,10],]],[[[10,200],[280,40]],[[250,10,20,30,5],[190,150,20,30,5],[260,100,20,30,5],[120,70,20,30,5],[30,20,20,30,5],[140,-10,20,30,5]],[[240,40,60,10],[10,200,80,10],[180,180,50,10],[240,130,70,10],[100,100,70,10],[2990,210,20,10],[10,50,60,10],[110,20,90,10]]],[[[20,190],[280,70]],[[160,110,20,30,5],[70,70,20,30,5],[150,20,20,30,5],[110,160,20,30,5]],[[20,190,270,10],[140,140,70,10],[50,100,60,10],[130,50,60,10],[230,70,70,10]]],[[[10,200],[290,200]],[],[[10,200,300,10],],"**[ You completed this game! ]**"]]defspawn(level):globalavatar,entities,plateforms,shoot,points,txt,gameF(0,0,320,222,backColor)shoot=[]iflevel==len(maps):game=Falsereturnmap=maps[level]points=map[0]plateforms=map[2]avatar=Entity(points[0][0],points[0][1]-30,20,30,10,False)avatar.drawing=[#player
(3,0,17,30,(R(0,100),R(0,100),R(0,100))),(0,3,12,10,"cyan"),]avatar.set_drawing_inverse()entities=[avatar,]foriinmap[1]:enemy_c=choice(["black",(135,0,0),(0,135,0),(0,0,135),(135,135,135),(65,25,95),(95,25,65),(R(0,255),R(0,255),R(0,255))])#enemy width and height
enemy_w=R(11,17)#original height=30
enemy_h=R(25,34)entities+=[Entity(i[0],i[1],i[2],i[3],i[4]),]entities[-1].drawing=[#Original width,height=17,30
(3,0,enemy_w,enemy_h,enemy_c),#enemy mask
(0,3,12,10,choice(["white","cyan","black","green",(120,0,0),(36,25,32),(R(0,255),R(0,255),R(0,255))])),]entities[-1].set_drawing_inverse()iflen(map)==4:STR(map[3],20,20,(150,)*3,backColor)avatar.draw()spawn(level)time_start=monotonic()game=Truewhilegame:ifavatar.dead:death_animation()spawn(level)draw_ground()foriinrange(len(entities)-1,0,-1):forjinrange(len(shoot)-1,-1,-1):ifentities[i].contact(shoot[j][0]-5,shoot[j][1]-5,shoot[j][0]+5,shoot[j][1]+5):F(entities[i].x,entities[i].y,20,30,backColor)F(shoot[j][0]-5,shoot[j][1]-5,10,10,backColor)delentities[i]delshoot[j]breakifkeydown(KEY_TOOLBOX)oris_shooting!=None:ifkeydown(KEY_TOOLBOX):ifis_shooting==None:is_shooting=1draw_shoot(backColor)is_shooting+=shooting_directionifis_shooting==len(shooting_list)-1oris_shooting==0:shooting_direction*=-1elifis_shooting!=None:shoot+=[get_shoot(avatar,is_shooting),]shoot[-1][0]+=shoot[-1][2]shoot[-1][1]+=shoot[-1][3]draw_shoot(backColor)is_shooting=Noneforiinentities:i.step()ifnottrainee:foriinshoot:F(i[0]-5,i[1]-5,10,10,backColor)foriinrange(len(shoot)-1,-1,-1):shoot[i][0]+=shoot[i][2]shoot[i][1]+=shoot[i][3]shoot[i][3]+=1ifshoot[i][1]>222:delshoot[i]continueF(shoot[i][0]-5,shoot[i][1]-5,10,10,shoot_color)#player collides into
foriinentities[1:]:ifi.contact(avatar.x,avatar.y,avatar.x+avatar.width,avatar.y+avatar.height)andshield_on==False:avatar.dead=TrueSTR("Time: "+str(round(time)),0,0,"black","cyan")STR("Energy: "+str(round(energy)),110,0,"black","orange")STR("Life: "+str(round(lives)),240,0,"black","yellow")#use the dot to access x,y,width,height
# Player losses energy fast
ifavatar.x+avatar.width>rect_xandavatar.x<rect_x+rect_wandavatar.y+avatar.height>rect_yandavatar.y<rect_y+rect_handshield_on==False:F(avatar.x,avatar.y,avatar.width,avatar.height,"red")energy-=2avatar.x-=5#for a few seconds,can jump higher!
ifavatar.x+avatar.width>food_xandavatar.x<food_x+food_wandavatar.y+avatar.height>food_yandavatar.y<food_y+food_h:F(avatar.x,avatar.y,avatar.width,avatar.height,"pink")F(food_x,food_y,food_w,food_h,backColor)food_y=R(-2000,-1500)food_x=R(2,310)lives+=0.5score+=R(50,100)ifavatar.x+avatar.width>shield_xandavatar.x<shield_x+shield_wandavatar.y+avatar.height>shield_yandavatar.y<shield_y+shield_h:F(avatar.x,avatar.y,avatar.width,avatar.height,"cyan")F(shield_x,shield_y,shield_w,shield_h,backColor)whilenotkeydown(KEY_OK):STR("Press [UP]+[Backspace]",20,50,"black","cyan")STR("to Super Jump!!",20,70,"black","cyan")STR("(Press [OK] to continue)",70,100,"black","yellow")STR("",20,50,backColor,backColor)STR("",20,70,backColor,backColor)STR("",70,100,backColor,backColor)sleep(0.3)time+=1lives+=0.25score+=R(200,500)shield_on=Trueshield_y=R(-3000,-2000)shield_x=R(2,300)shield_c=(R(0,255),R(0,255),R(0,255))ifshield_on:F(avatar.x,avatar.y,2,avatar.height,(R(0,255),R(0,255),R(0,255)))F(avatar.x+avatar.width-2,avatar.y,2,avatar.height,(R(0,255),R(0,255),R(0,255)))F(avatar.x,avatar.y,avatar.width,2,(R(0,255),R(0,255),R(0,255)))F(avatar.x,avatar.y+avatar.height-2,avatar.width,2,(R(0,255),R(0,255),R(0,255)))color=(R(0,255),R(0,255),R(0,255))STR("Shield:"+str(round(shield_time)),110,20,"black",(235,240,220))shield_time-=0.04ifshield_time<=0:shield_time=5shield_on=FalseSTR("",110,20,backColor,backColor)ifenergy<=0:lives-=1energy=25#Pause/Resume code
ifkeydown(KEY_VAR):whilenotkeydown(KEY_OK):STR("( PAUSE )",120,60,"black","cyan")STR("(PRESS [OK] KEY TO RESUME)",20,90,"black","yellow")STR("",120,60,backColor,backColor)STR("",20,90,backColor,backColor)F(rect_x,rect_y,rect_w,rect_h,rect_c)F(rect_x+rect_w,rect_y,7,rect_h,backColor)#border on rect
F(rect_x,rect_y,2,rect_h,"blue")F(rect_x+rect_w-2,rect_y,2,rect_h,"blue")F(rect_x,rect_y,rect_w,2,"blue")F(rect_x,rect_y+rect_h-2,rect_w,2,"blue")# temporary shield
F(shield_x,shield_y,shield_w,shield_h,shield_c)F(shield_x,shield_y-4,shield_w,4,backColor)F(shield_x,shield_y,2,shield_h,"white")F(shield_x+shield_w-2,shield_y,2,shield_h,"white")F(shield_x,shield_y,shield_w,2,"white")F(shield_x,shield_y+shield_h-2,shield_w,2,"white")#player outer color
ifshield_on==False:F(avatar.x,avatar.y,2,avatar.height,"black")F(avatar.x+avatar.width-2,avatar.y,2,avatar.height,"black")F(avatar.x,avatar.y,avatar.width,2,"black")F(avatar.x,avatar.y+avatar.height-2,avatar.width,2,"black")F(food_x,food_y,food_w,food_h,food_c)F(food_x,food_y-3,food_w,3,backColor)F(food_x,food_y,2,food_h,"pink")F(food_x+food_w-2,food_y,2,food_h,"pink")F(food_x,food_y,food_w,2,"pink")F(food_x,food_y+food_h-2,food_w,2,"pink")food_y+=3iffood_y+food_h>=lava_y:# food_y=lava_y-food_h
food_y-=2food_c=(R(100,255),0,0)iffood_y>222:food_y=R(-1200,-1000)food_x=R(2,310)rect_x-=7shield_y+=4ifshield_y+shield_h>=lava_y:# shield_y=lava_y-shield_h
shield_y-=1ifshield_y>222:shield_y=R(-1000,-800)shield_x=R(2,300)shield_c=(R(0,255),R(0,255),R(0,255))#rectangle enemy reaches left side of screen
ifrect_x+rect_w<0-R(5,10):rect_x=R(400,600)rect_y=R(10,198-rect_h)rect_w=R(10,30)rect_h=R(16,85)rect_c=choice([(R(0,125),R(0,125),R(0,125)),"red","white","yellow"])time-=0.005iftime<=0orlives<=0.9:game_over_draw()game=Falseifkeydown(KEY_UP)andshield_on:avatar.y-=4food_x-=R(-4,4)F(food_x-4,food_y,4,food_h,backColor)F(food_x+food_w,food_y,4,food_h,backColor)#player bullet colors are random
shoot_color=(R(0,255),R(0,255),R(0,255))draw_all_points()draw_all_plateforms(plateforms_color)ifavatar.y+avatar.height>=202:avatar.y=202-avatar.heightdraw_ground()avatar.y-=6lives-=0.02F(0,0,60,20,backColor)#this is the speed of game loop.
sleep(0.04)iftime<=0:print("\nYou ran out of time.\n")iflives<=0:print("\nYou ran out of chances.\n")#********The End....or is it ?...******
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
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.