Skip to content

Instantly share code, notes, and snippets.

View mihir-m-gandhi's full-sized avatar

Mihir Gandhi mihir-m-gandhi

View GitHub Profile
@mihir-m-gandhi
mihir-m-gandhi / Vehicle.py
Last active March 3, 2021 19:01
Modified Vehicle class
class Vehicle(pygame.sprite.Sprite):
def __init__(self, lane, vehicleClass, direction_number, direction, will_turn):
pygame.sprite.Sprite.__init__(self)
self.lane = lane
self.vehicleClass = vehicleClass
self.speed = speeds[vehicleClass]
self.direction_number = direction_number
self.direction = direction
self.x = x[direction][lane]
self.y = y[direction][lane]
@mihir-m-gandhi
mihir-m-gandhi / moveRight.py
Last active March 3, 2021 18:57
move() function for vehicles moving right
def move(self):
if(self.direction=='right'):
if(self.crossed==0 and self.x+self.image.get_rect().width>stopLines[self.direction]):
self.crossed = 1
vehicles[self.direction]['crossed'] += 1
if(self.willTurn==0):
vehiclesNotTurned[self.direction][self.lane].append(self)
self.crossedIndex = len(vehiclesNotTurned[self.direction][self.lane]) - 1
if(self.willTurn==1):
if(self.lane == 1):
@mihir-m-gandhi
mihir-m-gandhi / move.py
Last active March 3, 2021 19:00
Complete move() function
def move(self):
if(self.direction=='right'):
if(self.crossed==0 and self.x+self.image.get_rect().width>stopLines[self.direction]):
self.crossed = 1
vehicles[self.direction]['crossed'] += 1
if(self.willTurn==0):
vehiclesNotTurned[self.direction][self.lane].append(self)
self.crossedIndex = len(vehiclesNotTurned[self.direction][self.lane]) - 1
if(self.willTurn==1):
if(self.lane == 1):