aboutsummaryrefslogtreecommitdiff
path: root/entities
diff options
context:
space:
mode:
Diffstat (limited to 'entities')
-rw-r--r--entities/enemy.lua71
-rw-r--r--entities/eniity.lua14
-rw-r--r--entities/player.lua2
3 files changed, 86 insertions, 1 deletions
diff --git a/entities/enemy.lua b/entities/enemy.lua
new file mode 100644
index 0000000..7e18e95
--- /dev/null
+++ b/entities/enemy.lua
@@ -0,0 +1,71 @@
+Class = require("libs.hump.class")
+require("libs.tserial")
+Enemy = Class{
+ init = function(self, x, y, gameWorld)
+ self.x = x
+ self.y = y
+ self.world = gameWorld
+ end,
+ x=0,
+ y=0,
+ speed=60,
+ collider=nil,
+ world=nil,
+ chasing=false
+}
+
+function Enemy:draw()
+ love.graphics.setColor({1,0,0})
+ love.graphics.rectangle('fill', self.x, self.y, 16, 16)
+ if self.collider then
+
+ end
+end
+
+function Enemy:setCollider()
+ self.collider = self.world:newRectangleCollider(self.x, self.y, 16, 16)
+ self.collider:setFixedRotation(true)
+end
+
+function Enemy:update(dt)
+ if self.collider then
+ -- Do the Query
+ local colliders = self.world:queryCircleArea(self.x, self.y, 100,{'player'})
+ local vx = 0
+ local vy = 0
+ if #colliders then
+ self.chasing = true
+ for i,collider in pairs(colliders) do
+ local playerObject = collider:getObject()
+
+ if playerObject.dir=="up" then
+ vy = self.speed * -1
+ end
+
+ if playerObject.dir=="left" then
+ vx = self.speed * -1
+ end
+
+ if playerObject.dir=="down" then
+ vy = self.speed
+ end
+
+ if playerObject.dir=="right" then
+ vx = self.speed
+ end
+
+ directionX = playerObject.x - self.x
+ directionY = playerObject.y - self.y
+ distance = math.sqrt(directionX * directionX + directionY * directionY)
+ if distance >16 then
+ self.x = self.x + directionX / distance * self.speed * dt
+ self.y = self.y + directionY / distance * self.speed * dt
+ end
+ end
+ self.collider:setX(self.x+8)
+ self.collider:setY(self.y+8)
+ else
+ self.chasing = false
+ end
+ end
+end \ No newline at end of file
diff --git a/entities/eniity.lua b/entities/eniity.lua
new file mode 100644
index 0000000..1224649
--- /dev/null
+++ b/entities/eniity.lua
@@ -0,0 +1,14 @@
+Class = require("libs.hump.class")
+
+Entity = Class {
+ init = function(self)
+ end
+}
+
+Entity:draw()
+end
+
+Entity:update(dt)
+end
+
+return Entity \ No newline at end of file
diff --git a/entities/player.lua b/entities/player.lua
index 0afdfd0..8017681 100644
--- a/entities/player.lua
+++ b/entities/player.lua
@@ -1,7 +1,7 @@
local Class = require("libs.hump.class");
Player = Class{
- init = function(self)
+ init = function(self, x, y)
end
}