Skip to content

Commit fe0e56f

Browse files
author
Andy Belle-Isle
committed
All 3 entities now play with idle functions and rendering a bit SUPER BETA
1 parent 5b879ae commit fe0e56f

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ OBJEXT = o
3636
DEPEXT = d
3737

3838
LIBDIR = lib
39-
LIBS = -L$(LIBDIR) -lSDL2 -lpthread -lentityx -ldl -lluajit -lGLEW -lGL
39+
LIBS = -L$(LIBDIR) -lSDL2 -lpthread -lentityx -ldl -lluajit -lGLEW -lGL -lSDL_image
4040

4141
CXXFLAGS = -ggdb -std=c++17 -Wall -Wextra -Werror -pedantic
4242

Scripts/init.lua

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
bird = {
22
Position = {
3-
x = 1.2,
4-
y = 3.4
3+
x = 150,
4+
y = 75
55
},
66
Name = "bord",
77
Init = function(self)
88
print(self.Position.x .. "," .. self.Position.y)
99
print("Bird spawn")
10-
end
10+
end,
11+
Render = {
12+
texture = "",
13+
visible = true
14+
},
15+
Idle = function(self)
16+
if (self.visibleTick >= 20) then
17+
self.Render.visible = not self.Render.visible
18+
self.visibleTick = 0
19+
end
20+
self.visibleTick = self.visibleTick + 1
21+
end,
22+
visibleTick = 0
1123
}
1224

13-
dog = {
25+
cat = {
1426
Velocity = {
1527
x = 0.0,
1628
y = 0.0
@@ -20,7 +32,7 @@ dog = {
2032
y = 0
2133
},
2234
Render = {
23-
texture = "assets/tex.png",
35+
texture = "Assets/cat.png",
2436
visible = true
2537
},
2638
Init = function(self)
@@ -35,15 +47,25 @@ dog = {
3547
}
3648

3749
animal = {
50+
Name = "animal",
51+
Velocity = { -- This will automatically assign position to (0,0)
52+
x = 0.0,
53+
y = 0.0
54+
},
3855
Render = {
39-
texture = "assets/anim.png",
40-
visible = false
41-
}
56+
texture = "Assets/cat.png",
57+
visible = true
58+
},
59+
Idle = function(self)
60+
self.Velocity.x = -200 * math.sin(math.rad(self.counter));
61+
self.Velocity.y = 100 * math.cos(math.rad(self.counter*5));
62+
self.counter = self.counter + 5;
63+
end,
64+
counter = 0;
4265
}
4366

4467
birdSpawn = game.spawn(bird);
4568

46-
dogSpawn = game.spawn(dog);
69+
dogSpawn = game.spawn(cat);
4770

4871
animalSpawn = game.spawn(animal);
49-
print("Animal pos: " .. animalSpawn.Position.x)

src/engine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ int Engine::init(void)
4343
void Engine::logicLoop(void)
4444
{
4545
using namespace std::chrono_literals;
46+
namespace cr = std::chrono;
4647
typedef std::chrono::high_resolution_clock mc;
4748

4849
entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */

src/render.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
7979
* DRAWING *
8080
*************/
8181

82-
8382
entities.each<Render, Position>(
84-
[this, a](entityx::Entity, Render, Position &p){
83+
[this, a](entityx::Entity, Render &r, Position &p){
84+
85+
if (!r.visible)
86+
return;
8587

8688
GLuint tri_vbo;
8789
GLfloat tri_data[] = {

0 commit comments

Comments
 (0)