scenes/levels: add a basic ennemy system
This commit is contained in:
parent
e4c0d11a1c
commit
75be0acb2d
|
@ -8,8 +8,8 @@ return {
|
|||
height = 100,
|
||||
tilewidth = 16,
|
||||
tileheight = 16,
|
||||
nextlayerid = 7,
|
||||
nextobjectid = 27,
|
||||
nextlayerid = 8,
|
||||
nextobjectid = 31,
|
||||
backgroundcolor = { 85, 170, 255 },
|
||||
properties = {},
|
||||
tilesets = {
|
||||
|
@ -484,6 +484,71 @@ return {
|
|||
properties = {}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type = "objectgroup",
|
||||
id = 7,
|
||||
name = "ennemy",
|
||||
visible = true,
|
||||
opacity = 1,
|
||||
offsetx = 0,
|
||||
offsety = 0,
|
||||
draworder = "topdown",
|
||||
properties = {},
|
||||
objects = {
|
||||
{
|
||||
id = 27,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 528,
|
||||
y = 1424,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 28,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 576,
|
||||
y = 1424,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 29,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 624,
|
||||
y = 1424,
|
||||
width = 16,
|
||||
height = 16,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
},
|
||||
{
|
||||
id = 30,
|
||||
name = "",
|
||||
type = "",
|
||||
shape = "rectangle",
|
||||
x = 672,
|
||||
y = 1408,
|
||||
width = 32,
|
||||
height = 32,
|
||||
rotation = 0,
|
||||
visible = true,
|
||||
properties = {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="16" tileheight="16" backgroundcolor="#55aaff" nextobjectid="27">
|
||||
<map version="1.2" tiledversion="1.2.2" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="16" tileheight="16" infinite="0" backgroundcolor="#55aaff" nextlayerid="8" nextobjectid="31">
|
||||
<tileset firstgid="1" name="beastlands" tilewidth="16" tileheight="16" tilecount="2006" columns="59">
|
||||
<image source="tilesets/beastlands.png" trans="55aaff" width="944" height="544"/>
|
||||
</tileset>
|
||||
<layer name="Calque de Tile 1" width="100" height="100">
|
||||
<layer id="1" name="Calque de Tile 1" width="100" height="100">
|
||||
<data encoding="csv">
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
|
@ -107,13 +107,13 @@
|
|||
502,502,502,602,603,604,502,502,602,603,603,603,604,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502
|
||||
</data>
|
||||
</layer>
|
||||
<objectgroup name="block">
|
||||
<objectgroup id="2" name="block">
|
||||
<properties>
|
||||
<property name="item" value="coin"/>
|
||||
</properties>
|
||||
<object id="26" x="736" y="1392" width="144" height="48"/>
|
||||
</objectgroup>
|
||||
<objectgroup name="coin">
|
||||
<objectgroup id="3" name="coin">
|
||||
<object id="12" x="240" y="1472" width="16" height="16"/>
|
||||
<object id="13" x="272" y="1472" width="16" height="16"/>
|
||||
<object id="14" x="304" y="1472" width="16" height="16"/>
|
||||
|
@ -126,10 +126,10 @@
|
|||
<object id="21" x="144" y="1392" width="16" height="16"/>
|
||||
<object id="22" x="144" y="1360" width="16" height="16"/>
|
||||
</objectgroup>
|
||||
<objectgroup name="playerstart">
|
||||
<objectgroup id="4" name="playerstart">
|
||||
<object id="23" x="64" y="1472" width="32" height="32"/>
|
||||
</objectgroup>
|
||||
<objectgroup name="wall">
|
||||
<objectgroup id="5" name="wall">
|
||||
<object id="6" x="128" y="1536" width="80" height="64"/>
|
||||
<object id="7" x="48" y="1536" width="48" height="64"/>
|
||||
<object id="8" x="240" y="1504" width="80" height="16"/>
|
||||
|
@ -137,7 +137,13 @@
|
|||
<object id="11" x="736" y="1456" width="144" height="112"/>
|
||||
<object id="25" x="736" y="1264" width="144" height="128"/>
|
||||
</objectgroup>
|
||||
<objectgroup name="platform">
|
||||
<objectgroup id="6" name="platform">
|
||||
<object id="5" x="64" y="1504" width="96" height="32"/>
|
||||
</objectgroup>
|
||||
<objectgroup id="7" name="ennemy">
|
||||
<object id="27" x="528" y="1424" width="16" height="16"/>
|
||||
<object id="28" x="576" y="1424" width="16" height="16"/>
|
||||
<object id="29" x="624" y="1424" width="16" height="16"/>
|
||||
<object id="30" x="672" y="1408" width="32" height="32"/>
|
||||
</objectgroup>
|
||||
</map>
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
local Entity = require "scenes.levels.entities.parent"
|
||||
|
||||
local Ennemy = Entity:extend()
|
||||
|
||||
function Ennemy:new(level, x, y, w, h, hp, power, armor)
|
||||
local w = w or 16
|
||||
local h = h or 16
|
||||
Ennemy.super.new(self, level, "ennemy", x, y, w, h)
|
||||
self.power = power or 1
|
||||
self.armor = armor or 0
|
||||
self.maxhp = hp or 3
|
||||
self.hp = self.maxhp
|
||||
end
|
||||
|
||||
function Ennemy:update(dt)
|
||||
|
||||
end
|
||||
|
||||
function Ennemy:draw()
|
||||
love.graphics.setColor(1, 0, 0, 1)
|
||||
utils.graphics.box(self.x, self.y, self.w, self.h)
|
||||
love.graphics.setColor(0, 0, 0, 1)
|
||||
love.graphics.rectangle("fill", self.x, self.y - 6, self.w, 2)
|
||||
love.graphics.setColor(1, 0, 0, 1)
|
||||
local barwidth = math.floor((self.hp / self.maxhp) * self.w)
|
||||
love.graphics.rectangle("fill", self.x, self.y - 6, barwidth, 2)
|
||||
utils.graphics.resetColor()
|
||||
end
|
||||
|
||||
function Ennemy:getDamage(base_damage)
|
||||
local damage = math.max(base_damage - self.armor, 1)
|
||||
self.hp = math.max(0, self.hp - damage)
|
||||
if (self.hp == 0) then
|
||||
self:destroy()
|
||||
self.obj.GFX(self.level, self.x+8, self.y+8, "poof", 1)
|
||||
end
|
||||
end
|
||||
|
||||
return Ennemy
|
|
@ -12,12 +12,15 @@ Obj.GFX = require "scenes.levels.entities.gfx"
|
|||
Obj.Debris = require "scenes.levels.entities.debris"
|
||||
Obj.Player = require "scenes.levels.entities.player"
|
||||
|
||||
Obj.Ennemy = require "scenes.levels.entities.ennemies.parent"
|
||||
|
||||
Obj.index = {}
|
||||
|
||||
Obj.index["coin"] = Obj.Coin
|
||||
Obj.index["coin5"] = Obj.Coin5
|
||||
Obj.index["coin10"] = Obj.Coin10
|
||||
Obj.index["block"] = Obj.Block
|
||||
Obj.index["ennemy"] = Obj.Ennemy
|
||||
|
||||
Obj.collisions = {}
|
||||
Obj.collisions["wall"] = true
|
||||
|
|
|
@ -16,6 +16,8 @@ function Weapon:setFilter()
|
|||
return 'touch'
|
||||
elseif (other.collType=="block") then
|
||||
return "touch"
|
||||
elseif (other.collType=="ennemy") then
|
||||
return "touch"
|
||||
else
|
||||
return nil
|
||||
end
|
||||
|
@ -38,6 +40,10 @@ function Weapon:update(dt)
|
|||
self:destroy()
|
||||
other:breakBlock()
|
||||
end
|
||||
if other.collType=="ennemy" and (self.life == 1) then
|
||||
self:destroy()
|
||||
other:getDamage(1)
|
||||
end
|
||||
end
|
||||
|
||||
self.life = 1
|
||||
|
|
Loading…
Reference in New Issue