package world;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.io.File;
import java.util.Iterator;
import java.util.Random;
import java.util.Vector;
import javax.media.opengl.GL2;
import obj.Element;
import obj.Forme;
import View.Camera;
import View.Perso;
public class Editor implements World{
// aleatoire
Random rand = new Random();
private int[][] grid = null;
private int nbCol;
private int nbLig;
// forme de base
private Forme forme = new Forme();
// perso
public Perso perso = new Perso(1.5f,0.6f,1.5f,0.0f);
// spawn
public Vector<Point2D.Double> debut = new Vector<Point2D.Double>();
// Elements = perso + enemies + bullets
public Vector<Element> elements = new Vector<Element>();
public Editor() {
}
@Override
public void init(Point p){
nbCol = (int) p.getX();
nbLig = (int) p.getY();
grid = new int[nbCol][nbLig];
for(int x = 0 ; x < nbCol ; x++) {
for(int y = 0 ; y < nbLig ; y++) {
grid[x][y] = 0;
}
}
}
@Override
public void loadFile(File fic) {}
@Override
public void render(GL2 gl) {
// dessine le sol
forme.drawFloor(gl, 0.0f, 0.1f);
// dessine le plafond
forme.drawFloor(gl, 1.0f, 0.3f);
// dessine les cubes et les spawns
for ( int i = 0 ; i < nbLig ; i++ ){
for ( int j = 0 ; j < nbCol ; j++ ){
switch(grid[i][j]){
case 1:
//bloc
forme.drawQuads(gl, i, j);
break;
case 3:
//spawn
forme.drawRespawn(gl, i, j, 'g');
break;
default:
//autre chose
}
}
}
// dessine tout les elements
// elements = perso + enemies + bullets
Iterator<Element> iteratorElem = elements.iterator();
while ( iteratorElem.hasNext() ) {
Element elem = iteratorElem.next();
if (elem.actualise(grid)) {
iteratorElem.remove();
}else{
elem.draw(gl);
}
}
}
@Override
public Camera getCamera() {
return perso;
}
@Override
public void fire() {
//Fait planter le soft si appel, probleme d'initialisation des tableaux et des variables...
//Ca se r�glera tout seul quand tu auras g�rer toutes les initialisations.
//elements.add(new Bullet(perso.getX(), perso.getZ(), perso.getDir()));
}
@Override
public void reset() {
int nbDebut = debut.size();
int i = rand.nextInt(nbDebut);
perso.reset((float)debut.get(i).getX(), (float)debut.get(i).getY());
}
@Override
public int[][] getGrid(){
return grid;
}
}