aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-05-03 08:49:01 -0400
committerClyne Sullivan <tullivan99@gmail.com>2016-05-03 08:49:01 -0400
commitafb0ada00a2c50ea541ba6dc93058ccdb0286cdd (patch)
tree36b070d21fd237419a9f0a3bafb11add8fd68aa7
parentf102149e15ca1ac36cbb4e2627e5ce44f2d5273a (diff)
ortho snapping, reset option
-rw-r--r--Changelog11
-rw-r--r--include/inventory.hpp3
-rw-r--r--include/texture.hpp47
-rw-r--r--include/world.hpp5
-rw-r--r--main.cpp50
-rw-r--r--src/entities.cpp13
-rw-r--r--src/mob.cpp10
-rw-r--r--src/ui_action.cpp8
-rw-r--r--src/world.cpp23
9 files changed, 72 insertions, 98 deletions
diff --git a/Changelog b/Changelog
index 7118290..a604032 100644
--- a/Changelog
+++ b/Changelog
@@ -957,3 +957,14 @@
- render is now separated from the main loop
~8,100 lines of code
+
+5/3/2016:
+=========
+
+ - smoothed out ortho snapping
+ - improved arenas, fixed door texture
+ - fixed mob riding / ortho snaps
+ - added command line option handling, with -r option to clear .dat files
+ - found segfault when exiting game
+ - made string tokenizer for tokenizing strings
+ - messed with HLINE scaling, it's bad
diff --git a/include/inventory.hpp b/include/inventory.hpp
index bee2fbd..c34eadb 100644
--- a/include/inventory.hpp
+++ b/include/inventory.hpp
@@ -17,9 +17,10 @@ class Entity;
class Item {
private:
bool beingUsed;
-
+protected:
std::vector<Entity*> interact;
public:
+
// what we want to call each item
std::string name;
diff --git a/include/texture.hpp b/include/texture.hpp
index 22a2459..ecf85e4 100644
--- a/include/texture.hpp
+++ b/include/texture.hpp
@@ -86,69 +86,22 @@ public:
class Texturec{
private:
-
- /**
- * Contains the index in the image array of the currently loaded texture.
- */
-
unsigned int texState;
public:
- /**
- * Contains an array of the GLuints returned from Texture::loadTexture().
- */
-
std::vector<GLuint> image;
-
- /**
- * Contains the dimensions of each texture in the vector
- */
- //TODO
- //std::vector<vec2> imageDim;
-
- /**
- * Stores the location of all the images
- */
std::vector<std::string> texLoc;
- /**
- * Populates the image array from a list of strings, with each string as a
- * separate argument.
- */
-
Texturec(uint amt, ...);
-
- /**
- * Populates the image array from an array of strings.
- */
-
Texturec(uint amt,const char **paths);
Texturec(std::vector<std::string>vec);
Texturec(std::initializer_list<std::string> l);
- /**
- * Frees memory taken by the image array.
- */
-
~Texturec();
- /**
- * Binds the next texture in the array, incrementing texState.
- */
-
void bindNext();
-
- /**
- * Binds the previous texture in the array, decrementing texState.
- */
-
void bindPrev();
-
- /**
- * Binds the texture with the provided index.
- */
-
void bind(unsigned int);
};
diff --git a/include/world.hpp b/include/world.hpp
index 5d30161..2dd166a 100644
--- a/include/world.hpp
+++ b/include/world.hpp
@@ -320,11 +320,14 @@ private:
public:
// creates the arena with the world being left for it
- Arena(World *leave, Player *p, Mob *m);
+ Arena(void);
// frees memory
~Arena(void);
+ // starts a new fight??
+ void fight(World *leave, const Player *p, Mob *m);
+
// attempts to exit the arena, returning what world the player should be in
WorldSwitchInfo exitArena(Player *p);
};
diff --git a/main.cpp b/main.cpp
index ac9eb5d..cc6d5eb 100644
--- a/main.cpp
+++ b/main.cpp
@@ -39,6 +39,9 @@ World *currentWorld = NULL,
*currentWorldToLeft = NULL,
*currentWorldToRight = NULL;
+// an arena for fightin'
+Arena *arena = nullptr;
+
// the currently used folder to grab XML files
std::string xmlFolder;
@@ -80,6 +83,18 @@ int main(int argc, char *argv[]){
static SDL_GLContext mainGLContext = NULL;
+ // handle command line arguments
+ if (argc > 1) {
+ std::vector<std::string> args (argc, "");
+ for (int i = 1; i < argc; i++)
+ args[i] = argv[i];
+
+ for (const auto &s : args) {
+ if (s == "--reset" || s == "-r")
+ system("rm -f xml/*.dat");
+ }
+ }
+
// attempt to initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
UserError(std::string("SDL was not able to initialize! Error: ") + SDL_GetError());
@@ -218,9 +233,10 @@ int main(int argc, char *argv[]){
if (currentWorld == NULL)
UserError("Plot twist: The world never existed...?");
- /**************************
- **** GAMELOOP ****
- **************************/
+ arena = new Arena();
+ arena->setStyle("");
+ arena->setBackground(WorldBGType::Forest);
+ arena->setBGM("assets/music/embark.wav");
// the main loop, in all of its gloriousness..
gameRunning = true;
@@ -244,6 +260,7 @@ int main(int argc, char *argv[]){
// close up the game stuff
currentWorld->save();
+ delete arena;
//delete currentWorld;
//delete[] currentXML;
//aipreload.clear();
@@ -290,32 +307,27 @@ void mainLoop(void){
fps = 1000 / game::time::getDeltaTime();
debugY = player->loc.y;
}
- SDL_Delay(1);
}
SDL_Delay(1);
}
void render() {
- auto SCREEN_WIDTH = game::SCREEN_WIDTH;
- auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+ const auto SCREEN_WIDTH = game::SCREEN_WIDTH;
+ const auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
- // offset should contain the coordinates of the center of the player's view
- offset.x = player->loc.x + player->width/2;
- offset.y = SCREEN_HEIGHT/2;
+ offset.x = player->loc.x + player->width / 2;
- // snap the player's view if we're at a world edge
- if (currentWorld->getTheWidth() < (int)SCREEN_WIDTH) {
+ // ortho x snapping
+ if (currentWorld->getTheWidth() < (int)SCREEN_WIDTH)
offset.x = 0;
- } else {
- if (player->loc.x - SCREEN_WIDTH/2 < currentWorld->getTheWidth() * -0.5f)
- offset.x = ((currentWorld->getTheWidth() * -0.5f) + SCREEN_WIDTH / 2) + player->width / 2;
- if (player->loc.x + player->width + SCREEN_WIDTH/2 > currentWorld->getTheWidth() * 0.5f)
- offset.x = ((currentWorld->getTheWidth() * 0.5f) - SCREEN_WIDTH / 2) - player->width / 2;
- }
+ else if (offset.x - SCREEN_WIDTH / 2 < currentWorld->getTheWidth() * -0.5f)
+ offset.x = ((currentWorld->getTheWidth() * -0.5f) + SCREEN_WIDTH / 2);
+ else if (offset.x + SCREEN_WIDTH / 2 > currentWorld->getTheWidth() * 0.5f)
+ offset.x = ((currentWorld->getTheWidth() * 0.5f) - SCREEN_WIDTH / 2);
- if(player->loc.y > SCREEN_HEIGHT/2)
- offset.y = player->loc.y + player->height;
+ // ortho y snapping
+ offset.y = std::max(player->loc.y + player->height / 2, SCREEN_HEIGHT / 2.0f);
// "setup"
glMatrixMode(GL_PROJECTION);
diff --git a/src/entities.cpp b/src/entities.cpp
index 58c1651..216d9ef 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -64,15 +64,8 @@ void randGetomName(Entity *e)
names.close();
- switch(bufs[0]) {
- default :
- case 'm':
- e->gender = MALE;
- break;
- case 'f':
- e->gender = FEMALE;
- break;
- }
+ // gender is a binary construct
+ e->gender = (bufs[0] == 'm') ? MALE : FEMALE;
strcpy(e->name, bufs + 1);
@@ -343,7 +336,7 @@ void Entity::draw(void)
glColor3ub(255, 105, 180);
} else if (type == MOBT) {
if (Mobp(this)->rider != nullptr) {
- Mobp(this)->rider->loc.x = loc.x + width / 2;
+ Mobp(this)->rider->loc.x = loc.x + width * 0.25f;
Mobp(this)->rider->loc.y = loc.y + height - game::HLINE;
Mobp(this)->rider->vel.y = .12;
}
diff --git a/src/mob.cpp b/src/mob.cpp
index 1829240..6ce46ab 100644
--- a/src/mob.cpp
+++ b/src/mob.cpp
@@ -310,6 +310,8 @@ Mob::~Mob()
}
extern World *currentWorld;
+extern Arena *arena;
+
void Mob::wander(void)
{
static bool YAYA = false;
@@ -320,16 +322,12 @@ void Mob::wander(void)
if (aggressive && !YAYA && isInside(vec2 {player->loc.x + width / 2, player->loc.y + height / 4})) {
if (!ui::dialogBoxExists) {
std::thread([&](void){
- auto *a = new Arena(currentWorld, player, this);
- a->setStyle("");
- a->setBackground(WorldBGType::Forest);
- a->setBGM("assets/music/embark.wav");
-
+ arena->fight(currentWorld, player, this);
ui::toggleWhiteFast();
YAYA = true;
ui::waitForCover();
YAYA = false;
- currentWorld = a;
+ currentWorld = arena;
ui::toggleWhiteFast();
}).detach();
}
diff --git a/src/ui_action.cpp b/src/ui_action.cpp
index 960b222..ebdc705 100644
--- a/src/ui_action.cpp
+++ b/src/ui_action.cpp
@@ -5,6 +5,7 @@
#define ACTION_EPILOUGE { actioning = false; actionHover = 0; }
extern World *currentWorld;
+extern Arena *arena;
extern Player *player;
extern bool inBattle;
@@ -115,14 +116,11 @@ void actionAttack(void)
if (m->type == MOBT) {
if (!inBattle && m != nullptr) {
- Arena *a = new Arena(currentWorld, player, Mobp(m));
- a->setStyle("");
- a->setBackground(WorldBGType::Forest);
- a->setBGM("assets/music/embark.wav");
+ arena->fight(currentWorld, player, Mobp(m));
ui::toggleWhiteFast();
ui::waitForCover();
- currentWorld = a;
+ currentWorld = arena;
ui::toggleWhiteFast();
}
} else {
diff --git a/src/world.cpp b/src/world.cpp
index 223a8bc..80fc322 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -1488,26 +1488,31 @@ draw(Player *p)
p->draw();
}
-Arena::Arena(World *leave, Player *p, Mob *m)
+Arena::Arena(void)
{
generate(800);
addMob(new Door(), vec2 {100, 100});
+}
+
+Arena::~Arena(void)
+{
+ mmob->die();
+ deleteEntities();
+}
- inBattle = true;
+void Arena::fight(World *leave, const Player *p, Mob *m)
+{
+ inBattle = true;
- mob.push_back((mmob = m));
+ mob.push_back((mmob = m));
entity.push_back(mmob);
mmob->aggressive = false;
arenaNest.emplace_back(leave, p->loc);
}
-Arena::~Arena(void) {
- mmob->die();
- deleteEntities();
-}
-
-WorldSwitchInfo Arena::exitArena(Player *p) {
+WorldSwitchInfo Arena::exitArena(Player *p)
+{
if (!mmob->isAlive() &&
p->loc.x + p->width / 2 > mob[0]->loc.x &&
p->loc.x + p->width / 2 < mob[0]->loc.x + HLINES(12)) {