Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/game/components.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "components/battle/transition_data.h"
#include "components/battle/ui_object.h"

#include "components/audio/audio.h"
#include "components/audio/audio_component.h"
#include "components/bullethell/booming.h"
#include "components/bullethell/bullet.h"
#include "components/bullethell/bullet_clearer.h"
Expand Down Expand Up @@ -40,13 +40,13 @@
#include "components/rhythm/combo.h"
#include "components/rhythm/holdconnect.h"
#include "components/rhythm/holdstart.h"
#include "components/rhythm/judgement_line.h"
#include "components/rhythm/judgetext.h"
#include "components/rhythm/keyinput.h"
#include "components/rhythm/lane.h"
#include "components/rhythm/notefield.h"
#include "components/rhythm/notestatus.h"
#include "components/rhythm/notetype.h"
#include "components/rhythm/timing.h"
#include "components/rhythm/judgement_line.h"

#include "system/ecs.h"
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <string>
#include <unordered_map>

#include "audio.h"
#include "system/asset_manager.h"

namespace Game::Audio
Expand Down
169 changes: 75 additions & 94 deletions include/game/components/battle/bullet_data.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once
#include <vector>

#include "../audio/audio.h"
#include "../audio/audio_component.h"
#include "game/components/bullethell/pattern.h"
#include "game/components/physics/base_collider.h"
#include "maths/point.h"

namespace Game::Battle
{
Expand Down Expand Up @@ -97,26 +99,65 @@ namespace Game::Battle
{}
};

struct BulletMovementData
{
float posX, posY;
float vel, rot;
float acc, wvel;

BulletMovementData(const float posX = 0,
const float posY = 0,
const float vel = 0,
const float rot = 0,
const float acc = 0,
const float wvel = 0):
posX(posX), posY(posY), vel(vel), rot(rot), acc(acc), wvel(wvel){}
};

struct BulletTimingData
{
int delay_frame;
int lifetime;

BulletTimingData(const int delay_frame = 0, const int lifetime = 5000): delay_frame(delay_frame), lifetime(lifetime){}
};

struct BulletGraphicMap
{
ColliderData collider_data;
GraphicData graphic_data;
SpecialBulletData special_bullet_data;
float damage_mul;
int pierce;

BulletGraphicMap() : damage_mul(1), pierce(1)
BulletGraphicMap()
{}

explicit BulletGraphicMap(
const ColliderData &collider_data,
const GraphicData &graphic_data = {},
const GraphicData &graphic_data = {}) :
collider_data(collider_data),
graphic_data(graphic_data)
{}
};

struct StageBulletData
{
int graphicID;
SpecialBulletData special_bullet_data;
BulletTimingData bullet_timing_data;
Math::Point size;
float damage_mul;
int pierce;

explicit StageBulletData(
const int graphicID = 0,
const SpecialBulletData &special_bullet_data = {},
const BulletTimingData &bullet_timing_data = {},
const Math::Point size = Math::Point(1, 1),
const float damage_mul = 1,
const int pierce = 1) :
collider_data(collider_data),
graphic_data(graphic_data),
special_bullet_data(special_bullet_data),
graphicID(graphicID),
bullet_timing_data(bullet_timing_data),
size(size),
damage_mul(damage_mul),
pierce(pierce)
{}
Expand All @@ -125,101 +166,40 @@ namespace Game::Battle
struct BulletRegistry
{
std::vector<BulletGraphicMap> bulletGraphicMaps;
std::vector<StageBulletData> bulletStageMaps;
BulletRegistry() {};
explicit BulletRegistry(std::vector<BulletGraphicMap>& bulletGraphicMaps) : bulletGraphicMaps(std::move(bulletGraphicMaps))
{}
explicit BulletRegistry(std::vector<BulletGraphicMap>& bulletGraphicMaps, std::vector<StageBulletData>& bulletStageMaps) :
bulletGraphicMaps(std::move(bulletGraphicMaps)), bulletStageMaps(std::move(bulletStageMaps))
{}
};

struct BulletData
{
float posX, posY;
float vel, rot;
float acc, wvel;
uint16_t patternID;
int delay_frame;
int lifetime;
int graphicID;
BulletData(
const float posX,
const float posY,
const int delay_frame,
const int lifetime,
const int graphicID) :
posX(posX),
posY(posY),
vel(0),
rot(0),
acc(0),
wvel(0),
patternID(0),
delay_frame(delay_frame),
lifetime(lifetime),
graphicID(graphicID)
{}
BulletData(
const float posX,
const float posY,
const float vel,
const float rot,
const int delay_frame,
const int lifetime,
const int graphicID) :
posX(posX),
posY(posY),
vel(vel),
rot(rot),
acc(0),
wvel(0),
patternID(0),
delay_frame(delay_frame),
lifetime(lifetime),
graphicID(graphicID)
{}
BulletData(
const float posX,
const float posY,
const float vel,
const float rot,
const uint16_t patternID,
const int delay_frame,
const int lifetime,
const int graphicID) :
posX(posX), posY(posY), vel(vel), rot(rot), acc(0), wvel(0), patternID(patternID), delay_frame(delay_frame), lifetime(lifetime), graphicID(graphicID)
{}
BulletData(
const float posX,
const float posY,
const float vel,
const float rot,
const float acc,
const float wvel,
const int delay_frame,
const int lifetime,
const int graphicID) :
posX(posX),
posY(posY),
vel(vel),
rot(rot),
acc(acc),
wvel(wvel),
patternID(0),
delay_frame(delay_frame),
lifetime(lifetime),
graphicID(graphicID)
{}
BulletMovementData movement_data;
BulletHell::Pattern pattern;
int bullet_id;

BulletData() = default;

BulletData(
const float posX,
const float posY,
const float vel,
const float rot,
const float acc,
const float wvel,
const uint16_t patternID,
const int delay_frame,
const int lifetime,
const int graphicID) :
posX(posX), posY(posY), vel(vel), rot(rot), acc(acc), wvel(wvel), patternID(patternID), delay_frame(delay_frame), lifetime(lifetime), graphicID(graphicID)
const int bullet_id,
const float posX = 0,
const float posY = 0,
const float speed = 0,
const float rot = 0,
const float acc = 0,
const float vwel = 0,
const uint16_t pattern_id = 0,
const float p0 = 0,
const float p1 = 0,
const float p2 = 0,
const float p3 = 0
) :
movement_data({posX,posY, speed, rot,acc,vwel}),
pattern({pattern_id,p0,p1,p2,p3}),
bullet_id(bullet_id)
{}
};

Expand All @@ -232,6 +212,7 @@ namespace Game::Battle
struct BulletLoader
{
// this should be global.
bool initialized = false;
int current_frame;
int pointer;

Expand Down
6 changes: 5 additions & 1 deletion include/game/components/battle/pattern_container.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#pragma once
#include <array>

namespace Game::Battle
{
enum PatternOp : uint8_t
{
OP_SET,
OP_ADD
OP_ADD,
OP_MULT,
OP_PARAM
};
constexpr size_t MAX_PATTERNS = 128;
constexpr size_t MAX_PATTERN_SEQUENCE = 16;
Expand Down Expand Up @@ -45,6 +48,7 @@ namespace Game::Battle
std::vector<PatternSequence> pattern_sequences;
std::vector<PatternStep> pattern_steps;

PatternContainer() = default;
PatternContainer(
std::vector<PatternStep> steps,
std::vector<PatternSequence> seqs)
Expand Down
15 changes: 11 additions & 4 deletions include/game/components/bullethell/pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ namespace Game::BulletHell
int sequenceIdx = -1; // Would not be good but require for init
int delay = 0;

Pattern() : sequenceID(0)
float params[4];

Pattern() : sequenceID(0), params{}
{}

explicit Pattern(
const uint16_t sequenceID) :
sequenceID(sequenceID)
Pattern(const uint16_t sequenceID,
const float p0 = 0,
const float p1 = 0,
const float p2 = 0,
const float p3 = 0) : sequenceID(sequenceID), params{p0,p1,p2,p3}
{}


//TODO : Constructor with params
};
} // namespace Game::BulletHell
49 changes: 33 additions & 16 deletions include/game/systems/bullethell/bullet_load_system.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
#pragma once
#include "../../components/audio/audio.h"
#include "../../components/audio/audio_component.h"
#include "game/components.h"

// TODO : Render stuffs
namespace Game::BulletHell
{
// Refactor later
template<typename T>
void spawn_bullet(T &syscall, const Battle::BulletData& bullet_data, const Battle::BulletRegistry& bullet_registry, const Battle::BulletHellState bhs, const Audio::SoundRegistry sound_registry)
{
if (bullet_data.graphicID >= bullet_registry.bulletGraphicMaps.size()) return;
if (bullet_data.bullet_id >= bullet_registry.bulletStageMaps.size()) return;

const System::ECS::pid bullet = syscall.create_entity(Render::Transform(bullet_data.posX,bullet_data.posY), Delay(bullet_data.delay_frame));
const auto &bullet_stage_data = bullet_registry.bulletStageMaps[bullet_data.bullet_id];
const auto &bullet_graphic_data = bullet_registry.bulletGraphicMaps[bullet_stage_data.graphicID];

syscall.add_components(bullet, Rotation(bullet_data.rot,true), Velocity(bullet_data.vel), Acceleration(bullet_data.acc), AngularVelocity(bullet_data.wvel), Pattern(bullet_data.patternID));
auto &bullet_movement = bullet_data.movement_data;
auto &bullet_timing = bullet_stage_data.bullet_timing_data;

const Battle::BulletGraphicMap bullet_info = bullet_registry.bulletGraphicMaps[bullet_data.graphicID];
syscall.add_components(bullet, Bullet(static_cast<int>(bullet_info.damage_mul * static_cast<float>(bhs.damage)), bullet_info.pierce), Particle(bullet_data.lifetime));
const System::ECS::pid bullet = syscall.create_entity(Render::Transform(bullet_movement.posX,bullet_movement.posY,0,0,0,bullet_stage_data.size.x,bullet_stage_data.size.y,1), Delay(bullet_timing.delay_frame));

if (bullet_info.special_bullet_data.type == Battle::Booming) syscall.add_components(bullet, Booming(bullet_info.special_bullet_data.size, bullet_info.special_bullet_data.frame));
else if (bullet_info.special_bullet_data.type == Battle::Laser) syscall.add_components(bullet, Laser(bullet_data.posX, bullet_data.posY, bullet_info.special_bullet_data.size, bullet_info.special_bullet_data.frame));
syscall.add_components(bullet, Rotation(bullet_movement.rot,true), Velocity(bullet_movement.vel), Acceleration(bullet_movement.acc), AngularVelocity(bullet_movement.wvel), Pattern(bullet_data.pattern));

const Battle::GraphicData bullet_graphic = bullet_info.graphic_data;
syscall.add_components(bullet, Bullet(static_cast<int>(bullet_stage_data.damage_mul * static_cast<float>(bhs.damage)), bullet_stage_data.pierce), Particle(bullet_timing.lifetime));

if (bullet_stage_data.special_bullet_data.type == Battle::Booming) syscall.add_components(bullet, Booming(bullet_stage_data.special_bullet_data.size, bullet_stage_data.special_bullet_data.frame));
else if (bullet_stage_data.special_bullet_data.type == Battle::Laser) syscall.add_components(bullet, Laser(bullet_movement.posX, bullet_movement.posY, bullet_stage_data.special_bullet_data.size, bullet_stage_data.special_bullet_data.frame));

const Battle::GraphicData &bullet_graphic = bullet_graphic_data.graphic_data;
syscall.add_components(bullet, Render::Sprite{
.sp = get_assets_record_ptr(get_assets_id("bullet_sprite")),
.pos = {{bullet_graphic.dest_rect[0], bullet_graphic.dest_rect[3], 0}, {bullet_graphic.dest_rect[2], bullet_graphic.dest_rect[3], 0}, {bullet_graphic.dest_rect[2], bullet_graphic.dest_rect[1], 0}, {bullet_graphic.dest_rect[0], bullet_graphic.dest_rect[1], 0}},
Expand All @@ -30,21 +35,21 @@ namespace Game::BulletHell
.u1 = static_cast<float>(bullet_graphic.src_rect[2])/512,
.v1 = static_cast<float>(bullet_graphic.src_rect[3])/512}
, Render::Material(get_assets_record_ptr(get_assets_id("sprite_vs")),get_assets_record_ptr(get_assets_id("sprite_ps")), {bullet_graphic.r, bullet_graphic.g, bullet_graphic.b, bullet_graphic.a}));
if (const Battle::ColliderData bullet_collider = bullet_info.collider_data;
if (const Battle::ColliderData &bullet_collider = bullet_graphic_data.collider_data;
bullet_collider.type == Physics::RECTANGLE) syscall.add_components(bullet, Physics::RectangularCollider(bullet_collider.offsetX,bullet_collider.offsetY, bullet_collider.colX, bullet_collider.colY));
else if (bullet_collider.type == Physics::CIRCLE) syscall.add_components(bullet, Physics::CircularCollider(bullet_collider.offsetX,bullet_collider.offsetY, bullet_collider.colX, bullet_collider.colY));

auto sounds = sound_registry.audios;
switch (bullet_info.graphic_data.bullet_spawn_sound)
auto &sounds = sound_registry.audios;
switch (bullet_graphic_data.graphic_data.bullet_spawn_sound)
{
case 1 :
// Audio::audio_play(sounds["sound_bullet_spawn_0"]);
// Audio::audio_play(sounds.at("sound_bullet_spawn_0"));
break;
case 2 :
// Audio::audio_play(sounds["sound_bullet_spawn_1"]);
// Audio::audio_play(sounds.at("sound_bullet_spawn_1"));
break;
case 3 :
// Audio::audio_play(sounds["sound_bullet_spawn_2"]);
Audio::audio_play(sounds.at("sound_bullet_spawn_2"));
break;
default:;
}
Expand All @@ -63,6 +68,18 @@ namespace Game::BulletHell
auto &pointer = bullet_loader.pointer;
auto &batches = bullet_loader.batches;
const auto &current_frame = query3.front().get<Battle::BattleState>().clock_time / 1000;

// Sort bullet spawn frame
if (!bullet_loader.initialized)
{
std::sort(batches.begin(), batches.end(),
[](const Battle::BulletBatch & a, const Battle::BulletBatch& b)
{
return a.frame < b.frame;
});
bullet_loader.initialized = true;
}

while ((pointer < static_cast<int>(batches.size())) && (batches[pointer].frame <= current_frame))
{
for (auto& b : batches[pointer].bullets)
Expand Down
Loading