]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
All 3 entities now play with idle functions and rendering a bit SUPER BETA
authorAndy Belle-Isle <drumsetmonkey@gmail.com>
Sun, 1 Sep 2019 06:24:21 +0000 (02:24 -0400)
committerAndy Belle-Isle <drumsetmonkey@gmail.com>
Sun, 1 Sep 2019 06:24:21 +0000 (02:24 -0400)
Makefile
Scripts/init.lua
src/engine.cpp
src/render.cpp

index 79c55b933142af7f0896bc511904988241ad3a10..06a0ab511a483003a835ec61a4ba366be9a379e5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -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
 
index ad69ae631035dc369a19c5da4bdadbdfeffa5841..56a6977df7cff227c8682fd162ef572f38e13784 100644 (file)
@@ -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)
index 4579eb7e8fe8c75c9f678e9643e13e0972ab4ace..99c457b15539b231966970b188af4c0e945b2345 100644 (file)
@@ -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 */
index 5b3a1f1821e34cfc30fcf52948ee984077728b32..7c047f66637dce552abf3b866ca0531758bc5dc5 100644 (file)
@@ -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[] = {