aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndrajith K L2022-03-02 03:36:05 +0530
committerIndrajith K L2022-03-02 03:36:05 +0530
commit6322712259d46fc7af82ae6271852a236f66ba6e (patch)
tree3b38362efa04e97cae6ee934242705fbd5f947c8
parent384dda3616c7007da1c88a67ff2daebd6037baa7 (diff)
downloadYEAD-6322712259d46fc7af82ae6271852a236f66ba6e.tar.gz
YEAD-6322712259d46fc7af82ae6271852a236f66ba6e.tar.bz2
YEAD-6322712259d46fc7af82ae6271852a236f66ba6e.zip
* Test Enemy Added
* Basic Hacky Enemy AI
-rw-r--r--assets/maps/level1.lua31
-rw-r--r--conf.lua6
-rw-r--r--core/enitities.lua (renamed from core/enitity.lua)0
-rw-r--r--core/map.lua43
-rw-r--r--entities/enemy.lua71
-rw-r--r--entities/eniity.lua14
-rw-r--r--entities/player.lua2
-rw-r--r--scenes/level1_scene.lua5
-rw-r--r--scenes/menu_scene.lua4
9 files changed, 145 insertions, 31 deletions
diff --git a/assets/maps/level1.lua b/assets/maps/level1.lua
index 423becc..3681b3e 100644
--- a/assets/maps/level1.lua
+++ b/assets/maps/level1.lua
@@ -9,7 +9,7 @@ return {
tilewidth = 16,
tileheight = 16,
nextlayerid = 7,
- nextobjectid = 32,
+ nextobjectid = 33,
properties = {},
tilesets = {
{
@@ -300,8 +300,8 @@ return {
rotation = 0,
visible = true,
properties = {
- ["data"] = "Beware of the Alien Monster",
- ["interactive_type"] = "message_notification"
+ ["interactive_type"] = "message_notification",
+ ["talker_data"] = "Beware of the Alien Monster"
}
},
{
@@ -316,8 +316,8 @@ return {
rotation = 0,
visible = true,
properties = {
- ["data"] = "Acquired Potion",
- ["interactive_type"] = "pickable"
+ ["interactive_type"] = "pickable",
+ ["message"] = "Acquired Potion"
}
},
{
@@ -332,8 +332,8 @@ return {
rotation = 0,
visible = true,
properties = {
- ["data"] = "Acquired Potion",
- ["interactive_type"] = "pickable"
+ ["interactive_type"] = "pickable",
+ ["message"] = "Acquired Potion"
}
},
{
@@ -348,9 +348,22 @@ return {
rotation = 0,
visible = true,
properties = {
- ["data"] = "Acquired Potion",
- ["interactive_type"] = "pickable"
+ ["interactive_type"] = "pickable",
+ ["message"] = "Acquired Potion"
}
+ },
+ {
+ id = 32,
+ name = "",
+ type = "enemy",
+ shape = "rectangle",
+ x = 128,
+ y = 48,
+ width = 16,
+ height = 16,
+ rotation = 0,
+ visible = true,
+ properties = {}
}
}
},
diff --git a/conf.lua b/conf.lua
index 47b7d36..8fbb0e5 100644
--- a/conf.lua
+++ b/conf.lua
@@ -1,7 +1,7 @@
function love.conf(t)
- t.window.width = 1280
- t.window.height = 720
- t.window.fullscreen = true
+ t.window.width = 800
+ t.window.height = 600
+ t.window.fullscreen = false
t.window.title = "<Your Enemy is in Another Dungeon>"
t.window.usedpiscale = true
t.window.icon = "assets/images/icon.png"
diff --git a/core/enitity.lua b/core/enitities.lua
index e69de29..e69de29 100644
--- a/core/enitity.lua
+++ b/core/enitities.lua
diff --git a/core/map.lua b/core/map.lua
index 2bd0110..e4eb3b7 100644
--- a/core/map.lua
+++ b/core/map.lua
@@ -6,13 +6,14 @@ Camera = require("libs.hump.camera")
Windfield = require("libs.windfield")
require("libs.tserial")
require("core.notifications")
-
+require("entities.enemy")
local zoomFactor = 3
local player = {
x=0,
y=0,
sprite=love.graphics.newImage("assets/images/player_demo.png"),
- speed=100
+ speed=100,
+ dir="down"
}
local fullscreen = true
@@ -24,8 +25,10 @@ Map = Class {
__include=Gamestate,
init = function(self, mapName)
_gameWorld = Windfield.newWorld(0,0)
+ _gameWorld:setQueryDebugDrawing(true) -- Remove when deploy
_gameWorld:addCollisionClass('player')
_gameWorld:addCollisionClass('interactive')
+ _gameWorld:addCollisionClass('enemy')
effect = Moonshine(windowWidth, windowHeight, Moonshine.effects.crt)
.chain(Moonshine.effects.vignette)
.chain(Moonshine.effects.scanlines)
@@ -49,6 +52,11 @@ Map = Class {
player.collider:setFixedRotation(true)
player.collider:setCollisionClass('player')
+ player.collider:setObject({
+ x = player.x,
+ y = player.y,
+ dir = player.dir
+ })
end
if obj.type=="interactive" then
@@ -56,12 +64,18 @@ Map = Class {
local interactiveData = {
type = obj.type,
interactive_type = obj.properties.interactive_type,
- data = obj.properties.data
+ message = obj.properties.message and obj.properties.message or nil,
+ talker_data = obj.properties.talker_data and obj.properties.talker_data or nil
}
collider:setObject(interactiveData)
collider:setCollisionClass('interactive')
collider:setType("static")
end
+
+ if obj.type=="enemy" then
+ enemy = Enemy(obj.x, obj.y, _gameWorld)
+ enemy:setCollider()
+ end
end
end
@@ -81,18 +95,22 @@ function Map:update(dt)
if love.keyboard.isDown("w") then
vy = player.speed * -1
+ player.dir = "up"
end
if love.keyboard.isDown("a") then
vx = player.speed * -1
+ player.dir = "left"
end
if love.keyboard.isDown("s") then
vy = player.speed
+ player.dir = "down"
end
if love.keyboard.isDown("d") then
vx = player.speed
+ player.dir = "right"
end
player.collider:setLinearVelocity(vx, vy)
@@ -100,6 +118,11 @@ function Map:update(dt)
_gameWorld:update(dt)
player.x = player.collider:getX() - 4
player.y = player.collider:getY() - 4
+ player.collider:setObject({
+ x = player.x,
+ y = player.y,
+ dir = player.dir
+ })
camera:lookAt(player.x, player.y)
currentMap:update(dt)
@@ -127,16 +150,12 @@ function Map:update(dt)
local _interColliderData = player.collider:getEnterCollisionData('interactive')
local interactiveCollider = _interColliderData.collider
local interactiveData = interactiveCollider:getObject()
-
- if interactiveData.interactive_type=="pickable" then
- notifications:send(interactiveData.data)
- end
-
- if interactiveData.interactive_type=="message_notification" then
- notifications:send(interactiveData.data)
+ if interactiveData.message then
+ notifications:send(interactiveData.message)
end
end
notifications:update(dt)
+ enemy:update(dt)
end
function Map:draw()
@@ -146,7 +165,8 @@ function Map:draw()
drawMapLayer("decorations")
love.graphics.draw(player.sprite, player.x, player.y)
drawMapLayer("foreground")
- -- _gameWorld:draw() -- Debug Collision Draw
+ _gameWorld:draw() -- Debug Collision Draw
+ enemy:draw()
camera:detach()
notifications:draw()
end)
@@ -157,7 +177,6 @@ function Map:keypressed(key, scancode)
if(scancode=="f4") then
fullscreen = not fullscreen
love.window.setFullscreen(fullscreen)
- print("Fullscreen Toggle")
resize()
end
end
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
}
diff --git a/scenes/level1_scene.lua b/scenes/level1_scene.lua
index fb1ee0a..c7ad856 100644
--- a/scenes/level1_scene.lua
+++ b/scenes/level1_scene.lua
@@ -33,9 +33,4 @@ function level1:leave()
map = nil
end
-
-function printMessage()
- -- print('Hello')
-end
-
return level1 \ No newline at end of file
diff --git a/scenes/menu_scene.lua b/scenes/menu_scene.lua
index 8fd1587..085162c 100644
--- a/scenes/menu_scene.lua
+++ b/scenes/menu_scene.lua
@@ -69,8 +69,10 @@ function menu:draw()
love.graphics.setColor(titleFontColor1)
love.graphics.draw(starfield, love.graphics.getWidth() * 0.5, love.graphics.getHeight() * 0.5)
love.graphics.draw(titleText1,(windowWidth * 0.5) - (titleText1:getWidth() * 0.5), (windowHeight * 0.5) - 50)
- love.graphics.setColor(titleFontColor2)
love.graphics.setFont(titleFont2)
+ love.graphics.setColor({0,0,0,1})
+ love.graphics.draw(titleText2,(windowWidth * 0.5) - (titleText2:getWidth() * 0.5), (windowHeight * 0.5) + 1, -0.17)
+ love.graphics.setColor(titleFontColor2)
love.graphics.draw(titleText2,(windowWidth * 0.5) - (titleText2:getWidth() * 0.5), (windowHeight * 0.5) + 2, -0.17)
love.graphics.setFont(startMsgFont)