MovementNotify mn = (MovementNotify)arg;
// Log.info("notifica da UserInputController: "+mn.toString());
Actor gigiActor = getPlayerActor();
gigiActor.setStato(Helper.MOVIMENTO);
Entity gigi = gigiActor.getEntity();
boolean keyUp= mn.movement.equalsIgnoreCase(Helper.UP_DIR);
boolean keyDown= mn.movement.equalsIgnoreCase(Helper.DOWN_DIR);
boolean keyLeft= mn.movement.equalsIgnoreCase(Helper.LEFT_DIR);
boolean keyRight= mn.movement.equalsIgnoreCase(Helper.RIGHT_DIR);
int delta = mn.delta;
// associazione tasto/notifica a gigi del movimento voluto
if (keyRight) {
if (tryToMoveEntity(gigi,Helper.MOVE_SPEED,0)){
gigi.addHorizontalMovement(Helper.MOVE_SPEED);
gigi.getPlayerWalkRight().update(delta);
gigi.setMovementRight();
} else {
gigi.addHorizontalMovement(-Helper.GIGI_CONTROMOVIMENTO);
}
}
if (keyLeft) {
if (tryToMoveEntity(gigi,-Helper.MOVE_SPEED*1,0) ){
gigi.addHorizontalMovement(- Helper.MOVE_SPEED);
gigi.getPlayerWalkLeft().update(delta);
gigi.setMovementLeft();
} else {
gigi.addHorizontalMovement(Helper.GIGI_CONTROMOVIMENTO);
}
}
if (keyUp) {
if (tryToMoveEntity(gigi,0,-Helper.MOVE_SPEED*1)){
gigi.addVerticalMovement(- Helper.MOVE_SPEED);
gigi.getPlayerWalkUp().update(delta);
gigi.setMovementUp();
} else {
gigi.addVerticalMovement(Helper.GIGI_CONTROMOVIMENTO);
}
}
if (keyDown) {
if (tryToMoveEntity(gigi,0,Helper.MOVE_SPEED*1)){
gigi.addVerticalMovement(Helper.MOVE_SPEED);
gigi.getPlayerWalkDown().update(delta);
gigi.setMovementDown();
} else {
gigi.addVerticalMovement(-Helper.GIGI_CONTROMOVIMENTO);
}
}
// devo informare tutti gli altri attori di questo movimento!
for (int i = 0; i < actors.size(); i++) {
Actor actor = actors.get(i);
// evito di dirlo a gigi :P
if (actor.getAgent()!=null){
actor.getAgent().setPlayerMove(gigi.lastDirection);
}
}
}
// mi � arrivata notifica di movimento da un agente
if (o.getClass()==AgentInputController.class && arg.getClass() == MovementNotify.class){
MovementNotify mn = (MovementNotify)arg;
// Log.info("notifica da UserInputController: "+mn.toString());
Actor actorActor = getActorAgentByID(mn.entityID);
actorActor.setStato(Helper.MOVIMENTO);
Entity actor = actorActor.getEntity();
boolean keyUp= mn.movement.equalsIgnoreCase(Helper.UP_DIR);
boolean keyDown= mn.movement.equalsIgnoreCase(Helper.DOWN_DIR);
boolean keyLeft= mn.movement.equalsIgnoreCase(Helper.LEFT_DIR);
boolean keyRight= mn.movement.equalsIgnoreCase(Helper.RIGHT_DIR);
int delta = mn.delta;
// associazione tasto/notifica all'agente del movimento voluto
if (keyRight) {
if (tryToMoveEntity(actor,Helper.MOVE_SPEED*3,0)){
actor.addHorizontalMovement(Helper.MOVE_SPEED*3);
actor.getPlayerWalkRight().update(delta);
actor.setMovementRight();
}
}
if (keyLeft) {
if (tryToMoveEntity(actor,-Helper.MOVE_SPEED*3,0) ){
actor.addHorizontalMovement(- Helper.MOVE_SPEED*3);
actor.getPlayerWalkLeft().update(delta);
actor.setMovementLeft();
}
}
if (keyUp) {
if (tryToMoveEntity(actor,0,-Helper.MOVE_SPEED*3)){
actor.addVerticalMovement(- Helper.MOVE_SPEED*3);
actor.getPlayerWalkUp().update(delta);
actor.setMovementUp();
}
}
if (keyDown) {
if (tryToMoveEntity(actor,0,Helper.MOVE_SPEED*3)){
actor.addVerticalMovement(Helper.MOVE_SPEED*3);
actor.getPlayerWalkDown().update(delta);
actor.setMovementDown();
}
}
try {
actorActor.getAgent().getTS().getAg().addBel(Literal.parseLiteral("own_position(" + actor.getX() + "," + actor.getY() +")"));
} catch (RevisionFailedException e) {
e.printStackTrace();
}
}
// mi � arrivata notifica dell'attacco da parte dell'utente
if (o.getClass() == UserInputController.class && arg.getClass() == AttackNotify.class){
AttackNotify an = (AttackNotify)arg;
// Log.info("notifica da UserInputController: "+an.toString());
Actor gigi = getActorAgentByID(an.entityID);
gigi.setStato(Helper.ATTACCO);
Entity gigiEntity= gigi.getEntity();
if (gigiEntity.getLastDirection()== null){
return;
}
boolean keyUp= gigiEntity.getLastDirection().equalsIgnoreCase(Helper.UP_DIR);
boolean keyDown= gigiEntity.getLastDirection().equalsIgnoreCase(Helper.DOWN_DIR);
boolean keyLeft= gigiEntity.getLastDirection().equalsIgnoreCase(Helper.LEFT_DIR);
boolean keyRight= gigiEntity.getLastDirection().equalsIgnoreCase(Helper.RIGHT_DIR);
int delta = an.delta;
if (keyUp){
if (tryToMoveEntity(gigiEntity,0,-Helper.GIGI_ATTACK_SPEED)){
gigiEntity.addVerticalMovement(-Helper.MOVE_SPEED);
gigiEntity.getAnimAttackUp().update(delta);
gigiEntity.setAttackUp();
} else {
// potrei aver beccato un'entit�!
if (collideWithEntity(gigiEntity,0,-Helper.GIGI_ATTACK_SPEED)){
Log.info("collisione con entit�");
collisione(gigiEntity,0,-Helper.GIGI_ATTACK_SPEED);
}
}
}
if (keyDown){
if (tryToMoveEntity(gigiEntity,0,Helper.GIGI_ATTACK_SPEED)){
gigiEntity.addVerticalMovement(Helper.MOVE_SPEED);
gigiEntity.getAnimAttackDown().update(delta);
gigiEntity.setAttackDown();
}else {
// potrei aver beccato un'entit�!
if (collideWithEntity(gigiEntity,0,-Helper.GIGI_ATTACK_SPEED)){
Log.info("collisione con entit�");
collisione(gigiEntity,0,-Helper.GIGI_ATTACK_SPEED);
}
}
}
if (keyLeft){
if (tryToMoveEntity(gigiEntity,-Helper.GIGI_ATTACK_SPEED,0)){
gigiEntity.addHorizontalMovement(-Helper.MOVE_SPEED);
gigiEntity.getAnimAttackLeft().update(delta);
gigiEntity.setAttackLeft();
}else {
// potrei aver beccato un'entit�!
if (collideWithEntity(gigiEntity,0,-Helper.GIGI_ATTACK_SPEED)){
Log.info("collisione con entit�");
collisione(gigiEntity,0,-Helper.GIGI_ATTACK_SPEED);
}
}
}
if (keyRight){
if (tryToMoveEntity(gigiEntity,Helper.GIGI_ATTACK_SPEED,0)){
gigiEntity.addHorizontalMovement(Helper.MOVE_SPEED);
gigiEntity.getAnimAttackRight().update(delta);
gigiEntity.setAttackRight();
}else {
// potrei aver beccato un'entit�!
if (collideWithEntity(gigiEntity,0,-Helper.GIGI_ATTACK_SPEED)){
Log.info("collisione con entit�");
collisione(gigiEntity,0,-Helper.GIGI_ATTACK_SPEED);