Commit 0637e5f2 authored by Gwendoline's avatar Gwendoline
Browse files

I created a new version of Entity Display, in order to have a class for every...

I created a new version of Entity Display, in order to have a class for every anmation type. I don't think it is correct but I can't compile the project for now so
parent 9b23cdca
package graphics.guiSkeleton.entityDisplayer;
import core.gamestate.Action;
import core.gamestate.Entity;
import graphics.guiSkeleton.SpriteStorage;
import graphics.guiSkeleton.mapManagement.GraphicsMapPoint;
import graphics.guiSkeleton.mapManagement.PositionedSprite;
import java.io.Serializable;
import graphics.guiSkeleton.mapManagement.GraphicsMap;
import graphics.guiSkeleton.sprites.Sprite;
/**
* Created by dupriez on 14/11/15.
*
* Each entity should have one instance of a subclass of this class
* It is used by the gui to know how to display the said entity
*/
abstract public class EntityDisplayer implements Serializable {
// les images doivent avoir leurs animations alignées horizontalement
//The Entity this Displayer is associated to
private Entity associatedEntity;
int sprite_num; // le numéro d'image où on en est de l'animation
int persofixe[][] = new int[8][4]; // dim 1 : directions, dim 2 : case 0: position sur la sprite, 1: hauteur, 2: largeur, 3: nb_images
int marche[][] = new int[8][4];
int attaque[][] = new int[8][4];
int touche[][] = new int[8][4];
final static int DEFAULT_SPRITE=1;
public EntityDisplayer(Entity associatedEntity, int sprite_num, int[] nb_images,
int[][] persofixe, int[][] marche, int[][] attaque1, int[][] hit) {
this.associatedEntity = associatedEntity;
this.sprite_num = sprite_num;
for (int i =0; i<persofixe.length-1; i++){
System.arraycopy(persofixe[i], 0, this.persofixe[i], 0, this.persofixe[i].length);
System.arraycopy(marche[i], 0, this.marche[i], 0, this.marche[i].length);
System.arraycopy(attaque[i], 0, this.attaque[i], 0, this.attaque[i].length);
System.arraycopy(touche[i], 0, this.touche[i], 0, this.touche[i].length);
}
}
public PositionedSprite getPositionedSprite(GraphicsMap graphicsMap) {
/**
* The purpose of this function is to be called by the gui when it displays the entity related to this displayer
* @param graphicsMap: the GraphicsMap of the map the associatedEntity is on
* @return The PositionedSprite that the gui should display to represent this entity
*/
Sprite sprite = SpriteStorage.getInstance().getRonflex();
Entity entity = getAssociatedEntity();
GraphicsMapPoint entityPositionGraphicsMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
//applying translation
GraphicsMapPoint spriteTopLeftGraphicsMapPoint = entityPositionGraphicsMapPoint.translate(-sprite_width / 2, -sprite_height / 2);
int direction = entity.getDirection().ordinal();
int x_sprite = 0;
int y_sprite = 0;
int sprite_height = 0;
int sprite_width = 0;
int nbSprites = DEFAULT_SPRITE;
int index = direction / 45;
if (entity.hasAction(STAND)) {
y_sprite = persofixe[index][0];
sprite_height = persofixe[index][1];
sprite_width = persofixe[index][2];
nbSprites = persofixe[index][3];
} else if (entity.hasAction(WALK)) {
y_sprite = marche[index][0];
sprite_height = marche[index][1];
sprite_width = marche[index][2];
nbSprites = marche[index][3];
} else if (entity.hasAction(ATTACK)) {
y_sprite = attaque[index][0];
sprite_height = attaque[index][1];
sprite_width = attaque[index][2];
nbSprites = attaque[index][3];
} else if (entity.hasAction(HIT)) {
y_sprite = touche[index][0];
sprite_height = touche[index][1];
sprite_width = touche[index][2];
nbSprites = touche[index][3];
}
sprite_num = (sprite_num + 1) % (10 * nbSprites);
for (int u = 0; u < nbSprites; u++) {
if (sprite_num < 10 * u) x_sprite = x_sprite + sprite_width;
}
Sprite res = new Sprite((sprite.getSpriteImage()).getSubimage(x_sprite, y_sprite, sprite_height, sprite_width));
return PositionedSprite.PositionSprite(res, spriteTopLeftGraphicsMapPoint);
}
public Entity getAssociatedEntity() {
return associatedEntity;
}
}
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