2022-02-07 21:38:35 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "tinyengine/tinyengine.hpp"
|
|
|
|
#include "game/constants.hpp"
|
|
|
|
|
|
|
|
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-08 21:02:52 +08:00
|
|
|
class FightShipCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init(float degree) {
|
|
|
|
this->degree = degree;
|
|
|
|
}
|
|
|
|
void Release() {}
|
|
|
|
|
|
|
|
float degree;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FreightShipCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init() {}
|
|
|
|
void Release() {}
|
|
|
|
};
|
|
|
|
|
2022-02-07 21:38:35 +08:00
|
|
|
class SpaceshipWeaponCmpt: public Component {
|
|
|
|
public:
|
|
|
|
enum Type {
|
|
|
|
Orientation = 0x01,
|
|
|
|
FreeRotation = 0x02,
|
|
|
|
};
|
|
|
|
|
|
|
|
void Init(Type type,
|
|
|
|
Entity* owner,
|
|
|
|
int damage,
|
|
|
|
float shootSpeed,
|
|
|
|
float maxSpeed,
|
|
|
|
float duration) {
|
|
|
|
this->type = type;
|
|
|
|
this->owner = owner;
|
|
|
|
this->damage = damage;
|
|
|
|
this->shootSpeed = shootSpeed;
|
|
|
|
this->shootDuration = duration;
|
|
|
|
this->maxSpeed = maxSpeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Release() {}
|
|
|
|
bool IsCoolDowning() const { return coolDown >= 0; }
|
|
|
|
Entity* ShootBullet(const Point& dir);
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
int damage;
|
|
|
|
float shootSpeed;
|
|
|
|
float shootDuration;
|
|
|
|
float coolDown;
|
|
|
|
float maxSpeed;
|
|
|
|
Entity* owner;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SpaceshipArmorCmpt: public Component {
|
|
|
|
public:
|
|
|
|
void Init(int defence, float duration) {
|
|
|
|
this->defence = defence;
|
|
|
|
this->recoverDuration = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
int defence;
|
|
|
|
float recoverDuration;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
class BulletCmpt: public Component {
|
|
|
|
public:
|
|
|
|
inline void Init(int damage, Entity* owner) {
|
|
|
|
this->owner = owner;
|
|
|
|
this->damage = damage;
|
2022-02-08 21:02:52 +08:00
|
|
|
alive = true;
|
2022-02-07 21:38:35 +08:00
|
|
|
}
|
|
|
|
inline void Release() override {}
|
|
|
|
|
|
|
|
int damage;
|
|
|
|
Entity* owner;
|
|
|
|
bool alive;
|
|
|
|
};
|