Can i have someone debug this code? it keeps say there is a syntax error, and I don't know want that means yet

Question:
it keeps say there is a syntax error, and I don’t know want that means yet.
Repl link/Link to where the bug appears:

Screenshots, links, or other helpful context:

import pygame
import sys
import random
import math

# Constants
WIDTH, HEIGHT = 800, 600
PLAYER_SIZE = 40
MONSTER_SIZE = 40
PLATFORM_HEIGHT = 20
PLAYER_COLOR = (0, 128, 255)
MONSTER_COLOR = (255, 0, 0)
PLATFORM_COLOR = (128, 128, 128)
BACKGROUND_COLOR = (0, 0, 0)
PLAYER_SPEED = 5
MONSTER_BASE_SPEED = 2
MAX_MONSTER_SPEED = 5
LEVEL_DURATION = 10
LIGHT_RADIUS = 100  # Radius of the player's light aura

# Initialize Pygame
pygame.init()
window = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Combined Horror Platformer Game")

# Player
player = pygame.Rect(100, HEIGHT - PLAYER_SIZE - 100, PLAYER_SIZE, PLAYER_SIZE)
player_y_velocity = 0
player_x_velocity = 0
player_facing_right = True

# Monster
monster = pygame.Rect(random.randint(0, WIDTH - MONSTER_SIZE), HEIGHT - PLAYER_SIZE - MONSTER_SIZE, MONSTER_SIZE, MONSTER_SIZE)
monster_speed = MONSTER_BASE_SPEED

# Fake Game Crash
fake_crash_font = pygame.font.Font(None, 36)
fake_crash_text = fake_crash_font.render("Game has crashed!", True, (255, 255, 255))
fake_crash_displayed = False

# Level
current_level = 1
jump_scare_enemy_spawned = False  # Flag to track if the jump scare enemy has spawned

# Light System
light_radius = LIGHT_RADIUS
flashlight_angle = 0

# Introductory Section
introductory_section = True
intro_end_time = pygame.time.get_ticks() + 5000  # Intro lasts for 5 seconds

# Infinite Flat Floor (Level 3)
infinite_floor_y = HEIGHT - PLATFORM_HEIGHT  # Y-coordinate of the infinite flat floor

# Clock
clock = pygame.time.Clock()

def draw_objects():
    window.fill(BACKGROUND_COLOR)
    pygame.draw.rect(window, PLAYER_COLOR, player)
    pygame.draw.rect(window, MONSTER_COLOR, monster)
    pygame.draw.rect(window, PLATFORM_COLOR, (0, infinite_floor_y, WIDTH, PLATFORM_HEIGHT))
    if fake_crash_displayed:
        window.blit(fake_crash_text, (WIDTH // 2 - 100, HEIGHT // 2 - 18))
    
    pygame.draw.circle(window, (255, 255, 0), player.center, light_radius, 1)
    
    flashlight_end_x = player.centerx + flashlight_length * math.cos(math.radians(flashlight_angle))
    flashlight_end_y = player.centery - flashlight_length * math.sin(math.radians(flashlight_angle))
    pygame.draw.line(window, (255, 255, 0), player.center, (flashlight_end_x, flashlight_end_y), 3)

def move_player():
    global player_y_velocity, player_x_velocity, player_facing_right, flashlight_angle
    player_y_velocity += 1
    player.y += player_y_velocity
    if player.y >= HEIGHT - PLAYER_SIZE:
        player.y = HEIGHT - PLAYER_SIZE
        player_y_velocity = 0

    keys = pygame.key.get_pressed()
    
    # Horizontal movement
    player_x_velocity = 0
    
    if keys[pygame.K_LEFT] and player.x > 0:
        player_x_velocity = -PLAYER_SPEED
        player_facing_right = False
    if keys[pygame.K_RIGHT] and player.x < WIDTH - PLAYER_SIZE:
        player_x_velocity = PLAYER_SPEED
        player_facing_right = True

    # Jumping
    if keys[pygame.K_SPACE] and player.y == HEIGHT - PLAYER_SIZE:
        player_y_velocity = -15
    
    player.x += player_x_velocity
    
    # Update flashlight angle based on player's movement and facing direction
    horizontal_angle = math.degrees(math.atan2(player_y_velocity, player_x_velocity))
    if player_facing_right:
        flashlight_angle = -horizontal_angle
    else:
        flashlight_angle = 180 - horizontal_angle

def move_monster():
    global monster_speed
    monster.x += monster_speed
    if monster.right > WIDTH or monster.left < 0:
        monster_speed *= -1

def check_collisions():
    global fake_crash_displayed, current_level, jump_scare_enemy_spawned
    if current_level == 3:
        if player.colliderect(monster) and not jump_scare_enemy_spawned:
            # Spawn jump scare enemy at level 3
            jump_scare_enemy_spawned = True
            monster_speed = 0  # Stop the regular monster
            monster.x = WIDTH + 10  # Move the regular monster out of sight
            monster.y = HEIGHT + 10
            monster_jumpscare()
    elif current_level == 4:
        if player.colliderect((0, infinite_floor_y, WIDTH, PLATFORM_HEIGHT)):
            player.y = infinite_floor_y - PLAYER_SIZE
            player_y_velocity = 0
            next_level()

def monster_jumpscare():
    # Implement the jump scare logic here
    pass

def next_level():
    global monster_speed, fake_crash_displayed, current_level, jump_scare_enemy_spawned

    if current_level == 3:
        # Prepare for level 4
        jump_scare_enemy_spawned = False
        monster_speed = MONSTER_BASE_SPEED
        reset_player_position()
    elif current_level == 4:
        # End of the infinite flat floor at level 4
        current_level += 1
        reset_player_position()
    else:
        current_level += 1
        monster_speed = min(MAX_MONSTER_SPEED, monster_speed + 0.5)
        fake_crash_displayed = False
        reset_player_position()

def reset_player_position():
    global player
    player.x = 100
    player.y = HEIGHT - PLAYER_SIZE - 100

def main():
    global flashlight_length, introductory_section

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

        if introductory_section:
            if pygame.time.get_ticks() 

Hey @LoganSchwarz, welcome to the community!

What is the full error, and can you send the link to your Repl?

Yes of course! Here is the link! link

Your code seems to be cut off.

if pygame.time.get_ticks() 

You didn’t put the colon (:), but even if you did there would still be an error because there’s no line after it.

Change to this

            if pygame.time.get_ticks():
                pass
3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.