anti_tank.py

Created by wperez274

Created on February 01, 2023

4.18 KB

potential game


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

game=True

player_is_hit=False

night_vision_on=False

tank_x=0
tank_w=30
tank_h=20
tank_y=0
tank_c=(20,20,30)


e_dead=False

e_sees_player=False

e_shoots=False
e_hides=False
e_energy=5
e_dir=CH(["still","left","right"])
e_x=R(20,300)
e_w=R(2,6)
e_h=R(7,10)
e_y=100-e_h
e_c=CH(['red','green',
'yellow','brown','black',
'white','pink','orange',
'purple','gray'])




bg="black"

score=0
x=155
y=175
spr="+"

ammo=25
health=20

target_locked=False


sky=(0,0,140)


F(0,0,322,100,sky)
F(0,100,322,1,(120,0,0))
F(0,100,322,222,"black")


for i in range(0,322,R(8,25)):
  
  F(i,R(0,40),1,1,CH(["white","red","blue","orange"]))


while health>0:
  F(tank_x,tank_y,tank_w,tank_h,tank_c)

  F(tank_x,tank_y,1,tank_h,"green")
  F(tank_x+tank_w-1,tank_y,1,tank_h,"green")
  F(tank_x,tank_y,tank_w,1,"green")
  F(tank_x,tank_y+tank_h-1,tank_w,1,"green")
  F(e_x,e_y,e_w,e_h,e_c)
  F(e_x,e_y,1,e_h,"gray")
  F(e_x+e_w-1,e_y,1,e_h,"gray")
  F(e_x,e_y,e_w,1,"gray")
  F(e_x,e_y+e_h-1,e_w,1,"gray")
  
  F(0,100,322,1,(0,120,0))
  
  if target_locked==False:
    draw_string(spr,x,y,"cyan",bg)
  
  if target_locked:
    draw_string(spr,x,y,"red",bg)
  
  
  if keydown(KEY_LEFT):
    x-=2
  if keydown(KEY_RIGHT):
    x+=2
  if keydown(KEY_UP):
    y-=1
  if keydown(KEY_DOWN):
    y+=1  
  
  if keydown(KEY_BACKSPACE):
    cl_1=(R(20,150),R(20,150),R(20,150))
    cl_2=(R(50,200),R(50,200),R(50,200))
    while not keydown(KEY_TOOLBOX):
      STR("PAUSED",110,150,cl_1,bg)
      STR("Press [VAR] to resume",50,180,cl_2,bg)

    STR("      ",110,150,bg,bg)
    STR("                     ",50,180,bg,bg)
  

  draw_string("AMMO:",4,204,"orange",bg)
  draw_string(str(round(ammo)),54,204,"white",bg)
  draw_string("HEALTH:",200,204,"cyan",bg)
  draw_string(str(health),270,204,"green",bg)

  if x<0:
    x=0  
  if x>310:
    x=310 
  if y<0:
    y=0  
  if y>190:
    y=190  

  if keydown(KEY_OK):
    STR(spr,x,y,(100,0,0),"black")
    sleep(0.02)
    STR(spr,x,y,bg,bg)
    x+=CH([-1,1])
    y+=CH([-1,1])
    ammo-=0.2
    e_dir=CH(["still","left","right"])
    e_shoots=R(0,1)



  if e_sees_player:
    e_c="red"
    e_dir=CH(["still","left","right"])
    e_shoots=CH([True,False])
    
  
  if e_shoots:
    player_is_hit=CH([0,0,0,1,0])
    
  if e_x<0:
    player_is_hit=CH([0,1])
    e_x=0
    e_dir=CH(["still","left","right"])

  if e_x>315:
    player_is_hit=CH([0,1])
    e_x=315
    e_dir=CH(["still","left","right"])



  if player_is_hit:
    F(0,0,3,222,"red")
    F(315,0,3,222,"red")
    F(0,0,322,3,"red")
    F(0,217,322,3,"red")
    sleep(0.02)
    F(0,0,3,222,bg)
    F(315,0,3,222,bg)
    F(0,0,322,3,bg)
    F(0,217,322,3,bg)
    health-=0.2
    e_sees_player=False

  player_is_hit=False
    
    
    
        
  if e_dir=="left":
    e_x-=1
    if e_y<=101:
      F(e_x+e_w+1,e_y,1,e_h,sky)
    if e_y>=101:
      F(e_x+e_w+1,e_y,1,e_h,"black")

    
    
  if e_dir=="right":
    e_x+=1
    if e_y<=101:
      F(e_x+e_w+1,e_y,1,e_h,sky)
    if e_y>=101:
      F(e_x+e_w+1,e_y,1,e_h,"black")



  if keydown(KEY_OK) and e_x+e_w>=x and e_x<=x+9 and e_y+e_h>=y and e_y<=y+15:
    e_energy-=0.2
    F(e_x,e_y,e_w,e_h,"red")
    health+=0.2
    score+=R(1,5)
    
    
  if e_energy<=0:
    e_dead=True
    
  if e_dead:
    e_energy=R(2,6)
    e_dir=CH(["still","left","right"])
    e_x=R(20,300)
    e_w=R(2,5)
    e_h=R(7,10)
    e_y=R(50,200)
    e_dead=False
    e_c=CH(['red','green','yellow','brown','black','white','pink','orange','purple','gray'])

  if e_y>=120 and e_y<=160:
    e_w=R(3,5)
    e_h=R(8,12)
    
  if e_y>=160:
    e_w=R(4,6)
    e_h=R(10,15)
    
        
    
    
    
    
    
    
    
  if keydown(KEY_EXE):
    night_vision_on=True        


  if night_vision_on:
    tank_y+=R(0,1)
    tank_w+=1
    tank_h-=1
    if tank_y>200:
      tank_y=200
    if tank_w>320:
      tank_w=320        
    
    
    
    
 
  STR("Enemy: "+str(e_energy),200,2,"green","black")
    

  



STR("GAME OVER",100,100,"red","black")
STR("SCORE: "+str(score),100,140,"white","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.