Mothback/data/scripts/entity.lua

75 lines
1.7 KiB
Lua
Raw Normal View History

Entity = {
}
2021-10-16 23:06:11 +00:00
function Entity:New(x,y)
2021-10-16 23:06:11 +00:00
o = {}
o.pos = {x = x, y = y}
o.vel = {x = 0, y = 0}
o.class = "Entity"
o.anim_subframe = 0
o.anim_frame = 0
o.anim_imgs = {}
o.offset = {x = 0, y = 0}
o.scale = {x = 1, y = 1}
o.flip = { x = 1, y = 1}
2021-10-16 23:06:11 +00:00
setmetatable(o, self)
self.__index = self
return o
end
function Entity:Move(target, speed) -- target = {tx int, ty int} / speed = int
2021-10-16 23:06:11 +00:00
end
function Entity:Draw()
2021-10-16 23:06:11 +00:00
if self.sprite ~= nil then
love.graphics.draw(
self.sprite,
self.pos.x - Camera.pos.x + self.offset.x * game.scale * self.scale.x * self.flip.x,
self.pos.y - Camera.pos.y + self.offset.y * game.scale * self.scale.y * self.flip.y,
0,
game.scale * self.scale.x * self.flip.x,
game.scale * self.scale.y * self.flip.y
)
end
end
function Entity:Animate()
2021-10-16 23:06:11 +00:00
if game_paused ~= true then
-- try to animate
self.anim_subframe = self.anim_subframe + current_dt
if self.anim_subframe >= self.anim_speed then
self.anim_frame = self.anim_frame + 1
self.anim_subframe = self.anim_subframe - self.anim_speed
end
-- cycle
if self.anim_frame >= self.anim_frames+1 then
self.anim_frame = self.anim_frame - self.anim_frames
end
-- change
self.sprite = self.anim_imgs[self.anim_frame]
end
end
function Entity:LoadAnimation(anim,frames,speed)
2021-10-16 23:06:11 +00:00
if self.anim_path ~= anim and self.anim_path ~= anim.path then
if frames ~= nil and speed ~= nil then
self.anim_path = anim or nil
self.anim_frames = frames or 4
self.anim_speed = speed or frames
else
self.anim_path = anim.path
self.anim_frames = anim.frames
self.anim_speed = anim.speed
end
self.anim_imgs = anim.imgs
end
end
require "data/scripts/entities/kupo"
2021-10-16 23:06:11 +00:00
require "data/scripts/entities/player"