]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Animate and menu
authorAndy <drumsetmonkey@gmail.com>
Mon, 28 Nov 2016 13:43:31 +0000 (08:43 -0500)
committerAndy <drumsetmonkey@gmail.com>
Mon, 28 Nov 2016 13:43:31 +0000 (08:43 -0500)
include/components.hpp
src/ui_menu.cpp
xml/entities.xml

index 367b8a3755f1e8038f87484e52be47e65c1d7994..774429d972d7ed96687b2eb2c07f39e6cf8c70ad 100644 (file)
@@ -136,6 +136,8 @@ struct SpriteData {
        vec2 size;
 };
 
+using Frame = std::vector<std::pair<SpriteData, vec2>>;
+
 //TODO
 /**
  * @struct Sprite
@@ -202,14 +204,25 @@ struct Sprite {
                return dim;
        }
 
-       std::vector<std::pair<SpriteData, vec2>> sprite;
+       Frame sprite;
        bool faceLeft;
 };
 
 //TODO
 struct Animate {
-       std::vector<std::pair<SpriteData, vec2>> sprite_e;
-       std::vector<std::pair<SpriteData, vec2>> sprite_c;
+       // COMMENT
+       std::vector<Frame> frame;
+       // COMMENT      
+       std::vector<Frame>::iterator currentFrame;
+       
+       // COMMENT
+       Frame nextFrame() {
+               if (currentFrame != std::end(frame))
+                       currentFrame++;
+               else 
+                       currentFrame = std::begin(frame);
+       return *currentFrame;   
+       }
 };
 
 //TODO
@@ -240,8 +253,6 @@ struct Dialog {
        int rindex;
 };
 
-
-
 // movement styles
 
 /**
@@ -261,7 +272,6 @@ struct Wander {
        int countdown;
 };
 
-
 /**
  * SYSTEMS
  */
index e7845c2809dcaf6aae07a42c0f13dc0b582b0b11..f6f962db3f0e765f5a9f323df9d8c756f0c6480f 100644 (file)
@@ -198,12 +198,14 @@ namespace ui {
 
             SDL_Event e;
 
+                       bool clicked = false;
+
                        Render::useShader(&Render::textShader);
 
             setFontSize(24);
             game::config::update();
                        setFontZ(-9.0);
-
+       
             mouse.x = ui::premouse.x+offset.x-(SCREEN_WIDTH/2);
             mouse.y = (offset.y+SCREEN_HEIGHT/2)-ui::premouse.y;
 
@@ -218,6 +220,11 @@ namespace ui {
                     premouse.x=e.motion.x;
                     premouse.y=e.motion.y;
                     break;
+                               case SDL_MOUSEBUTTONUP:
+                                       if (e.button.button & SDL_BUTTON_LEFT) {
+                                               clicked = true;
+                                       }
+                                       break;  
                 case SDL_KEYUP:
                     if (SDL_KEY == SDLK_ESCAPE) {
                         currentMenu->gotoParent();
@@ -257,7 +264,7 @@ namespace ui {
                                                        cMult = 0.6f;
 
                             //if the mouse is over the button and clicks
-                            if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
+                            if (clicked) {
                                 switch(m.member) {
                                     case 0: //normal button
                                         m.button.func();
index 60b4424ed0609afa64ad00b32090657f7175c683..d95cdc768abe9f6ce1a6304b717ba6ba3f0dcc49 100644 (file)
@@ -4,6 +4,10 @@
        <Position value="0.0,100.0" />
        <Visible value="0.2" />
        <Sprite image="assets/NPC.png" />
+       <Animation>
+               <frame>assets/NPC.png</frame>
+               <frame>assets/NPC_Walk.png</frame>
+       </Animation>
        <Direction />
        <Solid />
        <Physics />