mirror of
https://github.com/Motschen/Adventura.git
synced 2025-12-17 12:15:10 +01:00
docs: more comments
This commit is contained in:
53
player.hpp
53
player.hpp
@@ -8,21 +8,52 @@
|
||||
|
||||
class Player {
|
||||
public:
|
||||
/**
|
||||
* Initializes a new Player at the specified starting position in the provided world.
|
||||
*
|
||||
* @param pos The initial position of the player within the world.
|
||||
* @param world A reference to the World object representing the game world.
|
||||
*/
|
||||
Player(BlockPos pos, World& world) : world(world) {
|
||||
this->pos = pos;
|
||||
this->world = world;
|
||||
playerTexture = REGULAR_PLAYER_TEXTURE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current position of the player in the world.
|
||||
*
|
||||
* @return The current BlockPos representing the player's position.
|
||||
*/
|
||||
BlockPos getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the player by the specified x and y offsets.
|
||||
*
|
||||
* @param x The x offset to move by.
|
||||
* @param y The y offset to move by.
|
||||
*/
|
||||
void move(int x, int y) {
|
||||
move(BlockPos(x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the player by the specified BlockPos offset.
|
||||
*
|
||||
* @param offset The BlockPos representing the offset to move the player by.
|
||||
*/
|
||||
void move(BlockPos offset) {
|
||||
setPos(pos + offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the player's position and checks for any conditions that would update the state of the player.
|
||||
*
|
||||
* @param pos The position to move the player to.
|
||||
*/
|
||||
void setPos(BlockPos pos) {
|
||||
if (!world.containsPos(pos)) {
|
||||
alive = false;
|
||||
@@ -50,17 +81,39 @@ public:
|
||||
|
||||
if (world.getBlockAt(pos.add(0, 2)).getSettings().isLethal()) unalive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the unfortunate case of a player dying :(
|
||||
*/
|
||||
void unalive() {
|
||||
playerTexture = DEAD_PLAYER_TEXTURE;
|
||||
redraw(world, this->mapToWorldspace());
|
||||
alive = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player is still alive.
|
||||
*
|
||||
* @return true if the player is alive, false otherwise.
|
||||
*/
|
||||
bool isAlive() {
|
||||
return alive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player has reached the goal in the current world.
|
||||
*
|
||||
* @return true if the player has reached the goal, false otherwise.
|
||||
*/
|
||||
bool hasReachedGoal() {
|
||||
return reachedGoal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the player texture to the player's position in the current game world.
|
||||
*
|
||||
* @return A 2D vector of characters representing the player's position in the world.
|
||||
*/
|
||||
vector<vector<char>> mapToWorldspace() {
|
||||
vector<vector<char>> map;
|
||||
for (unsigned int y = 0; y <= world.getMaxY(); y++) {
|
||||
|
||||
Reference in New Issue
Block a user