aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/controls.dat2
-rw-r--r--include/components.hpp6
-rw-r--r--include/entities.hpp6
-rw-r--r--include/player.hpp7
-rw-r--r--include/world.hpp1
-rw-r--r--main.cpp11
-rw-r--r--src/engine.cpp1
-rw-r--r--src/entities.cpp24
-rw-r--r--src/player.cpp51
-rw-r--r--src/world.cpp30
-rw-r--r--xml/bobshouse.xml3
-rw-r--r--xml/entities.xml1
12 files changed, 72 insertions, 71 deletions
diff --git a/config/controls.dat b/config/controls.dat
index c6b7131..679c014 100644
--- a/config/controls.dat
+++ b/config/controls.dat
@@ -1,4 +1,4 @@
-32
+119
97
100
1073742049
diff --git a/include/components.hpp b/include/components.hpp
index 857236f..becc839 100644
--- a/include/components.hpp
+++ b/include/components.hpp
@@ -75,6 +75,12 @@ struct Health {
int maxHealth;
};
+struct Portal {
+ Portal(std::string tf = "") : toFile(tf) {}
+
+ std::string toFile;
+};
+
/**
* @struct Solid
* @brief Allows an entity to collide with other objects.
diff --git a/include/entities.hpp b/include/entities.hpp
deleted file mode 100644
index f7c3894..0000000
--- a/include/entities.hpp
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef ENTITIES_HPP_
-#define ENTITIES_HPP_
-
-void entityxTest();
-
-#endif // ENTITIES_HPP_
diff --git a/include/player.hpp b/include/player.hpp
index 6bad917..e196fa4 100644
--- a/include/player.hpp
+++ b/include/player.hpp
@@ -10,7 +10,7 @@ constexpr const float PLAYER_SPEED_CONSTANT = 0.15f;
class PlayerSystem : public entityx::System<PlayerSystem>, public entityx::Receiver<PlayerSystem> {
private:
- entityx::Entity::Id pid;
+ entityx::Entity player;
bool moveLeft;
bool moveRight;
@@ -21,6 +21,8 @@ public:
PlayerSystem(void)
: moveLeft(false), moveRight(false), speed(1.0f) {}
+ void create(void);
+
void configure(entityx::EventManager&);
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
@@ -28,9 +30,6 @@ public:
void receive(const KeyUpEvent&);
void receive(const KeyDownEvent&);
- inline void setPlayer(const entityx::Entity& e)
- { pid = e.id(); }
-
vec2 getPosition(void) const;
};
diff --git a/include/world.hpp b/include/world.hpp
index 58dfc2c..fb0a5fa 100644
--- a/include/world.hpp
+++ b/include/world.hpp
@@ -167,6 +167,7 @@ public:
void goWorldLeft(Position& p);
void goWorldRight(Position& p);
+ void goWorldPortal(Position& p);
// worlddata2 stuff
WorldData2 worldData;
diff --git a/main.cpp b/main.cpp
index c6c41af..1076903 100644
--- a/main.cpp
+++ b/main.cpp
@@ -21,7 +21,6 @@ using namespace tinyxml2;
// local game includes
#include <common.hpp>
#include <config.hpp>
-#include <entities.hpp>
#include <world.hpp>
#include <ui.hpp>
#include <gametime.hpp>
@@ -203,9 +202,6 @@ int main(int argc, char *argv[])
ui::menu::init();
// game::events.emit<BGMToggleEvent>(currentWorld->bgm);
- //TODO
- entityxTest();
-
// the main loop, in all of its gloriousness..
std::thread([&]{
while (game::engine.shouldRun()) {
@@ -267,12 +263,7 @@ void render() {
const auto SCREEN_WIDTH = game::SCREEN_WIDTH;
const auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
- //offset.x = game::entities.Iterator.begin().component<Position>().x;// + player->width / 2;
-
- game::entities.each<Position>([](entityx::Entity entity, Position &position) {
- (void)entity;
- offset.x = position.x;
- });
+ offset.x = game::engine.getSystem<PlayerSystem>()->getPosition().x;// + player->width / 2;
auto worldWidth = game::engine.getSystem<WorldSystem>()->getWidth();
if (worldWidth < (int)SCREEN_WIDTH)
diff --git a/src/engine.cpp b/src/engine.cpp
index f4d19a2..04ea912 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -31,6 +31,7 @@ void Engine::init(void) {
systems.configure();
game::config::update();
+ getSystem<PlayerSystem>()->create();
}
void Engine::render(entityx::TimeDelta dt)
diff --git a/src/entities.cpp b/src/entities.cpp
deleted file mode 100644
index 29380c8..0000000
--- a/src/entities.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <entities.hpp>
-
-#include <engine.hpp>
-#include <player.hpp>
-#include <components.hpp>
-
-void entityxTest(void)
-{
- entityx::Entity e = game::entities.create();
- e.assign<Position>(100.0f, 100.0f);
- e.assign<Direction>(0.0f, 0.0f);
-
- e = game::entities.create();
- e.assign<Position>(0.0f, 100.0f);
- e.assign<Direction>(-0.01f, 0.0f);
- e.assign<Physics>(-0.001f);
- e.assign<Visible>(-.2f);
- auto sprite_h = e.assign<Sprite>();
- sprite_h->addSpriteSegment(SpriteData("assets/cat.png",
- vec2(0, 0)),
- vec2(0, 0));
-
- game::engine.getSystem<PlayerSystem>()->setPlayer(e);
-}
diff --git a/src/player.cpp b/src/player.cpp
index bc4ae76..8808a69 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -7,6 +7,20 @@
#include <world.hpp>
#include <components.hpp>
+void PlayerSystem::create(void)
+{
+ player = game::entities.create();
+ player.assign<Position>(0.0f, 100.0f);
+ player.assign<Direction>(0.0f, 0.0f);
+ player.assign<Physics>(-0.001f);
+ player.assign<Visible>(-0.2f);
+
+ auto sprite = player.assign<Sprite>();
+ sprite->addSpriteSegment(SpriteData("assets/cat.png",
+ vec2(0, 0)),
+ vec2(0, 0));
+}
+
void PlayerSystem::configure(entityx::EventManager &ev)
{
ev.subscribe<KeyUpEvent>(*this);
@@ -14,10 +28,11 @@ void PlayerSystem::configure(entityx::EventManager &ev)
}
void PlayerSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) {
+ (void)en;
(void)ev;
(void)dt;
- auto& vel = *en.get(pid).component<Direction>().get();
+ auto& vel = *player.component<Direction>().get();
if (moveLeft & !moveRight)
vel.x = -PLAYER_SPEED_CONSTANT;
@@ -28,8 +43,8 @@ void PlayerSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
vel.x *= speed;
- if (std::stoi(game::getValue("Slow")) == 1)
- vel.x /= 2.0f;
+ if (std::stoi(game::getValue("Slow")) == 1)
+ vel.x /= 2.0f;
}
void PlayerSystem::receive(const KeyUpEvent &kue)
@@ -61,21 +76,11 @@ void PlayerSystem::receive(const KeyUpEvent &kue)
void PlayerSystem::receive(const KeyDownEvent &kde)
{
+ static auto& worldSystem = *game::engine.getSystem<WorldSystem>();
+
auto kc = kde.keycode;
- auto& loc = *game::entities.get(pid).component<Position>().get();
- auto& faceLeft = game::entities.get(pid).component<Sprite>().get()->faceLeft;
-
- /*auto worldSwitch = [&](const WorldSwitchInfo& wsi){
- player->canMove = false;
- ui::toggleBlackFast();
- ui::waitForCover();
- game::events.emit<BGMToggleEvent>(wsi.first->bgm, wsi.first);
- std::tie(currentWorld, player->loc) = wsi; // using p causes segfault
- game::engine.getSystem<WorldSystem>()->setWorld(currentWorld);
- ui::toggleBlackFast();
- ui::waitForUncover();
- player->canMove = true; // using p causes segfault
- };*/
+ auto& loc = *player.component<Position>().get();
+ auto& faceLeft = player.component<Sprite>().get()->faceLeft;
/*if ((kc == SDLK_SPACE) && (game::canJump & p->ground)) {
p->loc.y += HLINES(2);
@@ -98,19 +103,23 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
worldSwitch(thing);
}).detach();
}*/
+
+ if (!ui::fadeIntensity)
+ worldSystem.goWorldPortal(loc);
+
} else if (kc == getControl(1)) {
if (!ui::fadeEnable) {
moveLeft = faceLeft = true;
moveRight = false;
- game::engine.getSystem<WorldSystem>()->goWorldLeft(loc);
+ worldSystem.goWorldLeft(loc);
}
} else if (kc == getControl(2)) {
if (!ui::fadeEnable) {
moveLeft = faceLeft = false;
moveRight = true;
- game::engine.getSystem<WorldSystem>()->goWorldRight(loc);
+ worldSystem.goWorldRight(loc);
}
} else if (kc == getControl(3)) {
if (game::canSprint)
@@ -145,6 +154,6 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
vec2 PlayerSystem::getPosition(void) const
{
- auto loc = *game::entities.get(pid).component<Position>().get();
- return vec2 {loc.x, loc.y};
+ auto& loc = *game::entities.component<Position>(player.id()).get();
+ return vec2(loc.x, loc.y);
}
diff --git a/src/world.cpp b/src/world.cpp
index e44406e..d7639c2 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -260,8 +260,8 @@ void WorldSystem::load(const std::string& file)
world.toLeft = world.toRight = "";
currentXMLFile = file;
-
-
+ game::entities.reset();
+ game::engine.getSystem<PlayerSystem>()->create();
// iterate through tags
while (wxml) {
@@ -357,6 +357,8 @@ void WorldSystem::load(const std::string& file)
sprite->addSpriteSegment(SpriteData(tex,
vec2(0, 0)),
vec2(0, 0));
+ } else if (tname == "Portal") {
+ entity.assign<Portal>(wxml->StrAttribute("inside"));
}
abcd = abcd->NextSiblingElement();
@@ -750,7 +752,7 @@ void WorldSystem::render(void)
std::vector<vec2> bg_tex;
bgTex++;
- vec2 mountainDim = bgTex.getTextureDim();
+ auto mountainDim = bgTex.getTextureDim();
auto xcoord = width / 2 * -1 + offset.x * 0.85f;
for (int i = 0; i <= width / mountainDim.x; i++) {
bg_items.emplace_back(mountainDim.x * i + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f);
@@ -1060,9 +1062,27 @@ void WorldSystem::goWorldLeft(Position& p)
if (!(world.toLeft.empty()) && (p.x < world.startX + HLINES(10))) {
ui::toggleBlack();
ui::waitForCover();
- auto file = world.toLeft;
- load(file);
+ load(world.toLeft);
p.x = world.startX * -1 - HLINES(15);
ui::toggleBlack();
}
}
+
+void WorldSystem::goWorldPortal(Position& p)
+{
+ game::entities.each<Position, Sprite, Portal>(
+ [&](entityx::Entity entity, Position& loc, Sprite &sprite, Portal &portal) {
+ (void)entity;
+
+ auto& size = sprite.sprite.front().first.size;
+ if (p.x > loc.x && p.x < loc.x + size.x) {
+ ui::toggleBlack();
+ ui::waitForCover();
+ load(portal.toFile);
+ p.x = 0;
+ ui::toggleBlack();
+ return;
+ }
+ }
+ );
+}
diff --git a/xml/bobshouse.xml b/xml/bobshouse.xml
index 41ca907..79f8a47 100644
--- a/xml/bobshouse.xml
+++ b/xml/bobshouse.xml
@@ -1,4 +1,7 @@
<?xml version="1.0"?>
+
+<include file="entities.xml"/>
+
<IndoorWorld>
<style background="0" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/"/>
<house width="800" texture="assets/style/classic/bg/insideWoodHouse.png" />
diff --git a/xml/entities.xml b/xml/entities.xml
index d955e38..bcaa455 100644
--- a/xml/entities.xml
+++ b/xml/entities.xml
@@ -10,6 +10,7 @@
<Position value="0.0,100.0" />
<Visible value="0.25" />
<Sprite image="assets/style/classic/house1.png" />
+ <Portal />
</structure>
<chest>