diff options
-rw-r--r-- | include/world.h | 8 | ||||
-rw-r--r-- | main.cpp | 40 | ||||
-rw-r--r-- | src/ui.cpp | 4 | ||||
-rw-r--r-- | src/world.cpp | 40 |
4 files changed, 82 insertions, 10 deletions
diff --git a/include/world.h b/include/world.h index dd06469..0b87134 100644 --- a/include/world.h +++ b/include/world.h @@ -43,7 +43,8 @@ enum class WorldBGType : unsigned char { enum class WorldWeather : unsigned char { Sunny = 0, /**< Sunny/daytime */ Dark, /**< Nighttime */ - Rain /**< Rain (to be implemented)*/ + Rain, /**< Rain */ + Snowy /**< Snow */ }; /** @@ -363,7 +364,8 @@ public: * velocity, color and duration (time to live). */ - void addParticle(float x, float y, float w, float h, float vx, float vy, Color color, int duration); + void addParticle(float x, float y, float w, float h, float vx, float vy, Color color, int d); + void addParticle(float x, float y, float w, float h, float vx, float vy, Color color, int d, bool gravity ); /** * Adds a light to the world with the specified coordinates and color. @@ -528,6 +530,8 @@ public: World *exitArena( Player *p ); }; +std::string getWorldWeatherStr( WorldWeather ww ); + /** * Loads the player into the world created by the given XML file. If a world is * already loaded it will be saved before the transition is made. @@ -415,6 +415,7 @@ int main(int argc, char *argv[]){ std::cout << "Num threads: " << std::thread::hardware_concurrency() << std::endl; //currentWorld->mob.back()->followee = player; + glClearColor(1,1,1,1); gameRunning = true; while ( gameRunning ) @@ -501,6 +502,7 @@ void mainLoop(void){ currentWorld->update(player,deltaTime); });*/ currentWorld->update( player, deltaTime ); + currentWorld->detect(player); /* * Update debug variables if necessary @@ -672,7 +674,7 @@ void render(){ ui::putText(offset.x-SCREEN_WIDTH/2, (offset.y+SCREEN_HEIGHT/2)-ui::fontSize, - "FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nTc: %u\nHA: %+.2f\nVol: %f", + "FPS: %d\nG:%d\nRes: %ux%u\nE: %d\nPOS: (x)%+.2f\n (y)%+.2f\nTc: %u\nHA: %+.2f\nVol: %f\nWea: %s", fps, player->ground, SCREEN_WIDTH, // Window dimensions @@ -682,7 +684,8 @@ void render(){ debugY, // The player's y coordinate tickCount, handAngle, - VOLUME_MASTER + VOLUME_MASTER, + getWorldWeatherStr( weather ).c_str() ); if(ui::posFlag){ @@ -756,7 +759,7 @@ void logic(){ * that exist in this world. */ - currentWorld->detect(player); + if(player->loc.y<.02)gameRunning=false; /* @@ -930,6 +933,37 @@ void logic(){ } /* + * Rain? + */ + + if ( weather == WorldWeather::Rain ) { + for ( unsigned int r = (randGet() % 25) + 11; r--; ) { + currentWorld->addParticle(randGet() % currentWorld->getTheWidth() - (currentWorld->getTheWidth() / 2), + offset.y + SCREEN_HEIGHT / 2, + HLINE * 1.25, // width + HLINE * 1.25, // height + randGet() % 7 * .01 * (randGet() % 2 == 0 ? -1 : 1), // vel.x + (4 + randGet() % 6) * .05, // vel.y + { 0, 0, 255 }, // RGB color + 2500 // duration (ms) + ); + } + } else if ( weather == WorldWeather::Snowy ) { + for ( unsigned int r = (randGet() % 25) + 11; r--; ) { + currentWorld->addParticle(randGet() % currentWorld->getTheWidth() - (currentWorld->getTheWidth() / 2), + offset.y + SCREEN_HEIGHT / 2, + HLINE * 1.25, // width + HLINE * 1.25, // height + .0001 + randGet() % 7 * .01 * (randGet() % 2 == 0 ? -1 : 1), // vel.x + (4 + randGet() % 6) * -.03, // vel.y + { 255, 255, 255 }, // RGB color + 5000, // duration (ms) + false + ); + } + } + + /* * Increment a loop counter used for animating sprites. */ @@ -16,6 +16,7 @@ extern SDL_Window *window; extern Player *player; extern World *currentWorld; +extern WorldWeather weather; /* * In the case of dialog, some NPC quests can be preloaded so that they aren't assigned until @@ -1460,6 +1461,9 @@ EXIT: return; } switch(SDL_KEY){ + case SDLK_z: + weather = WorldWeather::Snowy; + break; case SDLK_a: left = false; break; diff --git a/src/world.cpp b/src/world.cpp index ee2c33a..cdd945b 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -19,6 +19,11 @@ using namespace tinyxml2; #define INDOOR_FLOOR_HEIGHT 100 +/** + * Gravity thing + */ + +#define GRAVITY_CONSTANT 0.001f extern Player *player; // main.cpp? extern World *currentWorld; // main.cpp @@ -427,7 +432,7 @@ draw( Player *p ) // the sunny wallpaper is faded with the night depending on tickCount bgTex->bind( 0 ); - safeSetColorA( 255, 255, 255, 255 - worldShade * 4 ); + safeSetColorA( 255, 255, 255, weather == WorldWeather::Snowy ? 150 : 255 - worldShade * 4); glBegin( GL_QUADS ); glTexCoord2i( 0, 0 ); glVertex2i( worldStart, SCREEN_HEIGHT ); @@ -437,7 +442,7 @@ draw( Player *p ) glEnd(); bgTex->bindNext(); - safeSetColorA( 255, 255, 255, worldShade * 4 ); + safeSetColorA( 255, 255, 255, worldShade * 4); glBegin( GL_QUADS ); glTexCoord2i( 0, 0 ); glVertex2i( worldStart, SCREEN_HEIGHT ); @@ -818,7 +823,7 @@ singleDetect( Entity *e ) e->ground = true; return; } else if ( e->vel.y > -2 ) - e->vel.y -= .003 * deltaTime; + e->vel.y -= GRAVITY_CONSTANT * deltaTime; } /* @@ -874,7 +879,7 @@ detect( Player *p ) part.velx = 0; part.canMove = false; } else if ( part.gravity && part.vely > -2 ) - part.vely -= .003 * deltaTime; + part.vely -= GRAVITY_CONSTANT * deltaTime; } // handle particle creation @@ -986,6 +991,15 @@ addParticle( float x, float y, float w, float h, float vx, float vy, Color color particles.back().canMove = true; } +void World:: +addParticle( float x, float y, float w, float h, float vx, float vy, Color color, int d, bool gravity ) +{ + particles.emplace_back( x, y, w, h, vx, vy, color, d ); + particles.back().canMove = true; + particles.back().gravity = gravity; +} + + void World::addLight(vec2 loc, Color color){ if(light.size() < 64){ light.push_back(Light(loc,color,1)); @@ -1414,7 +1428,23 @@ World *Arena::exitArena(Player *p){ } } - +std::string getWorldWeatherStr( WorldWeather ww ) +{ + switch ( ww ) { + case WorldWeather::Sunny: + return "Sunny"; + break; + case WorldWeather::Dark: + return "Darky"; + break; + case WorldWeather::Rain: + return "Rainy"; + break; + default: + return "Look at the screen u scrub"; + break; + } +} static bool loadedLeft = false; static bool loadedRight = false; |