-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhud.js
More file actions
219 lines (178 loc) · 7.54 KB
/
hud.js
File metadata and controls
219 lines (178 loc) · 7.54 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*This software is released under MIT License. Texts for license are listed below:
* Aventura do Saber , a educational fantasy action RPG
* Copyright (c) 2012-2013, ITSimples Games
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*-------------------
START hud border entity
-------------------------------- */
// var HUDBorder = me.HUD_Item.extend({
// init: function(x, y) {
// this.parent(x, y);
// this.image = me.loader.getImage("hudbg");
// },
// draw: function(context, x, y) {
// context.drawImage(this.image, 0, 0);
// }
// });
/*--- END hud border entity ---*/
var hudInitialValues = {"vida" : 20,"conhecimento" : 10,"velocidade" : 2, "ouro" : 40,"sorte":1};
/*-------------------
START hud live entity
-------------------------------- */
var HUDLive = me.HUD_Item.extend({
init: function(x, y) {
this.parent(x, y);
this.font = new me.Font("MedievalSharp",ads_HUD_font_size,hudColorLive,"left");
this.value = hudInitialValues["vida"];
this.name= language.system.TRlive;
// calculate value position
this.itemHUDLength = ( ( this.name.length ) * ads_HUD_font_size ) / 2;
},
hudLength : function(){
return ( this.itemHUDLength + ads_HUD_font_size );
},
draw: function(context, x, y) {
this.font.draw(context, this.name, this.pos.x , this.pos.y);
this.font.draw(context, this.value, this.pos.x + this.itemHUDLength, this.pos.y);
}
});
/*--- END hud live entity ---*/
/*-------------------
START hud gold entity
-------------------------------- */
var HUDGold = me.HUD_Item.extend({
init: function(x, y) {
this.parent(x, y);
this.font = new me.Font("MedievalSharp",ads_HUD_font_size,hudColorGold,"left");
this.value = hudInitialValues["ouro"];
this.name = language.system.TRgold;
// calculate value position
this.itemHUDLength = ( ( this.name.length ) * ads_HUD_font_size ) / 2;
},
hudLength : function(){
return ( this.itemHUDLength + ads_HUD_font_size );
},
draw: function(context, x, y) {
this.font.draw(context, this.name, this.pos.x , this.pos.y);
this.font.draw(context, this.value, this.pos.x + this.itemHUDLength, this.pos.y);
}
});
/*--- END hud Gold entity ---*/
/*-------------------
START hud velocity entity
-------------------------------- */
var HUDVelocity = me.HUD_Item.extend({
init: function(x, y) {
this.parent(x, y);
this.font = new me.Font("MedievalSharp",ads_HUD_font_size,hudColorVelocity,"left");
this.value = hudInitialValues["velocidade"] * 2 ; //Hud information
this.name = language.system.TRvelocity;
// calculate value position
this.itemHUDLength = ( ( this.name.length ) * ads_HUD_font_size ) / 2;
},
hudLength : function(){
return ( this.itemHUDLength + ads_HUD_font_size );
},
draw: function(context, x, y) {
this.font.draw(context, this.name, this.pos.x , this.pos.y);
this.font.draw(context, this.value, this.pos.x + this.itemHUDLength, this.pos.y);
heroVelocity = this.value / 2;
// Update hero velocity
var player = adsGame.heroEntity();
player.setVelocity(heroVelocity, heroVelocity);
player = undefined;
}
});
/*--- END hud velocity entity ---*/
/*-------------------
START hud knowledge entity
-------------------------------- */
var HUDKnowledge = me.HUD_Item.extend({
init: function(x, y) {
this.parent(x, y);
this.font = new me.Font("MedievalSharp",ads_HUD_font_size,hudColorKnowledge,"left");
this.value = hudInitialValues["conhecimento"];
this.name = language.system.TRknowledge;
// calculate value position
this.itemHUDLength = (( ( this.name.length ) * ads_HUD_font_size ) / 2) + ads_HUD_X_Position;
},
hudLength : function(){
// Plus 10 because star on ads_HUD_X_Position
return (this.itemHUDLength + ads_HUD_font_size + ads_HUD_X_Position);
},
draw: function(context, x, y) {
this.font.draw(context, this.name, this.pos.x , this.pos.y);
this.font.draw(context, this.value, this.pos.x + this.itemHUDLength, this.pos.y);
}
});
/*--- END hud knowledge entity ---*//*-------------------
/*-------------------
START hud Lucky entity
-------------------------------- */
var HUDLucky = me.HUD_Item.extend({
init: function(x, y) {
this.parent(x, y);
this.font = new me.Font("MedievalSharp",ads_HUD_font_size,hudColorLucky,"left");
this.value = hudInitialValues["sorte"];
this.name = language.system.TRlucky;
// calculate value position
this.itemHUDLength = ( ( this.name.length ) * ads_HUD_font_size ) / 2;
},
hudLength : function(){
return ( this.itemHUDLength + ads_HUD_font_size );
},
draw: function(context, x, y) {
this.font.draw(context, this.name, this.pos.x , this.pos.y);
this.font.draw(context, this.value, this.pos.x + this.itemHUDLength, this.pos.y);
}
});
/*--- END hud Lucky entity ---*/
adsGame.initHUD = function(){
// Setup HUD
me.game.addHUD(0,0,ads_width,33,"#222222");
var hudSpace= ~~(ads_width / 16);
var hudLive = new HUDLive(ads_HUD_X_Position ,ads_HUD_Y_Position);
var hudKnowledge = new HUDKnowledge( hudLive.hudLength() +
(hudSpace * 1),ads_HUD_Y_Position);
var hudVelocity = new HUDVelocity( hudLive.hudLength() +
hudKnowledge.hudLength() +
(hudSpace * 2) ,ads_HUD_Y_Position);
var hudGold = new HUDGold( hudVelocity.hudLength() +
hudLive.hudLength() +
hudKnowledge.hudLength() +
(hudSpace * 3),ads_HUD_Y_Position);
var hudLucky = new HUDLucky( hudLive.hudLength() +
hudKnowledge.hudLength() +
hudVelocity.hudLength() +
hudGold.hudLength() + (hudSpace * 4),ads_HUD_Y_Position);
me.game.HUD.addItem("vida", hudLive );
me.game.HUD.addItem("conhecimento", hudKnowledge );
me.game.HUD.addItem("velocidade", hudVelocity );
me.game.HUD.addItem("ouro", hudGold );
me.game.HUD.addItem("sorte", hudLucky);
// HUD border must be last so it is on the bottom
// me.game.HUD.addItem("HUDborder", new HUDBorder(0,0));
};
adsGame.resetHUD = function(){
// Reset items on hud values
$.each(hudInitialValues , function (index , value){
if (index !== "velocidade"){
me.game.HUD.setItemValue(index, value );
}
});
};