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

package Game;

import java.awt.Graphics;
import java.util.ArrayList;
import javaPlay.GameEngine;

/**
 *
 * @author Jose Ricardo
 */
public class Scene {
    ArrayList<RenderableGameEntitie> gameObjects = new ArrayList<RenderableGameEntitie>();
    ArrayList<RenderableGameEntitie> toBeRemoved = new ArrayList<RenderableGameEntitie>();

    // Recupera instância global da classe
    private static Scene instance = null;
    public static Scene getInstance(){
        if (instance == null)
            instance = new Scene();

        return instance;
    }

    // Makes the constructor private
    private Scene(){
    }

    public void step(long timeElapsed){
        for (int i = 0; i < gameObjects.size(); i++){
            RenderableGameEntitie go = gameObjects.get(i);
            go.step(timeElapsed);
        }

        for (int i = 0; i < toBeRemoved.size(); i++){
            gameObjects.remove(toBeRemoved.get(i));
        }

        toBeRemoved.clear();
    }

    public void draw(Graphics g){
        for (int i = 0; i < gameObjects.size(); i++)
        {
            RenderableGameEntitie go = gameObjects.get(i);
            go.draw(g);
        }
    }

    public void addGameObject(RenderableGameEntitie go){
        gameObjects.add(go);
    }

    public void removeGameObject(RenderableGameEntitie go){
        toBeRemoved.add(go);
    }

    public Object[] getObjects(){
        return gameObjects.toArray();
    }

    public void clear(){
        gameObjects.clear();
        toBeRemoved.clear();
    }

    public static boolean collide(RenderableGameEntitie go1, RenderableGameEntitie go2){
        if (((go1.x + go1.width) > go2.x && go1.x < (go2.x + go2.width)) &&
            ((go1.y + go1.height) > go2.y && go1.y < (go2.y + go2.height))){
            return true;
        }

        return false;

    }

}
