2016-11-30 1 views
-1

내 폭탄 범이 아이템을 가져 오면 좋겠다. 그러나이 항목은 5 초 동안 만 작동합니다. 따라서 부울 collisionWithTiles 메서드에서 카운트 다운과 같은 것이 필요합니다.품목 픽업을위한 카운트 다운?

제안 사항?

package dev.codenmore.tilegame.entities.creatures; 

import java.awt.Graphics; 
import java.util.Timer; 
import java.util.TimerTask; 

import dev.codenmore.tilegame.Handler; 
import dev.codenmore.tilegame.entities.Entity; 
import dev.codenmore.tilegame.gfx.Assets; 
import dev.codenmore.tilegame.tiles.Star; 
import dev.codenmore.tilegame.tiles.Tile; 

public abstract class Creature extends Entity 
{ 
    public static final int DEFAULT_HEALTH = 10; 
    public static final float DEFAULT_SPEED = 0.3f; 
    // Setzt die Größe der Kreaturen in Pixel fest 
    // Auf diese Variablen wird von dem Konstruktor der Player-Klasse 
    // zugegriffen 
    public static final int DEFAULT_CREATURE_WIDTH = 64, DEFAULT_CREATUR_HEIGHT = 64; 
    protected float speed; 

    // Setzt das Leben des Spielers auf 10 
    public Creature(Handler handler, float x, float y, int width, int height) 
    { 
     super(handler, x, y, width, height); 
     health = DEFAULT_HEALTH; 
     speed = DEFAULT_SPEED; 
    } 

    // nimmt die x-Koordinate der Entity-Klasse und addiert 
    // die protected Variablen x und yMove 
    public void move(double delta, float moveX, float moveY) 
    { 
     if(!checkEntityCollisions()) 
     { 
      moveX(delta, moveX); 
      moveY(delta, moveY); 
     } 
    } 
    public void moveX(double delta, float xMove) 
    { 
     if (xMove > 0) 
     {// Bewegung nach rechts 
      int tx = (int) (x + xMove + bounds.x + bounds.width)/Tile.TILEWIDTH; 

      if (!collisionWithTile(tx, (int) (y + bounds.y)/Tile.TILEHEIGHT) && !collisionWithTile(tx, (int) (y + bounds.y + bounds.height)/Tile.TILEHEIGHT)) 
      { 
       x += xMove; 
      } 
     } 
     else if (xMove < 0) 
     {// Bewegung nach links 
      int tx = (int) (x + xMove + bounds.x)/Tile.TILEWIDTH; 

      if (!collisionWithTile(tx, (int) (y + bounds.y)/Tile.TILEHEIGHT) && !collisionWithTile(tx, (int) (y + bounds.y + bounds.height)/Tile.TILEHEIGHT)) 
      { 
       x += xMove; 
      } 
     } 
    } 

    public void moveY(double delta, float yMove) 
    { 
     if (yMove < 0) 
     {// Bewegung hoch 

      int ty = (int) (y + yMove + bounds.y)/Tile.TILEHEIGHT; 

      if (!collisionWithTile((int) (x + bounds.x)/Tile.TILEWIDTH, ty) && !collisionWithTile((int) (x + bounds.x + bounds.width)/Tile.TILEWIDTH, ty)) 
      { 
       y += yMove; 
      } 
     } 
     else if (yMove > 0) 
     {// Bewegung runter 

      int ty = (int) (y + yMove + bounds.y + bounds.height)/Tile.TILEHEIGHT; 

      if (!collisionWithTile((int) (x + bounds.x)/Tile.TILEWIDTH, ty) && !collisionWithTile((int) (x + bounds.x + bounds.width)/Tile.TILEWIDTH, ty)) 
      { 
       y += yMove; 
      } 
     } 
    } 
    //TEST 
    public static boolean test = false; 

    protected boolean collisionWithTile(int x, int y) 
    { 
     //Prüft ob der Stein vorhanden ist und ob eine kollision mit dem Tile Star besteht 
     if (handler.getWorld().getTile(x, y) == Tile.star && Stone.stone == false){ 

      this.speed = 1; 
      System.out.println("Tile"); 
      Creature.test = true; 
      return false; 
     } 
     return handler.getWorld().getTile(x, y).isSolid(); 
    } 

    protected boolean collisionWithEntity(int x, int y) 
    { 
     return isSolid(); 
    } 

    // Getters und Setters für die Protected Variablen 
    // Speed und Health 
    public int getHealth() 
    { 
     return health; 
    } 

    public void setHealth(int health) 
    { 
     this.health = health; 
    } 

    public float getSpeed() 
    { 
     return speed; 
    } 

    public void setSpeed(float speed) 
    { 
     this.speed = speed; 
    } 

    public boolean isSolid() 
    { 
     return false; 
    } 
} 

답변

0

우리는

protected boolean collisionWithTile(int x, int y) 
{  
    neueZeit = System.currentTimeMillis(); 
    differenzZeit = (int) ((neueZeit - alteZeit)/1000f); 

    // Prüft ob der Stein vorhanden ist und ob eine kollision mit dem Tile 
    // Star besteht 
    if (handler.getWorld().getTile(x, y) == Tile.star && Stone.isStone == false) 
    { 
     alteZeit = System.currentTimeMillis(); 

     handler.getWorld().setTile(x, y, Tile.grassTile); 
     return false; 
    } 

    if(differenzZeit <= dauer) 
    { 
     this.speed = (float)speedboot;//speedboost hat die geschwindigkeit von 0.7f statt 0.3f 
    } 
    else 
    { 
     this.speed = DEFAULT_SPEED; 
    } 
    return handler.getWorld().getTile(x, y).isSolid(); 
} 
일을했다