projekt_PP/vehicles.py

83 lines
2.1 KiB
Python

from random import randint
import time
class Car:
tracks=[]
def __init__(self,id,xi,yi,max_age):
self.id = id
self.x = xi
self.y = yi
self.tracks = []
self.R = randint(0,255)
self.G = randint(0,255)
self.B = randint(0,255)
self.done = False
self.state = '0' # 0 - wymaga dalszego sledzenia, 1 - przekroczyl mete, zostal policzony i mozna go bedzie usunac
self.age = 0 # o
self.max_age = max_age
self.dir = None
def getRGB(self):
return (self.R,self.G,self.B)
def getId(self):
return self.id
def getX(self): # szerokosc
return self.x
def getY(self): # wysokosc
return self.y
def getState(self):
return self.state
def getDir(self):
return self.dir
#stare wspolrzedne dodaj do listy "tropu" pojazdu, a nastepnie aktualizuj
def updateCoords(self, xNew, yNew):
self.age = 0
self.tracks.append([self.x, self.y])
self.x = xNew
self.y = yNew
def setDone(self):
self.done = True
def timedOut(self):
return self.done
def going_UP(self, finishLine):
if len(self.tracks)>=2:
if self.state=='0':
if self.tracks[-1][1]<finishLine and self.tracks[-2][1]>=finishLine:
self.state='1'
self.dir='up'
return True
else:
return False
else:
return False
else:
return False
def going_DOWN(self,finishLine):
if len(self.tracks)>=2:
if self.state=='0':
if self.tracks[-1][1]>finishLine and self.tracks[-2][1]<=finishLine:
self.state='1'
self.dir='down'
return True
else:
return False
else:
return False
else:
return False
def age_one(self):
self.age+=1
if self.age>self.max_age:
self.done=True
return True