diff options
author | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-09-01 02:24:21 -0400 |
---|---|---|
committer | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-09-01 02:24:21 -0400 |
commit | fe0e56fb268996f59d96bd9862170c9cf5779031 (patch) | |
tree | 78fa04df0a2b486b52bb739ae7a3f6c2b8df4ede | |
parent | 5b879ae253e71398880c7303539740be7b524ddb (diff) |
All 3 entities now play with idle functions and rendering a bit SUPER BETA
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | Scripts/init.lua | 42 | ||||
-rw-r--r-- | src/engine.cpp | 1 | ||||
-rw-r--r-- | src/render.cpp | 6 |
4 files changed, 38 insertions, 13 deletions
@@ -36,7 +36,7 @@ OBJEXT = o DEPEXT = d LIBDIR = lib -LIBS = -L$(LIBDIR) -lSDL2 -lpthread -lentityx -ldl -lluajit -lGLEW -lGL +LIBS = -L$(LIBDIR) -lSDL2 -lpthread -lentityx -ldl -lluajit -lGLEW -lGL -lSDL_image CXXFLAGS = -ggdb -std=c++17 -Wall -Wextra -Werror -pedantic diff --git a/Scripts/init.lua b/Scripts/init.lua index ad69ae6..56a6977 100644 --- a/Scripts/init.lua +++ b/Scripts/init.lua @@ -1,16 +1,28 @@ bird = { Position = { - x = 1.2, - y = 3.4 + x = 150, + y = 75 }, Name = "bord", Init = function(self) print(self.Position.x .. "," .. self.Position.y) print("Bird spawn") - end + end, + Render = { + texture = "", + visible = true + }, + Idle = function(self) + if (self.visibleTick >= 20) then + self.Render.visible = not self.Render.visible + self.visibleTick = 0 + end + self.visibleTick = self.visibleTick + 1 + end, + visibleTick = 0 } -dog = { +cat = { Velocity = { x = 0.0, y = 0.0 @@ -20,7 +32,7 @@ dog = { y = 0 }, Render = { - texture = "assets/tex.png", + texture = "Assets/cat.png", visible = true }, Init = function(self) @@ -35,15 +47,25 @@ dog = { } animal = { + Name = "animal", + Velocity = { -- This will automatically assign position to (0,0) + x = 0.0, + y = 0.0 + }, Render = { - texture = "assets/anim.png", - visible = false - } + texture = "Assets/cat.png", + visible = true + }, + Idle = function(self) + self.Velocity.x = -200 * math.sin(math.rad(self.counter)); + self.Velocity.y = 100 * math.cos(math.rad(self.counter*5)); + self.counter = self.counter + 5; + end, + counter = 0; } birdSpawn = game.spawn(bird); -dogSpawn = game.spawn(dog); +dogSpawn = game.spawn(cat); animalSpawn = game.spawn(animal); -print("Animal pos: " .. animalSpawn.Position.x) diff --git a/src/engine.cpp b/src/engine.cpp index 4579eb7..99c457b 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -43,6 +43,7 @@ int Engine::init(void) void Engine::logicLoop(void) { using namespace std::chrono_literals; + namespace cr = std::chrono; typedef std::chrono::high_resolution_clock mc; entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */ diff --git a/src/render.cpp b/src/render.cpp index 5b3a1f1..7c047f6 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -79,9 +79,11 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities, * DRAWING * *************/ - entities.each<Render, Position>( - [this, a](entityx::Entity, Render, Position &p){ + [this, a](entityx::Entity, Render &r, Position &p){ + + if (!r.visible) + return; GLuint tri_vbo; GLfloat tri_data[] = { |