aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-03-01 08:33:27 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-03-01 08:33:27 -0500
commit32cb1880f018fc149d1c8a71a83426a8f5a92a6a (patch)
treebfa73ddb4076018639b6ec2e14492471b82c0649
parent6241707a788269e09adb957c659397750d19fda3 (diff)
world rewrite
-rw-r--r--Changelog11
-rw-r--r--include/world.h2
-rw-r--r--main.cpp19
-rw-r--r--src/inventory.cpp4
-rw-r--r--src/ui.cpp44
-rw-r--r--src/world.cpp40
6 files changed, 70 insertions, 50 deletions
diff --git a/Changelog b/Changelog
index b85c195..9a9b927 100644
--- a/Changelog
+++ b/Changelog
@@ -690,10 +690,19 @@
- looked into better automated Makefiles
- improving villages, began work on shops
-2/26/2015:
+2/26/2016:
==========
- made fonts more memory-efficient
- C++-ified loaded texture handlers
- documented more stuff
- made merchant menu
+
+2/29/2016:
+==========
+
+ - renewed branch 'remake': re-wrote world.cpp and pushed
+ - fixed world linkage errors
+ - considered more formal coding? (as in documentation and indentation)
+ - fixed dialog boxes and options
+ - broke screenshots
diff --git a/include/world.h b/include/world.h
index 05b2a10..9833bb2 100644
--- a/include/world.h
+++ b/include/world.h
@@ -281,7 +281,7 @@ public:
* A vector of all light elements in this world.
*/
- std::vector<Light > light;
+ std::vector<Light> light;
/**
* Vector of all building textures for the current world style
diff --git a/main.cpp b/main.cpp
index 885c610..fd02cc1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -185,9 +185,11 @@ void mainLoop(void);
/*******************************************************************************
* MAIN ************************************************************************
*******************************************************************************/
-int main(/*int argc, char *argv[]*/){
- // *argv = (char *)argc;
- SDL_GLContext mainGLContext = NULL;
+int main(int argc, char *argv[]){
+ (void)argc;
+ (void)argv;
+
+ static SDL_GLContext mainGLContext = NULL;
gameRunning=false;
@@ -290,16 +292,7 @@ int main(/*int argc, char *argv[]*/){
if((err=glewInit()) != GLEW_OK){
std::cout << "GLEW was not able to initialize! Error: " << glewGetErrorString(err) << std::endl;
return -1;
- }
-
- /*
- * Initialize the FreeType libraries and select what font to use using functions from the ui
- * namespace, defined in include/ui.h and src/ui.cpp. These functions should abort with errors
- * if they have error.
- */
-
- //ui::initFonts();
- //ui::setFontFace("ttf/FreePixel.ttf"); // as in gamedev/ttf/<font>
+ }
/*
* Initialize the random number generator. At the moment, initRand is a macro pointing to libc's
diff --git a/src/inventory.cpp b/src/inventory.cpp
index b32b56f..203e707 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -407,6 +407,8 @@ int Inventory::useItem(void){
}
bool Inventory::detectCollision(vec2 one, vec2 two){
+ (void)one;
+ (void)two;
//float i = 0.0f;
/*if(items.empty() || !items[sel].count)
@@ -433,6 +435,6 @@ bool Inventory::detectCollision(vec2 one, vec2 two){
i+=HLINE;
}
}*/
- return !(one.x == two.y);
+ return false;
}
diff --git a/src/ui.cpp b/src/ui.cpp
index 6e616a7..47110cc 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -1039,42 +1039,48 @@ DONE:
vec2 oldpos,tmppos;
SDL_Event e;
- mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
- mouse.y=(offset.y+SCREEN_HEIGHT/2)-premouse.y;
+ // update mouse coords
+ mouse.x = premouse.x + offset.x - ( SCREEN_WIDTH / 2 );
+ mouse.y = ( offset.y + SCREEN_HEIGHT / 2 ) - premouse.y;
while(SDL_PollEvent(&e)){
switch(e.type){
+
+ // escape - quit game
case SDL_QUIT:
gameRunning=false;
break;
+
+ // mouse movement - update mouse vector
case SDL_MOUSEMOTION:
premouse.x=e.motion.x;
premouse.y=e.motion.y;
break;
+
+ // mouse clicks
case SDL_MOUSEBUTTONDOWN:
- if((e.button.button & SDL_BUTTON_RIGHT) && dialogBoxExists)
+ // right click advances dialog
+ if ( ( e.button.button & SDL_BUTTON_RIGHT ) && dialogBoxExists )
dialogAdvance();
- if((e.button.button & SDL_BUTTON_LEFT) && !dialogBoxExists)
+ // left click uses item
+ if ( ( e.button.button & SDL_BUTTON_LEFT ) && !dialogBoxExists )
player->inv->usingi = true;
break;
- /*
- KEYDOWN
- */
+
+ // key presses
case SDL_KEYDOWN:
- /*if(SDL_KEY == SDLK_ESCAPE){
- //gameRunning = false;
- pMenu = true;
- return;
- }else */if(SDL_KEY == SDLK_SPACE){
- /*if(dialogBoxExists)
- dialogAdvance();
- else */if(player->ground){
- player->vel.y=.4;
- player->loc.y+=HLINE*2;
- player->ground=false;
+
+ // space - make player jump
+ if ( SDL_KEY == SDLK_SPACE ) {
+ if ( player->ground ) {
+ player->loc.y += HLINE * 2;
+ player->vel.y = .4;
+ player->ground = false;
}
break;
- }else if(!dialogBoxExists || dialogPassive){
+
+ // only let other keys be handled if dialog allows it
+ } else if ( !dialogBoxExists || dialogPassive ) {
tmp = currentWorld;
switch(SDL_KEY){
case SDLK_a:
diff --git a/src/world.cpp b/src/world.cpp
index 76dccb8..4fa71d8 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -252,6 +252,7 @@ generate( unsigned int width )
for(wditer = worldData.begin(); wditer != worldData.end(); wditer++){
if ((*wditer).groundHeight)
+ // wditer + GROUND_HILLINESS can go out of bounds (invalid read)
geninc = ( (*(wditer + GROUND_HILLINESS)).groundHeight - (*wditer).groundHeight ) / (float)GROUND_HILLINESS;
else
(*wditer).groundHeight = (*(wditer - 1)).groundHeight + geninc;
@@ -260,7 +261,7 @@ generate( unsigned int width )
(*wditer).grassUnpressed = true;
(*wditer).grassHeight[0] = (randGet() % 16) / 3 + 2;
(*wditer).grassHeight[1] = (randGet() % 16) / 3 + 2;
-
+
// bound checks
if ( (*wditer).groundHeight < GROUND_HEIGHT_MINIMUM )
(*wditer).groundHeight = GROUND_HEIGHT_MINIMUM;
@@ -269,6 +270,7 @@ generate( unsigned int width )
if( (*wditer).groundHeight <= 0 )
(*wditer).groundHeight = GROUND_HEIGHT_MINIMUM;
+
}
// define x-coordinate of world's leftmost 'line'
@@ -674,11 +676,17 @@ draw( Player *p )
p->draw();
}
-/*
- * TODO
+/**
+ * Handles physics and such for a single entity.
+ *
+ * This function is kept private, as World::detect() should be used instead to
+ * handle stuffs for all entities at once.
*/
-void World::singleDetect(Entity *e){
+void World::
+singleDetect( Entity *e )
+{
+ std::string killed;
unsigned int i,j;
int l;
@@ -686,12 +694,12 @@ void World::singleDetect(Entity *e){
* Kill any dead entities.
*/
- if(!e->alive||e->health<=0){
- for(i=0;i<entity.size();i++){
- if(entity[i]==e){
- switch(e->type){
+ if ( !e->alive || e->health <= 0 ) {
+ for ( i = 0; i < entity.size(); i++) {
+ if ( entity[i] == e ){
+ switch ( e->type ) {
case STRUCTURET:
- std::cout<<"Killed a building..."<<std::endl;
+ killed = "structure";
for(j=0;j<build.size();j++){
if(build[j]==e){
delete build[j];
@@ -701,7 +709,7 @@ void World::singleDetect(Entity *e){
}
break;
case NPCT:
- std::cout<<"Killed an NPC..."<<std::endl;
+ killed = "NPC";
for(j=0;j<npc.size();j++){
if(npc[j]==e){
delete npc[j];
@@ -711,7 +719,7 @@ void World::singleDetect(Entity *e){
}
break;
case MOBT:
- std::cout<<"Killed a mob..."<<std::endl;
+ killed = "mob";
/*for(j=0;j<mob.size();j++){
if(mob[j]==e){
delete mob[j];
@@ -721,7 +729,7 @@ void World::singleDetect(Entity *e){
}*/
break;
case OBJECTT:
- std::cout<<"Killed an object..."<<std::endl;
+ killed = "object";
for(j=0;j<object.size();j++){
if(object[j]==e){
delete object[j];
@@ -733,6 +741,7 @@ void World::singleDetect(Entity *e){
default:
break;
}
+ std::cout << "Killed a " << killed << "..." << std::endl;
entity.erase(entity.begin()+i);
return;
}
@@ -884,8 +893,6 @@ void World::addStructure(BUILD_SUB sub, float x,float y, char *tex, const char *
else
strcpy((build.back()->inside = new char[1]),"\0");
- //strcpy((build.back()->outside = new char[1 + strlen((char *)(currentXML+4))]),(char *)(currentXML+4));
-
entity.push_back(build.back());
}
@@ -1010,6 +1017,7 @@ World *World::goWorldRight(Player *p){
}
std::vector<std::string> inside;
+
World *World::
goInsideStructure( Player *p )
{
@@ -1035,11 +1043,13 @@ goInsideStructure( Player *p )
tmp = loadWorldFromXML(inside.back().c_str());
for(auto &b : tmp->build){
if(!strcmp(current,b->inside)){
- p->loc.x = b->loc.x + (b->width / 2);
inside.pop_back();
ui::toggleBlackFast();
ui::waitForCover();
+
+ p->loc.x = b->loc.x + (b->width / 2);
+
ui::toggleBlackFast();
return tmp;