tron_v2.py

Created by wperez274

Created on September 01, 2022

8.41 KB

original by some smart dude..


#"Tron", Version 2
#Original By: some dude..
#Edited By: Wilson
#Email: wilsony175@gmail.com

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

game=True
level=1
#text_x=0
#text_y=200
#default
slow=100
medium=200
fast=500
speed=medium

distance_required=3000/(level**(1/7))
score=0
life=3
travel=0
total_travel=0
bg=(R(0,40),R(0,40),R(0,40))

#home screen
F(0,0,322,222,bg)
F(0,0,322,35,"blue")

while not keydown(KEY_OK) and not keydown(KEY_EXE):
  F(0,0,322,4,"cyan")
  draw_string("TRON V.2",100,10,"cyan","black")
  F(0,34,322,5,"cyan")
  draw_string("[TOOLBOX] = PAUSE",55,70,"orange",bg)
  draw_string("[LEFT],[RIGHT] = TURN",40,100,"white",bg)
  draw_string("[BACKSPACE] = SLOW DOWN",40,130,choice(["cyan","white",bg]),bg)
  draw_string("(  Press [OK] to Start  )",25,180,"white",bg)
#DONT CHANGE THIS "FOND" VALUE.
#///////////////////////////
FOND = (40,48,64)

class moto:
    dir = [[0,1],[1,0],[0,-1],[-1,0]]
    def __init__(self, nom, x, y, d, coul, ga, dr):
        self.nom = nom
        self.pos = [x, y]
        self.x=x
        self.y=y
        self.d = d
        self.coul = coul
        self.gauche = ga
        self.droite = dr
        self.tps = monotonic()
        self.fin=False
        
    def tourne(self, t):
      if monotonic() - self.tps > 0.3:
        self.tps = monotonic()
        self.d = (self.d + t) % 4

    def maj(self):
      global pdir,life,score,travel,player_dir
            
      if keydown(KEY_LEFT) or keydown(KEY_UP): 
        self.tourne(1)
        score+=R(1,2) 
      
      if keydown(KEY_RIGHT) or keydown(KEY_DOWN):
        self.tourne(-1)
        score+=R(1,2) 
      
      [x, y] = self.pos
      [dx, dy] = self.dir[self.d]
      self.pos = [x + dx, y + dy]
      [x, y] = self.pos

      if get_pixel(x, y) != FOND and life>=1:
        fill_rect(0,0,322,222,"black")
        life-=1
        while not keydown(KEY_OK) and not keydown(KEY_RIGHT):
          
          draw_string("You Crashed.",90,40,"white","black")
          F(0,90,322,2,"red")
          draw_string("Lives left = "+str(life),70,100,"cyan","black")
          F(0,125,322,2,"red")
          
          draw_string("Press [OK]/[RIGHT] to continue",5,200,"black",(200,255,255))
          
        draw_string("             ",100,100,FOND,FOND)
        draw_string("                              ",0,200,FOND,FOND)
        
        F(0,0,322,20,FOND)
        DrawBorder()
        travel=0
        
        speed=medium
        go()
        
      if life<=0:
        self.fin=True
        game=False
        
      else:  
        F(x,y,1,1,self.coul)
        
#the "*3" is just to
#make the border thicker.

b_c=(R(0,255),R(0,255),R(0,255))

def DrawBorder():
  global level,b_c
#top
  F(0,19,322,level*2,b_c)
#bottom
  F(0,201-level*2,322,level*2,b_c)

def PrintData():
  draw_string(chr(36)+":"+str(score),2,0,(150,255,200),FOND)
  draw_string("Vel="+str(round(speed/10))+"%",240,0,"white",FOND)
  draw_string("Life:",4,202,"yellow","black")
  draw_string(str(life),63,202,"black","yellow")
  draw_string("Level:"+str(level),230,204,"white","purple")

rect_x=R(70,200)
rect_y=R(20,150)
rect_w=R(25,70)
rect_h=R(20,70)
rect_c=(R(0,255),R(0,255),R(0,255))

rect_2_x=R(70,200)
rect_2_y=R(20,180)
rect_2_w=round((distance_required-travel)/60)
rect_2_h=level*6
rect_2_c=choice(['blue','red',
'green','yellow','brown',
'black','white','pink',
'orange','purple',"cyan",(R(0,255),0,0)
])



def DrawRect():
  global b_c,rect_x,rect_y,rect_w,rect_h,rect_c,rect_2_x,rect_2_y,rect_2_w,rect_2_h,rect_2_c

  F(rect_x,rect_y,rect_w,rect_h,rect_c)
#rect border
  F(rect_x,rect_y,2,rect_h,(R(0,255),R(0,255),R(0,255)))
  F(rect_x+rect_w-2,rect_y,2,rect_h,(R(0,255),R(0,255),R(0,255)))
  F(rect_x,rect_y,rect_w,2,(R(0,255),R(0,255),R(0,255)))
  F(rect_x,rect_y+rect_h-2,rect_w,2,(R(0,255),R(0,255),R(0,255)))


def DrawRect_2():
  global rect_2_x,rect_2_y,rect_2_w,rect_2_h,rect_2_c


  F(rect_2_x,rect_2_y,rect_2_w,rect_2_h,rect_2_c)
#rect border
  F(rect_2_x,rect_2_y,2,rect_2_h,choice(['green','yellow','brown','black','white','pink',"red","white","cyan"]))
  F(rect_2_x+rect_2_w-2,rect_2_y,2,rect_2_h,choice(['green','yellow','brown','black','white','pink',"red","white","cyan"]))
  F(rect_2_x,rect_2_y,rect_2_w,2,choice(['green','yellow','brown','black','white','pink',"red","white","cyan"]))
  F(rect_2_x,rect_2_y+rect_2_h-2,rect_2_w,2,choice(['green','yellow','brown','black','white','pink',"red","white","cyan"]))

def GameOver():
  while not keydown(KEY_OK):
    pass
    
  F(0,0,322,222,"black")
  draw_string("GAME OVER",100,60,"red","black")
  draw_string(chr(36)+" Earned: "+str(round(score)),70,120,"green", "black")
  draw_string("Total Pixels Traveled: "+str(round(total_travel/1.95)),30,170,(200,255,255),"black")
  draw_string("Press [OK] key",90,200,"white","black")
      
#////[main function]////
def go(n = 2):
  global score,travel,life,self,speed,b_c,total_travel,slow,medium,fast,speed,level,distance_required,rect_x,rect_alive
  F(0,0,320,222,FOND)
# ??..I dont know what this is..
#..Damn, real programmers..
  j1 = moto('TRON',0,110,1,(230,180,60),KEY_ONE,KEY_SEVEN)
  j2 = moto('MCP',320,110,3,(100,190,230),KEY_RIGHTPARENTHESIS,KEY_MINUS)
  j3 = moto('YORI',160,220,2,(220,100,30),KEY_ANS,KEY_DOT)
  joueurs = [j1, j2]

  if n > 2: joueurs.append(j3)

  DrawBorder()
  
  if level>=35:
    fill_rect(R(80,180),60,R(70,100),R(70,170),FOND)
  
  
  if level<=35:
    DrawRect()
    DrawRect_2()
#**************************      
#/////[main loop]/////
  F(0,0,322,20,b_c)
  F(0,198,322,25,b_c)
  
  DrawBorder()

  if level>=35:
    fill_rect(R(90,90),R(50,70),R(90,160),R(90,150),FOND)

  if level>=44:
    fill_rect(0,100,322,R(20,40),FOND)
#random laser bar
#makes each level more
#challenging and interesting.
#Players will find this
#cool because its a good challenge.
  laser_x=R(80,210)  
  laser_y=R(30,150)  
  laser_w=5  
  laser_h=round((distance_required-travel)/50)  
  laser_c="red"  
  
  if level>=10 and level<=20:
    F(R(100,200),R(21+level*2,190-level*2),R(50,100),R(5,10),choice(["blue","black",'brown','white','yellow']))
  
  while life>=1 and len(joueurs)>1:

    F(laser_x,laser_y,laser_w,laser_h,laser_c)
    F(laser_x,laser_y,laser_w,laser_h,choice([FOND,FOND,"black","red"]))
            

    PrintData()
#*******************************************    
#4000=distance to travel
    distance_required=4000/(level**(1/4))
#*******************************************    
    draw_string(str(round(distance_required-travel)),120,0,"black","cyan")
    
    if distance_required-travel>=997 and distance_required-travel<=999 or distance_required-travel>=97 and distance_required-travel<=99 or distance_required-travel>=7 and distance_required-travel<=9:
      draw_string("000000",120,0,b_c,b_c)
        
    if keydown(KEY_TOOLBOX):
      while not keydown(KEY_VAR):
        draw_string("<PAUSED>",100,0)
        draw_string("(Press [VAR])",80,200,"blue")
        
      draw_string("        ",100,0,b_c,b_c)
      draw_string("              ",80,200,b_c,b_c)
      

      DrawBorder()
          
    travel+=1

    for j in joueurs:
     j.maj()
     if j.fin: joueurs.remove(j)

#Speed of game
    
    sleep(1/speed)
    
    if level<25:
      speed+=0.1
    
  
    
 #slow down     
    if keydown(KEY_BACKSPACE):
      sleep(0.02)
    
    travel+=1
    total_travel+=1
    
    #***********************
    #the higher the level,
    #the less traavel
    #is required to complete
    #the level, as the walls
    #close in.
    #-----------------------
    #4000 and 7th root 
    #are constant.
    #***********************
# LEVEL CLEARED!
    if travel>=distance_required: #4000/(level**(1/10)):
      sleep(0.4)
      F(0,0,322,222,(200,255,255))
      life+=2
      score+=R(100,200)

      while not keydown(KEY_OK) and not keydown(KEY_RIGHT):

        draw_string("*** level "+str(level)+" cleared!! ***",30,30,"black","cyan")
        draw_string("life: "+str(life),90,80)
        draw_string(chr(36)+str(score),90,110,(0,120,0))
        draw_string("Press [OK]/[RIGHT] to continue",4,190,"black","yellow")
      
      b_c=(R(0,255),R(0,255),R(0,255))
      DrawBorder()
      travel=0
      level+=1
      rect_x=R(70,200)
      rect_y=R(20,150)
      rect_w=R(25,70)
      rect_h=R(20,70)
      rect_c=(R(0,40),R(0,40),R(0,40))
      if level<=10:
        speed=medium
      if level>=10:
        speed=slow
    
  j = joueurs[0]
  
#///////////////////////////
  GameOver()
  
  
go()

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.