Package it.timehero.entities

Examples of it.timehero.entities.Entity


   */
  private boolean collideWithEntity(Entity ent, float x, float y) {

    for (int p=0;p<getActorSize();p++) {
      for (int s=p+1;s<getActorSize();s++) {
        Entity me = (Entity) getActor(p).getEntity();
        Entity him = (Entity) getActor(s).getEntity();
        if (me.collidesWith(him,x,y)) {
          return true;
        }
      }
    }
View Full Code Here


   * @return entit� con la quale ent andr� in collisione, null se nessuna
   */
  private Entity entityCollision(Entity ent, float x, float y) {

    for (int p=0;p<getActorSize();p++) {
      Entity other = (Entity) getActor(p).getEntity();
      if ( !ent.equals(other) && ent.collidesWith(other,x,y)) {
          return other;
        }
      }
    return null;
View Full Code Here

      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);
View Full Code Here

   * Render everything on screen
   */
  public void render(GameContainer game, StateBasedGame state, Graphics g)
      throws SlickException {

    Entity gigi = world.getPlayerActor().getEntity();

    // draw the appropriate section of the tilemap based on the centre
    // (hence the -(TANK_SIZE/2)) of the player
    int playerTileX = (int) gigi.getX();
    int playerTileY = (int) gigi.getY();

    // caculate the offset of the player from the edge of the tile. As the
    // player moves around this varies and this tells us how far to offset the tile based rendering
    // to give the smooth motion of scrolling
    int playerTileOffsetX = (int) ((playerTileX - gigi.getX()) * world
        .getTileSize());
    int playerTileOffsetY = (int) ((playerTileY - gigi.getY()) * world
        .getTileSize());

    // render the section of the map that should be visible. Notice the -1
    // and +3 which renders a little extra map around the edge of the screen to cope with tiles
    // scrolling on and off the screen
    world.render(playerTileOffsetX - (gigi.ENTITY_SPRITE_SIZE / 2),
        playerTileOffsetY - (gigi.ENTITY_SPRITE_SIZE / 2), playerTileX
            - leftOffsetInTiles - 1, playerTileY - topOffsetInTiles
            - 1, widthInTiles + 3, heightInTiles + 3);

    // draw entities relative to the player that must appear in the centre
    // of the screen
    g.translate(400 - (int) (gigi.getX() * 32)300 - (int) (gigi.getY() * 32));

    // draw objects
    for (int i = 0; i < world.getOggettiSize(); i++) {
      OggettoGenerico og = ((OggettoGenerico)world.getOggetto(i));
      og.draw(g);
    }
   
    // remove actors with hit points < 0
    world.removeDeadActors();

    // draw entities
    for (int i = 0; i < world.getActorSize(); i++) {
      Entity ent = world.getActor(i).getEntity();
      ent.draw(g);
    }
   
    g.resetTransform();

    // draw user interface
View Full Code Here

   * @param x
   * @param y
   */
  private void collisione(Entity me, float x, float y) {

    Entity him = entityCollision(me,x,y);
    if (him == null) return;
     
    Actor meActor = findActor(me);
    Actor nemico = findActor(him);
    if (meActor==null || nemico==null) return;
View Full Code Here

   * @param numAnimazioni
   * @throws SlickException
   */
  public Gigi() {
      try {
      entity = new Entity(30,12, "data/grafica/hero3.gif",25,32,0,2,1,3,0,3);
    } catch (SlickException e) {
      e.printStackTrace();
    }
    setID(Helper.GIGI);
  }
View Full Code Here

    // brute force collisions, compare every entity against
    // every other entity. If any of them collide notify
    // both entities that the collision has occured
    for (int p=0;p<world.getActorSize();p++) {
      for (int s=p+1;s<world.getActorSize();s++) {
        Entity me = (Entity) world.getActor(p).getEntity();
        Entity him = (Entity) world.getActor(s).getEntity();
        if (me.collidesWith(him)) {
          me.collidedWith(him);
          him.collidedWith(me);
        }
      }
    }
     
    Entity gigi = world.getPlayerActor().getEntity();
   
        // draw the appropriate section of the tilemap based on the centre (hence the -(TANK_SIZE/2)) of
        // the player
        int playerTileX = (int) gigi.getX();
        int playerTileY = (int) gigi.getY();
        
        // caculate the offset of the player from the edge of the tile. As the player moves around this
        // varies and this tells us how far to offset the tile based rendering to give the smooth
        // motion of scrolling
        int playerTileOffsetX = (int) ((playerTileX - gigi.getX()) * world.getTileSize());
        int playerTileOffsetY = (int) ((playerTileY - gigi.getY()) * world.getTileSize());
        
        // render the section of the map that should be visible. Notice the -1 and +3 which renders
        // a little extra map around the edge of the screen to cope with tiles scrolling on and off
        // the screen
        world.render(playerTileOffsetX - (gigi.ENTITY_SPRITE_SIZE / 2), playerTileOffsetY - (gigi.ENTITY_SPRITE_SIZE / 2)
                   playerTileX - leftOffsetInTiles - 1
                   playerTileY - topOffsetInTiles - 1,
                   widthInTiles + 3, heightInTiles + 3);
        
        // draw entities relative to the player that must appear in the centre of the screen
        g.translate(400 - (int) (gigi.getX() * 32), 300 - (int) (gigi.getY() * 32));

        // elimino le entit� segnalate per la rimozione
        //removeEntity();
       
        // disegno entit�
        for (int i = 0; i < world.getActorSize(); i++) {
      Entity ent = world.getActor(i).getEntity();
      ent.draw(g);       
    }
        g.resetTransform();
       
        ui.render(g,punteggio);
       
View Full Code Here

  /**
   * Costruttore della strega, inizializza l'entity sottostante e l'agent
   */
  public Strega(WorldEngine we){
      try {
      setEntity(new Entity(26,9, "data/grafica/hero3.gif",25,32,4,6,5,7,0,3));
    } catch (SlickException e) {
      e.printStackTrace();
    }
      setID(new String("STREGA"));
      setAgent(new SimpleJasonAgent(we,getID()));
View Full Code Here

    if (o.getClass() == UserInputController.class){
      MovementNotify mn = (MovementNotify)arg;
      //Log.info("notifica da UserInputController: "+mn.toString());
     
      Actor gigiActor = getPlayerActor();
      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,gigi.MOVE_SPEED*1,0)){
          gigi.addHorizontalMovement(gigi.MOVE_SPEED);
          gigi.getPlayerWalkRight().update(delta);
          gigi.setMovementRight();
        }
      }
      if (keyLeft) {
        if (tryToMoveEntity(gigi,-gigi.MOVE_SPEED*1,0) ){
          gigi.addHorizontalMovement(- gigi.MOVE_SPEED);
          gigi.getPlayerWalkLeft().update(delta);
          gigi.setMovementLeft();
        }
      }
      if (keyUp) {
        if (tryToMoveEntity(gigi,0,-gigi.MOVE_SPEED*1)){
          gigi.addVerticalMovement(- gigi.MOVE_SPEED);
          gigi.getPlayerWalkUp().update(delta);
          gigi.setMovementUp();
        }
      }
      if (keyDown) {
        if (tryToMoveEntity(gigi,0,gigi.MOVE_SPEED*1)){
          gigi.addVerticalMovement(gigi.MOVE_SPEED);
          gigi.getPlayerWalkDown().update(delta);
          gigi.setMovementDown();
        }
      }
     
      // 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){
      MovementNotify mn = (MovementNotify)arg;
      //Log.info("notifica da UserInputController: "+mn.toString());
     
      Actor actorActor = getActorAgentByID(mn.entityID);
      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,actor.MOVE_SPEED*3,0)){
          actor.addHorizontalMovement(actor.MOVE_SPEED*3);
          actor.getPlayerWalkRight().update(delta);
          actor.setMovementRight();
        }
      }
      if (keyLeft) {
        if (tryToMoveEntity(actor,-actor.MOVE_SPEED*3,0) ){
          actor.addHorizontalMovement(- actor.MOVE_SPEED*3);
          actor.getPlayerWalkLeft().update(delta);
          actor.setMovementLeft();
        }
      }
      if (keyUp) {
        if (tryToMoveEntity(actor,0,-actor.MOVE_SPEED*3)){
          actor.addVerticalMovement(- actor.MOVE_SPEED*3);
          actor.getPlayerWalkUp().update(delta);
          actor.setMovementUp();
        }
      }
      if (keyDown) {
        if (tryToMoveEntity(actor,0,actor.MOVE_SPEED*3)){
          actor.addVerticalMovement(actor.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();
      }   
    }
   
View Full Code Here

TOP

Related Classes of it.timehero.entities.Entity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.