|
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