2022-02-07 21:38:35 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "tinyengine/tinyengine.hpp"
|
|
|
|
#include "game/constants.hpp"
|
2022-02-09 22:33:06 +08:00
|
|
|
#include "game/global.hpp"
|
2022-02-07 21:38:35 +08:00
|
|
|
|
|
|
|
class MoveCmpt: public Component {
|
|
|
|
public:
|
2022-02-08 21:02:52 +08:00
|
|
|
void Init(const Point& p) { position = p; oldPosition = position; }
|
2022-02-07 21:38:35 +08:00
|
|
|
void Release() {}
|
|
|
|
|
|
|
|
Point position;
|
2022-02-08 21:02:52 +08:00
|
|
|
Point oldPosition;
|
2022-02-07 21:38:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class MotionCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init(const Point& spd, float maxSpd) {
|
|
|
|
speed = spd;
|
|
|
|
maxSpeed = maxSpd;
|
2022-02-08 21:02:52 +08:00
|
|
|
acceleration = {0, 0};
|
2022-02-07 21:38:35 +08:00
|
|
|
}
|
|
|
|
void Release() {}
|
|
|
|
|
|
|
|
Point speed;
|
2022-02-08 21:02:52 +08:00
|
|
|
Point acceleration;
|
2022-02-07 21:38:35 +08:00
|
|
|
|
|
|
|
float maxSpeed;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CollisionCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init(const Size& size) { rect.w = size.w; rect.h = size.h; }
|
|
|
|
void Release() {}
|
|
|
|
|
|
|
|
Rect rect;
|
|
|
|
};
|
|
|
|
|
2022-02-09 22:33:06 +08:00
|
|
|
class BulletCmpt: public Component {
|
2022-02-08 21:02:52 +08:00
|
|
|
public:
|
2022-02-09 22:33:06 +08:00
|
|
|
enum Type {
|
|
|
|
Bullet = 1,
|
|
|
|
Missile,
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void Init(Type type, int damage, Entity* owner, Entity* target = nullptr) {
|
|
|
|
this->owner = owner;
|
|
|
|
this->damage = damage;
|
|
|
|
this->target = target;
|
|
|
|
this->type = type;
|
|
|
|
rotation = 0;
|
|
|
|
alive = true;
|
2022-02-08 21:02:52 +08:00
|
|
|
}
|
2022-02-09 22:33:06 +08:00
|
|
|
inline void Release() override {}
|
2022-02-08 21:02:52 +08:00
|
|
|
|
2022-02-09 22:33:06 +08:00
|
|
|
Type type;
|
|
|
|
int damage;
|
|
|
|
Entity* owner;
|
|
|
|
Entity* target;
|
|
|
|
float rotation;
|
|
|
|
bool alive;
|
2022-02-08 21:02:52 +08:00
|
|
|
};
|
|
|
|
|
2022-02-09 22:33:06 +08:00
|
|
|
|
2022-02-08 21:02:52 +08:00
|
|
|
|
2022-02-07 21:38:35 +08:00
|
|
|
class SpaceshipWeaponCmpt: public Component {
|
|
|
|
public:
|
|
|
|
enum Type {
|
|
|
|
Orientation = 0x01,
|
|
|
|
FreeRotation = 0x02,
|
|
|
|
};
|
|
|
|
|
2022-02-10 21:22:06 +08:00
|
|
|
static constexpr int InfBullet = -1;
|
|
|
|
|
2022-02-09 22:33:06 +08:00
|
|
|
void Init(const std::string& name,
|
|
|
|
Type type,
|
|
|
|
BulletCmpt::Type bulletType,
|
2022-02-07 21:38:35 +08:00
|
|
|
Entity* owner,
|
|
|
|
int damage,
|
|
|
|
float shootSpeed,
|
|
|
|
float maxSpeed,
|
2022-02-10 21:22:06 +08:00
|
|
|
float duration,
|
|
|
|
int bulletAmount = InfBullet) {
|
2022-02-09 22:33:06 +08:00
|
|
|
this->name = name;
|
2022-02-07 21:38:35 +08:00
|
|
|
this->type = type;
|
2022-02-09 22:33:06 +08:00
|
|
|
this->bulletType = bulletType;
|
2022-02-07 21:38:35 +08:00
|
|
|
this->owner = owner;
|
|
|
|
this->damage = damage;
|
|
|
|
this->shootSpeed = shootSpeed;
|
|
|
|
this->shootDuration = duration;
|
2022-02-09 22:33:06 +08:00
|
|
|
this->coolDown = 0;
|
2022-02-07 21:38:35 +08:00
|
|
|
this->maxSpeed = maxSpeed;
|
2022-02-10 21:22:06 +08:00
|
|
|
this->bulletAmount = bulletAmount;
|
2022-02-07 21:38:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Release() {}
|
|
|
|
bool IsCoolDowning() const { return coolDown >= 0; }
|
|
|
|
Entity* ShootBullet(const Point& dir);
|
2022-02-09 22:33:06 +08:00
|
|
|
Entity* ShootMissile(const Point& dir, Entity* target);
|
2022-02-07 21:38:35 +08:00
|
|
|
|
|
|
|
Type type;
|
2022-02-09 22:33:06 +08:00
|
|
|
BulletCmpt::Type bulletType;
|
|
|
|
std::string name;
|
2022-02-07 21:38:35 +08:00
|
|
|
int damage;
|
|
|
|
float shootSpeed;
|
|
|
|
float shootDuration;
|
|
|
|
float coolDown;
|
|
|
|
float maxSpeed;
|
|
|
|
Entity* owner;
|
2022-02-10 21:22:06 +08:00
|
|
|
int bulletAmount;
|
2022-02-07 21:38:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class SpaceshipArmorCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init(int defence, float duration) {
|
|
|
|
this->defence = defence;
|
|
|
|
this->recoverDuration = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
int defence;
|
|
|
|
float recoverDuration;
|
|
|
|
};
|
|
|
|
|
2022-02-09 22:33:06 +08:00
|
|
|
class FreightShipCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init(SpaceshipWeaponCmpt* weapon) {
|
|
|
|
this->weapon = weapon;
|
|
|
|
}
|
|
|
|
void Release() { ECSContext.DestroyComponent(weapon); }
|
|
|
|
|
|
|
|
SpaceshipWeaponCmpt* weapon;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FightShipCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init(SpaceshipWeaponCmpt* weapon1, SpaceshipWeaponCmpt* weapon2) {
|
|
|
|
this->degree = 0;
|
|
|
|
this->weapon1 = weapon1;
|
|
|
|
this->weapon2 = weapon2;
|
|
|
|
}
|
|
|
|
void Release() {
|
|
|
|
ECSContext.DestroyComponent(weapon1);
|
|
|
|
ECSContext.DestroyComponent(weapon2);
|
|
|
|
}
|
|
|
|
|
|
|
|
float degree;
|
|
|
|
SpaceshipWeaponCmpt* weapon1;
|
|
|
|
SpaceshipWeaponCmpt* weapon2;
|
|
|
|
};
|
|
|
|
|
2022-02-07 21:38:35 +08:00
|
|
|
class LifeCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init(int hp) { this->hp = hp; }
|
|
|
|
void Release() {}
|
|
|
|
|
|
|
|
int hp;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RenderCmpt: public Component {
|
|
|
|
public:
|
|
|
|
enum Type {
|
|
|
|
TypeTexture = 1,
|
|
|
|
TypeTile,
|
|
|
|
};
|
|
|
|
|
|
|
|
void Init(Texture* image) {
|
|
|
|
texture = image;
|
|
|
|
type = TypeTexture;
|
|
|
|
}
|
|
|
|
void Init(const Tile& tile) {
|
|
|
|
this->tile = tile;
|
|
|
|
type = TypeTile;
|
|
|
|
}
|
|
|
|
void Release() {}
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
union {
|
|
|
|
Texture* texture;
|
|
|
|
Tile tile;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-02-15 22:50:31 +08:00
|
|
|
class PlanetCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init(const Point& position, const Size& size) {
|
|
|
|
positionInSpace = position;
|
|
|
|
generateMap(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point positionInSpace;
|
|
|
|
Unique<Mat<Entity*>> map;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void generateMap(const Size& size);
|
|
|
|
};
|
|
|
|
|
|
|
|
class EnergyProductCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init(int amount, float duration) {
|
|
|
|
this->productAmount = amount;
|
|
|
|
this->duration = duration;
|
|
|
|
this->cooldown = duration;
|
|
|
|
this->amount = 0;
|
|
|
|
}
|
|
|
|
bool IsCoolDowning() { return cooldown > 0; }
|
|
|
|
void Release() {}
|
|
|
|
|
|
|
|
float duration;
|
|
|
|
float cooldown;
|
|
|
|
int productAmount;
|
|
|
|
int amount;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GroupCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init(int group) {
|
|
|
|
groupIdx = group;
|
|
|
|
}
|
|
|
|
void Release() {}
|
|
|
|
|
|
|
|
int groupIdx;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AICmpt: public Component {
|
|
|
|
public:
|
|
|
|
using AIFunc = std::function<void(Entity*)>;
|
|
|
|
|
|
|
|
void Init(AIFunc func) {
|
|
|
|
this->func = func;
|
2022-02-17 15:12:24 +08:00
|
|
|
target = nullptr;
|
2022-02-15 22:50:31 +08:00
|
|
|
}
|
|
|
|
void Release() {}
|
|
|
|
|
|
|
|
AIFunc func;
|
2022-02-17 15:12:24 +08:00
|
|
|
Entity* target;
|
2022-02-15 22:50:31 +08:00
|
|
|
};
|