36 bool isMoving =
false;
38 if (
input->leftPressed) {
41 if (
input->rightPressed) {
44 if (
input->upPressed) {
47 if (
input->downPressed) {
53 if (health->getHealth() <= 0) {
66 animations->setCurrentAnimation(
static_cast<size_t>(
m_currentState));
70 Vec2 position = transform->getWorldPosition();
72 if (
input->leftPressed) {
75 if (
input->rightPressed) {
78 if (
input->upPressed) {
81 if (
input->downPressed) {
87 int levelHeight = 640;
90 if (isDemo && position.
x < -levelWidth)
91 position.
x = -levelWidth;
92 else if (!isDemo && position.
x < -levelWidth + 632)
93 position.
x = -levelWidth + 632;
94 if (isDemo && position.
x > levelWidth - 48)
95 position.
x = levelWidth - 48;
96 else if (!isDemo && position.
x > levelWidth + 124)
97 position.
x = levelWidth + 124;
98 if (isDemo && position.
y < -levelHeight)
99 position.
y = -levelHeight;
100 else if (!isDemo && position.
y < -levelHeight + 640)
101 position.
y = -levelHeight + 640;
102 if (isDemo && position.
y > levelHeight - 48)
103 position.
y = levelHeight - 48;
104 else if (!isDemo && position.
y > levelHeight + 116)
105 position.
y = levelHeight + 116;
107 float dx = position.
x - transform->getWorldPosition().x;
108 float dy = position.
y - transform->getWorldPosition().y;
110 transform->updateWorldPosition(dx, dy);
115 Vec2 bowOffset(16, 8);
116 bow->getComponent<
Transform>()->setWorldPosition(position.
x + bowOffset.
x, position.
y + bowOffset.
y);
119 texture->setFlipHorizontal(dx < 0);
123 for (
auto wall : walls) {
124 auto wallCollide = wall->getComponent<
Collide>();
125 collide->preventCollision(wallCollide, dx, dy);
130 for (
auto table : tables) {
131 auto tableCollide = table->getComponent<
Collide>();
132 collide->preventCollision(tableCollide, dx, dy);
137 for (
auto key : keys) {
138 auto keyCollide = key->getComponent<
Collide>();
139 if (collide->isColliding(keyCollide)) {
140 key->getSceneNode()->setDestroy(
true);
147 auto enemyCollide = enemy->getComponent<
Collide>();
148 if (collide->isColliding(enemyCollide)) {
149 health->updateHealth(-10);
Manages a collection of animations for a game entity, with functionality to play, pause,...
Component to handle collisions between game objects.
T * getComponent()
Gets a component of the specified type.
std::vector< GameObject * > getChildren()
Gets all child GameObjects.
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.
virtual void input()
Virtual method for handling input. Should be overridden by derived classes.
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...