13 float val = (float) rand() / RAND_MAX;
24 if (players.empty())
return;
25 auto player = players[0];
30 float norm = sqrt(dx * dx + dy * dy);
35 texture->setFlipHorizontal(dx < 0);
39 for (
auto enemy : enemies) {
41 auto enemyCollide = enemy->getComponent<
Collide>();
42 collide->preventCollision(enemyCollide, dx, dy);
47 for (
auto wall : walls) {
48 auto wallCollide = wall->getComponent<
Collide>();
49 collide->preventCollision(wallCollide, dx, dy);
54 for (
auto table : tables) {
55 auto tableCollide = table->getComponent<
Collide>();
56 collide->preventCollision(tableCollide, dx, dy);
63 transform->updateWorldPosition(dx, dy);
69 Vec2 screenPos = transform->getScreenPosition();
70 Vec2 screenSize = transform->getScreenSize();
73 int health_width = (int) (20.0 * health->getHealth() / 200);
74 SDL_Rect rect = {(int) (screenPos.x + screenSize.
x / 2) - 10, (int) (screenPos.y + screenSize.
y / 2) - 8, health_width, 6};
78 rect = {(int) (screenPos.x + screenSize.
x / 2) - 10, (int) (screenPos.y + screenSize.
y / 2) - 8, 20, 6};
Component to handle collisions between game objects.
void update() override
Updates the behavior of the enemy each frame.
void render() override
Renders the enemy AI behavior.
EnemyAIScript()
Constructs a new Enemy AI Script object.
T * getComponent()
Gets a component of the specified type.
A component for managing health of game objects.
static SceneManager & getInstance()
Retrieves the singleton instance of SceneManager.
SceneTree * getSceneTree()
Retrieves the current scene tree managing the game objects.
std::vector< GameObject * > findGameObjectsByTag(std::string tag)
Finds GameObjects by a tag.
GameObject * m_owner
Pointer to the GameObject that owns this script.
Component for handling textures in the game engine.
Defines the Collide class, a component for managing collision detection and response.
Defines the Health class, a component for managing the health of game objects.
Defines the SceneManager class for managing scenes in the game.
A structure to represent 2D vectors.
float y
Y coordinate of the vector.
float x
X coordinate of the vector.
Defines the Texture component for managing textures within the Game Engine, encapsulating SDL texture...