-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStickyweb.java
More file actions
86 lines (66 loc) · 1.92 KB
/
Stickyweb.java
File metadata and controls
86 lines (66 loc) · 1.92 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
package entity;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class Stickyweb extends Entity {
private boolean hasHit;
private boolean shouldRemove;
private BufferedImage[] sprites;
private BufferedImage[] hitSprites;
public Stickyweb(double floor, boolean isRight) {
super(floor);
moveSpeed = 3.8;
if(isRight) dx = moveSpeed;
else dx = -moveSpeed;
width = 30;
height = 30;
collisionWidth = 15;
collisionHeight = 15;
// load sprites
try {
BufferedImage spritesheet = ImageIO.read(getClass().getClassLoader().getResourceAsStream("resources/sprites/player/stickyweb.png"));
sprites = new BufferedImage[1];
sprites[0] = spritesheet.getSubimage(0, 0, width, height);
hitSprites = new BufferedImage[1];
hitSprites[0] = spritesheet.getSubimage(0, height, width, height);
animation = new Animation();
animation.setFrames(sprites);
animation.setDelay(80);
}
catch (Exception e) {
e.printStackTrace();
}
}
// gets called to figure out whether or not the bullet has hit something
public void setHit() {
if(hasHit) return;
hasHit = true;
animation.setFrames(hitSprites);
animation.setDelay(200);
dx = 0;
}
public boolean shouldRemove() { return shouldRemove; }
public void update() {
checkTileMapCollision();
setPosition(xtemp, ytemp);
if(dx == 0 & !hasHit) {
setHit();
}
animation.update();
if(hasHit && animation.hasPlayedOnce()) {
shouldRemove = true;
}
}
public void draw(Graphics2D graphics) {
if(isRight) {
if(!hasHit)
graphics.drawImage(animation.getImage(),(int)x, (int)y, null);
else
graphics.drawImage(animation.getImage(),(int)x + 20, (int)y, null);
}
// draws the sprite inverted to left
else {
graphics.drawImage(animation.getImage(),(int)(x + width), (int)y, -width, height, null);
}
}
}