-
Notifications
You must be signed in to change notification settings - Fork 0
/
wagon.lua
90 lines (71 loc) · 1.88 KB
/
wagon.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import "CoreLibs/sprites"
import "CoreLibs/graphics"
class('Wagon').extends(playdate.graphics.sprite)
local gfx <const> = playdate.graphics
local geo <const> = playdate.geometry
function Wagon:init()
Wagon.super.init(self)
self.wagonImageTable = gfx.imagetable.new("img/wagon")
self:setImage(self.wagonImageTable:getImage(1))
self:setZIndex(0)
self:setCenter(0,0)
self:setCollideRect(0, 0, self.width, self.height - 3)
self.position = geo.point.new(30, 167)
self:reset()
end
function Wagon:reset()
self.currentImageIndex = 1
self.slowFrameSkip = true
self.animateSuccess = false
self.status = {"WALK", "TROT", "GALLOP"}
self.speed = 1
self.dead = false
end
function Wagon:update()
if gameOn or not self.dead then
if not self.slowFrameSkip then
self.currentImageIndex += 1
self.slowFrameSkip = true
else
self.slowFrameSkip = false
end
if self.animateSuccess then
if self.currentImageIndex > 8 then self.currentImageIndex = 6 end
else
if self.currentImageIndex > 3 then self.currentImageIndex = 1 end
end
self.position.x += self.speed
if self.x > 400 then self.position.x = -70
elseif self.x < -70 then self.position.x = 400 end
self:setImage(self.wagonImageTable[self.currentImageIndex])
end
end
function Wagon:startSuccessfulLanding()
print("startSuccessfulLanding")
self.animateSuccess = true
self.currentImageIndex = 6
end
function Wagon:stopSuccessfulLanding()
print("stopSuccessfulLanding")
self.animateSuccess = false
self.currentImageIndex = 1
end
function Wagon:hitDriver()
self:setImage(self.wagonImageTable[4])
self.dead = true
end
function Wagon:hitHorse()
self:setImage(self.wagonImageTable[5])
self.dead = true
end
function Wagon:setSpeed(s)
self.speed = s
end
function Wagon:increaseSpeed()
if self.speed < 3 then
self:setSpeed(self.speed + 1)
end
end
function Wagon:getStatus()
return self.status[self.speed]
end