179 lines
3.6 KiB
C++
179 lines
3.6 KiB
C++
#pragma once
|
|
|
|
#include "tinyengine/tinyengine.hpp"
|
|
#include "game/constants.hpp"
|
|
#include "game/global.hpp"
|
|
|
|
class MoveCmpt: public Component {
|
|
public:
|
|
void Init(const Point& p) { position = p; oldPosition = position; }
|
|
void Release() {}
|
|
|
|
Point position;
|
|
Point oldPosition;
|
|
};
|
|
|
|
class MotionCmpt: public Component {
|
|
public:
|
|
void Init(const Point& spd, float maxSpd) {
|
|
speed = spd;
|
|
maxSpeed = maxSpd;
|
|
acceleration = {0, 0};
|
|
}
|
|
void Release() {}
|
|
|
|
Point speed;
|
|
Point acceleration;
|
|
|
|
float maxSpeed;
|
|
};
|
|
|
|
class CollisionCmpt: public Component {
|
|
public:
|
|
void Init(const Size& size) { rect.w = size.w; rect.h = size.h; }
|
|
void Release() {}
|
|
|
|
Rect rect;
|
|
};
|
|
|
|
class BulletCmpt: public Component {
|
|
public:
|
|
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;
|
|
}
|
|
inline void Release() override {}
|
|
|
|
Type type;
|
|
int damage;
|
|
Entity* owner;
|
|
Entity* target;
|
|
float rotation;
|
|
bool alive;
|
|
};
|
|
|
|
|
|
|
|
class SpaceshipWeaponCmpt: public Component {
|
|
public:
|
|
enum Type {
|
|
Orientation = 0x01,
|
|
FreeRotation = 0x02,
|
|
};
|
|
|
|
void Init(const std::string& name,
|
|
Type type,
|
|
BulletCmpt::Type bulletType,
|
|
Entity* owner,
|
|
int damage,
|
|
float shootSpeed,
|
|
float maxSpeed,
|
|
float duration) {
|
|
this->name = name;
|
|
this->type = type;
|
|
this->bulletType = bulletType;
|
|
this->owner = owner;
|
|
this->damage = damage;
|
|
this->shootSpeed = shootSpeed;
|
|
this->shootDuration = duration;
|
|
this->coolDown = 0;
|
|
this->maxSpeed = maxSpeed;
|
|
}
|
|
|
|
void Release() {}
|
|
bool IsCoolDowning() const { return coolDown >= 0; }
|
|
Entity* ShootBullet(const Point& dir);
|
|
Entity* ShootMissile(const Point& dir, Entity* target);
|
|
|
|
Type type;
|
|
BulletCmpt::Type bulletType;
|
|
std::string name;
|
|
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 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;
|
|
};
|
|
|
|
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;
|
|
};
|
|
};
|
|
|