forked from HarleyV/ZeldaGroup_CSC17B
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventory.js
More file actions
134 lines (114 loc) · 3.96 KB
/
Inventory.js
File metadata and controls
134 lines (114 loc) · 3.96 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
function Bomb() {
GameObject.call(this);
this.animator = new Animator(bombAnim, this);
this.animator.setAnim("explode");
this.animator.play();
this.damage = 40;
this.size = new Vector2(12, 12);
this.canCollide = false;
}
Bomb.prototype = Object.create(GameObject.prototype);
Bomb.prototype.constructor = Bomb;
Bomb.prototype.resize = function() {
this.elem.style.width = scaleFact * this.spriteSize.x + "px";
this.elem.style.height = scaleFact * this.spriteSize.y + "px";
this.elem.style.backgroundSize = scaleFact * this.animator.sheet.x + "px " + scaleFact * this.animator.sheet.y + "px";
}
Bomb.prototype.update = function(deltaTime){
if (this.animator.frame >= 24) {
var db = new DmgBox(this, 0.1, this.damage, 400);
db.position = this.position.sub(new Vector2(16,17));
db.size = new Vector2(44, 46);
//if(db.collide(obj) && obj )
objs.push(db);
//delObject(db);
this.timer = 3;
bombExplode.play();
}
if (this.animator.playing == false) {
delObject(this);
}
}
Bomb.prototype.draw = function(deltaTime) {
this.animator.play();
this.animator.update(deltaTime, this);
this.elem.style.backgroundPosition = -this.sprite.x + "px " + -this.sprite.y + "px";
// Call the base version of the draw
GameObject.prototype.draw.call(this, deltaTime);
}
var bombAnim = {
"sheetURL": "assets/bomb_sheet.png",
"sheet":[704, 46], // Size of spritesheet in px
"cell":[44, 46], // Size of each cell in px
"offset":[-16,-21],
"anims": {
"explode": {
"loop": false,
"nFrames": 34,
"intervals": [1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05,
0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05,
0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05,
0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05],
"frames": [[0,0], [1,0], [2,0], [3,0], [4,0], [5,0], [6,0], [7,0],
[0,0], [1,0], [2,0], [3,0], [4,0], [5,0], [6,0], [7,0],
[0,0], [1,0], [2,0], [3,0], [4,0], [5,0], [6,0], [7,0],
[8,0], [9,0], [10,0], [9,0], [10,0], [11,0], [12,0], [13,0], [14,0], [15,0]] }
}
};
function Arrow(_dir) {
GameObject.call(this);
this.dir = _dir;
this.size = new Vector2(15, 15);
this.elem.style.backgroundImage = "url('assets/arrow_sheet.png')";
this.elem.style.backgroundSize = scaleFact * 60 + "px " + scaleFact * 15 + "px";
this.elem.style.width = scaleFact * this.size.x + "px";
this.elem.style.height = scaleFact * this.size.y + "px";
this.speed = 150;
this.damage = 15;
this.life = 10;
//this.canCollide = false;
}
Arrow.prototype = Object.create(GameObject.prototype);
Arrow.prototype.constructor = Arrow;
Arrow.prototype.setVelocity = function() {
if (this.dir === 0){
this.velocity = new Vector2(0, this.speed);
this.elem.style.backgroundPosition = 0 + "px 0px";
} else if (this.dir === 1){
this.velocity = new Vector2(this.speed, 0);
this.elem.style.backgroundPosition = -45 * scaleFact + "px 0px";
} else if (this.dir === 2){
this.velocity = new Vector2(0, 0 - this.speed);
this.elem.style.backgroundPosition = -15 * scaleFact + "px 0px";
} else if (this.dir === 3){
this.velocity = new Vector2(0 - this.speed, 0);
this.elem.style.backgroundPosition = -30 * scaleFact + "px 0px";
}
//console.log(this.velocity);
}
Arrow.prototype.collide = function(obj) {
if (obj != null) {
if (obj instanceof EntityLiving && obj != player) {
obj.damage(this.damage);
// Knockback
var centerCtr = new Vector2(this.position.x + this.size.x / 2, this.position.y + this.size.y / 2);
var centerObj = new Vector2(obj.position.x + obj.size.x / 2, obj.position.y + obj.size.y / 2);
//obj.velocity = centerObj.sub(centerCtr).normalize().mul(this.knockback);
delObject(this);
}
} else {
delObject(this);
}
arrowHit.play();
}
Arrow.prototype.update = function(deltaTime) {
this.life -= deltaTime;
if (this.life <= 0) {
delObject(this);
}
}
Arrow.prototype.draw = function(deltaTime) {
//console.log("test");
this.setVelocity();
GameObject.prototype.draw.call(this, deltaTime);
}