R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
AnimationDatabase.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** RTYPE
4** File description:
5** AnimationDatabase
6*/
7
8#pragma once
9
10#include <functional>
11#include <initializer_list>
12#include <unordered_map>
13#include "../ECS/Components/AnimationSet.hpp"
14
15namespace AnimDB {
25 inline ecs::AnimationClip makeClip(std::initializer_list<ecs::Rectangle> frames, float duration = 0.1f,
26 bool loop = true, const std::string &nextClip = "") {
27 return ecs::AnimationClip(std::vector<ecs::Rectangle>(frames), duration, loop, nextClip);
28 }
29
36 ecs::AnimationSet animSet("PlayerShip");
37
38 // Idle animation - single frame
39 animSet.addClip("player_idle", makeClip({{1, 69, 33, 14}}, 0.15f, true));
40
41 // Flying animation - 5 frames loop (slower animation with 0.15s per frame)
42 animSet.addClip(
43 "player_movement",
45 {{1, 69, 33, 14}, {34, 69, 33, 14}, {67, 69, 33, 14}, {100, 69, 33, 14}, {133, 69, 33, 14}},
46 0.2f, true));
47
48 return animSet;
49 }
50
57 ecs::AnimationSet animSet("OrbitalModule");
58
59 // Spin animation - 12 frames
60 animSet.addClip("orbital_spin", makeClip({{0, 0, 17, 18},
61 {17, 0, 17, 18},
62 {34, 0, 17, 18},
63 {51, 0, 17, 18},
64 {68, 0, 17, 18},
65 {85, 0, 17, 18},
66 {102, 0, 17, 18},
67 {119, 0, 17, 18},
68 {136, 0, 17, 18},
69 {153, 0, 17, 18},
70 {170, 0, 17, 18},
71 {187, 0, 17, 18}},
72 0.1f, true));
73
74 return animSet;
75 }
76
83 ecs::AnimationSet animSet("BasicEnemy");
84
85 // Simple 16 frames flying animation
86 animSet.addClip("enemy_fly", makeClip({{0, 0, 33, 34},
87 {33, 0, 33, 34},
88 {66, 0, 33, 34},
89 {99, 0, 33, 34},
90 {132, 0, 33, 34},
91 {165, 0, 33, 34},
92 {198, 0, 33, 34},
93 {231, 0, 33, 34},
94 {0, 34, 33, 34},
95 {33, 34, 33, 34},
96 {66, 34, 33, 34},
97 {99, 34, 33, 34},
98 {132, 34, 33, 34},
99 {165, 34, 33, 34},
100 {198, 34, 33, 34},
101 {231, 34, 33, 34}},
102 0.1f, true));
103
104 return animSet;
105 }
106
113 ecs::AnimationSet animSet("WalkingEnemy");
114
115 // Walking animation left 3 frames
116 animSet.addClip("walk_left",
117 makeClip({{0, 0, 33, 34}, {33, 0, 33, 34}, {66, 0, 33, 34}}, 0.15f, true));
118
119 // Walking animation right 3 frames
120 animSet.addClip("walk_right",
121 makeClip({{100, 0, 33, 34}, {133, 0, 33, 34}, {166, 0, 33, 34}}, 0.15f, true));
122
123 // Slightly flying left animation 3 frames
124 animSet.addClip("fly_left",
125 makeClip({{0, 34, 33, 34}, {33, 34, 33, 34}, {66, 34, 33, 34}}, 0.1f, true));
126
127 // Slightly flying right animation 3 frames
128 animSet.addClip("fly_right",
129 makeClip({{100, 34, 33, 34}, {133, 34, 33, 34}, {166, 34, 33, 34}}, 0.1f, true));
130
131 return animSet;
132 }
133
140 ecs::AnimationSet animSet("r-typesheet10");
141
142 // Idle animation
143 animSet.addClip("idle", makeClip({{0, 0, 128, 128}}, 0.1f, true));
144
145 // Hurt animation - flashes then returns to idle
146 animSet.addClip("hurt", makeClip({{128, 0, 128, 128}, {256, 0, 128, 128}}, 0.08f, false, "idle"));
147
148 // Attack animation - returns to idle after
149 animSet.addClip("attack", makeClip({{0, 128, 128, 128}, {128, 128, 128, 128}, {256, 128, 128, 128}},
150 0.12f, false, "idle"));
151
152 return animSet;
153 }
154
161 ecs::AnimationSet animSet("r-typesheet11");
162
163 // Idle animation
164 animSet.addClip("idle", makeClip({{0, 0, 64, 64}}, 0.1f, true));
165
166 // Attack animation
167 animSet.addClip("attack",
168 makeClip({{0, 0, 64, 64}, {64, 0, 64, 64}, {128, 0, 64, 64}}, 0.15f, false, "idle"));
169
170 return animSet;
171 }
172
179 ecs::AnimationSet animSet("Projectiles");
180
181 animSet.addClip("projectile_fly",
182 makeClip({{267, 84, 17, 13}, {284, 84, 17, 13}, {301, 84, 17, 13}}, 0.2F, true));
183 animSet.addClip("charged_projectile_1", makeClip(
184 {
185 {200, 121, 32, 10},
186 {232, 121, 32, 10},
187 },
188 0.2F, true));
189
190 return animSet;
191 }
192
199 ecs::AnimationSet animSet("r-typesheet2");
200
201 // Simple bullet animation
202 animSet.addClip("fly", makeClip({{0, 48, 8, 8}, {8, 48, 8, 8}}, 0.1f, true));
203
204 return animSet;
205 }
206
210 using AnimationFactory = std::function<ecs::AnimationSet()>;
211
217 inline const std::unordered_map<std::string, AnimationFactory> FACTORIES = {
218 {"player", createPlayerAnimations},
219 {"enemy_basic", createEnemyBasicAnimations},
220 {"boss_body", createBossBodyAnimations},
221 {"boss_arm", createBossArmAnimations},
222 {"player_bullet", createPlayerBulletAnimations},
223 {"enemy_bullet", createEnemyBulletAnimations}};
224
233 inline ecs::AnimationSet getAnimationSet(const std::string &entityType) {
234 auto it = FACTORIES.find(entityType);
235 if (it != FACTORIES.end()) {
236 return it->second();
237 }
238
239 // Default fallback - simple idle animation
240 ecs::AnimationSet defaultSet("r-typesheet1");
241 defaultSet.addClip("idle", makeClip({{0, 0, 32, 32}}));
242 return defaultSet;
243 }
244} // namespace AnimDB
Component containing all available animations for an entity.
void addClip(const std::string &clipName, const AnimationClip &clip)
Add an animation clip.
const std::unordered_map< std::string, AnimationFactory > FACTORIES
Map of entity types to their animation factory functions.
ecs::AnimationSet createPlayerAnimations()
Create player ship animations.
ecs::AnimationSet createEnemyWalkingAnimations()
Create walking enemy animations.
ecs::AnimationClip makeClip(std::initializer_list< ecs::Rectangle > frames, float duration=0.1f, bool loop=true, const std::string &nextClip="")
Helper to create animation clips easily.
ecs::AnimationSet createOrbitalModuleAnimations()
Create drone (orbital module) animations.
ecs::AnimationSet createEnemyBasicAnimations()
Create basic enemy animations.
ecs::AnimationSet createPlayerBulletAnimations()
Create player bullet animations.
ecs::AnimationSet createEnemyBulletAnimations()
Create enemy bullet animations.
ecs::AnimationSet createBossArmAnimations()
Create boss arm animations.
ecs::AnimationSet createBossBodyAnimations()
Create boss body animations.
ecs::AnimationSet getAnimationSet(const std::string &entityType)
Get an AnimationSet by entity type.
std::function< ecs::AnimationSet()> AnimationFactory
Factory function type for animation set creation.
Defines a sequence of frames for an animation.