-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerHUD.lua
144 lines (120 loc) · 5.84 KB
/
playerHUD.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
local utils = require "utils"
local entity = require "entity"
local image = require "image"
local particleSystem = require "particleSystem"
local playerHUD = {}
setfenv (1, playerHUD)
local baseImage1 = image.Image("assets/images/ui/p1_base.png")
local baseImage2 = image.Image("assets/images/ui/p2_base.png")
local baseImage3 = image.Image("assets/images/ui/p3_base.png")
local baseImage4 = image.Image("assets/images/ui/p4_base.png")
local coverImage1 = image.Image("assets/images/ui/p1_cover.png")
local coverImage2 = image.Image("assets/images/ui/p2_cover.png")
local coverImage3 = image.Image("assets/images/ui/p3_cover.png")
local coverImage4 = image.Image("assets/images/ui/p4_cover.png")
local lightImage1 = image.Image("assets/images/ui/p1_luz.png")
local lightImage2 = image.Image("assets/images/ui/p2_luz.png")
local lightImage3 = image.Image("assets/images/ui/p3_luz.png")
local lightImage4 = image.Image("assets/images/ui/p4_luz.png")
local hudEmitter1 = particleSystem.ParticleSystem ("assets.particles.particle_hud1", image.Image("assets/particles/ticles_shine.png").img)
local hudEmitter2 = particleSystem.ParticleSystem ("assets.particles.particle_hud2", image.Image("assets/particles/ticles_shine.png").img)
local hudEmitter3 = particleSystem.ParticleSystem ("assets.particles.particle_hud3", image.Image("assets/particles/ticles_shine.png").img)
local hudEmitter4 = particleSystem.ParticleSystem ("assets.particles.particle_hud4", image.Image("assets/particles/ticles_shine.png").img)
local barPosition1 = {x = 99, y = 35}
local barPosition2 = {x = 126, y = 35}
local barPosition3 = {x = 99, y = 34}
local barPosition4 = {x = 126, y = 34}
local initialStarPosition1 = {x = 25, y = 76}
local initialStarPosition2 = {x = 173, y = 76}
local initialStarPosition3 = {x = 24, y = -2}
local initialStarPosition4 = {x = 173, y = -2}
local starDistance = 10
local starsProgression = {0, 500, 1500, 3000, 5200, 7000, 10000}
local star = image.Image("assets/images/ui/ui_star.png")
PlayerHUD = utils.inheritsFrom (entity.Entity, function (self, playerId, scoreReference)
entity.Entity.__constructor(self)
self.scoreReference = scoreReference
self.stars = 1
if playerId == 1 then
self.position = {x = 0, y = 20}
self:addComponent(baseImage1)
self.bar = self:addComponent(image.Image("assets/images/ui/ui_bar.png"))
self.bar.x, self.bar.y = barPosition1.x, barPosition1.y
self:addComponent(coverImage1)
self.light = self:addComponent(lightImage1)
self.bar:setReference(self.position)
baseImage1:setReference(self.position)
coverImage1:setReference(self.position)
lightImage1:setReference(self.position)
self.initialStarPosition = initialStarPosition1
self.hudEmitter = self:addComponent(hudEmitter1)
self.hudEmitter.x = 188
self.hudEmitter.y = 65
self.growth = 1
elseif playerId == 2 then
self.position = {x = 1056, y = 20}
self:addComponent(baseImage2)
self.bar = self:addComponent(image.Image("assets/images/ui/ui_bar.png"))
self.bar.x, self.bar.y = barPosition2.x, barPosition2.y
self:addComponent(coverImage2)
self.light = self:addComponent(lightImage2)
self.bar:setReference(self.position)
baseImage2:setReference(self.position)
coverImage2:setReference(self.position)
lightImage2:setReference(self.position)
self.initialStarPosition = initialStarPosition2
self.hudEmitter = self:addComponent(hudEmitter2)
self.hudEmitter.x = 32
self.hudEmitter.y = 65
self.growth = -1
elseif playerId == 3 then
self.position = {x = 0, y = 600}
self:addComponent(baseImage3)
self.bar = self:addComponent(image.Image("assets/images/ui/ui_bar.png"))
self.bar.x, self.bar.y = barPosition3.x, barPosition3.y
self:addComponent(coverImage3)
self.light = self:addComponent(lightImage3)
self.bar:setReference(self.position)
baseImage3:setReference(self.position)
coverImage3:setReference(self.position)
lightImage3:setReference(self.position)
self.initialStarPosition = initialStarPosition3
self.hudEmitter = self:addComponent(hudEmitter3)
self.growth = 1
else
self.position = {x = 1056, y = 600}
self:addComponent(baseImage4)
self.bar = self:addComponent(image.Image("assets/images/ui/ui_bar.png"))
self.bar.x, self.bar.y = barPosition4.x, barPosition4.y
self:addComponent(coverImage4)
self.light = self:addComponent(lightImage4)
self.bar:setReference(self.position)
baseImage4:setReference(self.position)
coverImage4:setReference(self.position)
lightImage4:setReference(self.position)
self.initialStarPosition = initialStarPosition4
self.hudEmitter = self:addComponent(hudEmitter4)
self.growth = -1
end
self.hudEmitter:setReference(self.position)
self.light.visible = false
end)
function PlayerHUD:update()
entity.Entity.update(self)
if self.scoreReference.lastPoints ~= self.scoreReference.points then
self.hudEmitter:start()
self.light.visible = true
else
self.hudEmitter:stop()
self.light.visible = false
end
if self.scoreReference.points >= starsProgression[self.stars + 1] and self.stars + 1 < #starsProgression then
local star = self:addComponent(image.Image("assets/images/ui/ui_star.png"))
star.x = self.initialStarPosition.x + (self.stars - 1) * (star.width + starDistance)
star.y = self.initialStarPosition.y
star:setReference(self.position)
self.stars = self.stars + 1
end
self.bar.scale.x = (self.scoreReference.points - starsProgression[self.stars]) / (starsProgression[self.stars + 1] - starsProgression[self.stars]) * self.growth
end
return playerHUD