This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
113 lines (90 loc) · 2.77 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "Components/Transform.h"
#include "Components/Sprite.h"
#include "Components/AnimatedSprite.h"
#include "Components/PlayerComponent.h"
#include "Systems/PlayerSystem.h"
#include "Systems/RenderSystem.h"
#include "Components/BulletComponent.h"
#include "Systems/BulletSystem.h"
#include "Components/BoxCollider.h"
#include "Core/Input.h"
#include "Core/World.h"
#include "Core/Window.h"
#include <SDL2/SDL.h>
#ifdef _WIN32
#undef main
#endif
#ifdef ECS_DEBUG
#ifdef _MSC_VER
#pragma message("[ECS] Compiling in debug mode")
#else
#warning [ECS] Compiling in debug mode
#endif
#endif
int main() {
// Inits
World game_world;
Window::create_window("SDL Test", 640, 480);
// Entities/Components
Entity* ent = new Entity{};
Transform* t = new Transform{};
t->set_scale(Vector2{2, 2});
AnimatedSprite* spr = new AnimatedSprite{};
spr->add_textures({
"Sprites/Player/Player_up.png",
"Sprites/Player/Player_up2.png",
"Sprites/Player/Player_up3.png",
"Sprites/Player/Player_up4.png",
"Sprites/Player/Player_up5.png",
"Sprites/Player/Player_down.png",
"Sprites/Player/Player_down2.png",
"Sprites/Player/Player_down3.png",
"Sprites/Player/Player_down4.png",
"Sprites/Player/Player_down5.png",
"Sprites/Player/Player_left.png",
"Sprites/Player/Player_left2.png",
"Sprites/Player/Player_left3.png",
"Sprites/Player/Player_left4.png",
"Sprites/Player/Player_left5.png",
"Sprites/Player/Player_right.png",
"Sprites/Player/Player_right2.png",
"Sprites/Player/Player_right3.png",
"Sprites/Player/Player_right4.png",
"Sprites/Player/Player_right5.png"});
spr->add_animation("up", {0});
spr->add_animation("up_walk", {1, 2, 1, 0, 3, 4, 3, 0}, 10.0);
spr->add_animation("down", {5});
spr->add_animation("down_walk", {6, 7, 6, 5, 8, 9, 8, 5}, 10.0);
spr->add_animation("left", {10});
spr->add_animation("left_walk", {11, 12, 11, 10, 13, 14, 13, 10}, 10.0);
spr->add_animation("right", {15});
spr->add_animation("right_walk", {16, 17, 16, 15, 18, 19, 18, 15}, 10.0);
spr->set_centered(true);
PlayerComponent* player = new PlayerComponent{};
ent->add_component(t);
ent->add_component(spr);
ent->add_component(player);
PlayerSystem psys{};
RenderSystem rsys{};
BulletSystem bsys{};
game_world.add_entity(ent);
game_world.add_component(t);
game_world.add_component(spr);
game_world.add_component(player);
game_world.add_system(&psys);
game_world.add_system(&rsys);
game_world.add_system(&bsys);
BoxCollider* coll = new BoxCollider{Vector2{0, 0}, 10, 10};
ent->add_component(coll);
game_world.add_component(coll);
while (!game_world.is_game_quit()) {
game_world.poll_events();
game_world.tick_delta_time();
Window::clear();
game_world.process_systems();
Window::update();
}
game_world.cleanup();
Window::destroy_window();
SDL_Quit();
}