Commit 68defa68 authored by Gwendoline's avatar Gwendoline
Browse files

it should color the character in blue when it is hit, but it doesn't. maybe no...

it should color the character in blue when it is hit, but it doesn't. maybe no one adds the action HIT in the actionvector when it is hit?
parent 0405862a
......@@ -46,20 +46,22 @@ public class EntityDisplayer implements Serializable {
//Get the good image
int dir = associatedEntity.getDirection().ordinal();
Animation animation;
if (associatedEntity.hasAction(Action.HIT)) {
animation = animationMapTab[dir].get(Action.HIT);
associatedEntity.removeAction(Action.HIT);
}
else if (associatedEntity.hasAction(Action.ATTACK)) {
if (associatedEntity.hasAction(Action.ATTACK)) {
animation = animationMapTab[dir].get(Action.ATTACK);
if (associatedEntity.hasAction(Action.HIT))
animation.setHIT(true);
associatedEntity.removeAction(Action.ATTACK);
}
else if (associatedEntity.hasAction(Action.WALK)) {
animation = animationMapTab[dir].get(Action.WALK);
if (associatedEntity.hasAction(Action.HIT))
animation.setHIT(true);
associatedEntity.removeAction(Action.WALK);
}
else {
animation = animationMapTab[dir].get(Action.NONE);
if (associatedEntity.hasAction(Action.HIT))
animation.setHIT(true);
}
Sprite sprite = new Sprite(animation.getSpriteImage());
GraphicsMapPoint entityPositionGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(associatedEntity.getX(), associatedEntity.getY());
......
package graphics.guiSkeleton.sprites;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
......@@ -21,6 +22,9 @@ public class Animation implements Serializable, Displayable
private int inFrameCounter = 0;
private int currentFrame = 0;
private List<Frame> frames = new ArrayList<Frame>();
private boolean HIT = false;
private int delay_HIT = 0;
private int delay_HIT_max = 5;
public Animation(Sprite spriteSheet, int[] delayTable)
{
......@@ -71,6 +75,10 @@ public class Animation implements Serializable, Displayable
}
}
public void setHIT (boolean b){
this.HIT = b;
}
public static void updateAnimation()
{
globalCounter++;
......@@ -80,7 +88,26 @@ public class Animation implements Serializable, Displayable
{
while (localCounter < globalCounter)
update();
return frames.get(currentFrame).getSpriteImage();
BufferedImage sprite = frames.get(currentFrame).getSpriteImage();
if (HIT){ //si on est blessé on colore l'image en rouge pendant le tempsdelay_HIT_max
int width = sprite.getWidth();
int height = sprite.getHeight();
WritableRaster raster = sprite.getRaster();
for (int xx = 0; xx < width; xx++) {
for (int yy = 0; yy < height; yy++) {
int[] pixels = raster.getPixel(xx, yy, (int[]) null);
pixels[0] = 0;
pixels[1] = 0;
pixels[2] = 255;
raster.setPixel(xx, yy, pixels);
}
}
this.delay_HIT++;
if (this.delay_HIT > this.delay_HIT_max) {this.delay_HIT = 0; this.HIT = false;}
}
return sprite;
}
public void restart()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment