From a9a9777190086bd2ce2aa54e20a1101509614463 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 29 Mar 2016 08:48:52 -0400 Subject: [PATCH] began reworking indoors --- Changelog | 22 ++++ Makefile | 2 +- include/common.h | 3 +- include/config.h | 16 +-- include/entities.h | 6 +- include/inventory.h | 2 +- include/{Quest.h => quest.h} | 32 +++--- include/{Texture.h => texture.h} | 0 include/world.h | 13 ++- main.cpp | 6 +- src/config.cpp | 101 +++++++++-------- src/gameplay.cpp | 6 +- src/inventory.cpp | 4 +- src/{Quest.cpp => quest.cpp} | 47 ++++---- src/{Texture.cpp => texture.cpp} | 2 +- src/ui.cpp | 29 +++-- src/world.cpp | 170 +++++++++++++++-------------- xml/playerSpawnHill1.xml | 2 +- xml/playerSpawnHill1_Building1.xml | 7 +- 19 files changed, 253 insertions(+), 217 deletions(-) rename include/{Quest.h => quest.h} (83%) rename include/{Texture.h => texture.h} (100%) rename src/{Quest.cpp => quest.cpp} (60%) rename src/{Texture.cpp => texture.cpp} (99%) diff --git a/Changelog b/Changelog index 1a54ec3..00ba578 100644 --- a/Changelog +++ b/Changelog @@ -821,3 +821,25 @@ - found brazzier glitch - merchants inside stalls - z renders???? + +3/25/2016: +========== + + - relocated detect() to main loop, better thing handling now + - implemented rain, snow + - added weather to debug overlay thing + +3/28/2016: +========== + + - fixed bug with quest assignment + - made file names consistent + - namespace'd config stuff + - began work on improving rendering stuff + +3/29/2016: +========== + + - prevented structures from moving + - began making indoor worlds good + - inventory slots are actually being used diff --git a/Makefile b/Makefile index 4c56fb6..c8b09e3 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ ifeq ($(TARGET_OS),win32) -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype endif -CXXFLAGS = -m$(TARGET_BITS) -std=c++14 +CXXFLAGS = -m$(TARGET_BITS) -std=c++1z CXXINC = -Iinclude -Iinclude/freetype CXXWARN = -Wall -Wextra -Werror -pedantic-errors diff --git a/include/common.h b/include/common.h index 6f453b0..216dc01 100644 --- a/include/common.h +++ b/include/common.h @@ -117,7 +117,7 @@ typedef col Color; * Define the game's name (displayed in the window title). */ -#define GAME_NAME "Independent Study v.0.6 alpha - NOW WITH more c++" +#define GAME_NAME "Independent Study v0.7 alpha - NOW WITH lights and snow and stuff" /** * The desired width of the game window. @@ -176,6 +176,7 @@ extern float VOLUME_SFX; */ #define DEBUG_printf( message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__ ) +#define C(x) std::cout << x << std::endl; /** * Defines pi for calculations that need it. diff --git a/include/config.h b/include/config.h index 4d56d9c..e2f7239 100644 --- a/include/config.h +++ b/include/config.h @@ -1,14 +1,10 @@ #ifndef CONFIG_H #define CONFIG_H -#include -#include -#include +namespace config { + void read( void ); + void update( void ); + void save( void ); +} -void readConfig(void); - -void updateConfig(void); - -void saveConfig(); - -#endif //CONFIG_H \ No newline at end of file +#endif //CONFIG_H diff --git a/include/entities.h b/include/entities.h index 1250708..f455726 100644 --- a/include/entities.h +++ b/include/entities.h @@ -2,9 +2,9 @@ #define ENTITIES_H #include -#include +#include #include -#include +#include #include @@ -14,7 +14,7 @@ #define Structurep(n) ((Structures *)n) #define Mobp(n) ((Mob *)n) -#define PLAYER_INV_SIZE 30 // The size of the player's inventory +#define PLAYER_INV_SIZE 43 // The size of the player's inventory #define NPC_INV_SIZE 3 // Size of an NPC's inventory enum _TYPE { diff --git a/include/inventory.h b/include/inventory.h index 7369642..08a145e 100644 --- a/include/inventory.h +++ b/include/inventory.h @@ -4,7 +4,7 @@ #include #include -#include +#include #define DEBUG diff --git a/include/Quest.h b/include/quest.h similarity index 83% rename from include/Quest.h rename to include/quest.h index 8b1e142..4da38bf 100644 --- a/include/Quest.h +++ b/include/quest.h @@ -1,16 +1,15 @@ /** @file Quest.h * @brief The quest handling system. - * + * * This file contains Quest and QuestHandler, used to manage quests inside the * game. */ - + #ifndef QUEST_H #define QUEST_H -#include +#include -#include #include /** @@ -20,21 +19,16 @@ #define DEBUG -struct need_t { - std::string name; - int n; -}; - typedef struct { std::string title; std::string desc; struct item_t reward; - std::vector need; + std::vector> need; } Quest; /** * The Quest Handler class. - * + * * This class handles quests, including the assigning, dropping, and completing * of the quests. */ @@ -42,30 +36,30 @@ typedef struct { class QuestHandler { public: std::vectorcurrent; - + /** * Adds a quest to the current quest vector by its title. */ - + int assign(std::string title,std::string desc,std::string req); - + /** * Drops a quest through its title. */ - + int drop(std::string title); - + /** * Finishes a quest through it's title, also giving a pointer to the Entity * that gave the quest originally. */ - + int finish(std::string t); - + /** * Returns true if this handler is currently taking the quest. */ - + bool hasQuest(std::string t); }; diff --git a/include/Texture.h b/include/texture.h similarity index 100% rename from include/Texture.h rename to include/texture.h diff --git a/include/world.h b/include/world.h index 0b87134..f730715 100644 --- a/include/world.h +++ b/include/world.h @@ -165,7 +165,7 @@ protected: * World::detect(), which is why it is declared private. */ - void singleDetect( Entity *e ); + virtual void singleDetect( Entity *e ); /** * Empties all entity vectors. @@ -386,7 +386,7 @@ public: * half-width to positive half-width. */ - virtual void generate(unsigned int width); + void generate(unsigned int width); /** * Sets the background theme, collecting the required textures into a @@ -482,11 +482,18 @@ public: */ class IndoorWorld : public World { +private: + + std::vector> floor; + + void singleDetect( Entity *e ); + public: IndoorWorld(void); ~IndoorWorld(void); - void generate(unsigned int width); // Generates a flat world of width 'width' + void addFloor( unsigned int width ); + void draw(Player *p); // Draws the world (ignores layers) }; diff --git a/main.cpp b/main.cpp index f4a0005..4140ac7 100644 --- a/main.cpp +++ b/main.cpp @@ -243,8 +243,10 @@ int main(int argc, char *argv[]){ std::cout << "SDL_mixer could not initialize! Error: " << Mix_GetError() << std::endl; return -1; } + Mix_AllocateChannels(8); - updateConfig(); + + config::update(); // Run Mix_Quit when main returns atexit(Mix_Quit); @@ -253,7 +255,7 @@ int main(int argc, char *argv[]){ * Load saved settings into the game (see config/settings.xml) */ - readConfig(); + config::read(); /* * Create a window for SDL to draw to. Most parameters are the default, except for the diff --git a/src/config.cpp b/src/config.cpp index 45bab3f..e076528 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1,5 +1,10 @@ #include +#include + +#include + +#include #include using namespace tinyxml2; @@ -17,55 +22,57 @@ XMLDocument xml; XMLElement *scr; XMLElement *vol; -void readConfig(){ - unsigned int uval; - float fval; - bool bval; - - xml.LoadFile("config/settings.xml"); - scr = xml.FirstChildElement("screen"); - - if(scr->QueryUnsignedAttribute("width",&uval) == XML_NO_ERROR) - SCREEN_WIDTH = uval; - else SCREEN_WIDTH = 1280; - if(scr->QueryUnsignedAttribute("height",&uval) == XML_NO_ERROR) - SCREEN_HEIGHT = uval; - else SCREEN_HEIGHT = 800; - if(scr->QueryBoolAttribute("fullscreen",&bval) == XML_NO_ERROR) - FULLSCREEN = bval; - else FULLSCREEN = false; - if(xml.FirstChildElement("hline")->QueryUnsignedAttribute("size",&uval) == XML_NO_ERROR) - HLINE = uval; - else HLINE = 3; - - vol = xml.FirstChildElement("volume"); - - if(vol->FirstChildElement("master")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR) - VOLUME_MASTER = fval; - else VOLUME_MASTER = 50; - if(vol->FirstChildElement("music")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR) - VOLUME_MUSIC = fval; - else VOLUME_MUSIC = 50; - if(vol->FirstChildElement("sfx")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR) - VOLUME_SFX = fval; - else VOLUME_SFX = 50; - - ui::initFonts(); - ui::setFontFace(xml.FirstChildElement("font")->Attribute("path")); - updateConfig(); -} +namespace config { -void updateConfig(){ + void read( void ) { + unsigned int uval; + float fval; + bool bval; - Mix_Volume(0,VOLUME_MASTER); - Mix_Volume(1,VOLUME_SFX * (VOLUME_MASTER/100.0f)); - Mix_VolumeMusic(VOLUME_MUSIC * (VOLUME_MASTER/100.0f)); -} + xml.LoadFile("config/settings.xml"); + scr = xml.FirstChildElement("screen"); + + if(scr->QueryUnsignedAttribute("width",&uval) == XML_NO_ERROR) + SCREEN_WIDTH = uval; + else SCREEN_WIDTH = 1280; + if(scr->QueryUnsignedAttribute("height",&uval) == XML_NO_ERROR) + SCREEN_HEIGHT = uval; + else SCREEN_HEIGHT = 800; + if(scr->QueryBoolAttribute("fullscreen",&bval) == XML_NO_ERROR) + FULLSCREEN = bval; + else FULLSCREEN = false; + if(xml.FirstChildElement("hline")->QueryUnsignedAttribute("size",&uval) == XML_NO_ERROR) + HLINE = uval; + else HLINE = 3; + + vol = xml.FirstChildElement("volume"); + + if(vol->FirstChildElement("master")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR) + VOLUME_MASTER = fval; + else VOLUME_MASTER = 50; + if(vol->FirstChildElement("music")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR) + VOLUME_MUSIC = fval; + else VOLUME_MUSIC = 50; + if(vol->FirstChildElement("sfx")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR) + VOLUME_SFX = fval; + else VOLUME_SFX = 50; + + ui::initFonts(); + ui::setFontFace(xml.FirstChildElement("font")->Attribute("path")); + config::update(); + } + + void update( void ) { + Mix_Volume(0,VOLUME_MASTER); + Mix_Volume(1,VOLUME_SFX * (VOLUME_MASTER/100.0f)); + Mix_VolumeMusic(VOLUME_MUSIC * (VOLUME_MASTER/100.0f)); + } -void saveConfig(){ - vol->FirstChildElement("master")->SetAttribute("volume",VOLUME_MASTER); - vol->FirstChildElement("music")->SetAttribute("volume",VOLUME_MUSIC); - vol->FirstChildElement("sfx")->SetAttribute("volume", VOLUME_SFX); + void save( void ) { + vol->FirstChildElement("master")->SetAttribute("volume",VOLUME_MASTER); + vol->FirstChildElement("music")->SetAttribute("volume",VOLUME_MUSIC); + vol->FirstChildElement("sfx")->SetAttribute("volume", VOLUME_SFX); - xml.SaveFile("config/settings.xml", false); + xml.SaveFile("config/settings.xml", false); + } } diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 075aec3..3c98461 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -212,13 +212,13 @@ CONT: void commonPageFunc( Mob *callee ) { static bool lock = false; - + if ( !lock ) { lock = true; - + ui::drawPage( callee->heyid ); ui::waitForDialog(); - + callee->alive = false; lock = false; } diff --git a/src/inventory.cpp b/src/inventory.cpp index 7ba5909..d9ff756 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -9,9 +9,8 @@ extern Player *player; extern GLuint invUI; static float hangle = 0.0f; static bool swing = false; -//static float xc,yc; static vec2 itemLoc; -static const unsigned char numSlot = 7; +static const unsigned int numSlot = 2000; Mix_Chunk* swordSwing; static std::vector itemMap; @@ -190,7 +189,6 @@ void Inventory::setSelectionDown(){ void Inventory::draw(void){ static unsigned int lop = 0; - //const unsigned int numSlot = 7; static std::vectordfp(numSlot); static std::vectoriray(numSlot); static std::vectorcurCoord(numSlot); diff --git a/src/Quest.cpp b/src/quest.cpp similarity index 60% rename from src/Quest.cpp rename to src/quest.cpp index 8f3c33b..ba35c40 100644 --- a/src/Quest.cpp +++ b/src/quest.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include extern Player *player; @@ -8,28 +8,25 @@ extern Player *player; int QuestHandler::assign(std::string title,std::string desc,std::string req){ Quest tmp; char *tok; - + tmp.title = title; tmp.desc = desc; - std::unique_ptr buf (new char[req.size()]); - - strcpy(buf.get(),req.c_str()); - tok = strtok(buf.get(),"\n\r\t,"); - tmp.need.push_back({"\0",0}); - - while(tok){ - if(tmp.need.back().name != "\0"){ - tmp.need.back().n = atoi(tok); - tmp.need.push_back({"\0",0}); - }else - tmp.need.back().name = tok; - - tok = strtok(NULL,"\n\r\t,"); + tok = strtok( &req[0], "\n\r\t," ); + tmp.need.emplace_back( "", 0 ); + + while ( tok ) { + if ( !tmp.need.back().first.empty() ) { + tmp.need.back().second = atoi( tok ); + tmp.need.emplace_back( "", 0 ); + } else + tmp.need.back().first = tok; + + tok = strtok( NULL, "\n\r\t," ); } - + tmp.need.pop_back(); - current.push_back(tmp); + current.push_back( tmp ); return 0; } @@ -39,7 +36,7 @@ int QuestHandler::drop(std::string title){ current.end(), [&](Quest q){ return q.title == title; }), current.end() ); - + return 0; } @@ -47,18 +44,18 @@ int QuestHandler::finish(std::string t){ for ( auto c = current.begin(); c != current.end(); c++ ) { if ( (*c).title == t ) { for ( auto &n : (*c).need ) { - if ( player->inv->hasItem( n.name ) < n.n ) + if ( player->inv->hasItem( n.first ) < n.second ) return 0; } - + for ( auto &n : (*c).need ) - player->inv->takeItem( n.name, n.n ); - + player->inv->takeItem( n.first, n.second ); + current.erase( c ); return 1; } } - + return 0; } @@ -67,6 +64,6 @@ bool QuestHandler::hasQuest(std::string t){ if ( c.title == t ) return true; } - + return false; } diff --git a/src/Texture.cpp b/src/texture.cpp similarity index 99% rename from src/Texture.cpp rename to src/texture.cpp index 1ae5567..35d7b80 100644 --- a/src/Texture.cpp +++ b/src/texture.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include /** * A structure for keeping track of loaded textures. diff --git a/src/ui.cpp b/src/ui.cpp index c646458..69fe1bf 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -99,7 +99,7 @@ static GLuint pageTex = 0; void Menu::gotoParent(){ if(parent == NULL){ currentMenu = NULL; - updateConfig(); + config::update(); }else{ currentMenu = parent; } @@ -881,8 +881,8 @@ namespace ui { dialogBoxExists = false; currentMenu = NULL; gameRunning = false; - updateConfig(); - saveConfig(); + config::update(); + config::save(); } menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f){ @@ -955,7 +955,7 @@ namespace ui { void drawMenu(Menu *menu){ setFontSize(24); - updateConfig(); + config::update(); SDL_Event e; mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2); @@ -1311,13 +1311,20 @@ EXIT: if ( ( e.button.button & SDL_BUTTON_LEFT ) && !dialogBoxExists ) player->inv->usingi = true; - for ( auto &e : currentWorld->entity ) { - if( mouse.x > e->loc.x && mouse.x < e->loc.x + e->width && - mouse.y > e->loc.y && mouse.y < e->loc.y + e->height ) { - e->vel.y = .05; - fr = mouse; - ig = e; - break; + if( mouse.x > player->loc.x && mouse.x < player->loc.x + player->width && + mouse.y > player->loc.y && mouse.y < player->loc.y + player->height ) { + player->vel.y = .05; + fr = mouse; + ig = player; + } else { + for ( auto &e : currentWorld->entity ) { + if( mouse.x > e->loc.x && mouse.x < e->loc.x + e->width && + mouse.y > e->loc.y && mouse.y < e->loc.y + e->height ) { + e->vel.y = .05; + fr = mouse; + ig = e; + break; + } } } diff --git a/src/world.cpp b/src/world.cpp index d8fd2d3..623c1c2 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -17,7 +17,8 @@ using namespace tinyxml2; * Defines the height of the floor in an IndoorWorld. */ -#define INDOOR_FLOOR_HEIGHT 100 +#define INDOOR_FLOOR_THICKNESS 50 +#define INDOOR_FLOOR_HEIGHTT 400 /** * Gravity thing @@ -316,21 +317,19 @@ update( Player *p, unsigned int delta ) // update entity coords for ( auto &e : entity ) { - e->loc.y += e->vel.y * delta; // dont let structures move? - if ( e->type == STRUCTURET ) - e->canMove = true; - - if ( e->canMove ) { + if ( e->type != STRUCTURET && e->canMove ) { e->loc.x += e->vel.x * delta; + e->loc.y += e->vel.y * delta; // update boolean directions if ( e->vel.x < 0 ) e->left = true; else if ( e->vel.x > 0 ) e->left = false; - } + } else if ( e->vel.y < 0 ) + e->loc.y += e->vel.y * delta; } // iterate through particles particles.erase( std::remove_if( particles.begin(), particles.end(), [&delta](Particles &part){return part.kill(delta);}), particles.end()); @@ -1250,41 +1249,63 @@ IndoorWorld::~IndoorWorld(void){ deleteEntities(); } -void IndoorWorld::generate(unsigned int width){ // Generates a flat area of width 'width' - lineCount=width+GROUND_HILLINESS; // Sets line count to the desired width plus GEN_INC to remove incorrect line calculations. - if(lineCount<=0)abort(); +void IndoorWorld:: +addFloor( unsigned int width ) +{ + if ( floor.empty() ) + generate( width ); + floor.emplace_back( width, floor.size() * INDOOR_FLOOR_HEIGHTT + INDOOR_FLOOR_THICKNESS ); +} - worldData = std::vector (lineCount, WorldData { false, {0,0}, INDOOR_FLOOR_HEIGHT, 0 }); +void IndoorWorld:: +singleDetect( Entity *e ) +{ + if ( !e->alive ) + return; + if ( e->type == MOBT && Mobp(e)->subtype == MS_TRIGGER ) + return; + + for ( auto &f : floor ) { + if ( f[0] + INDOOR_FLOOR_HEIGHTT < e->loc.y ) { + C("floor"); + if ( e->loc.y < f[0] ) { + e->loc.y = f[0]; + e->vel.y = 0; + e->ground = true; + } else if ( e->vel.y > -2 ) + e->vel.y -= GRAVITY_CONSTANT * deltaTime; + break; + } + } + + if(e->loc.x < worldStart){ // Left bound + e->vel.x=0; + e->loc.x=(float)worldStart + HLINE / 2; + }else if(e->loc.x + e->width + HLINE > worldStart + worldStart * -2){ // Right bound + e->vel.x=0; + e->loc.x=worldStart + worldStart * -2 - e->width - HLINE; + } - worldStart = (width - GROUND_HILLINESS) * HLINE / 2 * -1; } -void IndoorWorld::draw(Player *p){ - unsigned int i,ie; - //int j,x,v_offset; +void IndoorWorld:: +draw( Player *p ) +{ + unsigned int i; int x; - /* - * Draw the background. - */ - - //glEnable(GL_TEXTURE_2D); - - for(auto &l : light){ - if(l.belongsTo){ - l.loc.x = l.following->loc.x + SCREEN_WIDTH/2; + // draw lights + for ( auto &l : light ) { + if ( l.belongsTo ) { + l.loc.x = l.following->loc.x + SCREEN_WIDTH / 2; l.loc.y = l.following->loc.y; } - if(l.flame){ - l.fireFlicker = .9+((rand()%2)/10.0f); - l.fireLoc.x = l.loc.x + (rand()%2-1)*3; - l.fireLoc.y = l.loc.y + (rand()%2-1)*3; - - //std::cout << l.fireLoc.x << "," << l.fireLoc.y << std::endl; - //std::cout << l.loc.x << "," << l.loc.y << std::endl << std::endl; - }else{ + if ( l.flame ) { + l.fireFlicker = .9 + ( (rand() % 2) / 10.0f ); + l.fireLoc.x = l.loc.x + (rand() % 2 - 1) * 3; + l.fireLoc.y = l.loc.y + (rand() % 2 - 1) * 3; + } else l.fireFlicker = 1.0f; - } } std::unique_ptr pointArrayBuf = std::make_unique (2 * (light.size())); @@ -1301,9 +1322,8 @@ void IndoorWorld::draw(Player *p){ } } - for(i = 0; i < light.size(); i++){ + for(i = 0; i < light.size(); i++) flameArray[i] = light[i].fireFlicker; - } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); @@ -1312,7 +1332,7 @@ void IndoorWorld::draw(Player *p){ glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); glUniform1f(glGetUniformLocation(shaderProgram, "amb" ), 0.02f + light.size()/50.0f); - if ( light.size() == 0) + if ( light.empty() ) glUniform1i(glGetUniformLocation(shaderProgram, "numLight"), 0); else { glUniform1i (glGetUniformLocation(shaderProgram, "numLight" ), light.size()); @@ -1321,53 +1341,38 @@ void IndoorWorld::draw(Player *p){ glUniform1fv(glGetUniformLocation(shaderProgram, "fireFlicker"), light.size(), flameArray); } - //delete[] flameArray; - bgTex->bind(0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction glColor4ub(255,255,255,255); - glBegin(GL_QUADS); - glTexCoord2i(0,1); glVertex2i( worldStart - SCREEN_WIDTH / 2,0); - glTexCoord2i((-worldStart*2+SCREEN_WIDTH)/512,1);glVertex2i(-worldStart + SCREEN_WIDTH / 2,0); - glTexCoord2i((-worldStart*2+SCREEN_WIDTH)/512,0);glVertex2i(-worldStart + SCREEN_WIDTH / 2,SCREEN_HEIGHT); - glTexCoord2i(0,0); glVertex2i( worldStart - SCREEN_WIDTH / 2,SCREEN_HEIGHT); - glEnd(); - - glUseProgram(0); - //glDisable(GL_TEXTURE_2D); - - /* - * Calculate the starting and ending points to draw the ground from. - */ - - /*v_offset = (p->loc.x - x_start) / HLINE; - j = v_offset - (SCREEN_WIDTH / 2 / HLINE) - GEN_INC; - if(j < 0)j = 0; - i = j; - - ie = v_offset + (SCREEN_WIDTH / 2 / HLINE) - GEN_INC; - if(ie > lineCount)ie = lineCount;*/ + glBegin(GL_QUADS); + glTexCoord2i(0,1); glVertex2i( worldStart - SCREEN_WIDTH / 2,0); + glTexCoord2i((-worldStart*2+SCREEN_WIDTH)/512,1);glVertex2i(-worldStart + SCREEN_WIDTH / 2,0); + glTexCoord2i((-worldStart*2+SCREEN_WIDTH)/512,0);glVertex2i(-worldStart + SCREEN_WIDTH / 2,SCREEN_HEIGHT); + glTexCoord2i(0,0); glVertex2i( worldStart - SCREEN_WIDTH / 2,SCREEN_HEIGHT); + glEnd(); - i = 0; - ie = lineCount; + glUseProgram(0); /* * Draw the ground. */ - glUseProgram(shaderProgram); - glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); - glBegin(GL_QUADS); - for(;i < ie - GROUND_HILLINESS;i++){ - safeSetColor(150,100,50); - - x = worldStart + i * HLINE; - glVertex2i(x ,worldData[i].groundHeight); - glVertex2i(x + HLINE,worldData[i].groundHeight); - glVertex2i(x + HLINE,worldData[i].groundHeight - 50); - glVertex2i(x ,worldData[i].groundHeight - 50); - } + + glUseProgram( shaderProgram ); + glUniform1i( glGetUniformLocation(shaderProgram, "sampler"), 0 ); + glBegin( GL_QUADS ); + safeSetColor( 150, 100, 50 ); + for ( auto &f : floor ) { + i = 0; + for ( h : f ) { + x = worldStart + i++ * HLINE; + glVertex2i( x , h ); + glVertex2i( x + HLINE, h ); + glVertex2i( x + HLINE, h - INDOOR_FLOOR_THICKNESS ); + glVertex2i( x , h - INDOOR_FLOOR_THICKNESS ); + } + } glEnd(); glUseProgram(0); @@ -1533,14 +1538,9 @@ loadWorldFromXMLNoSave( std::string path ) { tmp->setBackground((WorldBGType)wxml->UnsignedAttribute("background")); tmp->setBGM(wxml->StrAttribute("bgm")); } else if ( name == "generation" ) { - if(!strcmp(wxml->Attribute("type"),"Random")){ - if(Indoor) - ((IndoorWorld *)tmp)->generate(wxml->UnsignedAttribute("width")); - else { - - tmp->generate(wxml->UnsignedAttribute("width")); - } - }else if(Indoor) + if ( !Indoor && !strcmp(wxml->Attribute("type"),"Random") ) + tmp->generate(wxml->UnsignedAttribute("width")); + else if ( Indoor ) abort(); } else if ( name == "mob" ) { unsigned int type; @@ -1588,9 +1588,11 @@ loadWorldFromXMLNoSave( std::string path ) { tmp->mob.back()->heyid = wxml->Attribute("id"); } else if ( name == "hill" ) { tmp->addHill( ivec2 { wxml->IntAttribute("peakx"), wxml->IntAttribute("peaky") }, wxml->UnsignedAttribute("width") ); - } else if ( name == "time") { - tickCount = std::stoi( wxml->GetText() ); - } + } else if ( name == "time" ) { + tickCount = std::stoi( wxml->GetText() ); + } else if ( Indoor && name == "floor" ) { + ((IndoorWorld *)tmp)->addFloor( wxml->UnsignedAttribute("width") ); + } wxml = wxml->NextSiblingElement(); } diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index d3b5db4..a67a932 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -18,7 +18,7 @@ - + diff --git a/xml/playerSpawnHill1_Building1.xml b/xml/playerSpawnHill1_Building1.xml index f0c8a21..8fad154 100644 --- a/xml/playerSpawnHill1_Building1.xml +++ b/xml/playerSpawnHill1_Building1.xml @@ -1,9 +1,12 @@