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
|
||||
FPS = 60
|
||||
START_TIME = 0
|
||||
|
||||
#CLOCK
|
||||
clock = pygame.time.Clock()
|
||||
|
|
@ -42,16 +43,8 @@ while running:
|
|||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
|
||||
#score/timer
|
||||
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))
|
||||
#BG
|
||||
screen.fill(BG_COLOUR)
|
||||
|
||||
#INPUT
|
||||
keys = pygame.key.get_pressed()
|
||||
|
|
@ -65,23 +58,27 @@ while running:
|
|||
car_y += car_speed
|
||||
|
||||
#LANE SPEED
|
||||
lane_y += lane_speed
|
||||
if lane_y > HEIGHT:
|
||||
lane_y = 0
|
||||
|
||||
#BG
|
||||
screen.fill(BG_COLOUR)
|
||||
lane_y = (lane_y + lane_speed) % 80
|
||||
|
||||
#ROAD
|
||||
pygame.draw.rect(screen, ROAD_COLOUR, (200, 0, 400, HEIGHT))
|
||||
|
||||
#LANE DIVIDER
|
||||
for i in range(-1, 10):
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue