2025-01-18 01:21:58 +01:00
|
|
|
#include "Entity.h"
|
2025-01-18 19:10:38 +01:00
|
|
|
#include "../Environment/Maze.h"
|
2025-01-18 01:21:58 +01:00
|
|
|
|
|
|
|
namespace game {
|
2025-01-18 19:10:38 +01:00
|
|
|
Entity::Entity(PositionVector starting_position, char display_character): pos(starting_position), display_character(display_character), move_left(true){}
|
2025-01-18 01:21:58 +01:00
|
|
|
|
|
|
|
bool Entity::is_at_position(const PositionVector& position) const {
|
|
|
|
return this->pos.eq(position);
|
|
|
|
}
|
|
|
|
|
2025-01-18 19:10:38 +01:00
|
|
|
void Entity::tick(Maze& maze, const PositionVector& player_position){
|
|
|
|
switch (this->display_character) {
|
|
|
|
case 'A':
|
|
|
|
// No thoughts, head empty :P
|
|
|
|
return;
|
|
|
|
case 'B':
|
|
|
|
this->handle_bowie(maze);
|
|
|
|
return;
|
|
|
|
case 'C':
|
|
|
|
this->handle_connelly(maze, player_position);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entity::handle_bowie(Maze& maze) {
|
|
|
|
PositionVector target_position = {this->pos.x, this->pos.y};
|
|
|
|
if (this->move_left)
|
|
|
|
target_position.change_x(-1);
|
|
|
|
else
|
|
|
|
target_position.change_x(1);
|
|
|
|
if (maze.is_pos_free(target_position, false))
|
|
|
|
this->pos = target_position;
|
|
|
|
else
|
|
|
|
this->move_left = !this->move_left;
|
|
|
|
}
|
2025-01-18 01:21:58 +01:00
|
|
|
|
2025-01-18 19:10:38 +01:00
|
|
|
void Entity::handle_connelly(Maze& maze, const PositionVector& player_position) {
|
|
|
|
PositionVector diff = maze.get_distance_pos1_pos2(player_position, this->pos);
|
|
|
|
PositionVector normalized_diff = {diff.x, diff.y};
|
|
|
|
normalized_diff.normalize();
|
|
|
|
PositionVector target_position = {this->pos.x, this->pos.y};
|
|
|
|
}
|
|
|
|
|
|
|
|
char Entity::get_display_character() {
|
|
|
|
return this->display_character;
|
|
|
|
}
|
2025-01-18 01:21:58 +01:00
|
|
|
}
|