fix lane divider and scoring system
Signed-off-by: Better nya <nya@nya.com>
This commit is contained in:
parent
9b1dc0c48e
commit
218dc27b37
1 changed files with 14 additions and 17 deletions
31
main.py
31
main.py
|
|
@ -10,6 +10,7 @@ pygame.display.set_caption("Traffic Controller")
|
||||||
|
|
||||||
#CONSTANTS
|
#CONSTANTS
|
||||||
FPS = 60
|
FPS = 60
|
||||||
|
START_TIME = 0
|
||||||
|
|
||||||
#CLOCK
|
#CLOCK
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
@ -42,16 +43,8 @@ while running:
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
#BG
|
||||||
#score/timer
|
screen.fill(BG_COLOUR)
|
||||||
font = pygame.font.SysFont(None, 48)
|
|
||||||
start_time = 0
|
|
||||||
current_time = pygame.time.get_ticks()
|
|
||||||
elapsed_time = (current_time - start_time) // 1000
|
|
||||||
|
|
||||||
timer_text = font.render(f"Time: {elapsed_time}s", True, (255, 255, 255)) # Render the text
|
|
||||||
|
|
||||||
screen.blit(timer_text, (100, 100))
|
|
||||||
|
|
||||||
#INPUT
|
#INPUT
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
|
|
@ -65,23 +58,27 @@ while running:
|
||||||
car_y += car_speed
|
car_y += car_speed
|
||||||
|
|
||||||
#LANE SPEED
|
#LANE SPEED
|
||||||
lane_y += lane_speed
|
lane_y = (lane_y + lane_speed) % 80
|
||||||
if lane_y > HEIGHT:
|
|
||||||
lane_y = 0
|
|
||||||
|
|
||||||
#BG
|
|
||||||
screen.fill(BG_COLOUR)
|
|
||||||
|
|
||||||
#ROAD
|
#ROAD
|
||||||
pygame.draw.rect(screen, ROAD_COLOUR, (200, 0, 400, HEIGHT))
|
pygame.draw.rect(screen, ROAD_COLOUR, (200, 0, 400, HEIGHT))
|
||||||
|
|
||||||
#LANE DIVIDER
|
#LANE DIVIDER
|
||||||
for i in range(-1, 10):
|
for i in range(-2, HEIGHT // 80 + 3):
|
||||||
pygame.draw.rect(screen, LINE_COLOUR,
|
pygame.draw.rect(screen, LINE_COLOUR,
|
||||||
(WIDTH//2 - 5, lane_y + i * 80, 10, 40))
|
(WIDTH//2 - 5, lane_y + i * 80, 10, 40))
|
||||||
|
|
||||||
#CAR
|
#CAR
|
||||||
pygame.draw.rect(screen, CAR_COLOUR, (car_x, car_y, car_width, car_height))
|
pygame.draw.rect(screen, CAR_COLOUR, (car_x, car_y, car_width, car_height))
|
||||||
|
|
||||||
|
#score/timer
|
||||||
|
font = pygame.font.SysFont(None, 48)
|
||||||
|
current_time = pygame.time.get_ticks()
|
||||||
|
elapsed_time = ((current_time - START_TIME) // 1000) * 5
|
||||||
|
|
||||||
|
timer_text = font.render(f"Score: {elapsed_time}", True, (255, 255, 255)) # Render the text
|
||||||
|
|
||||||
|
screen.blit(timer_text, (50, 50))
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(FPS)
|
clock.tick(FPS)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue