]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
arrow rotation and actual pausing
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 20 Oct 2017 12:00:57 +0000 (08:00 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 20 Oct 2017 12:00:57 +0000 (08:00 -0400)
assets/items/arrow_crude.png
include/gametime.hpp
src/gametime.cpp
src/systems/render.cpp
src/ui.cpp
src/ui_menu.cpp

index 5fba709c5c36390612d2f929b715348f3e7a7d24..6b9a636b97186b790ec6f89ba3570a36183e7a20 100644 (file)
Binary files a/assets/items/arrow_crude.png and b/assets/items/arrow_crude.png differ
index e06a0d37498d735bf6d7c3f905fb70186dbab86b..7999f1c2f98290a1b577b21615b09843ff1db5ba 100644 (file)
@@ -7,6 +7,9 @@
 
 namespace game {
     namespace time {
+               void togglePause(void);
+               void togglePause(bool state);
+
                /**
                 * Sets the game's tick count to the desired amount.
                 * @param t desired tick count
index a5272e578c7b5b4b298daea9820cbec3ba6fe56b..6f6ac0e3eb0e6fe7489cd7c727dfaf582261c2cc 100644 (file)
@@ -5,9 +5,18 @@
 
 static unsigned int tickCount = 0;
 static unsigned int deltaTime = 1;
+static bool paused = false;
 
 namespace game {
     namespace time {
+               void togglePause(void) {
+                       paused ^= true;
+               }
+
+               void togglePause(bool state) {
+                       paused = state;
+               }
+
         void setTickCount(unsigned int t) {
             tickCount = t;
         }
@@ -17,7 +26,7 @@ namespace game {
         }
 
         unsigned int getDeltaTime(void) {
-            return (deltaTime > 0) ? deltaTime : 1;
+            return paused ? 0 : ((deltaTime > 0) ? deltaTime : 1);
         }
 
         void tick(void) {
index a25b152bd97f2f339f826e310219095bebafd336..f72832b41eac1eaefc0332781d54858498971adc 100644 (file)
@@ -78,7 +78,9 @@ void RenderSystem::render(void)
 
                        if (S.first.veltate) {
                                auto vel = entity.component<Direction>();
-                               float angle = static_cast<float>(std::atan(vel->y / vel->x)) * 180 / 3.14f;
+                               float angle = std::atan(vel->y / vel->x);
+                               if (vel->x < 0)
+                                       angle += 3.14f;
                                auto toOrigin = glm::translate(glm::mat4(1.0f), glm::vec3(-pos.x, -pos.y, 0.0f));
                                auto rotation = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0.0f, 0.0f, 1.0f));
                                auto toBack = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, pos.y, 0.0f));
index 7af77f0c58dd21e62186142abc82de02c1766ec0..8a2d64daa005b73ec78615f39622306b9fb3bb33 100644 (file)
@@ -169,41 +169,6 @@ namespace ui {
                return ret;
        }
 
-       /*void importantText(const char *text, ...) {
-               va_list args;
-
-               dialogBoxText.clear();
-
-               va_start(args, text);
-               auto s = uisprintf(text, args);
-               va_end(args);
-
-               dialogBoxText = s;
-
-               dialogBoxExists = true;
-               dialogImportant = true;
-               dialogPassive = false;
-               dialogPassiveTime = 0;
-       }
-
-       void passiveImportantText(int duration, const char *text, ...) {
-               va_list args;
-
-               dialogBoxText.clear();
-
-               va_start(args, text);
-               auto s = uisprintf(text, args);
-               va_end(args);
-
-               dialogBoxText = s;
-
-               dialogBoxExists = true;
-               dialogImportant = true;
-               dialogPassive = true;
-               dialogPassiveTime = duration;
-       }*/
-
-
        void drawPage(const GLuint& tex) {
                pageTex = tex;
                pageTexReady = true;
@@ -401,147 +366,7 @@ namespace ui {
             Render::textShader.disable();
                        Render::textShader.unuse();
 
-               } /* else if (dialogBoxExists) {
-                       rtext = typeOut(dialogBoxText);
-
-                       if (dialogImportant) {
-                               setFontColor(255, 255, 255);
-                               if (dialogPassive) {
-                                       dialogPassiveTime -= game::time::getDeltaTime() * 12;
-                                       if (dialogPassiveTime < 0) {
-                                               dialogPassive = false;
-                                               dialogImportant = false;
-                                               dialogBoxExists = false;
-                                       }
-                               }
-
-                               *if (fadeIntensity == 255 || dialogPassive) {
-                                       setFontSize(24);
-                                       putStringCentered(offset.x,offset.y,rtext);
-                                       setFontSize(16);
-                               }*
-                       } else { //normal dialog box
-
-                               float y = offset.y + SCREEN_HEIGHT / 2 - HLINES(8);
-                               float x = offset.x - 300;
-
-                               drawNiceBox(vec2 {x, y}, vec2 {x + 600, y - SCREEN_HEIGHT / 4}, -7.0);
-
-                               setFontZ(-7.2f);
-                               rtext = typeOut(dialogBoxText);
-                               UISystem::putString(vec2(x + HLINES(2), y - fontSize - game::HLINE), rtext);
-
-                               for (i = 0; i < dialogOptText.size(); i++) {
-                                       auto& sec = dialogOptText[i].second;
-
-                                       setFontColor(255, 255, 255);
-                                       auto tmp = putStringCentered(offset.x, sec.y,dialogOptText[i].first);
-                                       sec.z = offset.x + tmp;
-                                       sec.x = offset.x - tmp;
-                                       sec.y = y - SCREEN_HEIGHT / 4 + (fontSize + game::HLINE) * (i + 1);
-                                       if (mouse.x > sec.x && mouse.x < sec.z &&
-                                           mouse.y > sec.y && mouse.y < sec.y + 16) { // fontSize
-                                                 setFontColor(255, 255, 0);
-                                                 putStringCentered(offset.x, sec.y, dialogOptText[i].first);
-                                       }
-                               }
-
-                               setFontColor(255, 255, 255);
-                       }
-
-                       static unsigned int rtext_oldsize = 0;
-                       if (rtext_oldsize != rtext.size()) {
-                               if (!isspace(rtext[(rtext_oldsize = rtext.size()) - 1]))
-                                       Mix_PlayChannel(0, dialogClick, 0);
-
-                       }
-
-               } else {
-                       for (const auto &s : textToDraw)
-                               putString(s.first.x, s.first.y, s.second);
-               }*/
-
-               //if (!fadeIntensity) {
-                       /*vec2 hub = {
-                               (SCREEN_WIDTH/2+offset.x)-fontSize*10,
-                               (offset.y+SCREEN_HEIGHT/2)-fontSize
-                       };*/
-
-                       /*putText(hub.x,hub.y,"Health: %u/%u",player->health>0?(unsigned)player->health:0,
-                                                                                               (unsigned)player->maxHealth
-                                                                                               );*/
-                       /*static GLuint frontHealth = Texture::genColor(Color(255,0,0));
-                       static GLuint backHealth = Texture::genColor(Color(150,0,0));
-
-                       if (player->isAlive()) {
-                               hub.y-=fontSize*1.15;
-
-                GLfloat tex[] = {0.0, 0.0,
-                                 1.0, 0.0,
-                                 0.0, 1.0,
-                                 1.0, 1.0};
-
-                GLfloat back[] = {hub.x,        hub.y,      -7.0,
-                                  hub.x + 150,  hub.y,      -7.0,
-                                  hub.x,        hub.y + 12, -7.0,
-                                  hub.x + 150,  hub.y + 12, -7.0};
-
-                GLfloat front[] = {hub.x,       hub.y,      -7.1,
-                                   hub.x + 150, hub.y,      -7.1,
-                                   hub.x,       hub.y + 12, -7.1,
-                                   hub.x + 150, hub.y + 12, -7.1};
-
-
-                glUniform1i(Render::textShader.uniform[WU_texture], 0);
-
-                               Render::textShader.use();
-                               Render::textShader.enable();
-
-                glBindTexture(GL_TEXTURE_2D, frontHealth);
-
-                glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, front);
-                glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
-                glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
-                glBindTexture(GL_TEXTURE_2D, backHealth);
-
-                glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, back);
-                glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
-                glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
-                Render::textShader.disable();
-                               Render::textShader.unuse();
-            }*/
-
-                       /*
-                        *      Lists all of the quests the player is currently taking.
-                       */
-
-                       /*setFontColor(255,255,255,fontTransInv);
-                       if (player->inv->invOpen) {
-                               hub.y = player->loc.y + fontSize * 8;
-                               hub.x = player->loc.x;// + player->width / 2;
-
-                               putStringCentered(hub.x,hub.y,"Current Quests:");
-
-                               for(auto &c : player->qh.current) {
-                                       hub.y -= fontSize * 1.15;
-                                       putStringCentered(hub.x,hub.y,c.title);
-                               }
-
-                               hub.y = offset.y + 40*1.2;
-                               hub.x = offset.x + SCREEN_WIDTH/2 - 40*1.5;
-
-                               putStringCentered(hub.x,hub.y,"Equipment:");
-
-                               hub.y = offset.y + SCREEN_HEIGHT/2 - 20;
-                               hub.x = offset.x - SCREEN_WIDTH/2 + 45*4*1.5;
-
-                               putStringCentered(hub.x,hub.y,"Inventory:");
-                       }*/
-               //      setFontColor(255,255,255,255);
-               //}
-
+               }
                menu::draw();
 
                // draw the mouse
index 3afe0dc7460a5fe9f1be38c1b1eb71611fb72a03..052030a73c4db504090a546d70a912b514590238 100644 (file)
@@ -3,6 +3,7 @@
 #include <common.hpp>
 #include <engine.hpp>
 #include <fileio.hpp>
+#include <gametime.hpp>
 #include <render.hpp>
 #include <texture.hpp>
 #include <font.hpp>
@@ -56,6 +57,7 @@ void Menu::gotoParent(void)
        if (parent == nullptr) {
                game::config::update();
                FontSystem::setFontSize(FontSystem::SizeSmall);
+               game::time::togglePause(false);
        }
        
        currentMenu = parent;
@@ -241,6 +243,8 @@ namespace ui {
 
                void toggle(void) {
                        currentMenu = &pauseMenu;
+                       if (currentMenu != nullptr)
+                               game::time::togglePause(true);
                }
 
         void draw(void) {