-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprite.js
More file actions
236 lines (165 loc) · 4.25 KB
/
Sprite.js
File metadata and controls
236 lines (165 loc) · 4.25 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
function Sprite(){
//Atributos
//atributos de movimentos
this.mvRight = false;
this.mvLeft = false;
this.mvUp = false;
this.mvDown = false;
//recorte das imagens do personagem
this.srcX = 0;
this.srcY = 0;
//para um personagem
this.width = 24;
this.height = 36;
this.posX = 0;
this.posY = 0;
this.savePosX = 0;
this.savePosY = 0;
//imagem com os sprites
this.img = new Image();
this.battleSprite = new Image();
//atributos de combate
this.atributos = new AtributosGerais(100,100,20,10,50,0,0,0); //LP, MP, AD, DP, AP, MD, Money, XP
this.acessoryEquip = "Wooden Shield";
this.weaponEquip = "Wooden Sword";
//Atributos de Inventario
this.lastScene = 0;
this.inventoryStr = '{' +
'"items": {' +
'"potionHp": 0,' +
'"potionMp": 0' +
'},' +
'"acessories": {' +
'"bronzeShield": 0' +
'},' +
'"weapons": {' +
'"bronzeSword": 0' +
'}' +
'}';
this.inventory = JSON.parse(this.inventoryStr);
//velocidade do personagem
this.speed = 1;
this.spriteSpeed = 6;
this.countAnim = 0;
//Controle de animação de batalha
this.battleMode = 0;
this.battlePosX = 0;
this.battlePosY = 0;
this.battleWidth = 0;
this.battleHeight = 0;
this.rangeAnimation = [];
this.actions = [];
this.indiceActions = 0;
this.battleAction = 0;
this.runAnimation = false;
var i = 0;
//Controle do nivel das fases e seus inimigos
this.greenJewelLevel = 0;
this.redJewelLevel = 0;
this.yellowJewelLevel = 0;
this.blueJewelLevel = 0;
//Metodos
//desenho
this.draw = function(ctx){
if(this.battleMode == 0){
ctx.drawImage(this.img,this.srcX,this.srcY, this.width, this.height, this.posX,this.posY,this.width,this.height);
this.animation();
}
else{
ctx.drawImage(this.battleSprite,this.srcX,this.srcY, this.battleWidth, this.battleHeight, this.battlePosX,this.battlePosY,this.battleWidth,this.battleHeight);
this.battleAnimation();
}
}
//movimentacao
this.move = function(){
if(this.mvRight){
this.posX += this.speed;
this.srcY = this.height * 3;
} else
if(this.mvLeft){
this.posX -= this.speed;
this.srcY = this.height * 2;
} else
if(this.mvUp){
this.posY -= this.speed;
this.srcY = this.height * 1;
} else
if(this.mvDown){
this.posY += this.speed;
this.srcY = this.height * 0;
}
}
//animacao
this.animation = function(){
if(this.mvUp || this.mvDown || this.mvLeft || this.mvRight == true){
this.countAnim++;
if(this.countAnim >= (this.spriteSpeed * 7))
{
this.countAnim = this.spriteSpeed;
}
this.srcX = Math.floor(this.countAnim/this.spriteSpeed) * this.width;
}
}
this.setSprite = function (sprite){
this.img.src = sprite;
}
this.setBattleAnimationDetails = function (sprite, posX, posY, width, height, rangeVector, actionsVector){
this.battleSprite.src = sprite;
this.battlePosX = posX;
this.battlePosY = posY;
this.battleWidth = width;
this.battleHeight = height;
this.rangeAnimation = rangeVector;
this.actions = actionsVector;
}
this.resetBattleAnimation = function(){
this.srcX = 0;
this.srcY = 0;
this.countAnim = 0;
this.battleAction = 0;
this.spriteSpeed = 9;
}
this.enableBattleMode = function (){
this.resetBattleAnimation();
this.battleMode = 1;
this.runAnimation = true;
}
this.disableBattleMode = function (){
this.battleMode = 0;
this.srcX = 0;
this.srcY = 0;
this.countAnim = 0;
this.spriteSpeed = 6;
}
this.selectAction = function (action){
for(i = 0; i < this.rangeAnimation.length; i++)
{
if(this.actions[i] == action){
this.indiceActions = i;
break;
}
}
this.battleAction = this.indiceActions;
this.srcY = this.battleHeight * this.indiceActions;
this.srcX = 0;
this.runAnimation = true;
}
//animacao de batalha
this.battleAnimation = function(){
if(this.runAnimation == true){
this.countAnim++;
if(this.countAnim >= (this.spriteSpeed * this.rangeAnimation[this.battleAction]))
{
//this.countAnim = this.spriteSpeed;
this.countAnim = 0;
this.battleAction = 0;
this.srcY = this.battleHeight;
this.srcX = 0;
this.runAnimation = false;
}
else{
this.srcX = Math.floor(this.countAnim/this.spriteSpeed) * this.battleWidth;
}
}
}
}