diff --git a/Car Racing 2d/__pycache__/objects.cpython-313.pyc b/Car Racing 2d/__pycache__/objects.cpython-313.pyc new file mode 100644 index 0000000..f5edef9 Binary files /dev/null and b/Car Racing 2d/__pycache__/objects.cpython-313.pyc differ diff --git a/Car Racing 2d/main.py b/Car Racing 2d/main.py index f4a51c1..a0110ba 100644 --- a/Car Racing 2d/main.py +++ b/Car Racing 2d/main.py @@ -118,7 +118,7 @@ def center(image): counter = 0 counter_inc = 1 -speed = 3 +speed = 10 # increase the speed for better accleration and difficulty dodged = 0 coins = 0 cfuel = 100 @@ -276,9 +276,10 @@ def center(image): if counter % 60 == 0: tree = Tree(random.choice([-5, WIDTH-35]), -20) tree_group.add(tree) - - if counter % 270 == 0: - type = random.choices([1, 2], weights=[6, 4], k=1)[0] +# change here so that fuel appear every 150 frames(5 sec) +# to make game possible to continue + if counter % 150 == 0: # increase the changes of fuel instead of coin to 70% + type = random.choices([1, 2], weights=[3, 7], k=1)[0] x = random.choice(lane_pos)+10 if type == 1: count = random.randint(1, 3) @@ -318,13 +319,42 @@ def center(image): fuel_group.update(speed) fuel_group.draw(win) - p.update(move_left, move_right) +#changes here for the issue: +# the game every check the fuel bars status where it update the player object. +#therefore, add a check here: + if cfuel > 0: + #as long as the fuel bar greater than 0 + #keep updating the motion of the car base on control + p.update(move_left, move_right) + else: + speed = 0; p.draw(win) if cfuel > 0: pygame.draw.rect(win, GREEN, (20, 20, cfuel, 15), border_radius=5) pygame.draw.rect(win, WHITE, (20, 20, 100, 15), 2, border_radius=5) - cfuel -= 0.05 + cfuel -= 0.1 # increase the fuel consume so that the game is more difficult and engaging +#add to the issue about the fuel bar to make it more than just a +#display but actully slow down and stop the car + # as after the fuel decrease, check if it's less than 5% + #if it is, then slow down + if cfuel <= 5: + speed = max(1,speed - 0.05) + + # if the cfuel is <= 0 + if cfuel <= 0: + speed = 0 + #disable the control + move_left = False + move_right = False + + game_page = False + over_page = True # show the game page when car stopped +# empty everything + tree_group.empty() + coin_group.empty() + fuel_group.empty() + obstacle_group.empty() # COLLISION DETECTION & KILLS for obstacle in obstacle_group: