Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from time import sleep

import pygame
from pathlib2 import Path

import os

class CarRacing:
def __init__(self):
Expand All @@ -20,7 +19,9 @@ def __init__(self):
self.white = (255, 255, 255)
self.clock = pygame.time.Clock()
self.gameDisplay = None
self.root_path = str(Path(__file__).parent)
self.root_path = os.path.dirname(os.path.realpath(__file__))

self.quit_game = False

self.initialize()

Expand Down Expand Up @@ -60,7 +61,7 @@ def racing_window(self):

def run_car(self):

while not self.crashed:
while not self.quit_game:

for event in pygame.event.get():
if event.type == pygame.QUIT:
Expand All @@ -70,10 +71,12 @@ def run_car(self):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
self.car_x_coordinate -= 50
print "CAR X COORDINATES: %s" % self.car_x_coordinate
print ("CAR X COORDINATES: %s" % self.car_x_coordinate)
if event.key == pygame.K_RIGHT:
self.car_x_coordinate += 50
print "CAR X COORDINATES: %s" % self.car_x_coordinate
print ("CAR X COORDINATES: %s" % self.car_x_coordinate)
if event.key == pygame.K_ESCAPE:
self.quit_game = True
print ("x: {x}, y: {y}".format(x=self.car_x_coordinate, y=self.car_y_coordinate))

self.gameDisplay.fill(self.black)
Expand Down Expand Up @@ -124,10 +127,10 @@ def back_ground_road(self):
self.bg_y2 += self.bg_speed

if self.bg_y1 >= self.display_height:
self.bg_y1 = -600
self.bg_y1 = self.bg_y2 - 600

if self.bg_y2 >= self.display_height:
self.bg_y2 = -600
self.bg_y2 = self.bg_y1 - 600

def run_enemy_car(self, thingx, thingy):
self.gameDisplay.blit(self.enemy_car, (thingx, thingy))
Expand Down