]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Added crouch key world
authorAndy Belle-Isle <abelleisle@protonmail.com>
Sun, 13 Nov 2022 20:17:29 +0000 (14:17 -0600)
committerAndy Belle-Isle <abelleisle@protonmail.com>
Sun, 13 Nov 2022 20:17:29 +0000 (14:17 -0600)
* This allows players to move 2D to test collision

Makefile
Scripts/init.lua
lib/entityx
src/player.cpp
src/world.cpp

index c590bab58b0c6296078d2356289d6b2d15766ba5..991fce97e634a0d42384a07149d29199b61ddb11 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ EXEC = main
 EXECDIR = .
 
 SRCDIR = src
-OUTDIR = out
+OUTDIR = build
 SRCEXT = cpp
 OBJEXT = o
 DEPEXT = d
@@ -61,7 +61,7 @@ all: resources $(EXEC)
 
 resources: directories
 
-directories: 
+directories:
        @mkdir -p $(EXECDIR)
        @mkdir -p $(OUTDIR)
 
@@ -82,7 +82,7 @@ $(OUTDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
        @echo "  CXX   " $<
        @mkdir -p $(dir $@)
        @$(CXX) $(CXXFLAGS) $(CXXINCS) -c -o $@ $<
-       @$(CXX) $(CXXFLAGS) $(INCDEP) -MM $(SRCDIR)/$*.$(SRCEXT) > $(OUTDIR)/$*.$(DEPEXT)
+       @$(CXX) $(CXXFLAGS) $(CXXINCS) $(INCDEP) -MM $(SRCDIR)/$*.$(SRCEXT) > $(OUTDIR)/$*.$(DEPEXT)
        @cp -f $(OUTDIR)/$*.$(DEPEXT) $(OUTDIR)/$*.$(DEPEXT).tmp
        @sed -e 's|.*:|$(OUTDIR)/$*.$(OBJEXT):|' < $(OUTDIR)/$*.$(DEPEXT).tmp > $(OUTDIR)/$*.$(DEPEXT)
        @sed -e 's/.*://' -e 's/\\$$//' < $(OUTDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(OUTDIR)/$*.$(DEPEXT)
index 60f21c6d8ff032f6356b7c9318d2db86b8826c91..4f2c93a703e2cadfcad20f2b490e12a421ca2b57 100644 (file)
@@ -4,32 +4,36 @@ player = {
     Player = 0,
     EventListeners = {
         MoveLeftPressed = function(self)
-            --self.Velocity.x = self.Velocity.x - 3.0
-            self.Velocity.y = self.Velocity.y - 1.0
+            self.Velocity.x = self.Velocity.x - 3.0
             self.Render.flipx = true;
         end,
         MoveLeftReleased = function(self)
             -- TODO can't put text at world coordinates right now
             --game.puts("default", self.Position.x, self.Position.y+100, "Hey. Hag?")
-            --self.Velocity.x = self.Velocity.x + 3.0
-            self.Velocity.y = self.Velocity.y + 1.0
+            self.Velocity.x = self.Velocity.x + 3.0
         end,
         MoveRightPressed = function(self)
-            --self.Velocity.x = self.Velocity.x + 3.0
-            self.Velocity.y = self.Velocity.y + 1.0
+            self.Velocity.x = self.Velocity.x + 3.0
             self.Render.flipx = false;
         end,
         MoveRightReleased = function(self)
-            --self.Velocity.x = self.Velocity.x - 3.0
-            self.Velocity.y = self.Velocity.y - 1.0
+            self.Velocity.x = self.Velocity.x - 3.0
         end,
         JumpKeyPressed = function(self)
-            if self.Physics.standing == true then
-                game.play(self.Position, self.Audio)
-                self.Velocity.y = self.Velocity.y + 9
-            end
+            -- if self.Physics.standing == true then
+            --     game.play(self.Position, self.Audio)
+            --     self.Velocity.y = self.Velocity.y + 9
+            -- end
+            self.Velocity.y = self.Velocity.y + 3.0
         end,
         JumpKeyReleased = function(self)
+            self.Velocity.y = self.Velocity.y - 3.0
+        end,
+        CrouchKeyPressed = function(self)
+            self.Velocity.y = self.Velocity.y - 3.0
+        end,
+        CrouchKeyReleased = function(self)
+            self.Velocity.y = self.Velocity.y + 3.0
         end
     },
     Position = {
index 3989cf4cf81da1077a501a1d53e6114f55b812f9..e04b856006cfe6b7e8ba5d6c1434331351cc791a 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 3989cf4cf81da1077a501a1d53e6114f55b812f9
+Subproject commit e04b856006cfe6b7e8ba5d6c1434331351cc791a
index f40a1d16f3466899644902b453f4825f8f65e0cc..1f950df01dea779cdfa1e741f8b3a92839e64ce4 100644 (file)
@@ -71,6 +71,12 @@ void PlayerSystem::receive(const KeyDownEvent& kue)
                     el.tryListener("JumpKeyPressed",
                                    e.component<Scripted>()->caller);
                 });
+        } else if (kue.sym == SDLK_LSHIFT) {
+            entities.each<EventListener>(
+                [](entityx::Entity e, EventListener& el) {
+                    el.tryListener("CrouchKeyPressed",
+                                   e.component<Scripted>()->caller);
+                });
         }
     }
 }
@@ -96,6 +102,12 @@ void PlayerSystem::receive(const KeyUpEvent& kue)
                     el.tryListener("JumpKeyReleased",
                                    e.component<Scripted>()->caller);
                 });
+        } else if (kue.sym == SDLK_LSHIFT) {
+            entities.each<EventListener>(
+                [](entityx::Entity e, EventListener& el) {
+                    el.tryListener("CrouchKeyReleased",
+                                   e.component<Scripted>()->caller);
+                });
         }
     }
 }
index 48e54e36c575584399a36dbeba7bda35642f0480..517c88e4fee4c21a81dc8ccc1dc7814d0463a249 100644 (file)
@@ -69,7 +69,7 @@ World::getSize()
 void World::generateMesh()
 {
     for (auto &l : drawLayers) {
-        
+
         // Preallocate size of vertexes
 
         float Z = l->drawLayer;
@@ -89,9 +89,9 @@ void World::generateMesh()
                             0  , 0+h, Z, to.x     , to.y     , tr};
 
         glBindBuffer(GL_ARRAY_BUFFER, l->layerVBO);
-        glBufferData(GL_ARRAY_BUFFER, 
-                     36 * sizeof(GLfloat), 
-                     mesh, 
+        glBufferData(GL_ARRAY_BUFFER,
+                     36 * sizeof(GLfloat),
+                     mesh,
                      GL_STATIC_DRAW);
 
         meshAdd.push_back(WorldMeshUpdateEvent(l->layerVBO,
@@ -192,7 +192,7 @@ glm::vec3 World::collide(glm::vec3 &start, glm::vec3 &end, Physics &phys)
                 if (i == 0.0f) {
                     std::cout << inter.size() << std::endl;
                     if (inter.size()) {
-                        p.standing = true;
+                        // p.standing = true;
                     }
                 }