/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Game;

import javaPlay.GameEngine;
import javaPlay.Mouse;

/**
 *
 * @author Jose Ricardo
 */
public class PlayerBullet extends RenderableGameEntitie{
    
    @Override
    public void step(long timeElapsed) {        
        // Atualizar posicao da bala
        y -= Globals.PLAYER_BULLET_SPEED;

        // Verificar colisão
        Object[] gameObjects =
                Scene.getInstance().getObjects();

        for (int i = 0; i < gameObjects.length; i++){
            RenderableGameEntitie rge = (RenderableGameEntitie) gameObjects[i];

            if (rge.tag.equals("Enemy")){
                if (Scene.collide(this, rge)){
                    Scene.getInstance().removeGameObject(this);

                    // Destruir inimigo
                    Scene.getInstance().removeGameObject(rge);

                    // Incrementar o score
                    GamePlayState.setScore(GamePlayState.getScore() +
                            ((Enemy)gameObjects[i]).totalPoints());

                    // Decrementar total de inimigos
                    GamePlayState.setNum_inimigos(GamePlayState.getNum_inimigos() - 1);
                    
                    return;
                }
            }
        }

        // Verificar se ultrapassou o limite da viewport
        if (y + height < 0) Scene.getInstance().removeGameObject(this);
    }

}
