-
Notifications
You must be signed in to change notification settings - Fork 0
/
obstacle.lua
43 lines (36 loc) · 1.18 KB
/
obstacle.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'entity'
Obstacle = {}
Obstacle.__index = Obstacle
setmetatable(Obstacle, {__index = Entity})
function Obstacle:new(game, config)
local config = config or {}
local newObstacle = Entity:new(game)
newObstacle.type = "obstacle"
newObstacle.x = config.x or 0
newObstacle.y = config.y or 0
newObstacle.size = config.size or {
x = 40,
y = 52
}
newObstacle.graphics = config.graphics or {
source = "assets/images/cactus-sprites.png"
}
if game.graphics ~=nil and game.animation ~= nil then
newObstacle.graphics.sprites = game.graphics.newImage(newObstacle.graphics.source)
newObstacle.graphics.grid = game.animation.newGrid(
newObstacle.size.x, newObstacle.size.y,
newObstacle.graphics.sprites:getWidth(),
newObstacle.graphics.sprites:getHeight()
)
newObstacle.graphics.animation = game.animation.newAnimation(
newObstacle.graphics.grid("1-2", 1),
0.5
)
end
return setmetatable(newObstacle, self)
end
function Obstacle:update(dt)
if self.graphics.animation ~= nil then
self.graphics.animation:update(dt)
end
end