Skip to content

Commit

Permalink
feat(flappy): remove useless stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Nov 3, 2019
1 parent b496c8d commit 7ca43f9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 55 deletions.
4 changes: 1 addition & 3 deletions tutorials/flappy-bird/step_8/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ include(FetchContent)
##! We declare information about the dependance that we want to fetch.
FetchContent_Declare(
antara-gaming-sdk
URL https://github.com/KomodoPlatform/antara-gaming-sdk/archive/4e27acbe8f549f7817f1489402afcdff98e39212.zip

#https://github.com/KomodoPlatform/antara-gaming-sdk/archive/master.zip
URL https://github.com/KomodoPlatform/antara-gaming-sdk/archive/master.zip
)

##! We set extras modules from the SDK that we want to use, here we will use the SFML module.
Expand Down
84 changes: 32 additions & 52 deletions tutorials/flappy-bird/step_8/flappy-bird.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <random>
#include <antara/gaming/ecs/virtual.input.system.hpp>
#include <antara/gaming/collisions/basic.collision.system.hpp>
#include <antara/gaming/graphics/component.layer.hpp>
#include <antara/gaming/graphics/component.canvas.hpp>
Expand All @@ -9,7 +10,6 @@
#include <antara/gaming/sfml/resources.manager.hpp>
#include <antara/gaming/world/world.app.hpp>
#include <antara/gaming/graphics/component.sprite.hpp>
#include <iostream>
#include <antara/gaming/input/virtual.hpp>

//! For convenience
Expand Down Expand Up @@ -62,8 +62,8 @@ namespace {
// Input handling
namespace {
void init_buttons() {
input::virtual_input::create_input("jump", {input::key::space, input::key::w, input::key::up},
{input::mouse_button::left, input::mouse_button::right});
input::virtual_input::create("jump", {input::key::space, input::key::w, input::key::up},
{input::mouse_button::left, input::mouse_button::right});
}
/*std::map<std::string, bool> button_map_last_tick;
std::map<std::string, bool> button_pressed;
Expand Down Expand Up @@ -150,13 +150,13 @@ namespace {
registry.assign<graphics::fill_color>(text_entity, graphics::white);
registry.assign<graphics::text>(text_entity, score_ui_text(), constants.font_size);
registry.assign<transform::position_2d>(text_entity, canvas_width * 0.03f, canvas_height * 0.03f);
registry.assign<graphics::layer<9>>(text_entity);
registry.assign<entt::tag<"game_scene"_hs>>(text_entity);
registry.assign < graphics::layer < 9 >> (text_entity);
registry.assign < entt::tag < "game_scene"_hs >> (text_entity);

// Create score
registry.assign<score>(entity, 0, 0, text_entity);
registry.assign<entt::tag<"high_score"_hs>>(entity);
registry.assign<entt::tag<"game_scene"_hs>>(entity);
registry.assign < entt::tag < "high_score"_hs >> (entity);
registry.assign < entt::tag < "game_scene"_hs >> (entity);

return entity;
}
Expand Down Expand Up @@ -204,12 +204,12 @@ namespace {
constants.pipe_outline_color);

// Set layers, cap should be in front of body
registry.assign<graphics::layer<4>>(cap);
registry.assign<graphics::layer<3>>(body);
registry.assign<entt::tag<"game_scene"_hs>>(cap);
registry.assign<entt::tag<"game_scene"_hs>>(body);
registry.assign<entt::tag<"dynamic"_hs>>(cap);
registry.assign<entt::tag<"dynamic"_hs>>(body);
registry.assign < graphics::layer < 4 >> (cap);
registry.assign < graphics::layer < 3 >> (body);
registry.assign < entt::tag < "game_scene"_hs >> (cap);
registry.assign < entt::tag < "game_scene"_hs >> (body);
registry.assign < entt::tag < "dynamic"_hs >> (cap);
registry.assign < entt::tag < "dynamic"_hs >> (body);

// Construct a pipe with body and cap and return it
return {body, cap};
Expand Down Expand Up @@ -241,9 +241,9 @@ namespace {

// Make a column from these two pipes and mark it as "column"
registry.assign<column>(entity_column, top_pipe, bottom_pipe);
registry.assign<entt::tag<"column"_hs>>(entity_column);
registry.assign<entt::tag<"game_scene"_hs>>(entity_column);
registry.assign<entt::tag<"dynamic"_hs>>(entity_column);
registry.assign < entt::tag < "column"_hs >> (entity_column);
registry.assign < entt::tag < "game_scene"_hs >> (entity_column);
registry.assign < entt::tag < "dynamic"_hs >> (entity_column);
}

//! Factory for creating a Flappy Bird columns
Expand Down Expand Up @@ -278,8 +278,8 @@ namespace {
math::vec2f size{canvas_width, canvas_height};

auto sky = geometry::blueprint_rectangle(registry, size, constants.background_color, pos);
registry.assign<graphics::layer<1>>(sky);
registry.assign<entt::tag<"game_scene"_hs>>(sky);
registry.assign < graphics::layer < 1 >> (sky);
registry.assign < entt::tag < "game_scene"_hs >> (sky);
}

// Create Grass
Expand All @@ -294,8 +294,8 @@ namespace {

auto grass = geometry::blueprint_rectangle(registry, size, constants.grass_color, pos,
constants.grass_outline_color);
registry.assign<graphics::layer<3>>(grass);
registry.assign<entt::tag<"game_scene"_hs>>(grass);
registry.assign < graphics::layer < 3 >> (grass);
registry.assign < entt::tag < "game_scene"_hs >> (grass);
}

// Create Ground
Expand All @@ -308,8 +308,8 @@ namespace {
math::vec2f size{canvas_width, constants.ground_thickness};

auto ground = geometry::blueprint_rectangle(registry, size, constants.ground_color, pos);
registry.assign<graphics::layer<3>>(ground);
registry.assign<entt::tag<"game_scene"_hs>>(ground);
registry.assign < graphics::layer < 3 >> (ground);
registry.assign < entt::tag < "game_scene"_hs >> (ground);
}
}

Expand All @@ -322,10 +322,10 @@ namespace {
auto entity = graphics::blueprint_sprite(registry,
graphics::sprite{constants.player_image_name.c_str()},
transform::position_2d{constants.player_pos_x, canvas_height * 0.5f});
registry.assign<antara::gaming::graphics::layer<5>>(entity);
registry.assign<entt::tag<"player"_hs>>(entity);
registry.assign<entt::tag<"game_scene"_hs>>(entity);
registry.assign<entt::tag<"dynamic"_hs>>(entity);
registry.assign < antara::gaming::graphics::layer < 5 >> (entity);
registry.assign < entt::tag < "player"_hs >> (entity);
registry.assign < entt::tag < "game_scene"_hs >> (entity);
registry.assign < entt::tag < "dynamic"_hs >> (entity);

return entity;
}
Expand Down Expand Up @@ -412,7 +412,7 @@ class column_logic final : public ecs::logic_update_system<column_logic> {
};

//! Give a name to our system
REFL_AUTO(type(column_logic));
REFL_AUTO (type(column_logic));

class player_logic final : public ecs::logic_update_system<player_logic> {
public:
Expand All @@ -434,12 +434,6 @@ class player_logic final : public ecs::logic_update_system<player_logic> {
// Check if jump key is tapped
bool jump_key_tapped = input::virtual_input::is_tapped("jump");

if (jump_key_tapped)
std::cout << "true" << std::endl;
if (input::virtual_input::is_released("jump"))
std::cout << "false" << std::endl;


// If jump is tapped, add jump force to the movement speed
if (jump_key_tapped) movement_speed.set_y(-constants.jump_force);

Expand Down Expand Up @@ -482,7 +476,7 @@ class player_logic final : public ecs::logic_update_system<player_logic> {
};

//! Give a name to our system
REFL_AUTO(type(player_logic));
REFL_AUTO (type(player_logic));

class collision_logic final : public ecs::logic_update_system<collision_logic> {
public:
Expand All @@ -498,7 +492,7 @@ class collision_logic final : public ecs::logic_update_system<collision_logic> {
if (player_died) return;

// Loop all columns to check collisions with the pipes
for (auto entity : registry.view<graphics::layer<3>>()) {
for (auto entity : registry.view < graphics::layer < 3 >> ()) {
// Check collision between player and a collidable object
if (collisions::basic_collision_system::query_rect(registry, player, entity)) {
// Mark player died as true
Expand All @@ -513,7 +507,7 @@ class collision_logic final : public ecs::logic_update_system<collision_logic> {
};

//! Give a name to our system
REFL_AUTO(type(collision_logic));
REFL_AUTO (type(collision_logic));

class game_scene final : public scenes::base_scene {
public:
Expand Down Expand Up @@ -595,7 +589,7 @@ class game_scene final : public scenes::base_scene {

void destroy_all() {
//! Retrieve the collection of entities from the game scene
auto view = entity_registry_.view<entt::tag<"dynamic"_hs>>();
auto view = entity_registry_.view < entt::tag < "dynamic"_hs >> ();

//! Iterate the collection and destroy each entities
entity_registry_.destroy(view.begin(), view.end());
Expand Down Expand Up @@ -631,26 +625,12 @@ class game_scene final : public scenes::base_scene {
bool need_reset{false};
};

input::virtual_input::input_state_collection input::virtual_input::cached_states_ = {};

struct virtual_input_system final : ecs::logic_update_system<virtual_input_system> {
virtual_input_system(entt::registry &registry) noexcept : system(registry) {
input::virtual_input::init(registry);
}

void update() noexcept final {
input::virtual_input::update();
}
};

REFL_AUTO(type(virtual_input_system))

//! Game world
struct flappy_bird_world : world::app {
//! Game entry point
flappy_bird_world() noexcept {
//! Load our graphical system
system_manager_.create_system<virtual_input_system>();
system_manager_.create_system<ecs::virtual_input_system>();
auto &graphic_system = system_manager_.create_system<sfml::graphic_system>();

//! Load our resources system
Expand Down

0 comments on commit 7ca43f9

Please sign in to comment.