planet_z_v_9.py

Created by wperez274

Created on February 24, 2022

6.86 KB

Platform Game for NumWorks Calculator.


from math import *
from random import *
from kandinsky import *
from ion import *
from time import *
from kandinsky import fill_rect as F
from random import randint as R
from kandinsky import draw_string as STR
from ion import keydown as K
H=255
r=g=b=0
SW=322
SH=222
SA=SW*SH
#pipe
GX=400
GY=R(50,100)
GW=R(50,100)
GH=3
GC="yellow"
ground_y=R(180,215)
Lx=R(40,250)
GX2=R(0,100)
GY2=R(40,180)
GW2=R(40,100)
GH2=R(20,80)
GC2=(R(0,H),R(0,H),R(0,H))
GX3=R(150,270)
GY3=R(40,180)
GW3=R(30,150)
GH3=R(20,80)
GC3=(0,R(0,H),R(0,H))
nx=R(20,220)
ny=R(42,80)
area=1
world=1
game=1
bg=(R(0,100),R(0,50),R(0,100))

psc=0
pe=9
plife=3
ph=20
px=20
py=10
pw=12
pc="orange"
edash=0
edash_timer=0
eattacks=0
eruns=0
edefeated=0
dooropen=0
etimer=0
echase=0
edir=0
ex=R(180,280)
ey=R(40,100)
ew=R(20,30)
eh=R(10,30)
ee=0.5*ew*eh
ec=(R(0,H),R(0,H),R(0,H))
fballdir=1
fballx=ex
fbally=ey
fballw=round(0.2*ew)
fballh=round(0.6*eh)
fballc="red"
facingleft=0
facingright=1
doorx=-10
doory=-10
doorw=16
doorh=200
doorc="black"
vel=1
xVel=0
jumping=0
jumpCount=0
maxJump=25
falling=1

def pause():
  STR("(PAUSED)",110,50,"blue",bg)
  while K(KEY_OK):
    pass
  while not K(KEY_OK):
    pass
  while K(KEY_OK):
    STR("        ",110,50,bg,bg)
    pass

F(0,0,SW,21,"black")
F(0,22,SW,SH,bg)
F(0,0,SW,20,"black")
while game:
  etimer+=0.1
  #pipe
  F(GX,GY,GW,GH,GC)
  F(GX2,GY2,GW2,GH2,GC2)
  F(GX3,GY3,GW3,GH3,GC3)
  #player & enemy  
  F(px,py,pw,ph,pc)
  F(px+2,py+3,9,6,"cyan")
  F(ex,ey,ew,eh,ec)
  F(ex+4,ey+5,ew-7,round(eh/4),(R(140,H),R(0,80),0))
  F(0,20,322,3,"blue")
  STR("Energy: "+str(round(plife)),16,0,"gray","black")
  STR("Area: "+str(world),160,0,"white","black")

  if etimer>R(6,10):
    etimer=0
    edir=R(1,4)
    echase=R(0,1)
#enemy chase
  if echase:
    if ex<px:
      edir=2
    if ex>px:
      edir=1
    if ey<py:
      edir=4
    if ey>py:
      edir=3
  if dooropen:
    F(doorx,doory,doorw,doorh,(randint(0,255),randint(0,255),randint(0,255)))
    F(doorx,doory+doorh,doorw,2,"white")

  if K(KEY_LEFT):
    px += -vel
    F(px+pw,py,1,ph,bg)
    facingleft=True
    facingright=False

  if K(KEY_RIGHT):
    px += vel
    F(px-1,py,1,ph,bg)
    facingright=1
    facingleft=0
    
  if K(KEY_BACKSPACE) and jumping==0 and falling==0:
    jumping=1
    jumpCount=1
  
  if jumping:
    jumpCount+=1
    py-=3
    F(px,py+ph+1,pw,3,bg)

    if jumpCount==maxJump:
      jumping=0
      falling=1

  if px+pw>=GX2 and px<=GX2+GW2 and py+ph>=GY2:
    falling=0
  else:falling=1
  if py+ph>=GY2+GH2:
    falling=1
    
  if px+pw>=GX3 and px<=GX3+GW3 and py+ph>=GY3:
    falling=0
  if py+ph>=GY3+GH3:
    falling=1

  if falling:
    sleep(0.0001)
    py+=vel
    F(px,py-1,pw,1,bg)
  if px>doorx and px+pw<doorx+doorw and py+ph>=doory and py<=doory+doorh and edefeated==True:
    py-=2
    falling=0
  if py+ph<-5 and edefeated==1:
    sleep(0.2)
    while not K(KEY_OK):
      STR("World Cleared..(Press [OK])",30,100,"white",bg)
    
    Lx=R(10,300)
    px=20
    py=ground_y-ph
    
    bg=(R(0,100),R(0,50),R(0,100))
    fballx=ex
    fbally=ey
    fballw=round(0.2*ew)
    fballh=round(0.6*eh)
    
    ex=R(180,280)
    ey=R(40,100)
    ew=R(15,30)
    eh=R(15,60)
    ee=0.5*ew*eh
    world+=1
    edefeated=0
    ec=(R(0,H),R(0,H),R(0,H))
    dooropen=0
    
    F(0,22,SW,SH,bg)
    F(0,210,SW,50,(H,0,0))
    GX=R(400,500)
    GY=R(40,90)
    GW=R(50,100)
    
    GX2=R(0,150)
    GY2=R(20,190)
    GW2=R(20,140)
    GH2=R(10,50)
    GC2=(R(0,H),R(0,H),R(0,H))
    GX3=R(150,200)
    GY3=R(40,190)
    GW3=R(20,140)
    GH3=R(10,50)
    GC3=GC2=(R(0,H),R(0,H),R(0,H))
  
  if K(KEY_OK):
    pause()
      
  if K(KEY_TOOLBOX) and facingleft:
    F(0,py+4,px,3,(R(0,H),R(0,H),R(0,H)))
    sleep(0.0015)
    F(0,py+4,px,3,bg)

  if K(KEY_TOOLBOX) and facingright:
    F(px+pw,py+4,SW-px,3,(randint(150,255),randint(0,25),randint(0,25)))
    sleep(0.0015)
    F(px+pw,py+4,SW-px,3,bg)
  if facingleft:
    F(px+1,py+7,1,3,"white")
    facingright=0
  if facingright:
    F(px+pw-3,py+7,1,3,"white")
    facingleft=0
#enemy hit
  if K(KEY_TOOLBOX) and facingleft and ex<=px and py+4>=ey and py+4<=ey+eh:
    F(ex,ey,ew,eh,"red")
    ee-=0.2
    pe+=0.03

  if K(KEY_TOOLBOX) and facingright and ex>=px and py+4>=ey and py+4<=ey+eh:
    F(ex,ey,ew,eh,"red")
    ee-=0.2
    psc+=1
    pe+=0.05
#enemy gone  
  if ee<1:
    edefeated=1
    ee=0
    doorx=GX3+4
    doory=GY3-doorh
    dooropen=1
    
    for i in range(5):
      for j in range(5):
        i=R(ex,ex+ew)
        j=R(ey,ey+eh)
        F(i,j,R(2,5),R(2,5),"red")
    
    dooropen=1
  if dooropen:
    F(doorx,doory,doorw,doorh,(randint(0,99),randint(0,99),randint(0,99)))
    eattacks=0
    echase=0
    etimer=0
    edir=0
    
  if ex+ew<0:
    ex=321
   
  if ex>321:
    ex=0-ew
   
  if ey<=24:
    ey=24
  if ey+eh>SH:
    ey=SH-eh
   
  if edir==1:
    ex-=2
    F(ex+ew+1,ey,2,eh,bg)    
  if edir==2:
    ex+=2
    F(ex-2,ey,2,eh,bg)
  if edir==3:
    ey-=2
    F(ex,ey+eh+1,ew,2,bg)    
  if edir==4:
    ey+=2
    F(ex,ey-2,ew,2,bg)
  if ey+eh>ground_y:
    ey=ground_y-eh
    
  if px+pw<0:
    px=321
  if px>SW:
    px=1
  if py<20 and edefeated==0:
    py=20

  if py+ph>ground_y:
    falling=0
    py=ground_y-ph-2
    
  if px+pw>=ex and px<=ex+ew and py+ph>=ey and py<=ey+eh and edefeated==False:
    F(px,py,pw,ph,"red")
    sleep(0.001)
    pe-=0.05
    ee+=0.1
    edir=R(1,4)
  if plife<2:
    F(px,py,pw,ph,bg)
  if ee<50:
    F(ex,ey,ew,eh,"gray")
  if pe<1:
    pe=9
    plife-=1
  if pe>9:
    pe=1
    plife+=1

  if px+pw>ex and px<ex+ew and py+ph>ey and py+ph<ey+eh:
    pe-=0.1
    ee-=0.2    
    py-=2
  
  if fbally+fballh>ground_y:
    fbally=ground_y-fballh
  if fbally<22:
    fbally=22
    fballdir=4
  if fballx<-20-fballw or fballx>R(320,400):
    fballx=ex
    fbally=ey
    fballw=R(4,10)
    fballh=eh
#fireball  
  F(fballx,fbally,fballw,fballh,(R(100,255),R(0,25),R(0,55)))

  if px<ex:fballdir=1
  if px>ex:fballdir=2
  if fballdir==1:
    fbally=fbally+R(-3,3) 
    fballx-=1
    F(fballx+fballw+1,fbally-4,1,fballh+8,bg)

  if fballdir==2:
    fbally=fbally+R(-3,3) 
    fballx+=1
    F(fballx-1,fbally-4,1,fballh+8,bg)

  if px+pw>=fballx and px<=fballx+fballw and py+ph>=fbally and py<=fbally+fballh:
    F(px,py,pw,ph,"red")
    pe-=0.4
  if plife<0:
    game=False
  if keydown(KEY_DOWN) and py==22:
    py=23
    
  if py==22:
    py=22
    py-=2
    falling=0
  
  
  if py==GY and px+pw>=GX and px<=GX+GW:
    py=GY
    py-=2
    
    F(px+pw+1,py,1,ph,bg)
    falling=0
  
  GX-=1
  if GX+GW<-10:
    GX=400
    GY=R(40,90)

  F(GX+GW+1,GY,1,GH,bg)

  F(GX2,GY2-2,GW2,2,"white")
  F(GX3,GY3-2,GW3,2,"green")
  
  F(0,ground_y,SW,SH,"black")

  if px+pw>Lx and px<Lx+12:py-=3
  
  
  F(Lx,ground_y-170,15,170,"cyan")
  F(Lx-2,ground_y-170,2,170,"blue")
  F(Lx+16,ground_y-170,2,170,"blue")
  F(0,ground_y-2,322,2,(0,140,0))
  F(ex,ey,ew,1,"red")  
  

F(0,0,322,222,"black")  
STR("GAME OVER",100,100,"white","black")      
STR("SCORE:"+str(psc),100,140,"cyan","black")

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.