11 float norm = sqrt(dx * dx + dy * dy);
13 m_dx = dx / norm * speed;
14 m_dy = dy / norm * speed;
21 Vec2 position = transform->getWorldPosition();
24 transform->setWorldPosition(position);
34 if (position.x < -1200 || position.x > 1200 || position.y < -1200 || position.y > 1200) {
43 auto walls = sceneTree->findGameObjectsByTag(
"Wall");
44 for (
auto wall: walls) {
45 if (collide->isColliding(wall->getComponent<
Collide>())) {
50 for (
auto enemy : enemies) {
51 if (collide->isColliding(enemy->getComponent<
Collide>())) {
53 enemy->getComponent<
Health>()->updateHealth(-100);
58 enemy->getSceneNode()->setDestroy(
true);
Component to handle collisions between game objects.
SceneNode * getSceneNode()
Gets the SceneNode associated with this GameObject.
T * getComponent()
Gets a component of the specified type.
A component for managing health of game objects.
int getHealth()
Retrieves the current health of the game object.
float m_dx
Horizontal velocity component of the projectile.
float m_dy
Vertical velocity component of the projectile.
ProjectileScript(float dx, float dy)
Constructs a ProjectileScript with specified velocity components.
void update() override
Updates the position of the projectile based on its velocity.
static SceneManager & getInstance()
Retrieves the singleton instance of SceneManager.
SceneTree * getSceneTree()
Retrieves the current scene tree managing the game objects.
void setDestroy(bool destroy)
Sets the destruction state of this node.
std::vector< GameObject * > findGameObjectsByTag(std::string tag)
Finds GameObjects by a tag.
GameObject * m_owner
Pointer to the GameObject that owns this script.
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 x
X coordinate of the vector.