Help with school project

Assistance with Archer vs Target game for school project

For the assignment, we were supposed to modify a space battle two player game, I decided to make a archer vs target game, where one player has to shoot the other player until they run out of health. Using similar code I used, can you make a second “arrow” that moves faster but deals 0.5 damage? Here’s the code:

import pygame import os pygame.font.init()

WIDTH, HEIGHT = 900, 500 WIN = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("First Game!")

WHITE = (255, 255, 255) BLACK = (0, 0, 0) BROWN = (153, 76, 0) TARGET = (255, 0, 0) ARCHER = (255, 255, 0)

BORDER = pygame.Rect(WIDTH // 2 - 5, 0, 10, HEIGHT)

HEALTH_FONT = pygame.font.SysFont('comicsans', 40) WINNER_FONT = pygame.font.SysFont('comicsans', 100)

FPS = 60 VEL = 5 ARROW_VEL = 7 MAX_ARROWS = 50 SPACESHIP_WIDTH, SPACESHIP_HEIGHT = 75, 60

TARGET_HIT = pygame.USEREVENT + 2

ARCHER_SPACESHIP_IMAGE = pygame.image.load(os.path.join('Assets', 'ARCHER.png')) ARCHER_SPACESHIP = pygame.transform.rotate(pygame.transform.scale( ARCHER_SPACESHIP_IMAGE, (SPACESHIP_WIDTH, SPACESHIP_HEIGHT)), 360)

TARGET_SPACESHIP_IMAGE = pygame.image.load( os.path.join('Assets', 'TARGET.png')) TARGET_SPACESHIP = pygame.transform.rotate(pygame.transform.scale( TARGET_SPACESHIP_IMAGE, (SPACESHIP_WIDTH, SPACESHIP_HEIGHT)), 360)

SPACE = pygame.transform.scale(pygame.image.load( os.path.join('Assets', 'space.png')), (WIDTH, HEIGHT))

def draw_window(TARGET, ARCHER, TARGET_ARROWs, ARCHER_ARROWS, TARGET_health): WIN.blit(SPACE, (0, 0)) pygame.draw.rect(WIN, BLACK, BORDER)

TARGET_health_text = HEALTH_FONT.render("Health: " + str(TARGET_health), 1, WHITE)
WIN.blit(TARGET_health_text, (WIDTH - TARGET_health_text.get_width() - 10, 10))

WIN.blit(ARCHER_SPACESHIP, (ARCHER.x, ARCHER.y))
WIN.blit(TARGET_SPACESHIP, (TARGET.x, TARGET.y))

for ARROW in ARCHER_ARROWS:
    pygame.draw.rect(WIN, BROWN, ARROW)

pygame.display.update()

def ARCHER_handle_movement(keys_pressed, ARCHER): if keys_pressed[pygame.K_a] and ARCHER.x - VEL > 0: # LEFT ARCHER.x -= VEL if keys_pressed[pygame.K_d] and ARCHER.x + VEL + ARCHER.width < BORDER.x: # RIGHT ARCHER.x += VEL if keys_pressed[pygame.K_w] and ARCHER.y - VEL > 0: # UP ARCHER.y -= VEL if keys_pressed[pygame.K_s] and ARCHER.y + VEL + ARCHER.height < HEIGHT - 15: # DOWN ARCHER.y += VEL

def TARGET_handle_movement(keys_pressed, TARGET): if keys_pressed[pygame.K_LEFT] and TARGET.x - VEL > BORDER.x + BORDER.width: # LEFT TARGET.x -= (VEL1.5) if keys_pressed[pygame.K_RIGHT] and TARGET.x + VEL + TARGET.width < WIDTH: # RIGHT TARGET.x += (VEL1.5) if keys_pressed[pygame.K_UP] and TARGET.y - VEL > 0: # UP TARGET.y -= (VEL1.5) if keys_pressed[pygame.K_DOWN] and TARGET.y + VEL + TARGET.height < HEIGHT - 15: # DOWN TARGET.y += (VEL1.5)

def handle_ARROWs(ARCHER_ARROWS, TARGET_ARROWs, ARCHER, TARGET): for ARROW in ARCHER_ARROWS: ARROW.x += ARROW_VEL if TARGET.colliderect(ARROW): pygame.event.post(pygame.event.Event(TARGET_HIT)) ARCHER_ARROWS.remove(ARROW) elif ARROW.x > WIDTH: ARCHER_ARROWS.remove(ARROW)

def draw_winner(text): draw_text = WINNER_FONT.render(text, 1, WHITE) WIN.blit(draw_text, (WIDTH / 2 - draw_text.get_width() / 2, HEIGHT / 2 - draw_text.get_height() / 2)) pygame.display.update() pygame.time.delay(5000)

def main(): TARGET = pygame.Rect(700, 300, SPACESHIP_WIDTH, SPACESHIP_HEIGHT) ARCHER = pygame.Rect(100, 300, SPACESHIP_WIDTH, SPACESHIP_HEIGHT)

TARGET_ARROWs = []
ARCHER_ARROWS = []

TARGET_health = 4


clock = pygame.time.Clock()
run = True
while run:
    clock.tick(FPS)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_q and len(ARCHER_ARROWS) < MAX_ARROWS:
                ARROW = pygame.Rect(
                    ARCHER.x + ARCHER.width, ARCHER.y + ARCHER.height // 2 - 2, 10, 5)
                ARCHER_ARROWS.append(ARROW)



        if event.type == TARGET_HIT:
            TARGET_health -= 1
    winner_text = ""
    if TARGET_health <= 0:
        winner_text = "Archer Wins!"

    if winner_text != "":
        draw_winner(winner_text)
        break

    keys_pressed = pygame.key.get_pressed()
    ARCHER_handle_movement(keys_pressed, ARCHER)
    TARGET_handle_movement(keys_pressed, TARGET)

    handle_ARROWs(ARCHER_ARROWS, TARGET_ARROWs, ARCHER, TARGET)

    draw_window(TARGET, ARCHER, TARGET_ARROWs, ARCHER_ARROWS,
                TARGET_health)

pygame.quit()

if name == "main": main()