src package#

Submodules#

src.academic_adventure module#

academic_adventure.py

This module contains the main game logic for the Academic Adventure game. It uses the pygame library to create a game window, handle events, and render the game state to the screen.

class src.academic_adventure.Game[source]#

Bases: object

The main class representing the game.

Attributes#

bg_musicpygame.mixer.Sound

The background music for the game.

screenpygame.Surface

The main game window.

clockpygame.time.Clock

A clock to control the game’s frame rate.

xint

An example attribute for demonstration purposes.

runningbool

Flag indicating whether the game is currently running.

Methods#

__init__()

Initializes the game, including pygame and the game window.

new()

Initializes a new game, creating a new level and menu.

run()

Runs the main game loop, handling events and updating the game state.

new()[source]#

Initializes a new game by creating a new level and menu.

Parameters#

None.

Returns#

None.

run()[source]#

Runs the main game loop, handling events and updating the game state.

Parameters#

None.

Returns#

None.

src.classes module#

class src.classes.Collectible(pos, value)[source]#

Bases: Entity

Represents a collectible item in the game.

Attributes#

imagepygame.Surface

Surface representing the collectible.

rectpygame.Rect

Rectangular area of the collectible.

valueint

Value associated with the collectible.

Methods#

__change_books(amount)

Changes the number of books collected and updates the UI.

__change_health(amount)

Changes the player’s health by the specified amount.

update(x_shift)

Updates the position of the collectible along the x-axis.

update(x_shift)[source]#

Updates the position of the collectible along the x-axis.

Parameters#

x_shiftint

The amount to be shifted along the x-axis.

Returns#

None.

class src.classes.Entity(pos)[source]#

Bases: Sprite

Base class for game entities.

Attributes#

rectpygame.Rect

The rectangular area of the entity.

Methods#

__init__(self, pos)

Initializes the entity

update(self)

update()[source]#

method to control sprite behavior

Sprite.update(*args, **kwargs):

The default implementation of this method does nothing; it’s just a convenient “hook” that you can override. This method is called by Group.update() with whatever arguments you give it.

There is no need to use this method if not using the convenience method by the same name in the Group class.

class src.classes.Finish(pos, size)[source]#

Bases: Tile

Class representing a finish block in the game.

Attributes#

imagepygame.Surface

The surface (image) of the finish block.

rectpygame.Rect

The rectangular area of the finish block.

Methods#

__init__(self, pos, size)

Initializes the finish block.

update(self, x_shift)

Updates the position of the finish block along the x-axis.

update(x_shift)[source]#

Updates the position of the finish block along the x-axis.

Parameters#

x_shiftint

The amount to be shifted along the x-axis.

Returns#

None.

class src.classes.Level(level_list, bg_list, surface)[source]#

Bases: object

Represents a level in the game.

Attributes#

display_surfacepygame.Surface

The display surface for rendering the level.

levelslist

List containing level layouts.

current_levelint

Index of the current level.

world_shiftint

Horizontal shift of the world.

current_xint

Current x-coordinate.

background_imagepygame.Surface

The background image of the level.

bg_xint

Background x-coordinate.

game_overbool

Flag indicating whether the game is over.

collectibles_collectedint

Number of collectibles (books) collected.

book_barpygame.Surface

Image representing the book bar.

uiUI

The user interface for the level.

Methods#

initialize_level(layout)

Initializes the level based on the given layout.

next_level()

Moves to the next level.

scroll_x()

Handles horizontal scrolling based on player position.

horizontal_movement_collision()

Handles collisions during horizontal movement.

vertical_movement_collision()

Handles collisions during vertical movement.

check_npc_collision()

Checks for collisions between the player and NPCs.

check_collectible_collisions()

Checks for collisions between the player and collectibles.

change_collectible(value)

Changes the number of collected collectibles.

is_completed()

Checks if the level is completed.

run()

Runs the main logic for the level.

change_collectible(value)[source]#

Changes the number of collected collectibles.

Parameters#

valueint

The change in the number of collectibles.

Returns#

None.

check_collectible_collisions()[source]#

Checks for collisions between the player and collectibles.

Parameters#

None.

Returns#

None.

check_npc_collision()[source]#

Checks for collisions between the player and NPCs.

Parameters#

None.

Returns#

None.

horizontal_movement_collision()[source]#

Handles collisions during horizontal movement.

Parameters#

None.

Returns#

None.

initialize_level(layout)[source]#

Initializes the level based on the given layout.

Parameters#

layoutlist

Layout representing the level.

Returns#

None.

is_completed()[source]#

Checks if the level is completed.

Parameters#

None.

Returns#

bool

True if the level is completed, False otherwise.

next_level()[source]#

Moves to the next level.

Parameters#

None.

Returns#

None.

restart()[source]#

Restarts the game.

Parameters#

None.

Returns#

None.

run()[source]#

Runs the main logic for the level.

Parameters#

None.

Returns#

None.

scroll_x()[source]#

Handles horizontal scrolling based on player position.

Parameters#

None.

Returns#

None.

show_score()[source]#

Displays the score on the screen.

Parameters#

None.

Returns#

None.

vertical_movement_collision()[source]#

Handles collisions during vertical movement.

Parameters#

None.

Returns#

None.

class src.classes.NPC(pos, list_of_questions, question_index)[source]#

Bases: Entity

Represents a non-player character (NPC) in the game.

Attributes#

imagepygame.Surface

Surface representing the NPC (blue rectangle).

rectpygame.Rect

Rectangular area of the NPC.

list_of_questionslist

List of dictionaries containing questions and answers.

question_indexint

Index indicating the current question from the list.

was_answeredbool

True if the NPC’s question was answered.

Methods#

update(x_shift)

Updates the position of the NPC along the x-axis.

question(list_of_questions, question_index)

Displays a question and handles player input for answering it.

question(list_of_questions, question_index)[source]#

Displays a question and handles player input for answering it.

Parameters#

list_of_questionslist

List of dictionaries containing questions and answers.

question_indexint

Index indicating the current question from the list.

Returns#

int

1 if the answer is correct, 0 otherwise.

update(x_shift)[source]#

Updates the position of the NPC along the x-axis.

Parameters#

x_shiftint

The amount to be shifted along the x-axis.

Returns#

None.

class src.classes.Player(pos)[source]#

Bases: Entity

Attributes#

frame_indexfloat

Index used for animation frames.

animation_speedfloat

Speed of the animation.

imagepygame.Surface

Current image of the player.

directionpygame.math.Vector2

Vector representing the player’s movement direction.

speedint

Speed of the player’s movement.

_gravityfloat

Acceleration which the player moves downward.

jump_speedint

Vertical speed during a jump.

statusstr

Current status of the player (e.g., ‘idle_direita’, ‘fall’, ‘walking_right’).

on_groundbool

True if the player is on the ground.

on_ceilingbool

True if the player is on the ceiling.

on_leftbool

True if the player is touching a surface on the left.

on_rightbool

True if the player is touching a surface on the right.

Methods#

__init__(pos)

Initializes the player instance.

import_character_assets()

Imports character animations.

update()

Updates the player’s state.

handle_input()

Handles player input.

handle_status()

Handles player status based on direction.

apply_gravity()

Applies gravity to the player’s vertical movement.

jump()

Initiates a jump.

animate()

Animates the player based on the current status.

animate()[source]#

Animates the player based on the current status.

Parameters#

None.

Returns#

None.

apply_gravity()[source]#

Applies gravity to the player’s vertical movement.

Parameters#

None.

Returns#

None.

handle_input()[source]#

Handles player input.

Parameters#

None.

Returns#

None.

handle_status()[source]#

Handles player status based on direction.

Parameters#

None.

Returns#

None.

import_character_assets()[source]#

Imports character animations.

Parameters#

None.

Returns#

None.

jump()[source]#

Initiates a jump.

Parameters#

None.

Returns#

None.

property speed#

Getter for the speed

update()[source]#

Updates the player’s state.

Parameters#

None.

Returns#

None.

property x#

Getter for the x-coordinate

property y#

Getter for the y-coordinate

class src.classes.Tile(pos, size)[source]#

Bases: Entity

Class representing a block (tile) in the game.

Attributes#

imagepygame.Surface

The surface (image) of the block.

rectpygame.Rect

The rectangular area of the block.

Methods#

__init__(self, pos, size)

Initializes the block.

update(self, x_shift)

Updates the position of the block along the x-axis.

update(x_shift)[source]#

Updates the position of the block along the x-axis.

Parameters#

x_shiftint

The amount to be shifted along the x-axis.

Returns#

None.

class src.classes.UI(surface, book_bar_image_path)[source]#

Bases: object

Represents the user interface in the game.

Attributes#

display_surfacepygame.Surface

The display surface for rendering the UI.

book_barpygame.Surface

The image representing the book bar.

book_bar_toplefttuple

The top-left coordinates of the book bar.

bar_max_widthint

The maximum width of the book bar.

bar_heightint

The height of the book bar.

bookpygame.Surface

The image representing a book.

book_rectpygame.Rect

The rectangular area of the book image.

fontpygame.font.Font

The font used for rendering text on the UI.

Methods#

show_health(current, full)

Displays the health bar on the UI based on the current and full health values.

show_books(amount)

Displays the collected books and their amount on the UI.

show_books(amount)[source]#

Displays the collected books and their amount on the UI.

Parameters#

amountint

The number of collected books.

Returns#

None.

show_health(current, full)[source]#

Displays the health bar on the UI based on the current and full health values.

Parameters#

currentint

The current health value.

fullint

The full health value.

Returns#

None.

src.classes.import_folder(path)[source]#

Import images of a folder

Parameters#

pathstr

The path of the folder containing the images

Returns#

list

A list of surfaces (images)

src.menu module#

class src.menu.Button(image, pos, text_input, font, base_color, hovering_color)[source]#

Bases: object

Represents a clickable button in the game.

Attributes#

imagepygame.Surface

The image representing the button.

x_posint

The x-coordinate of the button’s center.

y_posint

The y-coordinate of the button’s center.

fontpygame.font.Font

The font used for rendering text on the button.

base_colorstr

The base color of the button’s text.

hovering_colorstr

The color of the button’s text when hovering.

text_inputstr

The text displayed on the button.

textpygame.Surface

The rendered text surface.

rectpygame.Rect

The rectangular area of the button.

text_rectpygame.Rect

The rectangular area of the rendered text.

Methods#

update(screen)

Updates and renders the button on the given screen.

check_for_input(position)

Checks if a given position is within the button’s area.

change_color(position)

Changes the color of the button’s text based on the mouse position.

change_color(position)[source]#

Changes the color of the button’s text based on the mouse position.

Parameters#

positiontuple

The x, y coordinates of the mouse position.

Returns#

None.

check_for_input(position)[source]#

Checks if a given position is within the button’s area.

Parameters#

positiontuple

The x, y coordinates of the position to check.

Returns#

bool

True if the position is within the button’s area, False otherwise.

update(screen)[source]#

Updates and renders the button on the given screen.

Parameters#

screenpygame.Surface

The screen where the button will be rendered.

Returns#

None.

class src.menu.Menu(level_instance)[source]#

Bases: object

Represents the menu system in the game.

Attributes#

current_screenstr

The current active screen.

levelLevel

The instance of the game level associated with the menu.

Methods#

main_menu(background_image_path)

Displays the main menu screen with buttons for play, credits, and quit.

credits()

Displays the credits screen with information about the game developers.

pause()

Displays the pause screen with options to resume, go to the main menu, or quit the game.

game_over()

Displays the game over screen with the option to return to the main menu.

credits()[source]#

Displays the credits screen with information about the game developers.

Returns#

None.

Returns#

None.

game_over()[source]#

Displays the game over screen with the option to return to the main menu.

Returns#

None.

main_menu(background_image_path)[source]#

Displays the main menu screen with buttons for play, credits, and quit.

Parameters#

background_image_pathstr

The file path for the background image of the main menu.

Returns#

None.

pause()[source]#

Displays the pause screen with options to resume, go to the main menu, or quit the game.

Returns#

None.

src.menu.get_font(size)[source]#

Get a Pygame font object with a specified size.

Parameters#

sizeint

The font size.

Returns#

pygame.font.Font

A Pygame font object.

src.settings module#

This module contains all the game settings.

src.settings.import_csv_layout(path)[source]#

Function to import a CSV file and convert it into a terrain map.

Parameters#

path (str): The path to the CSV file.

Returns#

list: A list of strings representing the terrain map.

Module contents#