agentx3150.py

Created by wperez274

Created on September 06, 2023

8.94 KB

side scroll game. avoid getting hit or hurting your foot on the messed up concrete groung. shoot enemies.


from math import *
from random import *
from random import randint as RAND
from kandinsky import *
from kandinsky import fill_rect as F
from ion import *
from time import *

F(0,0,322,222,(0,0,0))
intro="""
You work for the US Secret 
Emergency Response Force,
a small group of elite,
highly trained individuals,
who's mission is to protect...
                              

*[BACKSPACE] = Shoot
*[Toolbox] = Menu, Pause                            
*[Arrows] = MOVE,

"""


mx=0
my=160



while my>-80 and not keydown(KEY_OK) and not keydown(KEY_EXE):
  sleep(0.01)    
  my-=RAND(0,1)
      
  draw_string(str(intro),mx,my,'orange',(0,0,0))
  if my<-80:
    my=-80


sleep(1)

while not keydown(KEY_OK):
  draw_string("          PRESS [OK]          ",0,170,(0,0,0),(0,255,255))


MAPX=0
MAPY=0

bg=(255,)*3
    

x=MAPX+50
y=MAPY+100

F(0,0,322,222,bg)  



shoot=True


rx=RAND(550,1000)
ry=RAND(20,180)
rw=20
rh=15
rc=(RAND(0,255),RAND(0,255),RAND(0,255))


box_x=RAND(850,1500)
box_y=60
box_w=RAND(40,100)
box_h=-80
box_c=choice(['blue','red',
'green','yellow','brown','black',
'white','pink','orange',
'purple','gray',(0,255,255)
])

door_x=RAND(1000,1200)
door_y=RAND(60,100)
door_w=RAND(200,600)
door_h=-220
door_c=(RAND(0,255),RAND(0,255),RAND(0,255))

level=1

score=0
ammo=40
energy=30



refill_x=x+RAND(-60,60)
refill_y=-300
refill_w=15
refill_h=10
refill_c=(220,220,220)



pothole_x=RAND(300,500)
pothole_y=RAND(70,150)

pothole_w=RAND(20,35)
pothole_h=RAND(10,15)

pothole_c=(25,14,20)

drones=RAND(10,20)

inroom=False


coffee_x=RAND(20,300)
coffee_y=RAND(-300,-100)


lightsout=False
lights_timer=0


while energy>0:
  coffee_y+=1
  
  
  F(coffee_x, coffee_y-1,14,1,bg)
  F(coffee_x+0, coffee_y+0, 14, 14, 'cyan')
  F(coffee_x+0,coffee_y+0, 14, 4, (37, 68, 68))
  F(coffee_x+3,coffee_y+6, 10, 6, (191, 76, 67))
 
  
  F(pothole_x,pothole_y,pothole_w,pothole_h,pothole_c)

  F(pothole_x+pothole_w+1,pothole_y,1,pothole_h,bg)

  F(pothole_x,pothole_y,pothole_w,4,(155,)*3)
  F(pothole_x+pothole_w-4,pothole_y,4,pothole_h,(155,)*3)

  F(pothole_x,pothole_y,1,pothole_h,(222,)*3)
  F(pothole_x+pothole_w-1,pothole_y,1,pothole_h,(222,)*3)
  F(pothole_x,pothole_y,pothole_w,1,(222,)*3)
  F(pothole_x,pothole_y+pothole_h-1,pothole_w,1,(222,)*3)

  

  F(refill_x,refill_y,refill_w,refill_h,refill_c)
  F(refill_x,refill_y-1,refill_w,1,bg)


  F(refill_x,refill_y,1,refill_h,(0,0,0))
  F(refill_x+refill_w-1,refill_y,1,refill_h,(0,0,0))
  F(refill_x,refill_y,refill_w,1,(0,0,0))
  F(refill_x,refill_y+refill_h-1,refill_w,1,(0,0,0))



  
  refill_y+=1
  
  if drones>0:
    F(rx,ry,rw,rh,rc)

    F(rx,ry,2,rh,(0,0,0))
    F(rx+rw-2,ry,2,rh,(0,0,0))
    F(rx,ry,rw,2,(0,0,0))
    F(rx,ry+rh-2,rw,2,(0,0,0))
    F(rx+rw+1,ry,3,rh,bg)
    rx-=3



  F(0,60,322,2,(0,0,0))


  F(x+0, y+18, 6, 26, (0,60,0))
  F(x+6, y+3, 6, 66, (0,30,0))

  F(x+6, y+0, 14, 16, (0,30,0))


  F(x+6, y+69, 12, 6, (15,20,30))
  F(x+12, y+3, 8, 10, (220,220,220))


  
  
    
  if keydown(KEY_LEFT):
    F(x,y,20,80,bg)
    x-=4

    
  if keydown(KEY_RIGHT):
    F(x,y,20,80,bg)
    F(box_x+box_w+1,box_y,3,box_h,bg)
    F(pothole_x+pothole_w+1,pothole_y,3,pothole_h,bg)

    x+=4
    if door_x>50:
      if x>200:
        box_x-=2
        refill_x-=2
        pothole_x-=2
        door_x-=2
  

  if keydown(KEY_UP):
    F(x,y,20,80,bg)
    y-=4

  if keydown(KEY_DOWN):
    F(x,y,20,80,bg)
    y+=4
    
    
    
  if y<-12:
    y=-12
  
  if y>200:
    y=200

  if x<0:
    x=0
    
  if x>200:
    x=200





  if keydown(KEY_BACKSPACE):

    F(x+9, y+21, 30,5,(85,95,62))
    F(x+40, y+21, 15,6,(0,0,0))
    sleep(0.005)
    F(x+9, y+21, 30,5,bg)
    F(x+40, y+21, 15,6,bg)


    if ammo>0:
      shoot=True
      F(x+49,y+22,322-x+9,3,(RAND(0,255),RAND(0,255),RAND(0,255)))
      sleep(0.025)
      F(x+49,y+22,322-x+9,3,bg)
  else:
    shoot=False
    

  
  
  if rx<-40:
    rx=RAND(500,700)
    ry=RAND(50,180)
    rw=RAND(12,28)
    rh=RAND(15,25)
    
    
    rc=(RAND(0,255),RAND(0,255),RAND(0,255))
    F(0,0,3,222,(255,0,0))
    F(318,0,3,222,(255,0,0))

    sleep(0.1)
    F(0,0,322,222,bg)
    energy-=2
    
    
  

  if pothole_x<-100:
    pothole_x=RAND(500,700)
    pothole_y=choice([RAND(70,180),y+105+RAND(-10,10)])

    pothole_w=RAND(20,55)
    pothole_h=RAND(10,18)


        


  
  if keydown(KEY_BACKSPACE):
    ammo-=0.5
    
    if ammo>0 and ry+rh>y+20 and ry<y+27 and rx>x+40:
     

      for i in range(rx,rx+rw,RAND(2,6)):
        F(i,ry+RAND(-20,20),RAND(2,5),RAND(2,5),(0,0,0))
      sleep(0.04)
      F(rx-20,ry-20,rw+40,rh+40,bg)  
      
      rx=RAND(500,700)
      ry=RAND(10,200)
      rw=RAND(20,30)
      rh=RAND(10,30)
      rc=(RAND(0,255),RAND(0,255),RAND(0,255))
      score+=RAND(25,50)
      energy+=2
      drones-=1
      
  F(box_x,box_y,box_w,box_h,box_c)
  F(box_x+box_w+1,box_y,2,box_h,bg)


  F(box_x,box_y,1,box_h,(0,0,0))
  F(box_x+box_w-3,box_y,3,box_h,(0,0,0))
  F(box_x,box_y,box_w,1,(0,0,0))
  F(box_x,box_y+box_h-2,box_w,2,(0,0,0))





  if box_x+box_w<-100:
    box_x=RAND(350,500)
    box_c=choice(['blue','red',
    'green','yellow','brown','black',
    'white','pink','orange',
    'purple','gray',(0,255,255)
    ])



    

  if refill_y+refill_h>180:
    refill_y=180-refill_h

  

  if refill_x<-RAND(100,200):
    refill_x=x+RAND(-60,60)
    refill_y=-RAND(150,500)




  if keydown(KEY_TOOLBOX):
    F(0,0,322,222,(197, 130, 7))
    F(12, 14, 300, 196, 'black')
    F(18, 20, 288, 184, (192, 249, 149))  

    while not keydown(KEY_OK):
      draw_string("Level:"+str(level),50,30,(0,255,255),(0,0,0))
    
      draw_string("Energy:"+str(int(energy)),50,60,(0,255,0),(0,0,0))
      draw_string("Drones:"+str(drones),50,90,(255,200,200),(0,0,0))
  
      draw_string("Ammo:"+str(int(ammo)),50,120,(0,0,0),'gray')

      draw_string("EXIT:"+str(door_x),50,150,(0,0,0),(255,255,0))


      draw_string("PRESS OK",60,180,(0,RAND(0,255),0),(0,0,0))
    
    F(0,0,322,222,bg)



  if x+6+8>refill_x and x+6<refill_x+refill_w and y+75>refill_y and y+75<refill_y+refill_h:
    sleep(0.2)
    F(refill_x,refill_y,refill_w,refill_h,bg)
    refill_x=RAND(20,300)
    refill_y=RAND(-500,-300)
    ammo+=20
    energy+=2

  if x+6+8>coffee_x and x+6<coffee_x+14 and y+75>coffee_y and y+75<coffee_y+14:
    sleep(0.2)
    F(coffee_x,coffee_y,14,14,bg)
    coffee_x=RAND(20,300)
    coffee_y=RAND(-1500,-1000)

    energy+=5


    
  if x+6+8>pothole_x and x+6<pothole_x+pothole_w and y+75>pothole_y and y+75<pothole_y+pothole_h:
    F(x+6,y,6,75,(255,0,0))
    sleep(0.021)
    energy-=0.5



    
    
    
    
    
  if ammo<0:
    ammo=0




  if x+6+6>rx and x<rx+rw and y+75>ry and y<ry+rh:
    F(x+6,y,6,75,(255,0,0))
    sleep(0.021)
    energy-=0.75
   



  F(door_x,door_y,door_w,door_h,door_c)    

  F(door_x+30,door_y,40,-120,'black')


  F(door_x,door_y,2,door_h,(0,0,0))
  F(door_x+door_w-2,door_y,2,door_h,(0,0,0))
  F(door_x,door_y,door_w,2,(0,0,0))
  F(door_x,door_y+door_h-2,door_w,2,(0,0,0))


  if door_x<50:
    door_x=50
    
  if door_x<250 and drones<1:
    rx=0
    ry=-50
    refill_x=0
    refill_y=-100
    
    
        
  if door_x<150 and drones<1:
    sleep(2)


    F(0, 0, 322, 222, (0, 68, 107))
    F(12, 15, 296, 196, 'white')
    
    
    while not keydown(KEY_OK):
      draw_string("MISSION COMPLETED!!",80,60)
      draw_string("PRESS [OK]",100,160)
    
    bg=(RAND(0,255),RAND(0,255),RAND(0,255))

    
    F(0,0,322,222,bg)
    door_x=RAND(1500,2000)
    rx=RAND(800,1000)
    ry=RAND(20,180)
    x=40
    y=50
    energy+=20
    coffee_y=-500
    level+=1
    drones=RAND(12,20)+2*level
    
    
    
  if keydown(KEY_BACKSPACE):
    ry-=choice([-3,-2,-1,0,1,2,3])


 
  if door_x>150:
    box_x-=1
    pothole_x-=1





  if drones<1:
    refill_y=-100



  F(rx+4,ry+4,8,5,choice(['red','cyan']))


  F(refill_x,refill_y,refill_w,refill_h,(RAND(0,255),RAND(0,255),RAND(0,255)))




  F(rx+10,ry+52,rw,2,(0,0,0))

  F(rx+10+rw+1,ry+52,rw,2,bg)

  F(rx+10,ry+49,rw,2,bg)
  F(rx+10,ry+53,rw,2,bg)



  F(0,0,116, 28, 'black')
  F(3, 3, 108, 20, (240,)*3)
  draw_string("AMMO:",3,4,(0,255,0),(0,0,0))
  F(60,6,int(ammo/2),12,(0,200,200))


  F(200,0,116, 28, 'black')
  F(203, 3, 108, 20, (240,)*3)
  draw_string("Energy:",205,4,(255,)*3,(0,0,0))
  F(280,6,int(energy/2),12,(255,0,0))




  if ammo>90:

    ammo=90

  if drones<1:
    ry=-100
    
  if drones>0:  
    if ry>y and ry<y+60:
      rx-=RAND(2,3)
      F(rx+rw+1,ry,5,rh,bg)
      
    if rx-x<100 and ry<y:
      F(rx,ry-2,rw+2,2,bg)
      ry+=2

    if rx-x<100 and ry>y+60:
      F(rx,ry+rh+2,rw+2,2,bg)
      ry-=2
    
    


  if coffee_y+14>90:
    F(coffee_x,coffee_y+12,14,2,(0,0,0))

    coffee_y=90-14

  if keydown(KEY_RIGHT):
    coffee_x-=2
    F(coffee_x+14+1,coffee_y,2,14,bg)

  if coffee_x<-25:
    coffee_x=RAND(100,300)
    coffee_y=RAND(-1800,-1500)
    

    


  if drones<1:
    bg=(0,0,0)
    F(0,0,322,222,bg)






 
sleep(1)
F(0,0,322,222,(0,0,0))
sleep(1)

draw_string("GAME OVER",100,100,'orange',(0,0,0))
sleep(1.5)
draw_string("Score:     ",100,150,'white',(0,0,0))
sleep(1)
draw_string(str(score),165,150,(0,255,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.