tron.py

Created by wperez274

Created on April 06, 2023

3.15 KB


import math 
from cmath import *
from kandinsky import *
from kandinsky import fill_rect as F
from random import *
from ion import *
from time import *



game=True

bg=(randint(0,255),randint(0,255),randint(0,255))


gravty=True
jump=False
fall_speed=1
jump_max=8
jump_time=0



px=20
py=20
pw=10
ph=16
pc="blue"
psc=0



rtimer=0

rdir=randint(1,4)


rx=200
ry=100
rw=randint(10,30)
rh=5
rc="black"

laser_c="red"


door_x=randint(10,300)
door_y=randint(10,170)
door_w=12
door_h=19
door_c=(randint(0,255),randint(0,255),randint(0,255))

key_x=randint(10,300)
key_y=randint(10,170)
key_w=6
key_h=12
key_c="yellow"


rect_x=randint(10,200)
rect_y=randint(10,150)
rect_w=20
rect_h=50
rect_c="black"

fill_rect(0,0,322,222,bg)

while game:
  
  psc+=0.03
  gravty=True

  rtimer+=0.1

  F(px,py,pw,ph,pc)
  F(px,py-1,pw,1,bg)
  
  F(px,py,1,ph,"white")
  F(px+pw-1,py,1,ph,"white")
  F(px,py,pw,1,"white")
  F(px,py+ph,pw,1,"white")

  
  F(key_x,key_y,key_w,key_h,key_c)
    
  F(key_x,key_y,1,key_h,"blue")
  F(key_x+key_w-1,key_y,1,key_h,"blue")
  F(key_x,key_y,key_w,1,"blue")
  F(key_x,key_y+key_h-1,key_w,1,"blue")
  
  
  
  F(rx,0,2,222,laser_c)
  F(rx+rw-2,0,2,222,laser_c)
  
  F(0,ry,322,2,"purple")
  F(0,ry+rh-2,322,2,"white")
  
    
  F(rx,ry,rw,rh,rc)
  
  F(rx,ry,2,rh,"red")
  F(rx+rw-2,ry,2,rh,"red")
  F(rx,ry,rw,2,"red")
  F(rx,ry+rh-2,rw,2,"red")
  
  
  if rdir==1:
    rx-=choice([1,2])
    F(rx+rw,0,2,222,bg)
  
  if rdir==2:
    rx+=choice([1,2])
    F(rx-2,0,2,222,bg)
  
    
  if rdir==3:
    ry-=choice([0,1])
    F(0,ry+rh,322,2,bg)
  
  if rdir==4:
    ry+=choice([0,1])
    
    F(0,ry-2,322,2,bg)
  
  
  if rx<20:
    rx=20
    
  if rx>300:
    rx=300
    
  if ry<0:
    ry=222
    
  if ry>222:
    ry=0
    
  if keydown(KEY_LEFT):
    px-=1
    F(px+pw,py,2,ph,bg)
  
  if keydown(KEY_RIGHT):
    px+=1
    F(px-1,py,1,ph,bg)
  
  if keydown(KEY_UP):
    jump_time+=0.4
    py-=1
    F(px,py+ph+1,pw,1,bg)
  
  if keydown(KEY_BACKSPACE):
    jump=True
    
  if jump and jump_time<jump_max:    
      jump_time+=0.5
      py-=2
      px+=1
      fill_rect(px,py-1,pw,1,bg)
      if jump_time>=jump_max:
        
        jump=False
    
        
    
    
  F(0,0,3,222,"black")
  F(318,0,3,222,"black")
  F(0,0,322,2,"black")
  F(0,219,322,2,"black")

  if px+pw<0:px=322  

  if px>322:px=0  
  
  
  if py+ph>ry:
    py=ry-ph
    
    jump_time=0
    jump=False

  
  if gravty:  
    py+=choice([0,1])
    
  
  if rtimer>randint(8,14):
    rtimer=0
    rdir=randint(1,4)


  if px+pw==rx or px==rx+rw:
    game=False
    

  F(door_x,door_y,door_w,door_h,"black")    
  
  F(door_x,door_y,2,door_h,"cyan")    
  F(door_x+door_w-2,door_y,2,door_h,"cyan")    
  F(door_x,door_y,door_w,2,"cyan")    
  F(door_x,door_y+door_h-2,door_w,2,"cyan")    
  
  F(0,door_y+door_h,322,5,"black")    
  F(0,door_y-2,322,2,"black")    
  



  draw_string(str(bg),100,200)

      
#game over

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

F(0,0,3,222,"cyan")
F(318,0,3,222,"cyan")
F(0,0,322,4,"cyan")
F(0,218,322,4,"cyan")


  
draw_string("GAME OVER",100,90,"red","black")      
sleep(1)
draw_string("SCORE:",100,140,"white","black")
sleep(1.1)
draw_string(str(round(psc)),170,140,"cyan","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.