This repository has been archived on 2022-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
2022-02-07 21:38:35 +08:00
|
|
|
#include "game/component.hpp"
|
|
|
|
#include "game/entity.hpp"
|
|
|
|
|
|
|
|
Entity* SpaceshipWeaponCmpt::ShootBullet(const Point& dir) {
|
|
|
|
Entity* bullet = CreateBullet(damage, owner, maxSpeed);
|
|
|
|
bullet->Use<MotionCmpt>()->speed = Normalize(dir) * shootSpeed;
|
|
|
|
bullet->Use<MoveCmpt>()->position = owner->Get<MoveCmpt>()->position;
|
|
|
|
return bullet;
|
|
|
|
}
|
2022-02-09 22:33:06 +08:00
|
|
|
|
|
|
|
Entity* SpaceshipWeaponCmpt::ShootMissile(const Point& dir, Entity* target) {
|
|
|
|
Entity* bullet = CreateMissile(damage, owner, maxSpeed, target);
|
|
|
|
if (target) {
|
|
|
|
bullet->Use<BulletCmpt>()->rotation = Degrees(std::acos(Dot(dir, Normalize(target->Get<MoveCmpt>()->position - owner->Get<MoveCmpt>()->position))));
|
|
|
|
}
|
|
|
|
bullet->Use<MotionCmpt>()->speed = Normalize(dir) * shootSpeed;
|
|
|
|
bullet->Use<MoveCmpt>()->position = owner->Get<MoveCmpt>()->position;
|
|
|
|
return bullet;
|
|
|
|
}
|