]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
snowww
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 25 Mar 2016 12:39:35 +0000 (08:39 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 25 Mar 2016 12:39:35 +0000 (08:39 -0400)
include/world.h
main.cpp
src/ui.cpp
src/world.cpp

index dd06469f6c8219c43dcba4925ad457307a77ddd8..0b87134ce094fed349a965dd2f590b6982fff992 100644 (file)
@@ -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.
index 7b8f2d93ab7edc5728854544166372682162be99..0be7256ae23ac6ce6edf1c7ff307513d16076851 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -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;
 
        /*
@@ -929,6 +932,37 @@ void logic(){
                else fadeIntensity = 0;
        }
 
+       /*
+        * 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.
        */
index e9b8067ab233b4f4782157347ba20e3506ea7ea5..c646458dda699e6bd6c50484af5740deeffd4dda 100644 (file)
@@ -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;
index ee2c33a79c37e35a1f9038704df098fa92575f70..cdd945b01a5a96c0aca36c71f0481e2f96b9e425 100644 (file)
@@ -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;