]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Stuff is solid
authorAndy <drumsetmonkey@gmail.com>
Wed, 26 Oct 2016 12:43:43 +0000 (08:43 -0400)
committerAndy <drumsetmonkey@gmail.com>
Wed, 26 Oct 2016 12:43:43 +0000 (08:43 -0400)
include/components.hpp
include/events.hpp
src/player.cpp
src/window.cpp
src/world.cpp
xml/entities.xml

index becc83937cb466465c36386435aa2aec718eac13..c0b711098153c4af204e1c88198b27ee87dc4a40 100644 (file)
@@ -92,12 +92,16 @@ struct Solid {
         * @param w The desired width of the entity.
         * @param h The desired height of the entity.
         */
-       Solid(float w = 0.0f, float h = 0.0f): width(w), height(h) {}
-       Solid(float w = 0.0f, float h = 0.0f, vec2 offset = 0.0f): width(w), height(h), offset(offset) {}
+       Solid(float w = 0.0f, float h = 0.0f): width(w), height(h) {offset = 0.0f; passable = true; }
+       //Solid(float w = 0.0f, float h = 0.0f, vec2 offset = 0.0f): width(w), height(h), offset(offset) {passable = true; }
+       
+       void Passable(bool v) {passable = v;}
+       bool Passable(void)   {return passable;}
 
        float width; /**< The width of the entity in units */
        float height; /**< The height of the entity in units */
        vec2 offset; /**< This allows us to make the hitbox in any spot */
+       bool passable; /**< This determines whether or not one can pass by the entity */
 };
 
 struct SpriteData {
@@ -153,6 +157,32 @@ struct Sprite {
                return 0;
        }
 
+       vec2 getSpriteSize() {
+               vec2 st; /** the start location of the sprite */
+               vec2 dim; /** how wide the sprite is */
+               
+               if (sprite.size()) {
+                       st.x = sprite[0].second.x;
+                       st.y = sprite[0].second.y;
+               } else {
+                       return vec2(0.0f, 0.0f);
+               }
+
+               for (auto &s : sprite) {
+                       if (s.second.x < st.x)
+                               st.x = s.second.x;
+                       if (s.second.y < st.y)
+                               st.y = s.second.y;
+
+                       if (s.second.x + s.first.size.x > dim.x)
+                               dim.x = s.second.x + s.first.size.x;
+                       if (s.second.y + s.first.size.y > dim.y)
+                               dim.y = s.second.y + s.first.size.y;
+               }
+
+               return dim;
+       }
+
        std::vector<std::pair<SpriteData, vec2>> sprite;
        bool faceLeft;
 };
index 5cd804091b9817e900d2d8d558f76135501b83b7..d98d52ae2b021765e6cc9b44316bd8f426eb8105 100644 (file)
@@ -48,7 +48,7 @@ struct BGMToggleEvent {
 };
 
 struct WindowResizeEvent {
-       WindowResizeEvent(int w, int h)
+       WindowResizeEvent(int w = 640, int h = 480)
                : x(w), y(h) {}
        
        int x;
index 8808a69ec4123d5c049590f5e3d3b598936c93e9..59274b37f677ea789c6a161976d0788783d47b5f 100644 (file)
@@ -19,6 +19,9 @@ void PlayerSystem::create(void)
        sprite->addSpriteSegment(SpriteData("assets/cat.png",
                                                                                vec2(0, 0)),
                                                         vec2(0, 0));
+       vec2 dim = player.component<Sprite>().get()->getSpriteSize();
+       float cdat[2] = {dim.x, dim.y};
+       player.assign<Solid>(cdat[0], cdat[1]);
 }
 
 void PlayerSystem::configure(entityx::EventManager &ev)
index 69c383cc490f4cf2bc3753a204698d39c8f8b357..4c73b8ba03762825a3dc592942bb34b28b7ce06e 100644 (file)
@@ -71,9 +71,9 @@ void WindowSystem::configure(entityx::EventManager &ev)
 
 void WindowSystem::receive(const WindowResizeEvent &wre)
 {
-       
        game::SCREEN_WIDTH = wre.x;
        game::SCREEN_HEIGHT = wre.y;
+       
        glViewport(0, 0, wre.x, wre.y);
        SDL_SetWindowSize(window, wre.x, wre.y);
 }      
index d7639c29cff44a497452da57907fe332f47ad56f..365345db90b7579fe51d34dbcfcc1ae9b1bd5a89 100644 (file)
@@ -359,6 +359,17 @@ void WorldSystem::load(const std::string& file)
                                                                         vec2(0, 0));
                                        } else if (tname == "Portal") {
                                                entity.assign<Portal>(wxml->StrAttribute("inside"));
+                                       } else if (tname == "Solid") {
+                                               vec2 dim;
+
+                                               if (abcd->Attribute("value") != nullptr) {
+                                                       dim = str2coord(abcd->StrAttribute("value"));
+                                               } else {
+                                                       dim = entity.component<Sprite>().get()->getSpriteSize();        
+                                               }
+                                               
+                                               float cdat[2] = {dim.x, dim.y};
+                                               entity.assign<Solid>(cdat[0], cdat[1]);
                                        }
 
                                        abcd = abcd->NextSiblingElement();
index bcaa455c778ed6618612bd54e0afbaf095329c09..306085b5b1f21c77ad4a5a0fd8190b9a65aa51a4 100644 (file)
@@ -4,6 +4,7 @@
        <Position value="0.0,100.0" />
        <Visible value="0.2" />
        <Sprite image="assets/NPC.png" />
+       <Solid />
 </npc>
 
 <structure>
        <Visible value="0.25" />
        <Sprite image="assets/style/classic/house1.png" />
        <Portal />
+       <Solid />
 </structure>
 
 <chest>
        <Position value="0.0,100.0" />
        <Visible value="0.15" />
        <Sprite image="assets/chest.png" />
+       <Solid />
 </chest>