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.
space-war/src/game/component.cpp

28 lines
1.1 KiB
C++
Raw Normal View History

#include "game/component.hpp"
#include "game/entity.hpp"
Entity* SpaceshipWeaponCmpt::ShootBullet(const Point& dir) {
2022-02-10 21:22:06 +08:00
if (bulletAmount == 0) return nullptr;
if (bulletAmount != InfBullet) {
bulletAmount --;
}
2022-02-15 22:50:31 +08:00
Entity* bullet = CreateBullet(owner->Get<GroupCmpt>()->groupIdx, 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) {
2022-02-10 21:22:06 +08:00
if (bulletAmount == 0) return nullptr;
if (bulletAmount != InfBullet) {
bulletAmount --;
}
2022-02-15 22:50:31 +08:00
Entity* bullet = CreateMissile(owner->Get<GroupCmpt>()->groupIdx, damage, owner, maxSpeed, target);
2022-02-09 22:33:06 +08:00
if (target) {
2022-02-10 21:22:06 +08:00
bullet->Use<BulletCmpt>()->rotation = Degrees(std::acos(Dot(dir, Normalize(target->Get<MoveCmpt>()->position - owner->Get<MoveCmpt>()->position))));
2022-02-09 22:33:06 +08:00
}
bullet->Use<MotionCmpt>()->speed = Normalize(dir) * shootSpeed;
bullet->Use<MoveCmpt>()->position = owner->Get<MoveCmpt>()->position;
return bullet;
}