Skip to content

Commit 04091f9

Browse files
committed
wip moving transform
1 parent d193d59 commit 04091f9

File tree

8 files changed

+181
-297
lines changed

8 files changed

+181
-297
lines changed

proj-BirdEngine/include/containers.h

+23-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,29 @@
55
#include <string>
66
#include <map>
77

8-
struct Vector2 { public: int x, y; };
9-
struct Direction : public Vector2 { public: Direction(int x = 0, int y = 0) : Vector2{ x, y } {} };
10-
struct Size : public Vector2 { public: Size(int width = 0, int height = 0) : Vector2{ width, height } {} };
11-
struct Position : public Vector2 { public: Position(int x = 0, int y = 0) : Vector2{ x, y } {} };
12-
struct Rect { Position position; Size size; };
8+
struct Vector2 {
9+
public:
10+
float x, y;
11+
};
12+
struct Direction : public Vector2 {
13+
public:
14+
Direction(float x = 0, float y = 0) : Vector2{ x, y } {}
15+
Direction(int x = 0, int y = 0) : Vector2{ (float)x, (float)y } {}
16+
};
17+
struct Size : public Vector2 {
18+
public:
19+
Size(float width = 0, float height = 0) : Vector2{ width, height } {}
20+
Size(int width = 0, int height = 0) : Vector2{ (float)width, (float)height } {}
21+
};
22+
struct Position : public Vector2 {
23+
public:
24+
Position(float x = 0, float y = 0) : Vector2{ x, y } {}
25+
Position(int x = 0, int y = 0) : Vector2{ (float)x, (float)y } {}
26+
};
27+
struct Rect {
28+
Position position;
29+
Size size;
30+
};
1331

1432
struct Color {
1533
static constexpr Color RED() { return Color(255, 0, 0); }

proj-BirdEngine/src/device_interface/renderer.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,21 @@ namespace WING {
7272
}
7373

7474
void draw_drawable(Drawable d) {
75-
auto rect = SDL_Rect{ d.transform->position.x, d.transform->position.y, d.transform->size.x, d.transform->size.y };
76-
SDL_RenderCopyEx(_renderer, asset_manager->get_texture(d.texture_id), NULL, &rect, d.transform->rotation, NULL, SDL_FLIP_NONE);
75+
auto rect = SDL_Rect{
76+
(int) d.transform->position.x,
77+
(int) d.transform->position.y,
78+
(int) d.transform->size.x,
79+
(int) d.transform->size.y
80+
};
81+
SDL_RenderCopyEx(
82+
_renderer,
83+
asset_manager->get_texture(d.texture_id),
84+
NULL,
85+
&rect,
86+
d.transform->rotation,
87+
NULL,
88+
SDL_FLIP_NONE
89+
);
7790
}
7891

7992
void add_drawable(Drawable drawable) {

proj-BirdEngine/src/device_interface/window.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace WING {
7171
const Rect& display_rect() {
7272
SDL_Rect r;
7373
SDL_GetDisplayBounds(0, &r);
74-
return Rect{ Position{r.x, r.y}, Size{r.w, r.h } };
74+
return Rect{ Position{(float)r.x, (float)r.y}, Size{(float)r.w, (float)r.h } };
7575
}
7676

7777
SDL_Window* sdl_window() {

proj-BirdEngine/src/registry/registry.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ namespace WING {
2727
Scene* new_scene = new Scene();
2828
all_scenes_list.push_back(new_scene);
2929
id_scene_map.insert({ new_scene->id(), new_scene });
30+
if (_starting_scene_id == -1) {
31+
_starting_scene_id = new_scene->id();
32+
}
3033
return new_scene->id();
3134
}
3235

proj-BirdEngine/src/registry/registry.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace WING {
1313

1414
std::vector<Scene*> all_scenes_list;
1515
std::map<SceneID, Scene*> id_scene_map;
16-
SceneID _starting_scene_id;
16+
SceneID _starting_scene_id = -1;
1717

1818
SceneID current_editing_scene_id;
1919
std::vector<SceneID> build_scene_list;

proj-FlappyBird/src/entities/pipe.h

+78-77
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,78 @@
1-
#pragma once
2-
#include "SDL.h"
3-
#include <iostream>
4-
#include <math/vector2.h>
5-
#include <system_component/transform.h>
6-
#include <system_component/drawable.h>
7-
#include <system_component/updatable.h>
8-
#include <system_component/entity.h>
9-
#include <system_component/collider.h>
10-
#include <entities/flappy_bird.h>
11-
#include <entities/flappy_bird.h>
12-
#include <state_machine_base/state_machine.h>
13-
#include <utils/class_type_check.h>
14-
#include <game/gameplay_base.h>
15-
16-
class Pipe : public StateMachineListener, public Transform, public Drawable, public Updatable, public Entity, public RectangleCollider {
17-
public:
18-
Pipe(StateMachineEventEmitter* game_sm_emitter, SDL_Texture* texture, Vector2 position, Vector2 size, float speed_x, SDL_RendererFlip flip = SDL_FLIP_NONE)
19-
: game_sm_emitter{ game_sm_emitter },
20-
Transform{ position, size },
21-
Drawable{ texture, this, 0, flip },
22-
Entity{}, speed_x{ speed_x },
23-
RectangleCollider{ this, this, Vector2{0.92, 0.99} }
24-
{
25-
auto current_state = game_sm_emitter->subscribe(this);
26-
check_new_game_state(current_state);
27-
}
28-
29-
RectangleCollider* rectangle_collider() { return this; }
30-
31-
~Pipe() {
32-
game_sm_emitter->unsubscribe(this);
33-
}
34-
35-
void check_new_game_state(State* state) {
36-
if (ClassTypeCheck::is_class_type<GameplayBase>(state)) {
37-
stop = true;
38-
}
39-
}
40-
41-
// Inherited via StateMachineListener
42-
void on_state_changed(State* old_state, State* new_state) override {
43-
check_new_game_state(new_state);
44-
}
45-
46-
void update(double elapsed_time) override {
47-
if (stop) {
48-
return;
49-
}
50-
// move left
51-
position = Vector2{ position.x + speed_x * elapsed_time, position.y };
52-
}
53-
54-
void collided(Collider* other) override {
55-
if (stop || collided_with_player) {
56-
return;
57-
}
58-
59-
// check collision with player
60-
bool other_is_player = other->owner()->tags().find(PLAYER) != other->owner()->tags().end();
61-
if (other_is_player) {
62-
FlappyBird* player = static_cast<FlappyBird*>(other->owner());
63-
player->die();
64-
collided_with_player = true;
65-
}
66-
}
67-
68-
private:
69-
bool stop = false;
70-
StateMachineEventEmitter* game_sm_emitter;
71-
bool collided_with_player = false;
72-
float speed_x = -100;
73-
const float jump_force = 4;
74-
const float gravity = -9.8;
75-
const float world_space_proportion = 90;
76-
const float relative_gravity = gravity * world_space_proportion;
77-
};
1+
//#pragma once
2+
//#include <wing.h>
3+
//#include "SDL.h"
4+
//#include <iostream>
5+
////#include <math/vector2.h>
6+
////#include <system_component/transform.h>
7+
////#include <system_component/drawable.h>
8+
//#include <system_component/updatable.h>
9+
//#include <system_component/entity.h>
10+
//#include <system_component/collider.h>
11+
//#include <entities/flappy_bird.h>
12+
//#include <entities/flappy_bird.h>
13+
//#include <state_machine_base/state_machine.h>
14+
//#include <utils/class_type_check.h>
15+
//#include <game/gameplay_base.h>
16+
//
17+
//class Pipe : public StateMachineListener, public Transform, public Drawable, public Updatable, public Entity, public RectangleCollider {
18+
//public:
19+
// Pipe(StateMachineEventEmitter* game_sm_emitter, SDL_Texture* texture, Position position, Size size, float speed_x, SDL_RendererFlip flip = SDL_FLIP_NONE)
20+
// : game_sm_emitter{ game_sm_emitter },
21+
// Transform{ position, size },
22+
// Drawable{ texture, this, 0, flip },
23+
// Entity{}, speed_x{ speed_x },
24+
// RectangleCollider{ this, this, Vector2{0.92, 0.99} }
25+
// {
26+
// auto current_state = game_sm_emitter->subscribe(this);
27+
// check_new_game_state(current_state);
28+
// }
29+
//
30+
// RectangleCollider* rectangle_collider() { return this; }
31+
//
32+
// ~Pipe() {
33+
// game_sm_emitter->unsubscribe(this);
34+
// }
35+
//
36+
// void check_new_game_state(State* state) {
37+
// if (ClassTypeCheck::is_class_type<GameplayBase>(state)) {
38+
// stop = true;
39+
// }
40+
// }
41+
//
42+
// // Inherited via StateMachineListener
43+
// void on_state_changed(State* old_state, State* new_state) override {
44+
// check_new_game_state(new_state);
45+
// }
46+
//
47+
// void update(double elapsed_time) override {
48+
// if (stop) {
49+
// return;
50+
// }
51+
// // move left
52+
// position = Vector2{ position.x + speed_x * elapsed_time, position.y };
53+
// }
54+
//
55+
// void collided(Collider* other) override {
56+
// if (stop || collided_with_player) {
57+
// return;
58+
// }
59+
//
60+
// // check collision with player
61+
// bool other_is_player = other->owner()->tags().find(PLAYER) != other->owner()->tags().end();
62+
// if (other_is_player) {
63+
// FlappyBird* player = static_cast<FlappyBird*>(other->owner());
64+
// player->die();
65+
// collided_with_player = true;
66+
// }
67+
// }
68+
//
69+
//private:
70+
// bool stop = false;
71+
// StateMachineEventEmitter* game_sm_emitter;
72+
// bool collided_with_player = false;
73+
// float speed_x = -100;
74+
// const float jump_force = 4;
75+
// const float gravity = -9.8;
76+
// const float world_space_proportion = 90;
77+
// const float relative_gravity = gravity * world_space_proportion;
78+
//};

0 commit comments

Comments
 (0)