-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sprite.java
54 lines (46 loc) · 1.33 KB
/
Sprite.java
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
import java.awt.Graphics;
public abstract class Sprite {
int x, y, w, h;
Model model;
//////////////////////////////////////
/////////// Abstract Methods /////////
//////////////////////////////////////
public abstract void update();
public abstract void draw(Graphics g);
public abstract Json marshal();
//////////////////////////////////////
/////// Identification Methods ///////
//////////////////////////////////////
public boolean isBrick() {
return false;
}
public boolean isMario() {
return false;
}
public boolean isCoin() {
return false;
}
public boolean isCoinBlock() {
return false;
}
//////////////////////////////////////
////////// Utility Methods ///////////
//////////////////////////////////////
public abstract Sprite cloneSprite(Model m);
public boolean checkCollision(Model m, Sprite a, Sprite b) {
// Check left of brick
if (a.x + m.cameraPos + a.w < b.x)
return false;
// Check right of brick
else if (a.x + m.cameraPos > b.x + b.w)
return false;
// Check top of the brick
else if (a.y + a.h < b.y)
return false;
// Check bottom of brick
else if (a.y > b.y + b.h)
return false;
else
return true;
}
}