From 01f6f3c988dd536027a4a44f776fb48664edc731 Mon Sep 17 00:00:00 2001 From: Micaiah Akuffo Date: Sat, 20 Dec 2025 11:09:18 +0000 Subject: [PATCH 1/3] Changed the health text color logic. The health text for each of the spaceships, gradually changes to red when the health points reaches specific values. --- main.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index cf19df3..0eb4923 100644 --- a/main.py +++ b/main.py @@ -48,9 +48,29 @@ def draw_window(red, yellow, red_bullets, yellow_bullets, red_health, yellow_hea pygame.draw.rect(WIN, BLACK, BORDER) red_health_text = HEALTH_FONT.render( - "Health: " + str(red_health), 1, WHITE) + "Health: " + str(red_health), 1, GREEN) + if red_health < 8 and red_health > 5: + red_health_text = HEALTH_FONT.render( + "Health: " + str(red_health), 1, YELLOW) + elif red_health < 6 and red_health > 3: + red_health_text = HEALTH_FONT.render( + "Health: " + str(red_health), 1, ORANGE) + elif red_health < 4: + red_health_text = HEALTH_FONT.render( + "Health: " + str(red_health), 1, RED) + yellow_health_text = HEALTH_FONT.render( - "Health: " + str(yellow_health), 1, WHITE) + "Health: " + str(yellow_health), 1, GREEN) + if yellow_health < 8 and yellow_health > 5: + yellow_health_text = HEALTH_FONT.render( + "Health: " + str(yellow_health), 1, YELLOW) + elif yellow_health < 6 and yellow_health > 3: + yellow_health_text = HEALTH_FONT.render( + "Health: " + str(yellow_health), 1, ORANGE) + elif yellow_health < 4: + yellow_health_text = HEALTH_FONT.render( + "Health: " + str(yellow_health), 1, RED) + WIN.blit(red_health_text, (WIDTH - red_health_text.get_width() - 10, 10)) WIN.blit(yellow_health_text, (10, 10)) From 05715f0d570eac1774693e04bc8fd1c64a91a0e4 Mon Sep 17 00:00:00 2001 From: Micaiah Akuffo Date: Sat, 20 Dec 2025 11:26:09 +0000 Subject: [PATCH 2/3] Changed the health text color display logic This changes the color of the health text of each spaceship, depending on specific health points it has reached. --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index 0eb4923..89cf88a 100644 --- a/main.py +++ b/main.py @@ -11,6 +11,8 @@ BLACK = (0, 0, 0) RED = (255, 0, 0) YELLOW = (255, 255, 0) +GREEN = (0, 255, 0) +ORANGE = (255, 165, 0) BORDER = pygame.Rect(WIDTH//2 - 5, 0, 10, HEIGHT) From 99e5b19f83f5bfc5f218679cb825927cfb491a1f Mon Sep 17 00:00:00 2001 From: Micaiah Akuffo Date: Sat, 20 Dec 2025 19:32:53 +0000 Subject: [PATCH 3/3] Improve health display logic for players Refactor health display logic for color coding based on health values. This is the same change previously but used short code for it, for better readability for beginners. --- main.py | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index 89cf88a..1523d59 100644 --- a/main.py +++ b/main.py @@ -49,29 +49,33 @@ def draw_window(red, yellow, red_bullets, yellow_bullets, red_health, yellow_hea WIN.blit(SPACE, (0, 0)) pygame.draw.rect(WIN, BLACK, BORDER) + # Red health color coding + if red_health == 10: + color = GREEN + elif red_health >= 7: + color = YELLOW + elif red_health >= 4: + color = ORANGE + elif red_health >= 1: + color = RED + else: + color = BLACK red_health_text = HEALTH_FONT.render( - "Health: " + str(red_health), 1, GREEN) - if red_health < 8 and red_health > 5: - red_health_text = HEALTH_FONT.render( - "Health: " + str(red_health), 1, YELLOW) - elif red_health < 6 and red_health > 3: - red_health_text = HEALTH_FONT.render( - "Health: " + str(red_health), 1, ORANGE) - elif red_health < 4: - red_health_text = HEALTH_FONT.render( - "Health: " + str(red_health), 1, RED) - + "Health: " + str(red_health), 1, color) + + # Yellow health color coding + if yellow_health == 10: + color = GREEN + elif yellow_health >= 7: + color = YELLOW + elif yellow_health >= 4: + color = ORANGE + elif yellow_health >= 1: + color = RED + else: + color = BLACK yellow_health_text = HEALTH_FONT.render( - "Health: " + str(yellow_health), 1, GREEN) - if yellow_health < 8 and yellow_health > 5: - yellow_health_text = HEALTH_FONT.render( - "Health: " + str(yellow_health), 1, YELLOW) - elif yellow_health < 6 and yellow_health > 3: - yellow_health_text = HEALTH_FONT.render( - "Health: " + str(yellow_health), 1, ORANGE) - elif yellow_health < 4: - yellow_health_text = HEALTH_FONT.render( - "Health: " + str(yellow_health), 1, RED) + "Health: " + str(yellow_health), 1, color) WIN.blit(red_health_text, (WIDTH - red_health_text.get_width() - 10, 10)) WIN.blit(yellow_health_text, (10, 10)) @@ -201,3 +205,4 @@ def main(): if __name__ == "__main__": main() +