-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathParticle.java
More file actions
89 lines (72 loc) · 2.6 KB
/
Particle.java
File metadata and controls
89 lines (72 loc) · 2.6 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
package com.fundynamic.d2tm.game.entities.particle;
import com.fundynamic.d2tm.game.behaviors.Destructible;
import com.fundynamic.d2tm.game.entities.Entity;
import com.fundynamic.d2tm.game.entities.EntityRepository;
import com.fundynamic.d2tm.game.entities.EntityType;
import com.fundynamic.d2tm.game.types.EntityData;
import com.fundynamic.d2tm.math.Coordinate;
import com.fundynamic.d2tm.math.Random;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SpriteSheet;
public class Particle extends Entity implements Destructible {
private boolean destroyed = false;
private float sprite = 0;
private float animationSpeed;
private float alpha = 1.0f;
private float scale = 1.0f;
public Particle(Coordinate coordinate, SpriteSheet spriteSheet, EntityData entityData, EntityRepository entityRepository) {
super(coordinate, spriteSheet, entityData, null, entityRepository);
animationSpeed = entityData.animationSpeed;
// scale += Math.random() * 3;
}
@Override
public EntityType getEntityType() {
return EntityType.PARTICLE;
}
@Override
public void render(Graphics graphics, int x, int y) {
if (graphics == null) throw new IllegalArgumentException("Graphics must be not-null");
Image sprite = getSprite();
sprite.setImageColor(1, 1, 1, alpha);
sprite.draw(x, y, scale);
sprite.setImageColor(1, 1, 1, 1);
graphics.resetTransform();
graphics.scale(1f,1f);
}
public Image getSprite() {
return spritesheet.getSprite((int) sprite, 0);
}
@Override
public void update(float deltaInSeconds) {
sprite += EntityData.getRelativeSpeed(animationSpeed, deltaInSeconds);
if ("SMOKE".equals(this.entityData.name)) {
alpha = 1f - (sprite / spritesheet.getHorizontalCount());
} else {
alpha = 1.5f - (sprite / spritesheet.getHorizontalCount()); // all other sprites never fade out entirely
}
if (sprite >= spritesheet.getHorizontalCount()) {
destroyed = true;
}
}
@Override
public void takeDamage(int hitPoints, Entity origin) {
// particles can't take damage...
}
@Override
public boolean isDestroyed() {
return destroyed;
}
@Override
public int getHitPoints() {
return 0;
}
@Override
public String toString() {
return "Particle{" +
"destroyed=" + destroyed +
", sprite=" + sprite +
", animationSpeed=" + animationSpeed +
'}';
}
}