Skip to content

Commit

Permalink
added attack particle effects
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisj42 committed Feb 22, 2018
1 parent 4947bd0 commit b8a24e9
Show file tree
Hide file tree
Showing 79 changed files with 637 additions and 27 deletions.
Binary file modified core/assets/sprites/entities.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
509 changes: 496 additions & 13 deletions core/assets/sprites/entities.txt

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion core/src/miniventure/game/world/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import miniventure.game.util.MyUtils;
import miniventure.game.world.entity.Entity;
import miniventure.game.world.entity.ItemEntity;
import miniventure.game.world.entity.Particle;
import miniventure.game.world.entity.mob.AiType;
import miniventure.game.world.entity.mob.Mob;
import miniventure.game.world.entity.mob.Player;
Expand Down Expand Up @@ -206,7 +207,13 @@ public void render(Rectangle renderSpace, SpriteBatch batch, float delta, Vector
objects.addAll(getOverlappingTiles(renderSpace)); // tiles first

Array<Entity> entities = getOverlappingEntities(renderSpace); // entities second
entities.sort((e1, e2) -> Float.compare(e2.getCenter().y, e1.getCenter().y));
entities.sort((e1, e2) -> {
if(e1 instanceof Particle && !(e2 instanceof Particle))
return 1;
if(!(e1 instanceof Particle) && e2 instanceof Particle)
return -1;
return Float.compare(e2.getCenter().y, e1.getCenter().y);
});
objects.addAll(entities);

for(WorldObject obj: objects)
Expand Down
29 changes: 21 additions & 8 deletions core/src/miniventure/game/world/entity/ActionParticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,28 @@
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.Array;

public class ActionParticle extends Entity {
public class ActionParticle extends Entity implements Particle {

// may be animated; lasts as long as the animation, or lasts a given time, with a single frame.

public enum ActionType {
SLASH(0.5f, true),
PUNCH(0.3f, true),
IMPACT(0.4f, false);

private final float animationTime;
private final boolean directional;

ActionType(float animationTime, boolean directional) {
this.animationTime = animationTime;
this.directional = directional;
}

public ActionParticle get(Direction dir) {
return new ActionParticle("particle/"+name().toLowerCase()+(directional?"-"+dir.name().toLowerCase():""), animationTime);
}
}

private Animation<TextureRegion> animation;
private final float animationTime;
private float timeElapsed;
Expand All @@ -23,13 +41,8 @@ public ActionParticle(String spriteName, float animationTime) {
this.animationTime = animationTime;
Array<AtlasRegion> frames = GameCore.entityAtlas.findRegions(spriteName);
animation = new Animation<>(animationTime / frames.size, frames);
}

@Override
public Rectangle getBounds() {
Rectangle bounds = super.getBounds();
bounds.setSize(1);
return bounds;

setSprite(animation.getKeyFrame(0));
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions core/src/miniventure/game/world/entity/Particle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package miniventure.game.world.entity;

public interface Particle {
}
2 changes: 1 addition & 1 deletion core/src/miniventure/game/world/entity/TextParticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import org.jetbrains.annotations.NotNull;

public class TextParticle extends BounceEntity {
public class TextParticle extends BounceEntity implements Particle {

@NotNull private final String text;
@NotNull private final Color main, shadow;
Expand Down
2 changes: 1 addition & 1 deletion core/src/miniventure/game/world/entity/mob/Mob.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class Mob extends Entity {
private static final float HURT_COOLDOWN = 0.5f; // minimum time between taking damage, in seconds; prevents a mob from getting hurt multiple times in quick succession.

@NotNull private Direction dir;
@NotNull private MobAnimationController animator;
@NotNull protected MobAnimationController animator;

private final int maxHealth;
private int health;
Expand Down
21 changes: 19 additions & 2 deletions core/src/miniventure/game/world/entity/mob/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import miniventure.game.item.Recipes;
import miniventure.game.world.Level;
import miniventure.game.world.WorldObject;
import miniventure.game.world.entity.ActionParticle;
import miniventure.game.world.entity.ActionParticle.ActionType;
import miniventure.game.world.entity.mob.MobAnimationController.AnimationState;
import miniventure.game.world.tile.Tile;

import com.badlogic.gdx.Gdx;
Expand Down Expand Up @@ -97,6 +100,9 @@ public void checkInput(@NotNull Vector2 mouseInput) {
attack();
else if (pressingKey(Input.Keys.V))
interact();

//if(Gdx.input.isKeyPressed(Input.Keys.C) || Gdx.input.isKeyPressed(Input.Keys.V))
// animator.requestState(AnimationState.ATTACK);
}

hands.resetItemUsage();
Expand Down Expand Up @@ -181,9 +187,20 @@ private Array<WorldObject> getInteractionQueue() {
}

private void attack() {
for(WorldObject obj: getInteractionQueue())
if(hands.attack(obj))
Level level = getLevel();

for(WorldObject obj: getInteractionQueue()) {
if (hands.attack(obj)) {
if(level != null)
level.addEntity(ActionParticle.ActionType.SLASH.get(getDirection()), getCenter().add(getDirection().getVector().scl(getSize().scl(0.5f)))/*getInteractionRect().getCenter(new Vector2())*/, true);
return;
}
}

// didn't hit anything

if(level != null)
level.addEntity(ActionParticle.ActionType.PUNCH.get(getDirection()), /*getCenter().add(getDirection().getVector().scl(getSize().scl(0.5f)))*/getInteractionRect().getCenter(new Vector2()), true);
}

private void interact() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import miniventure.game.item.ToolItem.Material;
import miniventure.game.item.ToolType;
import miniventure.game.world.ItemDrop;
import miniventure.game.world.Level;
import miniventure.game.world.WorldObject;
import miniventure.game.world.entity.ActionParticle;
import miniventure.game.world.entity.TextParticle;
import miniventure.game.world.entity.mob.Mob;

Expand Down Expand Up @@ -79,6 +81,9 @@ boolean tileAttacked(@NotNull Tile tile, @NotNull Mob attacker, @NotNull Item at

boolean tileAttacked(Tile tile, WorldObject attacker, int damage) {
if(damage > 0) {
// add damage particle
tile.getLevel().addEntity(ActionParticle.ActionType.IMPACT.get(null), tile.getCenter(), true);

int health = totalHealth > 1 ? new Integer(tile.getData(getClass(), tileType, HEALTH_IDX)) : 1;
health -= damage;
if(totalHealth > 1)
Expand Down
Binary file added sprites/entity-sprites/particle/impact_00.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_02.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_03.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_04.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_05.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_06.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_07.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_08.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_09.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_11.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/impact_12.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-down_00.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-down_01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-down_02.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-down_03.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-down_04.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-down_05.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-left_00.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-left_01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-left_02.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-left_03.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-left_04.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprites/entity-sprites/particle/punch-left_05.png
Binary file added sprites/entity-sprites/particle/punch-right_00.png
Binary file added sprites/entity-sprites/particle/punch-right_01.png
Binary file added sprites/entity-sprites/particle/punch-right_02.png
Binary file added sprites/entity-sprites/particle/punch-right_03.png
Binary file added sprites/entity-sprites/particle/punch-right_04.png
Binary file added sprites/entity-sprites/particle/punch-right_05.png
Binary file added sprites/entity-sprites/particle/punch-up_00.png
Binary file added sprites/entity-sprites/particle/punch-up_01.png
Binary file added sprites/entity-sprites/particle/punch-up_02.png
Binary file added sprites/entity-sprites/particle/punch-up_03.png
Binary file added sprites/entity-sprites/particle/punch-up_04.png
Binary file added sprites/entity-sprites/particle/punch-up_05.png
Binary file added sprites/entity-sprites/particle/slash-down_00.png
Binary file added sprites/entity-sprites/particle/slash-down_01.png
Binary file added sprites/entity-sprites/particle/slash-down_02.png
Binary file added sprites/entity-sprites/particle/slash-down_03.png
Binary file added sprites/entity-sprites/particle/slash-down_04.png
Binary file added sprites/entity-sprites/particle/slash-down_05.png
Binary file added sprites/entity-sprites/particle/slash-down_06.png
Binary file added sprites/entity-sprites/particle/slash-down_07.png
Binary file added sprites/entity-sprites/particle/slash-left_00.png
Binary file added sprites/entity-sprites/particle/slash-left_01.png
Binary file added sprites/entity-sprites/particle/slash-left_02.png
Binary file added sprites/entity-sprites/particle/slash-left_03.png
Binary file added sprites/entity-sprites/particle/slash-left_04.png
Binary file added sprites/entity-sprites/particle/slash-left_05.png
Binary file added sprites/entity-sprites/particle/slash-left_06.png
Binary file added sprites/entity-sprites/particle/slash-left_07.png
Binary file added sprites/entity-sprites/particle/slash-right_00.png
Binary file added sprites/entity-sprites/particle/slash-right_01.png
Binary file added sprites/entity-sprites/particle/slash-right_02.png
Binary file added sprites/entity-sprites/particle/slash-right_03.png
Binary file added sprites/entity-sprites/particle/slash-right_04.png
Binary file added sprites/entity-sprites/particle/slash-right_05.png
Binary file added sprites/entity-sprites/particle/slash-right_06.png
Binary file added sprites/entity-sprites/particle/slash-right_07.png
Binary file added sprites/entity-sprites/particle/slash-up_00.png
Binary file added sprites/entity-sprites/particle/slash-up_01.png
Binary file added sprites/entity-sprites/particle/slash-up_02.png
Binary file added sprites/entity-sprites/particle/slash-up_03.png
Binary file added sprites/entity-sprites/particle/slash-up_04.png
Binary file added sprites/entity-sprites/particle/slash-up_05.png
Binary file added sprites/entity-sprites/particle/slash-up_06.png
Binary file added sprites/entity-sprites/particle/slash-up_07.png
83 changes: 82 additions & 1 deletion sprites/entity_spritesheet.tps
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<key>fileFormatVersion</key>
<int>4</int>
<key>texturePackerVersion</key>
<string>4.5.0</string>
<string>4.6.2</string>
<key>fileName</key>
<string>/home/chris/Documents/minicraft/miniventure/sprites/entity_spritesheet.tps</string>
<key>autoSDSettings</key>
Expand Down Expand Up @@ -199,6 +199,87 @@
</struct>
<key>individualSpriteSettings</key>
<map type="IndividualSpriteSettingsMap">
<key type="filename">entity-sprites/particle/impact_00.png</key>
<key type="filename">entity-sprites/particle/impact_01.png</key>
<key type="filename">entity-sprites/particle/impact_02.png</key>
<key type="filename">entity-sprites/particle/impact_03.png</key>
<key type="filename">entity-sprites/particle/impact_04.png</key>
<key type="filename">entity-sprites/particle/impact_05.png</key>
<key type="filename">entity-sprites/particle/impact_06.png</key>
<key type="filename">entity-sprites/particle/impact_07.png</key>
<key type="filename">entity-sprites/particle/impact_08.png</key>
<key type="filename">entity-sprites/particle/impact_09.png</key>
<key type="filename">entity-sprites/particle/impact_10.png</key>
<key type="filename">entity-sprites/particle/impact_11.png</key>
<key type="filename">entity-sprites/particle/impact_12.png</key>
<key type="filename">entity-sprites/particle/punch-down_00.png</key>
<key type="filename">entity-sprites/particle/punch-down_01.png</key>
<key type="filename">entity-sprites/particle/punch-down_02.png</key>
<key type="filename">entity-sprites/particle/punch-down_03.png</key>
<key type="filename">entity-sprites/particle/punch-down_04.png</key>
<key type="filename">entity-sprites/particle/punch-down_05.png</key>
<key type="filename">entity-sprites/particle/punch-left_00.png</key>
<key type="filename">entity-sprites/particle/punch-left_01.png</key>
<key type="filename">entity-sprites/particle/punch-left_02.png</key>
<key type="filename">entity-sprites/particle/punch-left_03.png</key>
<key type="filename">entity-sprites/particle/punch-left_04.png</key>
<key type="filename">entity-sprites/particle/punch-left_05.png</key>
<key type="filename">entity-sprites/particle/punch-right_00.png</key>
<key type="filename">entity-sprites/particle/punch-right_01.png</key>
<key type="filename">entity-sprites/particle/punch-right_02.png</key>
<key type="filename">entity-sprites/particle/punch-right_03.png</key>
<key type="filename">entity-sprites/particle/punch-right_04.png</key>
<key type="filename">entity-sprites/particle/punch-right_05.png</key>
<key type="filename">entity-sprites/particle/punch-up_00.png</key>
<key type="filename">entity-sprites/particle/punch-up_01.png</key>
<key type="filename">entity-sprites/particle/punch-up_02.png</key>
<key type="filename">entity-sprites/particle/punch-up_03.png</key>
<key type="filename">entity-sprites/particle/punch-up_04.png</key>
<key type="filename">entity-sprites/particle/punch-up_05.png</key>
<key type="filename">entity-sprites/particle/slash-down_00.png</key>
<key type="filename">entity-sprites/particle/slash-down_01.png</key>
<key type="filename">entity-sprites/particle/slash-down_02.png</key>
<key type="filename">entity-sprites/particle/slash-down_03.png</key>
<key type="filename">entity-sprites/particle/slash-down_04.png</key>
<key type="filename">entity-sprites/particle/slash-down_05.png</key>
<key type="filename">entity-sprites/particle/slash-down_06.png</key>
<key type="filename">entity-sprites/particle/slash-down_07.png</key>
<key type="filename">entity-sprites/particle/slash-left_00.png</key>
<key type="filename">entity-sprites/particle/slash-left_01.png</key>
<key type="filename">entity-sprites/particle/slash-left_02.png</key>
<key type="filename">entity-sprites/particle/slash-left_03.png</key>
<key type="filename">entity-sprites/particle/slash-left_04.png</key>
<key type="filename">entity-sprites/particle/slash-left_05.png</key>
<key type="filename">entity-sprites/particle/slash-left_06.png</key>
<key type="filename">entity-sprites/particle/slash-left_07.png</key>
<key type="filename">entity-sprites/particle/slash-right_00.png</key>
<key type="filename">entity-sprites/particle/slash-right_01.png</key>
<key type="filename">entity-sprites/particle/slash-right_02.png</key>
<key type="filename">entity-sprites/particle/slash-right_03.png</key>
<key type="filename">entity-sprites/particle/slash-right_04.png</key>
<key type="filename">entity-sprites/particle/slash-right_05.png</key>
<key type="filename">entity-sprites/particle/slash-right_06.png</key>
<key type="filename">entity-sprites/particle/slash-right_07.png</key>
<key type="filename">entity-sprites/particle/slash-up_00.png</key>
<key type="filename">entity-sprites/particle/slash-up_01.png</key>
<key type="filename">entity-sprites/particle/slash-up_02.png</key>
<key type="filename">entity-sprites/particle/slash-up_03.png</key>
<key type="filename">entity-sprites/particle/slash-up_04.png</key>
<key type="filename">entity-sprites/particle/slash-up_05.png</key>
<key type="filename">entity-sprites/particle/slash-up_06.png</key>
<key type="filename">entity-sprites/particle/slash-up_07.png</key>
<struct type="IndividualSpriteSettings">
<key>pivotPoint</key>
<point_f>0.5,0.5</point_f>
<key>scale9Enabled</key>
<false/>
<key>scale9Borders</key>
<rect>8,8,16,16</rect>
<key>scale9Paddings</key>
<rect>8,8,16,16</rect>
<key>scale9FromFile</key>
<false/>
</struct>
<key type="filename">entity-sprites/player/idle-down_1.png</key>
<key type="filename">entity-sprites/player/idle-up_1.png</key>
<struct type="IndividualSpriteSettings">
Expand Down

0 comments on commit b8a24e9

Please sign in to comment.