Compare commits

...

3 commits

Author SHA1 Message Date
Better nya
218dc27b37 fix lane divider and scoring system
Signed-off-by: Better nya <nya@nya.com>
2026-02-18 09:40:56 +11:00
Better nya
9b1dc0c48e add gameplay
Signed-off-by: Better nya <nya@nya.com>
2026-02-18 08:54:31 +11:00
Better nya
fe2ccf5edf add gameplay
Signed-off-by: Better nya <nya@nya.com>
2026-02-17 10:32:59 +11:00

70
main.py
View file

@ -1,16 +1,39 @@
import sys
import pygame
import sys
pygame.init()
pygame.font.init()
#SETUP
WIDTH, HEIGHT = 800, 800
WINDOW = pygame.display.set_mode((WIDTH, HEIGHT))
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Traffic Controller")
#CONSTANTS
FPS = 60
START_TIME = 0
# Game loop
#CLOCK
clock = pygame.time.Clock()
#COLOURS
ROAD_COLOUR = (50, 50, 50)
LINE_COLOUR = (255, 255, 0)
CAR_COLOUR = (200, 0, 0)
BG_COLOUR = (30, 150, 30)
#CAR
car_width = 40
car_height = 70
car_x = WIDTH // 2 - car_width // 2
car_y = HEIGHT - car_height - 20
car_speed = 4
lane_speed = 5
#LANE
lane_y = 0
#LOOP
running = True
while running:
clock.tick(FPS)
@ -20,3 +43,42 @@ while running:
pygame.quit()
sys.exit()
#BG
screen.fill(BG_COLOUR)
#INPUT
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] or keys[pygame.K_a]:
car_x -= car_speed
if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
car_x += car_speed
if keys[pygame.K_UP] or keys[pygame.K_w]:
car_y -= car_speed
if keys[pygame.K_DOWN] or keys[pygame.K_s]:
car_y += car_speed
#LANE SPEED
lane_y = (lane_y + lane_speed) % 80
#ROAD
pygame.draw.rect(screen, ROAD_COLOUR, (200, 0, 400, HEIGHT))
#LANE DIVIDER
for i in range(-2, HEIGHT // 80 + 3):
pygame.draw.rect(screen, LINE_COLOUR,
(WIDTH//2 - 5, lane_y + i * 80, 10, 40))
#CAR
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()
clock.tick(FPS)