Skip to content

Commit

Permalink
Parameterize Particle
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhendriks committed Oct 2, 2015
1 parent 678b700 commit d4bec50
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ public class EntityData {

public float moveSpeed;
public int hitPoints;

public int damage;
public int explosionId = -1;
public float animationSpeed; // in frames per second

public EntityData() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public EntityRepository(Map map, Recolorer recolorer) throws SlickException {
createStructure(CONSTRUCTION_YARD, "structures/2x2_constyard.png", 64, 64, 5, 1000);
createStructure(REFINERY, "structures/3x2_refinery.png", 96, 64, 5, 1500);

createParticle(EXPLOSION_NORMAL, "explosions/explosion_3.png", 48, 48);
createParticle(EXPLOSION_NORMAL, "explosions/explosion_3.png", 48, 48, 3f);

createProjectile(ROCKET, "missiles/Bullet_LargeRocket.png", 48, 48, EXPLOSION_NORMAL, 160f, 200);
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public Entity placeOnMap(Vector2D mapCoordinate, EntityData entityData, Player p
break;
case PARTICLE:
spriteSheet = new SpriteSheet(recoloredImage, entityData.width, entityData.height);
createdEntity = new Particle(mapCoordinate, spriteSheet, this);
createdEntity = new Particle(mapCoordinate, spriteSheet, entityData, this);
entitiesSet.add(createdEntity);
break;
default:
Expand All @@ -122,8 +122,9 @@ public void createProjectile(int id, String pathToImage, int widthInPixels, int
entity.explosionId = explosionId;
}

public void createParticle(int id, String pathToImage, int widthInPixels, int heightInPixels) throws SlickException {
createEntity(id, pathToImage, widthInPixels, heightInPixels, EntityType.PARTICLE, -1, -1, -1);
public void createParticle(int id, String pathToImage, int widthInPixels, int heightInPixels, float framesPerSecond) throws SlickException {
EntityData entity = createEntity(id, pathToImage, widthInPixels, heightInPixels, EntityType.PARTICLE, -1, -1, -1);
entity.animationSpeed = framesPerSecond;
}

public void createStructure(int id, String pathToImage, int widthInPixels, int heightInPixels, int sight, int hitPoints) throws SlickException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.fundynamic.d2tm.game.behaviors.Destructible;
import com.fundynamic.d2tm.game.entities.Entity;
import com.fundynamic.d2tm.game.entities.EntityData;
import com.fundynamic.d2tm.game.entities.EntityRepository;
import com.fundynamic.d2tm.game.entities.EntityType;
import com.fundynamic.d2tm.math.Vector2D;
Expand All @@ -14,9 +15,11 @@ public class Particle extends Entity implements Destructible {

boolean destroyed = false;
private float sprite = 0;
private float animationSpeed;

public Particle(Vector2D mapCoordinates, SpriteSheet spriteSheet, EntityRepository entityRepository) {
public Particle(Vector2D mapCoordinates, SpriteSheet spriteSheet, EntityData entityData, EntityRepository entityRepository) {
super(mapCoordinates, spriteSheet, 0, null, entityRepository);
animationSpeed = entityData.animationSpeed;
}

@Override
Expand All @@ -37,7 +40,7 @@ public Image getSprite() {

@Override
public void update(float deltaInSeconds) {
sprite += 3f * deltaInSeconds;
sprite += animationSpeed * deltaInSeconds;

if (sprite >= spriteSheet.getHorizontalCount()) {
destroyed = true;
Expand Down

0 comments on commit d4bec50

Please sign in to comment.