aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-04-29 18:28:28 -0400
committerClyne Sullivan <tullivan99@gmail.com>2017-04-29 18:28:28 -0400
commit40d164ea3d8437cd5a06a06d5b89bd938d3dd906 (patch)
treeec22853ca9a18706a3318ea9d16464d9a36a7419 /src
parent18380eb2e6443c2736b4958b01e7ba2fe2cfa318 (diff)
no more getSystem
Diffstat (limited to 'src')
-rw-r--r--src/attack.cpp4
-rw-r--r--src/components.cpp13
-rw-r--r--src/engine.cpp2
-rw-r--r--src/inventory.cpp11
-rw-r--r--src/particle.cpp9
-rw-r--r--src/player.cpp17
-rw-r--r--src/quest.cpp6
-rw-r--r--src/render.cpp20
-rw-r--r--src/ui.cpp4
-rw-r--r--src/ui_menu.cpp3
-rw-r--r--src/weather.cpp61
-rw-r--r--src/window.cpp3
-rw-r--r--src/world.cpp26
13 files changed, 129 insertions, 50 deletions
diff --git a/src/attack.cpp b/src/attack.cpp
index e91b4cd..f627631 100644
--- a/src/attack.cpp
+++ b/src/attack.cpp
@@ -45,7 +45,7 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
en.each<Health, Position, Solid>([&](entityx::Entity e, Health& health, Position& pos, Solid& dim) {
if (!e.has_component<Player>() && inrange(ppos.x, pos.x, pos.x + dim.width) && inrange(ppos.y, pos.y - 2, pos.y + dim.height)) {
health.health -= hit.damage;
- game::engine.getSystem<ParticleSystem>()->addMultiple(15, ParticleType::SmallBlast,
+ ParticleSystem::addMultiple(15, ParticleType::SmallBlast,
[&](){ return vec2(pos.x + dim.width / 2, pos.y + dim.height / 2); }, 300, 7);
die = !hit.pierce;
} else if (WorldSystem::isAboveGround(vec2(ppos.x, ppos.y - 5)))
@@ -69,7 +69,7 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
if (inrange(a.pos.x, pos.x, pos.x + dim.width, HLINES(shortSlashLength)) &&
inrange(a.pos.y, pos.y, pos.y + dim.height)) {
h.health -= a.power;
- game::engine.getSystem<ParticleSystem>()->addMultiple(15, ParticleType::DownSlash,
+ ParticleSystem::addMultiple(15, ParticleType::DownSlash,
[&](){ return vec2(pos.x + dim.width / 2, pos.y + dim.height / 2); }, 300, 7);
}
}
diff --git a/src/components.cpp b/src/components.cpp
index dcb1551..f5faf6b 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -20,6 +20,9 @@
using namespace std::literals::chrono_literals;
+std::string RenderSystem::loadTexString;
+Texture RenderSystem::loadTexResult;
+
static std::vector<std::string> randomDialog (readFileA("assets/dialog_en-us"));
void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
@@ -50,7 +53,7 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
fl = (direction.x < 0);
}
- auto ppos = game::engine.getSystem<PlayerSystem>()->getPosition();
+ auto ppos = PlayerSystem::getPosition();
if (ppos.x > position.x && ppos.x < position.x + entity.component<Solid>()->width) {
if (entity.has_component<Aggro>()) {
auto dim = entity.component<Solid>();
@@ -280,8 +283,7 @@ void DialogSystem::receive(const MouseClickEvent &mce)
auto ixml = exml->FirstChildElement("give");
if (ixml != nullptr) {
do {
- game::engine.getSystem<InventorySystem>()->add(
- ixml->StrAttribute("name"), ixml->IntAttribute("count"));
+ InventorySystem::add(ixml->StrAttribute("name"), ixml->IntAttribute("count"));
ixml = ixml->NextSiblingElement();
} while (ixml != nullptr);
}
@@ -289,7 +291,6 @@ void DialogSystem::receive(const MouseClickEvent &mce)
auto qxml = exml->FirstChildElement("quest");
if (qxml != nullptr) {
const char *qname;
- auto qsys = game::engine.getSystem<QuestSystem>();
do {
// assign quest
@@ -297,14 +298,14 @@ void DialogSystem::receive(const MouseClickEvent &mce)
if (qname != nullptr) {
questAssignedText = qname;
auto req = qxml->GetText();
- qsys->assign(qname, qxml->StrAttribute("desc"), req ? req : "");
+ QuestSystem::assign(qname, qxml->StrAttribute("desc"), req ? req : "");
}
// check / finish quest
else {
qname = qxml->Attribute("check");
if (qname != nullptr) {
- if (qname != nullptr && qsys->finish(qname) == 0) {
+ if (qname != nullptr && QuestSystem::finish(qname) == 0) {
d.index = 9999;
} else {
UISystem::dialogBox(name.name, /*"", false,*/ "Finish my quest u nug");
diff --git a/src/engine.cpp b/src/engine.cpp
index 970904b..07b453c 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -54,7 +54,7 @@ void Engine::init(void) {
ui::initSounds();
ui::menu::init();
game::config::update();
- getSystem<PlayerSystem>()->create();
+ PlayerSystem::create();
}
void Engine::update(entityx::TimeDelta dt)
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 761ca43..434eac6 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -17,6 +17,15 @@ using namespace tinyxml2;
extern vec2 offset;
+std::unordered_map<std::string, Item> InventorySystem::itemList;
+std::vector<InventoryEntry> InventorySystem::items;
+vec2 InventorySystem::hotStart;
+vec2 InventorySystem::hotEnd;
+vec2 InventorySystem::fullStart;
+vec2 InventorySystem::fullEnd;
+int InventorySystem::movingItem = -1;
+bool InventorySystem::fullInventory = false;
+
inline bool isGoodEntry(const InventoryEntry& ie) {
return (ie.item != nullptr) && (ie.count > 0);
}
@@ -142,7 +151,7 @@ void InventorySystem::render(void)
i.item->sprite.use();
glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
- auto pos = game::engine.getSystem<PlayerSystem>()->getPosition();
+ auto pos = PlayerSystem::getPosition();
vec2 sta (pos.x, pos.y);
vec2 end (sta + (i.item->sprite.getDim() * game::HLINE));
GLfloat coords[18] = {
diff --git a/src/particle.cpp b/src/particle.cpp
index a546c0c..f2604a6 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -7,9 +7,12 @@
#include <mutex>
+std::vector<Particle> ParticleSystem::parts;
+unsigned int ParticleSystem::maximum;
+
ParticleSystem::ParticleSystem(unsigned int max)
- : maximum(max)
{
+ maximum = max;
parts.reserve(maximum);
}
@@ -36,7 +39,7 @@ void ParticleSystem::render(void)
constexpr auto entrySize = (6 * 5) * sizeof(GLfloat);
static std::once_flag init;
- std::call_once(init, [this](GLuint& vbo) {
+ std::call_once(init, [&entrySize](GLuint& vbo) {
// generate VBO
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
@@ -168,7 +171,7 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
}
}
-int ParticleSystem::getCount(void) const
+int ParticleSystem::getCount(void)
{
return parts.size();
}
diff --git a/src/player.cpp b/src/player.cpp
index a458479..0256190 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -68,6 +68,15 @@ static const char *animationXML =
</movement>\
</Animation>";
+entityx::Entity PlayerSystem::player;
+bool PlayerSystem::moveLeft = false;
+bool PlayerSystem::moveRight = false;
+float PlayerSystem::speed = 1.0f;
+
+PlayerSystem::PlayerSystem(void)
+{
+}
+
void PlayerSystem::create(void)
{
player = game::entities.create();
@@ -180,7 +189,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
if (game::canSprint)
speed = 2.0f;
- game::engine.getSystem<ParticleSystem>()->addMultiple(10, ParticleType::SmallBlast,
+ ParticleSystem::addMultiple(10, ParticleType::SmallBlast,
[&](){ return vec2(loc.x, loc.y); }, 500, 7);
} else if (kc == getControl(4)) {
speed = .5;
@@ -204,7 +213,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
}
}
-vec2 PlayerSystem::getPosition(void) const
+vec2 PlayerSystem::getPosition(void)
{
auto& loc = *game::entities.component<Position>(player.id()).get();
return vec2(loc.x, loc.y);
@@ -224,7 +233,7 @@ void PlayerSystem::receive(const UseItemEvent& uie)
loc.x += solid.width / 2, loc.y += solid.height / 2;
game::events.emit<AttackEvent>(loc, AttackType::ShortSlash, true);
} else if (uie.item->type == "Bow") {
- if (game::engine.getSystem<InventorySystem>()->take("Arrow", 1)) {
+ if (InventorySystem::take("Arrow", 1)) {
auto e = game::entities.create();
auto pos = getPosition();
e.assign<Position>(pos.x, pos.y + 10);
@@ -235,7 +244,7 @@ void PlayerSystem::receive(const UseItemEvent& uie)
e.assign<Visible>(-5);
e.assign<Physics>();
auto sprite = e.assign<Sprite>();
- auto tex = game::engine.getSystem<InventorySystem>()->getItem("Arrow");
+ auto tex = InventorySystem::getItem("Arrow");
sprite->addSpriteSegment(SpriteData(tex.sprite), 0);
auto dim = HLINES(sprite->getSpriteSize());
e.assign<Solid>(dim.x, dim.y);
diff --git a/src/quest.cpp b/src/quest.cpp
index 71a37fd..6017247 100644
--- a/src/quest.cpp
+++ b/src/quest.cpp
@@ -6,6 +6,8 @@
#include <inventory.hpp>
#include <tokens.hpp>
+std::vector<Quest> QuestSystem::current;
+
std::string& trim(std::string& s)
{
auto start = std::find_if(s.begin(), s.end(),
@@ -63,12 +65,12 @@ int QuestSystem::finish(std::string title)
return -1;
for (const auto& r : quest->reqs) {
- if (!game::engine.getSystem<InventorySystem>()->take(r.first, r.second))
+ if (!InventorySystem::take(r.first, r.second))
return -1;
}
for (const auto& r : quest->rewards)
- game::engine.getSystem<InventorySystem>()->add(r.first, r.second);
+ InventorySystem::add(r.first, r.second);
drop(title);
diff --git a/src/render.cpp b/src/render.cpp
index 8b99847..935e609 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -132,9 +132,8 @@ void preRender(void)
// set the ortho
//
- auto ps = game::engine.getSystem<PlayerSystem>();
- auto ploc = ps->getPosition();
- offset.x = ploc.x + ps->getWidth() / 2;
+ auto ploc = PlayerSystem::getPosition();
+ offset.x = ploc.x + PlayerSystem::getWidth() / 2;
const auto& worldWidth = WorldSystem::getWidth();
if (worldWidth < (int)SCREEN_WIDTH2 * 2)
@@ -178,20 +177,17 @@ void render(const int& fps)
preRender();
WorldSystem::render();
-
- game::engine.getSystem<ParticleSystem>()->render();
-
- game::engine.getSystem<RenderSystem>()->render();
-
- game::engine.getSystem<InventorySystem>()->render();
+ ParticleSystem::render();
+ RenderSystem::render();
+ InventorySystem::render();
// draw the debug overlay if desired
if (ui::debug) {
- auto pos = game::engine.getSystem<PlayerSystem>()->getPosition();
+ auto pos = PlayerSystem::getPosition();
UISystem::putText(vec2(offset.x - game::SCREEN_WIDTH / 2, (offset.y + game::SCREEN_HEIGHT / 2) - FontSystem::getSize()),
"loc: %s\noffset: %s\nfps: %d\nticks: %d\npcount: %d\nxml: %s\nmem: %llukb (%d)",
pos.toString().c_str(), offset.toString().c_str(), fps,
- game::time::getTickCount(), game::engine.getSystem<ParticleSystem>()->getCount(),
+ game::time::getTickCount(), ParticleSystem::getCount(),
WorldSystem::getXMLFile().c_str(), getUsedMem() / 1024, balance
);
}
@@ -201,5 +197,5 @@ void render(const int& fps)
//ui::drawFade();
ui::draw();
- game::engine.getSystem<WindowSystem>()->render();
+ WindowSystem::render();
}
diff --git a/src/ui.cpp b/src/ui.cpp
index d14b0a6..e1e6ecc 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -965,7 +965,7 @@ void UISystem::render(void)
if (!dialogText.empty()) {
vec2 where (offset.x - 300, game::SCREEN_HEIGHT - 60);
ui::drawNiceBox(vec2(where.x - 10, where.y - 200), vec2(where.x + 620, where.y + 20), -5.5f);
- putString(where, dialogText, where.x + 600);
+ putString(where, ui::typeOut(dialogText), where.x + 600);
if (!dialogOptions.empty()) {
float y = where.y - 180;
@@ -988,7 +988,7 @@ void UISystem::render(void)
if (!importantText.empty()) {
FontSystem::setFontSize(24);
FontSystem::setFontZ(-9.0f);
- putStringCentered(vec2(offset.x, 400), importantText);
+ putStringCentered(vec2(offset.x, 400), ui::typeOut(importantText));
FontSystem::setFontZ(-6.0f);
FontSystem::setFontSize(16);
}
diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp
index 08d45e7..138a281 100644
--- a/src/ui_menu.cpp
+++ b/src/ui_menu.cpp
@@ -29,7 +29,8 @@ void SDLReceiver::receive(const MainSDLEvent& mse)
case SDL_KEYUP:
if (currentMenu != nullptr && mse.event.key.keysym.sym == SDLK_ESCAPE) {
currentMenu->gotoParent();
- return;
+ } else {
+ clicked = false;
}
break;
default:
diff --git a/src/weather.cpp b/src/weather.cpp
new file mode 100644
index 0000000..59396d8
--- /dev/null
+++ b/src/weather.cpp
@@ -0,0 +1,61 @@
+#include <weather.hpp>
+
+#include <config.hpp>
+#include <random.hpp>
+#include <particle.hpp>
+
+constexpr const char *weatherStrings[] = {
+ "Sunny",
+ "Rainy",
+ "Snowy"
+};
+
+Weather WeatherSystem::weather;
+
+WeatherSystem::WeatherSystem(Weather w)
+{
+ weather = w;
+}
+
+void WeatherSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
+{
+ (void)en;
+ (void)ev;
+ (void)dt;
+
+ static int newPartDelay = 0; // TODO no
+
+ switch (weather) {
+ case Weather::Sunny:
+ break;
+ case Weather::Rainy:
+ if (newPartDelay++ == 4) {
+ newPartDelay = 0;
+ ParticleSystem::add(vec2(offset.x - game::SCREEN_WIDTH / 2 + randGet() % game::SCREEN_WIDTH,
+ offset.y + game::SCREEN_HEIGHT / 2 + 100),
+ ParticleType::Drop, 3000, 3);
+ }
+ break;
+ case Weather::Snowy:
+ if (newPartDelay++ == 6) {
+ newPartDelay = 0;
+ ParticleSystem::add(vec2(offset.x - game::SCREEN_WIDTH + randGet() % game::SCREEN_WIDTH * 2,
+ offset.y + game::SCREEN_HEIGHT / 2 + 50),
+ ParticleType::Confetti, 10000, 0);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void WeatherSystem::setWeather(const std::string& w)
+{
+ for (int i = 0; i < static_cast<int>(Weather::count); i++) {
+ if (w == weatherStrings[i]) {
+ weather = static_cast<Weather>(i);
+ return;
+ }
+ }
+}
+
diff --git a/src/window.cpp b/src/window.cpp
index df584be..af0f63b 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -9,6 +9,9 @@
constexpr const char* WINDOW_TITLE = "gamedev";
+SDL_Window* WindowSystem::window;
+SDL_GLContext WindowSystem::glContext;
+
WindowSystem::WindowSystem(void)
{
// attempt to initialize SDL
diff --git a/src/world.cpp b/src/world.cpp
index 29f77a2..bf34973 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -192,7 +192,7 @@ void WorldSystem::fight(entityx::Entity entity)
door.assign<Portal>(exit);
auto sprite = door.assign<Sprite>();
- auto dtex = game::engine.getSystem<RenderSystem>()->loadTexture("assets/style/classic/door.png");
+ auto dtex = RenderSystem::loadTexture("assets/style/classic/door.png");
sprite->addSpriteSegment(SpriteData(dtex), 0);
auto dim = HLINES(sprite->getSpriteSize());
@@ -201,8 +201,6 @@ void WorldSystem::fight(entityx::Entity entity)
void WorldSystem::load(const std::string& file)
{
- auto& render = *game::engine.getSystem<RenderSystem>();
-
entityx::Entity entity;
// check for empty file name
@@ -266,17 +264,16 @@ void WorldSystem::load(const std::string& file)
//game::entities.reset();
if (!savedEntities.empty()) {
- savedEntities.emplace_back(game::engine.getSystem<PlayerSystem>()->getId());
+ savedEntities.emplace_back(PlayerSystem::getId());
game::entities.each<Position>(
[&](entityx::Entity entity, Position& p) {
(void)p;
- if (std::find(savedEntities.begin(), savedEntities.end(), entity.id())
- == savedEntities.end())
+ if (std::find(savedEntities.begin(), savedEntities.end(), entity.id()) == savedEntities.end())
entity.destroy();
}, true);
} else {
game::entities.reset();
- game::engine.getSystem<PlayerSystem>()->create();
+ PlayerSystem::create();
}
// iterate through tags
@@ -313,16 +310,15 @@ void WorldSystem::load(const std::string& file)
UserError("<house> can only be used inside <IndoorWorld>");
//world.indoorWidth = wxml->FloatAttribute("width");
- world.indoorTex = render.loadTexture(wxml->StrAttribute("texture")); // TODO winbloze lol
+ world.indoorTex = RenderSystem::loadTexture(wxml->StrAttribute("texture")); // TODO winbloze lol
auto str = wxml->StrAttribute("texture");
- auto tex = render.loadTexture(str);
+ auto tex = RenderSystem::loadTexture(str);
world.indoorTex = tex;
}
// weather tag
else if (tagName == "weather") {
- game::engine.getSystem<WeatherSystem>()->setWeather(wxml->GetText());
- //setWeather(wxml->GetText());
+ WeatherSystem::setWeather(wxml->GetText());
}
// link tags
@@ -1092,7 +1088,7 @@ void WorldSystem::detect(entityx::TimeDelta dt)
vel.y = 0;
if (!vel.grounded) {
vel.grounded = true;
- game::engine.getSystem<ParticleSystem>()->addMultiple(20, ParticleType::SmallPoof,
+ ParticleSystem::addMultiple(20, ParticleType::SmallPoof,
[&](){ return vec2(loc.x + randGet() % static_cast<int>(dim.width), loc.y);}, 500, 30);
}
}
@@ -1101,11 +1097,9 @@ void WorldSystem::detect(entityx::TimeDelta dt)
// insure that the entity doesn't fall off either edge of the world.
if (loc.x < world.startX) {
- std::cout << "Left!\n";
vel.x = 0;
loc.x = world.startX + HLINES(0.5f);
} else if (loc.x + dim.width + game::HLINE > -(static_cast<int>(world.startX))) {
- std::cout << "Right\n";
vel.x = 0;
loc.x = -(static_cast<int>(world.startX)) - dim.width - game::HLINE;
}
@@ -1120,7 +1114,7 @@ void WorldSystem::goWorldRight(Position& p, Solid &d)
while (waitToSwap)
std::this_thread::sleep_for(1ms);
load(world.toRight);
- game::engine.getSystem<PlayerSystem>()->setX(world.startX + HLINES(10));
+ PlayerSystem::setX(world.startX + HLINES(10));
UISystem::fadeToggle();
}
}
@@ -1133,7 +1127,7 @@ void WorldSystem::goWorldLeft(Position& p)
while (waitToSwap)
std::this_thread::sleep_for(1ms);
load(world.toLeft);
- game::engine.getSystem<PlayerSystem>()->setX(world.startX * -1 - HLINES(15));
+ PlayerSystem::setX(world.startX * -1 - HLINES(15));
UISystem::fadeToggle();
}
}