-
Notifications
You must be signed in to change notification settings - Fork 8
/
objects.js
291 lines (231 loc) · 6.78 KB
/
objects.js
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
function area(name, bgSprite, type, doors, prev, next){
this.name = name;
this.bgSprite = bgSprite;
this.type = type;
this.doors = doors;
this.prev = prev;
this.next = next;
//this.monster = new monster();
this.door = new door();
}
area.prototype.nextArea = function(){
return this.next;
}
area.prototype.prevArea = function(){
return this.prev;
}
function chest(level_num, chest_num){
this.seal = chest_num * ( 3 + level_num); // The number of kills needed to open.
this.gold = 0;
this.type = "";
this.sprite = new PIXI.Sprite.fromImage("res/chest_closed.png");
this.sprite.scale.x = this.sprite.scale.y = 5;
this.sprite.position.x = 10;
this.sprite.position.y = 10;
this.sprite.interactive = false;
this.sprite.buttonMode = false;
this.sprite.tint = 0x999966;
var texture;
this.num = Math.floor((Math.random() * 10));
if((this.num % 2) == 0){
this.sprite.click = this.sprite.touchstart = function(e){
//this.fail;
if(this.type != "gold"){
//console.log(" GOLD! " + this.num);
texture = new PIXI.Texture.fromImage("res/chest_full.png");
this.sprite.texture = texture;
this.type = "gold";
//this.fail = "fail";
}else{
this.gold = 10 + (5 * level_num);
texture = new PIXI.Texture.fromImage("res/chest_empty.png");
this.sprite.texture = texture;
this.sprite.click = this.sprite.touchstart = null;
this.interactive = false;
this.buttonMode = false;
}
}.bind(this);
}else{
this.sprite.click = this.sprite.touchstart = function(e){
//console.log(" Empty");
texture = new PIXI.Texture.fromImage("res/chest_empty.png");
this.sprite.texture = texture;
this.type = "empty";
this.sprite.interactive = false;
this.sprite.buttonMode = false;
}.bind(this);
}
}
door.prototype.reset = function() {
console.log(" RESET!");
}
// Object holding the information of the doors/chests/loot system.
function door(area, monsters2Kill, num){
//console.log("DOOR!");
this.number = 0;
this.currentDoor = "Back";
this.doorTypes = [
"Trap",
"Trap",
"Trap",
"Monster",
"Monster",
"Treasure",
"Monster",
"Treasure",
"Treasure",
"Treasure",
"Monster"
];
}
//This will return a door object that is either a trap, monster and escapes.
door.prototype.openDoor = function() {
var num = Math.floor(Math.random() * 10);
this.currentDoor = this.doorTypes[num];
}
// New monster object, it takes an index and returns the monster's sprite.
function Monsters(level_num){
// Randomly init some values
this.clickDamage = 0;
this.gold = 1 + level_num;
this.health = 5 + Math.floor(level_num * 1.15);
this.current_health = parseInt(this.health);
this.name = "Firerat";
this.animated = false; // This is for damage animation.
//var XY = this.randomXY();
this.generateMonster(level_num);
//console.log(" Created a new " + this.name);
this.monsterContainer = new PIXI.Container();
// Setting up sprite object
this.sprite = new PIXI.Sprite.fromImage(this.name +'.png');
this.sprite.scale.x = this.sprite.scale.y = 6;
this.sprite.position.x = 200;//XY[0];
this.sprite.position.y = 350;//XY[1];
this.sprite.interactive = true;
this.sprite.buttonMode = true;
this.monsterContainer.addChild(this.sprite);
// Setting up name text
this.name_text = new PIXI.Text(this.name, {font:"bold 21px sans-serif", fill:"#ff4d4d", align:"center"});
this.name_text.position.x = 190;
this.name_text.position.y = 340;
this.monsterContainer.addChild(this.name_text);
// New monster ratio bar.
this.health_text = new PIXI.Text(this.current_health +"/" + this.health, {font:"bold 17px sans-serif", fill:"#ff4d4d", align:"center"});
this.health_text.position.x = 220;
this.health_text.position.y = 451;
this.monsterContainer.addChild(this.health_text);
this.sprite.click = this.sprite.touchstart = function(e){
if(!this.animated){
//this.current_health = this.current_health - 3;
//console.log(" "+ this.clickDamage);
this.current_health = this.current_health - this.clickDamage;
this.health_text.text = this.current_health + "/" + this.health;
//this.bar.drawRect(215,475,(this.current_health/100)*800,14);
this.sprite.tint = 0xff0000;
this.sprite.position.x += 3;
//var tempFilter = new PIXI.ColorMatrixFilter();
//this.sprite.filters = [tempFilter];
this.animated = true;
setTimeout(this.sprite.click, 130);
//console.log("sleepoing");
}else{
//console.log("Doing it!");
//this.sprite.filters = null;
this.sprite.position.x -= 3;
this.sprite.tint = 0xffffff;
this.animated = false;
}
}.bind(this);
// Don't know why this bind thing works, but fixes my scope issues.
this.randomXY();
//this.monsterContainer.position.x = XY[0];
//this.monsterContainer.position.y = XY[1];
}
// Sloppily selects two random values for monster placement.
Monsters.prototype.randomXY = function(){
var xy = [1, 1];
xy[0] = Math.floor((Math.random() * 340));
xy[1] = Math.floor((Math.random() * 80));
//this.monsterContainer.position.x = xy[0];
//this.monsterContainer.position.y = xy[1];
this.monsterContainer.position.x = xy[0];
this.monsterContainer.position.y = xy[1];
//console.log(xy[0] + " " + xy[1]);
//return xy;
}
// Changes the current name and texture of the monster object.
Monsters.prototype.generateMonster = function(level_num){
this.array = [
//Cave
"Redslime",
"Redslime",
"Redslime",
"Redslime",
"Flamemoth",
"Flamemoth",
"Direrat",
"Direrat",
"Direrat",
//Starting to get to Forest
"Piggy",
"Piggy",
"Greenslime",
"Shallot",
"Shallot",
"Leafae",
//Waterfall
"Snake",
"Snake",
"Shroomy",
"Greenslime",
"Pebble",
"Pebble",
//Riverside
"Groaf",
"Groaf",
//Bridge
"Gaobo",
"Grot",
"Rindslug",
//Beach
"Fluffpuff",
"Fluffpuff",
"Dingo",
"Piggy",
//Woods
"Stig",
"Direrat",
"Deku",
"Deku",
"Shada",
"Shada",
//Dungeon
"Oneye",
"Oneye",
"Bones",
"Fallen",
"Fallen",
"Bones",
"Direrat",
//Mountain
"Flameskull",
""
];
var num = level_num + Math.floor((Math.random() * 10));
this.name = this.array[num];
}
// The basic object that holds all the values of the player's character.
function char(n, r, ge, go, l, t, a){
this.name = n;
this.race = r;
// This value is subject to change.
this.gender = ge;
this.gold = go;
this.current_Level = l;
this.tier = t;
this.attributes = a;
}
char.prototype.print = function() {
console.log(" name:" + this.name + " gold:" + this.gold);
}
//end of area.js