diff --git a/build/vs/7DRL2015.vcxproj b/build/vs/7DRL2015.vcxproj
index 57143cb..964dbef 100644
--- a/build/vs/7DRL2015.vcxproj
+++ b/build/vs/7DRL2015.vcxproj
@@ -100,8 +100,8 @@ xcopy /s /e /d /y "..\..\data" "$(OutDir)data\"
-
+
@@ -128,8 +128,8 @@ xcopy /s /e /d /y "..\..\data" "$(OutDir)data\"
-
+
diff --git a/build/vs/7DRL2015.vcxproj.filters b/build/vs/7DRL2015.vcxproj.filters
index bdc1e94..78791c5 100644
--- a/build/vs/7DRL2015.vcxproj.filters
+++ b/build/vs/7DRL2015.vcxproj.filters
@@ -39,9 +39,6 @@
Classes
-
- Classes
-
Classes
@@ -102,6 +99,9 @@
Source Files
+
+ Classes\Things
+
@@ -116,9 +116,6 @@
Classes
-
- Classes
-
Classes
@@ -182,5 +179,8 @@
Source Files
+
+ Classes\Things
+
\ No newline at end of file
diff --git a/src/Core.cpp b/src/Core.cpp
index ac5d96e..ed53e9e 100644
--- a/src/Core.cpp
+++ b/src/Core.cpp
@@ -33,11 +33,11 @@ int Core::initSystem() {
// get our displayyyy
SDL_DisplayMode dmode;
SDL_GetDesktopDisplayMode(0, &dmode);
- v_width = dmode.w;
- v_height = dmode.h;
+ v_width = dmode.w/2; // TEMP: just for a smaller window per-default
+ v_height = dmode.h/2;
v_flags = SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE;
// create our windowww
- if ((v_window = SDL_CreateWindow("GodEater", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, v_width, v_height, v_flags)) == NULL) {
+ if ((v_window = SDL_CreateWindow("GodEater", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, v_width, v_height, v_flags)) == NULL) {
LOG(LOG_ERROR) << SDL_GetError();
return 1;
}
diff --git a/src/PlayerController.cpp b/src/PlayerController.cpp
index 43f7f8a..d7a22c0 100644
--- a/src/PlayerController.cpp
+++ b/src/PlayerController.cpp
@@ -14,28 +14,28 @@ int PlayerController::onEvent(SDL_Event event) {
case SDLK_h:
case SDLK_KP_4:
thought.type = Thought::MOVE;
- thought.loc.x = thing->position.x-1;
+ thought.loc.x = -1;
thing->pushThought(thought);
break;
case SDLK_RIGHT:
case SDLK_l:
case SDLK_KP_6:
thought.type = Thought::MOVE;
- thought.loc.x = thing->position.x+1;
+ thought.loc.x = 1;
thing->pushThought(thought);
break;
case SDLK_UP:
case SDLK_k:
case SDLK_KP_8:
thought.type = Thought::MOVE;
- thought.loc.y = thing->position.y-1;
+ thought.loc.y = -1;
thing->pushThought(thought);
break;
case SDLK_DOWN:
case SDLK_j:
case SDLK_2:
thought.type = Thought::MOVE;
- thought.loc.y = thing->position.y+1;
+ thought.loc.y = 1;
thing->pushThought(thought);
break;
}
diff --git a/src/PlayerController.hpp b/src/PlayerController.hpp
index fdb4c65..a5ca237 100644
--- a/src/PlayerController.hpp
+++ b/src/PlayerController.hpp
@@ -3,6 +3,7 @@
#include "Controller.hpp"
#include "SDL.h"
class PlayerController : Controller {
+ friend class GameState;
public:
PlayerController();
~PlayerController();
diff --git a/src/Thing.cpp b/src/Thing.cpp
deleted file mode 100644
index 0aa16b3..0000000
--- a/src/Thing.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "Thing.hpp"
-/* ======== Constructor/Destructor ======== */
-Thing::Thing() { flags = 0; sprite = NULL; }
-Thing::~Thing() {}
-/* ======== Interfaces ======== */
-int Thing::doThink() {
- return 0;
-}
-int Thing::onTouch(Thing *toucher) {
- return 0;
-}
-/* ======== Adding/Access ======== */
-int Thing::pushThought(Thought thought) {
- thoughts.push_back(thought);
- return thoughts.size();
-}
-/* ======== Etc. ======== */
-bool destroyThing(Thing *thing) {
- if (thing->flags & Thing::THING_DESTROY) return true;
- return false;
-}
diff --git a/src/Thing.hpp b/src/Thing.hpp
deleted file mode 100644
index da0ba5d..0000000
--- a/src/Thing.hpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef THING_HPP
-#define THING_HPP
-#include "Thought.hpp"
-#include "RenderObject.hpp"
-#include "Sprite.hpp"
-#include
-
-class Thought; // fwd declaration
-
-class Thing {
- friend class PlayerController;
- friend class AiController;
- public:
- Thing();
- ~Thing();
- // interface
- virtual int doThink();
- virtual int onTouch(Thing *thing);
- //
- int pushThought(Thought thought);
- //
- enum Flags {
- THING_DESTROY = (1 << 1)
- };
- int flags;
- protected:
- Vec3 position;
- Vec2 scale;
- std::vector thoughts;
- //
- Sprite *sprite;
-};
-
-bool destroyThing(Thing* thing);
-#endif
diff --git a/src/Thought.cpp b/src/Thought.cpp
index 1b9893b..6055f84 100644
--- a/src/Thought.cpp
+++ b/src/Thought.cpp
@@ -1,5 +1,6 @@
#include "Thought.hpp"
#include
+#include
Thought::Thought() {
type = 0;
@@ -7,3 +8,9 @@ Thought::Thought() {
}
Thought::~Thought() {
}
+
+std::string Thought::dumpInfo() {
+ std::ostringstream oss;
+ oss << type << ", " << loc.x << "x" << loc.y << "x" << loc.z;
+ return oss.str();
+}
\ No newline at end of file
diff --git a/src/Thought.hpp b/src/Thought.hpp
index 9d9cbd2..24af579 100644
--- a/src/Thought.hpp
+++ b/src/Thought.hpp
@@ -8,9 +8,10 @@ Put more plainly, a thought is an action in a Thing's event/action queue.
#ifndef THOUGHT_HPP
#define THOUGHT_HPP
#include "Vec.hpp"
-#include "Thing.hpp"
+#include
+//#include "Thing.hpp"
-class Thing; // fwd declaration
+//class Thing; // fwd declaration
class Thought {
friend class Thing;
@@ -19,12 +20,13 @@ class Thought {
public:
Thought();
~Thought();
+ std::string dumpInfo();
enum Act {
MOVE = (1 << 1),
ABILITY = (1 << 2),
WAIT = (1 << 3)
};
- protected:
+ //protected:
int type;
union {
Thing *target;
diff --git a/src/states/GameState.cpp b/src/states/GameState.cpp
index f53deaf..745f700 100644
--- a/src/states/GameState.cpp
+++ b/src/states/GameState.cpp
@@ -1,6 +1,7 @@
#include "GameState.hpp"
#include "Core.hpp"
#include "Log.hpp"
+#include "Denizen.hpp"
#include // remove_if
/* ======== Constructor & Destructor ======== */
@@ -15,13 +16,18 @@ GameState::GameState() {
current_map = new QMap(16, 16);
current_map->setTile(4, 4, new Tile());
+ pc.thing = new Denizen();
+ current_map->thing.push_back(pc.thing);
+
LOG(LOG_INFO);
}
GameState::~GameState() {
}
/* ======== Base Methods ======== */
int GameState::onEvent(SDL_Event event) {
- LOG(LOG_INFO);
+ if (pc.thing != NULL) {
+ pc.onEvent(event);
+ }
return 0;
}
int GameState::doProcess(unsigned int ticks) {
@@ -30,13 +36,26 @@ int GameState::doProcess(unsigned int ticks) {
std::vector::iterator thing_it, thing_end;
for (thing_it = current_map->thing.begin(), thing_end = current_map->thing.end(); thing_it != thing_end; ++thing_it) {
Thing *thing = *thing_it;
- thing->doThink();
+ thing->doThink(ticks);
}
// remove things desiring to be removed
thing_it = std::remove_if(current_map->thing.begin(), current_map->thing.end(), destroyThing);
current_map->thing.erase(thing_it, current_map->thing.end());
// 3. for each thing, do their physics movement
+ for (thing_it = current_map->thing.begin(), thing_end = current_map->thing.end(); thing_it != thing_end; ++thing_it) {
+ Thing *thing = *thing_it;
+ float x = thing->velocity.x;
+ float y = thing->velocity.y;
+ if (x != 0) thing->velocity.x += -x;
+ if (y != 0) thing->velocity.y += -y;
+ if (x != 0 && y != 0) {
+ thing->position.x += x;
+ thing->position.y += y;
+ LOG(LOG_INFO) << thing->position.x << "x" << thing->position.y;
+ }
+ //thing->doThink(ticks);
+ }
return 0;
}
int GameState::doRender() {
diff --git a/src/things/Denizen.cpp b/src/things/Denizen.cpp
index b01e8e3..7689a95 100644
--- a/src/things/Denizen.cpp
+++ b/src/things/Denizen.cpp
@@ -1,10 +1,37 @@
#include "Denizen.hpp"
Denizen::Denizen() {
+ name = "Denizen";
}
Denizen::~Denizen() {
}
-int Denizen::doThink() {
+int Denizen::doThink(unsigned int ticks) {
+ // get new thought if we have nothing to think about
+ if (!thought_current.type) {
+ if (thoughts.size() > 0) {
+ thought_current = thoughts.front();
+ thought_delay = 100; // assume 100 ms
+ thoughts.pop_front();
+ }
+ }
+ // process current thought
+ if (thought_current.type) {
+ thought_elapsed += ticks;
+ if (thought_elapsed >= thought_delay) {
+ // attempt to do the associated action
+ switch(thought_current.type) {
+ case Thought::MOVE:
+ addVelocity(thought_current.loc);
+ break;
+ case Thought::ABILITY:
+ break;
+ case Thought::WAIT:
+ break;
+ }
+ thought_current.type = 0;
+ thought_elapsed = 0;
+ }
+ }
return 0;
}
int Denizen::onTouch(Thing *thing) {
diff --git a/src/things/Denizen.hpp b/src/things/Denizen.hpp
index e166f03..d728d66 100644
--- a/src/things/Denizen.hpp
+++ b/src/things/Denizen.hpp
@@ -2,12 +2,12 @@
#define DENIZEN_HPP
#include "Thing.hpp"
-class Denizen : Thing {
+class Denizen : public Thing {
public:
Denizen();
~Denizen();
// interface
- virtual int doThink();
+ virtual int doThink(unsigned int ticks);
virtual int onTouch(Thing *thing);
};
diff --git a/src/things/Thing.cpp b/src/things/Thing.cpp
new file mode 100644
index 0000000..dda9afd
--- /dev/null
+++ b/src/things/Thing.cpp
@@ -0,0 +1,31 @@
+#include "Thing.hpp"
+#include "Log.hpp"
+/* ======== Constructor/Destructor ======== */
+Thing::Thing() { flags = 0; sprite = NULL; name = "Thing"; thought_current.type = 0; thought_delay = thought_elapsed = 0; }
+Thing::~Thing() {}
+/* ======== Interfaces ======== */
+int Thing::doThink(unsigned int ticks) {
+ return 0;
+}
+int Thing::onTouch(Thing *toucher) {
+ return 0;
+}
+/* ======== Adding/Access ======== */
+int Thing::pushThought(Thought thought) {
+ if (thoughts.size() > thoughts_max) return 0;
+ LOG(LOG_INFO) << name << " has a new thought( " << thoughts.size()+1 << "): " << thought.dumpInfo();
+ thoughts.push_back(thought);
+ return thoughts.size();
+}
+/* ======== Velocity/Position ======== */
+void Thing::addVelocity(Vec3 vel) {
+ velocity += vel;
+}
+void Thing::setVelocity(Vec3 vel) {
+ velocity = vel;
+}
+/* ======== Etc. ======== */
+bool destroyThing(Thing *thing) {
+ if (thing->flags & Thing::THING_DESTROY) return true;
+ return false;
+}
diff --git a/src/things/Thing.hpp b/src/things/Thing.hpp
new file mode 100644
index 0000000..56fc9f4
--- /dev/null
+++ b/src/things/Thing.hpp
@@ -0,0 +1,46 @@
+#ifndef THING_HPP
+#define THING_HPP
+#include "Thought.hpp"
+#include "RenderObject.hpp"
+#include "Sprite.hpp"
+#include
+#include
+
+//class Thought; // fwd declaration
+
+class Thing {
+ friend class GameState;
+ friend class PlayerController;
+ friend class AiController;
+ public:
+ Thing();
+ ~Thing();
+ // interface
+ virtual int doThink(unsigned int ticks);
+ virtual int onTouch(Thing *thing);
+ //
+ int pushThought(Thought thought);
+ //
+ enum Flags {
+ THING_DESTROY = (1 << 1)
+ };
+ int flags;
+ // position and velocity
+ void addVelocity(Vec3 vel);
+ void setVelocity(Vec3 vel);
+ protected:
+ std::string name;
+ Vec3 velocity; // although this is a rug-like, velocity makes life easier
+ Vec3 position;
+ Vec2 scale;
+ unsigned int thoughts_max; // our maximum # of thoughts
+ std::deque thoughts; // our queue of thoughts
+ Thought thought_current; // current thought, popped from thoughts
+ unsigned int thought_delay; // time required for current thought
+ unsigned int thought_elapsed; // elapsed time spent on current thought
+ //
+ Sprite *sprite;
+};
+
+bool destroyThing(Thing* thing);
+#endif