quest_2.py

Created by wperez274

Created on February 11, 2022

6.1 KB

key [OK] = Pause/Resume key [Backspace] = Float/Fly


from math import *
from kandinsky import fill_rect as F
from random import *
from ion import *
from kandinsky import *
from time import *
from random import randint as R
from random import randrange as RR
from random import choice as CH
from ion import keydown as K
from kandinsky import draw_string as STR

edefeat=0
game=1
SW=322
SH=222
low=100
med=150
H=255
BL=(0,0,0)
bg=(0,0,R(0,H))
    
area=0
world=1
#enemy
Mchase=False
Mdir=0
Mt=-100
Me=20
Mx=500
My=-500
Mw=16
Mh=10
Mc=(R(0,H),R(0,H),R(0,H))
#stars
c1=(R(0,H),R(0,H),R(0,H))
c2=(H,0,0)
crit_t=0
star_t=0
nb=R(20,60)
st = [0]*nb
pr = [0]*nb
NR=BL
def point():
  return [RR(SW),0,RR(1,10)]
for i in range(nb): st[i] = point()
#i guess for stars
F(0,0,SW,SH,NR)
J=0
fall=0
J_c=0
max_j=med
Left=0
Right=1
Gy=R(90,215)
Lw=R(40,100)
Lx=R(100,SW-Lw)
Lh=200
Ly=Gy
Lc="red"
Lfall=0
Lrise=0
psc=0
pe=20
pscale=5
pw=12
ph=22
px=30
py=Ly-ph
pc=(7,20,170)
pside=25
#food
Qt=0
Qsize=1
Qx=R(low,200)
Qy=R(-200,0)
Qw=2*Qsize
Qh=2*Qsize
Qc=(R(0,H),R(0,H),R(0,H))
def pLeft():
  global px,py,pw,ph,bg,Left,Right
  Left=0
  Right=0
  px-=1
  F(px+pw,py,1,ph,bg)
  F(px,py+2,6,7,"cyan")
def pRight():
  global px,py,pw,ph,bg,Right,Left
  Right=0
  Left=0  
  px+=1
  F(px-1,py,1,ph,bg)
  F(px+5,py+2,6,7,"cyan")
def pUp():
  global px,py,pw,ph,bg
  py-=2
  F(px,py+ph+1,pw,1,bg)
def pDOWN():
  global px,py,pw,ph,bg
  py+=1
  F(px,py-1,pw,1,bg)
F(0,0,SW,SH,bg)
F(0,Gy,322,150,(R(0,H),R(0,H),R(0,H)))
F(0,18,322,2,BL)
while game:
  STR("World:"+str(world),220,0,"green",BL)
  STR("E:"+str(round(pe)),2,0,"cyan",BL)
  F(Qx,Qy-1,Qw,1,bg)
  F(Lx,Ly,Lw,Lh,Lc)
  F(px,py,pw,ph,pc)
  F(Qx,Qy,Qw,Qh,Qc)
  F(px+3,py+4,6,7,"cyan")
  
  if Qt>R(3,6) and edefeat==0:
    Qt=0
    F(Qx,Qy,Qw,Qh,BL)
    Qsize=R(1,3)
    Qx=R(-20,400)
    Qy=R(-40,0)
    Qw=3*Qsize
    Qh=3*Qsize
  fall=1
  Mt+=1
  Qc=(R(0,H),R(0,H),R(0,H))
  Qy+=1
  if Mt>R(100,300):
    Mdir=R(0,4)
    Mchase=R(0,1)
    Mt=0 
  if fall:
    pDOWN()
  if K(KEY_LEFT):
    Left=1
    Right=0
    pLeft()
  if K(KEY_RIGHT):
    Right=1
    Left=0
    pRight()
  if K(KEY_BACKSPACE) and J_c<=max_j:
    pUp()
    F(px,py+ph-4,pw,4,(R(0,H),R(0,H),R(0,H)))
    J_c+=1
    J=0
    pe-=0.001
    F(0,0,100,18,bg)
  
  else:
    fall=0
  if py>Ly+Lw:
    fall=1
  if J_c==max_j:
    J_c=0
    fall=1
    J=0
  if J:
    fall=False
    J=False
    py-=2
    F(px,py+ph+1,pw,1,bg)
  if py<=20:
    py=R(19,20)
    Mchase=R(0,1)
  if Mchase:
    F(Mx-2,My-2,Mw+2,Mh+2,bg)

    if px<Mx:
      if py<My:
        for i in range(3):
          Mx-=1
          My-=1
    if px>Mx:
      if py>My:
        for i in range(3):
          Mx+=1
          My+=1
  if px<0-pw:
    px=SW
  if px>SW:
    px=1
  if py>SH and edefeat:
    bg=(0,0,R(0,H))
    
    edefeat=0
    Gy=R(90,215)
    
    F(0,0,SW,SH,bg)
    F(0,Gy,322,200,(R(0,H),R(0,H),R(0,H)))
    px=10
    py=Gy-ph
    Qx=R(-50,410)
    Qy=R(-40,20)
    Lx=R(40,250)
    Ly=Gy
    Lw=R(30,100)
    Lh=200
    area+=1    
    Mt=0
    Me=20
    Mx=R(240,310)
    My=R(40,100-Mh)
    Mw=R(15,35)
    Mh=R(9,22)
    Mc=(R(0,H),R(0,H),R(0,H))
    Qsize=R(1,3)
    Qx=R(40,H)
    Qy=R(40,Gy-Qh)
    Qw=3*Qsize
    Qh=3*Qsize
    F(Lx,Ly,Lw,Lh,Lc)

  if area>R(5,8):
    world+=1
    while not K(KEY_OK):
      STR("WORLD: "+str(world),100,100,"white",BL)
      sleep(0.01)   
      F(0,0,SW,SH,BL)
    sleep(0.2)
    area=1
    pe+=R(2,5)
    Gy=R(90,215)
    px=10
    py=Gy-ph
    Lx=R(40,250)
    Ly=Gy
    Lw=R(35,120)
    Lh=200
    bg=(0,0,R(0,H))
    F(0,0,SW,SH,bg)
    F(0,Gy,SW,200,(R(0,H),R(0,H),R(0,H)))
    psc+=R(25,100)
    Mt=0
    Me=R(10,25)
    Mx=R(240,310)
    My=R(40,100-Mh)
    Mw=R(10,25)
    Mh=R(8,22)
    Mc=(R(0,H),R(0,H),R(0,H))
    Qx=R(-40,410)
    Qy=R(-400,-20)
    Qsize=R(1,3)
    Qw=2*Qsize
    Qh=2*Qsize
#player on ground          
  if py+ph>Gy and px<=Lx-1 or py+ph>=Gy and px+pw+1>=Lx+Lw:
    py=Gy-ph
    fall=0
    jump_c=0
    max_j=150
    
  if py+ph>=Gy and px<=Lx-1 or py+ph>=Gy and px+pw+1>=Lx+Lw:
    pe+=0.002
    for i in range(0.0001):
      i=R(0,SW)
      F(i,Gy+R(-2,2),R(1,2),R(1,3),"green")
  if pe<0:
    game=0
  
  if K(KEY_OK):
    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
  
  star_t+=0.1
  if star_t>R(3,7):
    star_t=0
  
    for i in range(nb):
      st[i][1] += RR(1,int(50/st[i][2]))
      z = st[i][2]
      Sx = st[i][0]
      Sy = min(Gy,st[i][1])
      if Sy >= Gy: st[i] = point()
      if pr[i] != 0: set_pixel(pr[i][0],pr[i][1],bg)
      pr[i] = [int(Sx),int(Sy)]
      r=R(100,H)
      g=R(100,H)
      b=R(100,H)
      set_pixel(pr[i][0],pr[i][1],color(r,g,b))
    
  if Gy>SH:
    grdfall=1    
  grdfall=0  

  if py>SH:
    py=30
    fall=1
    fell=0
    if fell:
      jump=0
  if px+pw>=Qx and px<=Qx+Qw and py+ph>=Qy and py<=Qy+Qh:
    F(Qx,Qy,Qw,Qh,bg)
    for i in range(0.0001):
      i=R(0,SW)
      F(i,Gy+R(0,4),R(1,2),R(1,2),choice(["yellow",(0,0,0),"green"]))
    Qx=R(-200,510)
    Qy=R(-300,0)
    pe+=0.1*Qw
    psc+=R(20,100)
  if Qy+Qh>Gy and Qx<Lx or Qy+Qh>Gy and Qx+Qw>Lx:
    Qy=Gy-Qh
    Qt+=0.01
  F(Mx,My,Mw,Mh,Mc)
  F(Mx+2,My+2,2,2,"white")
  F(Mx+7,My+2,2,2,"white")
  if Mdir==1:
    Mx-=1
    F(Mx+Mw+1,My,1,Mh,bg)
  if Mdir==2:
    Mx+=1
    F(Mx-1,My,1,Mh,bg)
  if Mdir==3:
    My-=1
    F(Mx,My+Mh,Mw,1,bg)
  if Mdir==4:
    My+=1
    F(Mx,My-1,Mw,1,bg)
  if Mx<1:
    Mx=1
    Mdir=2
  if Mx+Mw>SW:
    Mx=SW-Mw
    Mdir=1
  if My<20:
    My=20
    Mdir=4
  if My+10>Gy:
    My=Gy-Mh
    Mdir=R(1,2)
    

  F(0,0,100,18,bg)
#player on enemy
  if py+ph>My and px+pw>=Mx and px<=Mx+Mw and py+ph<=My+Mh and Me>0:
    Mx+=R(-3,3)
    py=My-ph
    fall=0
    Mdir=R(1,2)
    Mchase=0
    F(Mx,My,Mw,Mh,"red")
    Me-=0.05
    pe+=0.01
    psc+=25
  if Me<10:
    F(Mx,My,Mw,Mh,"red")
  
  if Me<0:
    Mx=400
    Mdir=0
    Qt=0
    edefeat=1
    F(Mx,My,Mw,Mh,BL)
    Mx=H
    My=H
    Ly+=1
    F(Lx,Ly-1,Lw,1,bg)
  if px>Lx and px<Lx+Lw and py+ph>Ly and edefeat==0:
    pe-=0.1
    py+=R(0,1)
    if py+ph>222:game=0

  if edefeat:F(Lx,Ly,Lw,Lh,BL)  

STR("GAME OVER",100,100,"green",bg)      
STR("SCORE:"+str(psc),100,140,"white",bg)

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.