-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.js
79 lines (70 loc) · 2.06 KB
/
object.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
class GameObject {
constructor(name, color_, size) {
this.name = name;
this.color = color(color_);
this.setSize(size);
this.position = createVector(floor(random(total_space_over_map[0])), floor(random(total_space_over_map[1])));
// this.in_inventory_slot;
this.image;
this.amount_of_shadowblur = 0;
this.states_of_shadowblur = "up";
}
draw(pos_x, pos_y, halfH, is_tick) {
if(is_tick) {
let player_circle = {
x: main_map.player.canvas_position.x,
y: main_map.player.canvas_position.y,
radius: main_map.player.radius
};
let block_rect = {
x: pos_x,
y: pos_y,
halfWidth: this.half_size,
halfHeight: halfH
};
if(Utils.rectCircleOverlap(block_rect, player_circle) !== false) {
let that_space = main_map.space[this.position.x][this.position.y];
that_space.is_stuff_available = false;
that_space.floating_stuff = undefined;
if(this instanceof ItemPill || this instanceof ItemWeapon) {
main_map.player.inventory.addSpecialItem(this);
} else {
main_map.player.inventory.addStuff(this);
}
}
}
if(typeof this.image !== "undefined") {
let newHeight = this.size;
if(this.image.width != this.image.height) {
let aspectRatio = this.image.width / this.image.height;
newHeight /= aspectRatio;
pos_y += abs(newHeight-this.size)*0.5;
}
image(
this.image,
pos_x,
pos_y,
this.size,
newHeight
);
return true;
}
if(is_tick) {
if(this.amount_of_shadowblur <= 0) {
this.states_of_shadowblur = "up";
} else if(this.amount_of_shadowblur >= 10) {
this.states_of_shadowblur = "down";
}
if(this.states_of_shadowblur == "up") {
this.amount_of_shadowblur++;
} else if(this.states_of_shadowblur == "down") {
this.amount_of_shadowblur--;
}
}
return false;
}
setSize(size) {
this.size = size;
this.half_size = size*0.5;
}
}