aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Belle-Isle <abelleisle@protonmail.com>2022-11-13 14:17:29 -0600
committerAndy Belle-Isle <abelleisle@protonmail.com>2022-11-13 14:17:29 -0600
commit8254af1179db18e2a71c34ab9b7090cda16f0f07 (patch)
tree50a2e5fe2cccbac0c5141a4dc4c713e3dc533573
parent38e2036d031bdeaea76ef4b6c3c2af5247ed93ec (diff)
Added crouch keyworld
* This allows players to move 2D to test collision
-rw-r--r--Makefile6
-rw-r--r--Scripts/init.lua28
m---------lib/entityx0
-rw-r--r--src/player.cpp12
-rw-r--r--src/world.cpp10
5 files changed, 36 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index c590bab..991fce9 100644
--- 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)
diff --git a/Scripts/init.lua b/Scripts/init.lua
index 60f21c6..4f2c93a 100644
--- a/Scripts/init.lua
+++ b/Scripts/init.lua
@@ -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 = {
diff --git a/lib/entityx b/lib/entityx
-Subproject 3989cf4cf81da1077a501a1d53e6114f55b812f
+Subproject e04b856006cfe6b7e8ba5d6c1434331351cc791
diff --git a/src/player.cpp b/src/player.cpp
index f40a1d1..1f950df 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -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);
+ });
}
}
}
diff --git a/src/world.cpp b/src/world.cpp
index 48e54e3..517c88e 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -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;
}
}