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:
objectThe 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.
src.classes module#
- class src.classes.Collectible(pos, value)[source]#
Bases:
EntityRepresents 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.
- class src.classes.Entity(pos)[source]#
Bases:
SpriteBase 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:
TileClass 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.
- class src.classes.Level(level_list, bg_list, surface)[source]#
Bases:
objectRepresents 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.
- class src.classes.NPC(pos, list_of_questions, question_index)[source]#
Bases:
EntityRepresents 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.
- class src.classes.Player(pos)[source]#
Bases:
EntityAttributes#
- 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.
- property speed#
Getter for the speed
- property x#
Getter for the x-coordinate
- property y#
Getter for the y-coordinate
- class src.classes.Tile(pos, size)[source]#
Bases:
EntityClass 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.
- class src.classes.UI(surface, book_bar_image_path)[source]#
Bases:
objectRepresents 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.
src.settings module#
This module contains all the game settings.