ninjabot.py

Created by wperez274

Created on March 26, 2023

4.33 KB


from math import *
from kandinsky import *
from random import *
from random import randint as R
from ion import *
from time import *

GAME=True

bg=(R(0,55),R(0,55),R(0,55))
    

ground_x=0
ground_y=R(120,220)
ground_c=(R(0,255),R(0,255),R(0,255))


poisonx=R(450,1250)
poisony=R(0,222)
poisonw=poisonh=10
poisonc=(0,0,0)



score=0
energy=30

wave=1

level=1

jump=15



water_x=0
water_y=R(160,210)
water_w=322
water_h=100
water_c=(0,0,R(50,255))





px=50
py=90
pw=13
ph=24
pc=(0,0,255)
pc2=(0,0,0)

ex=R(450,500)

eh=R(3,15)
ey=ground_y-eh
ew=R(7,30)
ec=(R(0,255),R(0,255),R(0,255))
ec2=(R(0,100),R(0,100),R(0,100))
    
def show_enemy():
  fill_rect(ex,ey,ew,eh,ec)
  fill_rect(ex+ew,ey,3,eh,bg)

  fill_rect(ex,ey,1,eh,ec2)
  fill_rect(ex+ew-1,ey,1,eh,ec2)
  fill_rect(ex,ey,ew,1,ec2)
  fill_rect(ex,ey+eh-1,ew,1,ec2)
  
  



def show_player():
  global px,py,pw,ph,pc,energy
  
  draw_string("Energy: "+str(round(energy)),1,1,'yellow','black')
  draw_string("SCORE: "+str(score),180,1,'orange','black')
  
  
  fill_rect(px,py,pw,ph,pc)

  fill_rect(px+2,py+4,pw-2,5,'white')


  
  
  fill_rect(px+5,py+5,3,5,(0,0,0))
  fill_rect(px+10,py+5,3,5,(0,0,0))



  fill_rect(px,py,1,ph,pc2)
  fill_rect(px+pw-1,py,1,ph,pc2)
  fill_rect(px,py,pw,1,pc2)
  fill_rect(px,py+ph-1,pw,1,pc2)


  
def move_player():
  global px,py,pw,ph,pc,bg,energy,ex,ey,ew,eh,ec,ground_y,score,jump
  
  if keydown(KEY_LEFT):
    px-=2
    fill_rect(px+pw+2,py,2,ph,bg)

  if keydown(KEY_RIGHT):
    px+=2
    fill_rect(px-2,py,2,ph,bg)


  if jump>0:

    if keydown(KEY_UP):


      jump-=0.6
      py-=4
      ph=24
      fill_rect(px,py+ph+1,pw,4,bg)

    if keydown(KEY_DOWN):
      ph=15
      fill_rect(px,py,pw,ph,bg) 



def update():
  show_player()
  show_enemy()
  move_player()
  
fill_rect(0,0,322,222,bg)


while GAME:
  fill_rect(ground_x,ground_y,322,2,ground_c)

  
  


  
  

  show_player()
  show_enemy()
  py+=2
  
  
  fill_rect(px,py-2,pw,2,bg)
   
  if py+ph>=ground_y:
    py=ground_y-ph

  ex-=2
  jump+=0.15
  
  
  if ex+ew<=R(-20,-5):
    ex=R(325,500)
    
    ey=choice([R(60,ground_y-eh),py])
    ew=R(15,80)
    eh=R(10,40)
    
    ec=(R(0,255),R(0,255),R(0,255))
    ec2=(R(0,255),R(0,255),R(0,255))
    score+=R(20,50)
    energy+=0.315
    wave+=1
    
    
  if wave>=R(10,20):
    bonus=R(100,200)
    fill_rect(0,0,322,222,(0,0,0))
      
    while not keydown(KEY_OK):
      draw_string("Level Completed!",80,100,'white',(0,0,0))

      draw_string("SCORE: "+str(score),100,140,'green',(0,0,0))
      
      bonus-=1
      sleep(0.01)
      if bonus>0:
        score+=1
        
      if bonus<1:
        draw_string("Press [OK] to continue",40,180,'orange','black')
      
      
      
    
    wave=1
    bg=(R(0,255),R(0,255),R(0,255))

    fill_rect(0,0,322,222,bg)
    ground_c=(R(0,255),R(0,255),R(0,255))
    ground_y=R(100,220)

    px=15
    py=ground_y-ph
    energy+=5
    
    ex=R(450,500)
    ey=R(80,150)

    ec=(R(0,255),R(0,255),R(0,255))
    ew=R(10,25)
    eh=R(10,25)
    poisonx=R(50,250)
    poisony=ground_y-1


    

    
  if jump>15:
    jump=15  
  
  
  
  
  
  if px+pw>=ex and px<=ex+ew and py+ph>=ey and py<=ey+eh:
    sleep(0.051)
    fill_rect(px,py,pw,ph,(255,0,0))
    fill_rect(0,0,100,20,(0,0,0))
    energy-=0.5
    
  if px+pw>=poisonx and px<=poisonx+poisonw and py+ph>=poisony and py<=poisony+poisonh:
    
    fill_rect(px,py,pw,ph,(255,0,0))

    energy-=1.2


    
    




  
  if energy<=0:
    sleep(1)
    fill_rect(px,py,pw,ph,(R(0,255),0,0))
    GAME=False
  
      
    
    sleep(1)
    GAME=False

    
  fill_rect(poisonx,poisony,poisonw,poisonh,poisonc)
  fill_rect(poisonx+2,poisony+2,2,2,(250,0,0))

  
  if poisonx>px:
    poisonx-=R(-1,1)
    fill_rect(poisonx+poisonw,poisony,1,poisonh,bg)

  
  if poisonx<px:
    poisonx+=R(-1,1)
    fill_rect(poisonx-1,poisony,1,poisonh,bg)

  
  if poisony>py:
    poisony-=R(-1,1)
  
  if poisony<py:
    poisony+=R(-1,1)
    
    
    
    
  poisonx-=choice([0,1,2,3,4,5])

  if poisonx+poisonw<0-R(10,20):
    poisonx=R(400,600)
    poisony=R(py-poisonh,py+ph)    
    
    
    
  
  update()

  
line_c=(R(0,200),R(0,200),R(0,200))
fill_rect(0,0,322,222,(0,0,0))
fill_rect(0,60,322,2,line_c)

fill_rect(0,190,322,2,line_c)
draw_string("GAME OVER",100,100,(R(100,255),R(0,255),R(100,255)),(0,0,0))

draw_string("SCORE: "+str(score),100,140,(R(100,255),R(100,255),R(100,255)),(0,0,0))

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.