chute_v2.py

Created by wperez274

Created on August 16, 2022

17.4 KB

i just edited this game. i added some cool features. original author: https://my.numworks.com/python/antarctus


# Edited by:
#  Wilson.
from kandinsky import *
from kandinsky import fill_rect as F
from ion import *
from time import *
from random import *
from random import randint as R

sleep(0.2)
def draw_home_screen():
  clone_x=R(10,35)
  clone_y=170
  F(0,0,322,222,"black")
  while not keydown(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,"blue")
    F(clone_x+5,clone_y+5,12,8,"gray")
    draw_string("Chute 2",100,34,"black","yellow")
    draw_string("keys [left]/[Right] = Move",25,70,"white","black")
    draw_string("key [Backspace] = Jump",30,90,"yellow","black")
    draw_string("key [Toolbox] = Shoot",40,110,"gray","black")
    draw_string("key [VAR] = Pause",60,130,"cyan","black")
    draw_string("(Press [OK] to Start)",90,160,(R(200,255),0,0),"black")

def print_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,"cyan")
  sleep(0.8)
  draw_string(text[0],10,30,"black","cyan")
  sleep(0.75)
  draw_string(text[1],10,50,"black","cyan")
  sleep(0.7)
  draw_string(text[2],10,70,"black","cyan")
  sleep(0.65)
  draw_string(text[3],10,90,"black","cyan")
  sleep(0.6)
  draw_string(text[4],10,110,"black","cyan")
  sleep(0.6)
  draw_string(text[5],10,130,"black","cyan")
  sleep(2)
  
  while not keydown(KEY_OK):
    draw_string("Press [OK] to Start",50,180)
    
draw_home_screen()
sleep(0.2)
print_intro()

time=9
time_2=1
lives=3
score=0
energy=30
shield_on=False
shield_time=5
shield_x=R(2,310)
shield_y=R(-20,0)
shield_w=16
shield_h=16
shield_c=(R(0,255),R(0,255),R(0,255))
food_x=R(2,315)
food_y=R(-100,-50)
food_w=9
food_h=16
food_c=(R(0,255),R(0,255),R(0,255))

lava_y=210
#dark red
lava_c=(150,0,0)

rect_x=300
rect_y=R(20,200)
rect_w=R(20,50)
rect_h=R(4,10)

rect_c=(R(0,255),R(0,255),R(0,255))

#background
backColor=choice([
"black","white",(135,24,20),
(randint(0,255),R(0,255),randint(0,255))
])

def game_over_draw():
  F(0,0,322,222,"black")
  for x in range(0,322,14):
    for y in range(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")
  while not keydown(KEY_OK):
    draw_string("GAME OVER",100,100,"white","black")
    draw_string("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=False
level=0

class Entity():
  def __init__(self,x,y,width,height,speed,ma=True):
    self.x=x
    self.y=y
    self.width=width
    self.height=height
    self.speed=speed
    self.move_alone=ma
    self.chute=0
    self.gx=self.x+int(self.width/2)
    self.gy=self.y+self.height
    self.dead=False
    self.drawing=[]
    self.shooting=None

  def set_drawing_inverse(self):
    self.drawing_inverse=[None,]*len(self.drawing)
    for i in range(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]]

  def contact(self,x1,y1,x2,y2):
    if self.x<=x1<=self.x+self.width or self.x<=x2<=self.x+self.width:
      if self.y<=y1<=self.y+self.height or self.y<=y2<=self.y+self.height:
        return True
    return False

  def step(self):
    x=self.x
    y=self.y
    self.move()
    if self.x!=x or self.y!=y or len(shoot):
      fill_rect(x,y,20,30,backColor)
      self.draw()
    if is_shooting:
      draw_shoot((0,)*3)
#assign global variables..
  def move(self):
    global level,energy,lives
    if is_shooting: draw_shoot(backColor)
    if self.chute:
      if self.chute>0:
        if self.tomber():
          self.y+=self.chute
          self.chute+=1
        else:
          self.y=plateforms[self.get_plateform()][1]-self.height

#player dies
        if self.y+self.height>lava_y+4 or time_2<=0:
          self.dead=True
          lives-=1
#6 spaces for this else          
      else:
        self.y+=self.chute
        self.chute+=1

    if self.move_alone:
      self.x+=self.speed
      if self.tomber():
        self.speed*=-1
        self.x+=self.speed
    else:
      x=(keydown(3)-keydown(0))

      if x:
        self.speed=abs(self.speed)*x
        self.x+=self.speed
# Jump
      if keydown(KEY_BACKSPACE) and not self.tomber():
        self.y=plateforms[self.get_plateform()][1]-self.height
# I guess jump velicity
# and height of jump..
        self.chute=-10
      if (not self.tomber()):
        if self.contact(points[1][0],points[1][1],points[1][0]+20,points[0][1]+5):
          level+=1
          self.dead=True
          
    if self.tomber() and self.chute==0:
      self.chute=1
  def tomber(self):
    self.gx=self.x+int(self.width/2)
    self.gy=self.y+self.height
    for i in plateforms:
      if self.gy<=i[1]<=self.gy+self.chute:
        if i[0]<=self.gx<=i[0]+i[2]:
          return False
    return True

  def get_plateform(self):
    if not self.tomber():
      for i in plateforms:
        if self.gy<=i[1]<=self.gy+self.chute:
          if i[0]<=self.gx<=i[0]+i[2]:
            return plateforms.index(i)

  def draw(self):
    if self.speed<=0:
      for i in self.drawing:
        fill_rect(self.x+i[0],self.y+i[1],i[2],i[3],i[4])
    else:
      for i in self.drawing_inverse:
        fill_rect(self.x+i[0],self.y+i[1],i[2],i[3],i[4])

#Plateforms    
def draw_all_plateforms(color):
  for i in plateforms:
    fill_rect(i[0],i[1],i[2],i[3],color)

#Entites
def draw_all_entities():
  for i in entities:
    i.move()
    i.draw()

#Shoot
is_shooting=None
shooting_direction=1
shoot=[]
shooting_list=[]

for i in range(20):
  shooting_list+=[[int((15**2-(i-10)**2)**0.5),i-10],]

def get_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..
def draw_shoot(color):
  shoot_color="cyan"
  c=get_shoot(avatar,is_shooting)
  fill_rect(c[0]+c[2]*2-5,c[1]+c[3]*2-2,9,9,color)
#Screen when died or
#when complete level
def new_area_screen():
  F(0,0,322,222,"black")
  while not keydown(KEY_OK):
    draw_string("Life: "+str(round(lives)),60,60,"gray","black")
    draw_string("Press [OK] to conitue",70,120,"white","black")
  
#////////////////////////  
def death_animation():
  F(0,0,322,222,"black")
  for x in range(0,322,16):
    for y in range(0,222,5):
      sleep(0.0006)
      F(x,y,15,4,choice(["white","black"]))
  
  F(0,70,322,110,"black")
  while not keydown(KEY_OK):
    draw_string("Life: "+str(round(lives)),100,90,"gray","black")
    draw_string("Press [OK] to conitue",70,120,"white","black")
  
#///////////////
#points

points=[]

def draw_all_points():
  fill_rect(points[0][0],points[0][1]-5,20,5,(R(0,255),R(0,255),R(0,255)))
  fill_rect(points[1][0],points[1][1]-5,20,5,(100,100,255))


#Spawn

maps=[
# Below:
# 10 = portal on the left (start position).
# 200 = portal on the right (goal).
# [spawn/end,monsters,plateforms(,txt)]
  [    
    [[10,200],[290,200]],
    [],
    [
      [10,200,300,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! ]**"
  ]
]

def spawn(level):
  global avatar,entities,plateforms,shoot,points,txt,game
  fill_rect(0,0,320,222,backColor)
  shoot=[]
  if level==len(maps):
    game=False
    return
  map=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,"blue"),
  (0,3,12,10,"cyan"),
  ]
  avatar.set_drawing_inverse()
  entities=[avatar,]
  for i in map[1]:
    enemy_c=choice(["white",
    "black","red","yellow",
    "purple","orange","pink",
    "blue","green","magenta",
    (29,69,38),(48,94,89),
    (41,241,65),(34,26,147),
    (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,32)
    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",
    "pink","gray","red","orange",
    (14,25,137),(25,64,158),(210,201,236),
    (225,214,240),(145,25,219),(125,25,41),
    (120,0,0),(R(0,255),R(0,255),R(0,255))
    ])),
    ]
    entities[-1].set_drawing_inverse()

  if len(map)==4:
    draw_string(map[3],20,20,(150,)*3,backColor)


  avatar.draw()

spawn(level)

time_start=monotonic()

game=True

#main
while game:
  
  
  lava_c=choice([(120,0,0),
  (70,0,0),(100,0,0)
  ])
  
  fill_rect(0,lava_y,322,20,lava_c)


  if avatar.dead:
    death_animation()
    spawn(level)


  for i in range(len(entities)-1,0,-1):
    for j in range(len(shoot)-1,-1,-1):
      if entities[i].contact(shoot[j][0]-5,shoot[j][1]-5,shoot[j][0]+5,shoot[j][1]+5):
        fill_rect(entities[i].x,entities[i].y,20,30,backColor)
        fill_rect(shoot[j][0]-5,shoot[j][1]-5,10,10,backColor)
        del entities[i]
        del shoot[j]
        break

  if keydown(KEY_TOOLBOX) or is_shooting!=None:
    if keydown(KEY_TOOLBOX):
      if is_shooting==None:
        is_shooting=1

      draw_shoot(backColor)

      is_shooting+=shooting_direction

      if is_shooting==len(shooting_list)-1 or is_shooting==0:
        shooting_direction*=-1

    elif is_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=None

  for i in entities:
    i.step()

  if not trainee:
    for i in shoot:
      fill_rect(i[0]-5,i[1]-5,10,10,backColor)

  for i in range(len(shoot)-1,-1,-1):
    shoot[i][0]+=shoot[i][2]
    shoot[i][1]+=shoot[i][3]
    shoot[i][3]+=1
    if shoot[i][1]>222:
      del shoot[i]
      continue
    fill_rect(shoot[i][0]-5,shoot[i][1]-5,10,10,shoot_color)

#player collides into
#enemies and losses life.
  for i in entities[1:]:
    if i.contact(avatar.x,avatar.y,avatar.x+avatar.width,avatar.y+avatar.height) and shield_on==False:
      avatar.dead=True


#//////MY EDIT/////#//////#///
  draw_string("Time: "+str(time),0,0,"black","cyan")      
  draw_string("Energy: "+str(round(energy)),110,0,"black","orange")      
  draw_string("Life: "+str(round(lives)),240,0,"black","yellow")      
  
#avatar=player
#use the dot to 
#access x,y,width,height
# Player losses energy fast
# when hit with rectangles. 
  if avatar.x+avatar.width>rect_x and avatar.x<rect_x+rect_w and avatar.y+avatar.height>rect_y and avatar.y<rect_y+rect_h and shield_on==False:
    F(avatar.x,avatar.y,avatar.width,avatar.height,"red")
    energy-=2
    avatar.x-=5

#player avatar gets invisible
#shield or cloak
#for a few seconds
#Can jump higher!

  if avatar.x+avatar.width>food_x and avatar.x<food_x+food_w and avatar.y+avatar.height>food_y and avatar.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.5
    score+=R(50,100)      


  if avatar.x+avatar.width>shield_x and avatar.x<shield_x+shield_w and avatar.y+avatar.height>shield_y and avatar.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)
    while not keydown(KEY_OK):
      draw_string("Press [UP]+[Backspace]",20,50,"black","cyan")
      draw_string("to Super Jump!!",20,70,"black","cyan")
      draw_string("(Press [OK] to continue)",70,100,"black","yellow")
    
    draw_string("                       ",20,50,backColor,backColor)
    draw_string("               ",20,70,backColor,backColor)
    draw_string("                          ",70,100,backColor,backColor)
    sleep(0.3)
#:-)    
    time+=2
    lives+=0.5
    score+=R(100,200)
    shield_on=True
    shield_y=R(-3000,-2000)
    shield_x=R(2,300)
    shield_c=(R(0,255),R(0,255),R(0,255))
    
  if shield_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)))

    draw_string("Shield:"+str(round(shield_time)),110,20,"black",(235,240,220))
    shield_time-=0.04
    
  if shield_time<=0:
    shield_time=5
    shield_on=False
    draw_string("          ",110,20,backColor,backColor)

    
  if energy<=0:
    lives-=1
    energy=25
    
# simple Pause/Resume code
  if keydown(KEY_VAR):
    while not keydown(KEY_OK):
      draw_string("( PAUSE )",120,60,"black","cyan")  
      draw_string("(PRESS [OK] KEY TO RESUME)",20,90,"black","yellow")  
    draw_string("          ",120,60,backColor,backColor)  
    draw_string("                               ",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
  if shield_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+=3

  if food_y+food_h>=lava_y:
#    food_y=lava_y-food_h
    food_y-=2
    food_c=(R(100,255),0,0)

  if food_y>222:
    food_y=R(-1200,-1000)
    food_x=R(2,310)
    
  
  rect_x-=7

  shield_y+=4


  if shield_y+shield_h>=lava_y:
   # shield_y=lava_y-shield_h
    shield_y-=1
    
  if shield_y>222:
    shield_y=R(-1000,-800)
    shield_x=R(2,300)
    shield_c=(R(0,255),R(0,255),R(0,255))
    
        
  if rect_x+rect_w<0-R(5,10):
    rect_x=R(400,600)
    rect_y=R(10,210)
    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_2-=0.009
  
  if time_2<0 or time_2==9:
    time_2=1
    time-=1
    F(0,0,92,18,backColor)

#time = time for player
#to complete a series of areas.
#Good luck!
    
  if time<=0 or lives<=0:
    game_over_draw()
    game=False
      
#if the player does not
#press certain keys

#  if not keydown(KEY_LEFT):
#    pass
#*************************
# SUPER / Double Jump when 
# shield is activated.        
  if keydown(KEY_UP) and shield_on:
    avatar.y-=4
#**************************


  shoot_color=(R(0,255),R(0,255),R(0,255))
  draw_all_points()
  draw_all_plateforms(plateforms_color)

#this is the speed of
#everything 
#The lower the value,
#the faster the loop
  sleep(0.04)  

if time<=0:
  print("****************************")
  print("\nYou ran out of time.\n")
if lives<=0:
  print("\nYou ran out of chances.\n")
if score<200:
  print("****************************")
  print("\nYou need practice.\n")

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.