forked from Pomax/Pjs-2D-Game-Engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecal.pde
executable file
·88 lines (77 loc) · 2.3 KB
/
Decal.pde
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
/**
* Decals cannot be interacted with in any way.
* They are things like the number of points on
* a hit, or the dust when you bump into something.
* Decals run through one state, and then expire,
* so they're basically triggered, temporary graphics.
*/
class Decal extends Sprite {
// indicates whether to kill off this decal
boolean remove = false;
// indicates whether this is an auto-expiring decal
boolean expiring = false;
// indicates how long this decal should live
protected int duration = -1;
// decals can be owned by something
Positionable owner = null;
/**
* non-expiring constructor
*/
Decal(String spritesheet, float x, float y) {
this(spritesheet, x, y, false, -1);
}
Decal(String spritesheet, int rows, int columns, float x, float y) {
this(spritesheet, rows, columns, x, y, false, -1);
}
/**
* expiring constructor
*/
Decal(String spritesheet, float x, float y, int duration) {
this(spritesheet, x, y, true, duration);
}
Decal(String spritesheet, int rows, int columns, float x, float y, int duration) {
this(spritesheet, rows, columns, x, y, true, duration);
}
/**
* full constructor (1 x 1 spritesheet)
*/
private Decal(String spritesheet, float x, float y, boolean expiring, int duration) {
this(spritesheet, 1, 1, x, y, expiring, duration);
}
/**
* full constructor (n x m spritesheet)
*/
private Decal(String spritesheet, int rows, int columns, float x, float y, boolean expiring, int duration) {
super(spritesheet, rows, columns);
setPosition(x,y);
this.expiring = expiring;
this.duration = duration;
if(expiring) { setPath(); }
}
/**
* subclasses must implement the path on which
* decals travel before they expire
*/
void setPath() {}
/**
* decals can be owned, in which case they inherit their
* position from their owner.
*/
void setOwner(Positionable owner) {
this.owner = owner;
}
// PREVENT PJS FROM GOING INTO AN ACCIDENTAL HIERARCHY LOOP
void draw() { super.draw(); }
void draw(float x, float y) { super.draw(x,y); }
/**
* Once expired, decals are cleaned up in Level
*/
void draw(float vx, float vy, float vw, float vh) {
if(!expiring || duration-->0) {
super.draw();
}
else {
remove = true;
}
}
}