aboutsummaryrefslogtreecommitdiffstats
path: root/main.cpp
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 /main.cpp
parentf102149e15ca1ac36cbb4e2627e5ce44f2d5273a (diff)
ortho snapping, reset option
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp50
1 files changed, 31 insertions, 19 deletions
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);