14
Dez
2013
Das ist die letzte Version des Projekts Fuzzy-Game. Damit sollte das Slick-Framework ein Wenig unter die Lupe genommen werden. In der aktuellen Version kann man Zäune aufstellen und löschen, um den Fuzzy durch Kollisionen ins Ziel zu lenken. Wenn er im Ziel ist (unten rechts) Dann wird das Spiel beendet. Das ist ein ganz einfacher Aufbau eines Kollisions-basierten Spiels mit Slick. Weitere Level können sehr einfach in einer XML-Datei erstellt werden.
Wie man merkt, handelt es sich hierbei nicht um ein Tutorial, sondern um ein Code-Beispiel, dass dazu genutzt werden kann, um das Prinzip von Slick zu verstehen.
Quellcode
- package pixilab.gp.slic.game.rebound;
-
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.Image;
- import org.newdawn.slick.Input;
- import org.newdawn.slick.SlickException;
-
-
- private int xPos;
- private int yPos;
- private float buttonScale = 0.8f;
- private boolean pressed;
-
- this.image = image;
- this.xPos = xPos;
- this.yPos = yPos;
- }
-
- public void init() throws SlickException {
- }
-
- public void render() throws SlickException {
- buttonImage.draw(xPos, yPos, buttonScale);
- }
-
- public void update(GameContainer container, int delta) throws SlickException {
- Input input = container.getInput();
- boolean insideButton = isInsideButton(input.getMouseX(), input.getMouseY());
- scaleEffekt(insideButton, delta);
-
- if(insideButton && input.isMousePressed(Input.MOUSE_LEFT_BUTTON)){
- pressed = true;
- } else {
- pressed = false;
- }
- }
-
- public boolean isPressed() {
- return pressed;
- }
-
- // --
-
- private boolean isInsideButton(int mouseX, int mouseY) {
- return (( mouseX >= xPos && mouseX <= xPos + buttonImage.getWidth()) &&
- ( mouseY >= yPos && mouseY <= yPos + buttonImage.getHeight())) ? true : false;
- }
-
- private void scaleEffekt(boolean insideButton, int delta) {
-
- float scaleStep = 0.0002f;
- if(insideButton){
- if(buttonScale > 0.7f) {
- buttonScale -= scaleStep * delta;
- }
- } else {
- if(buttonScale < 0.8f) {
- buttonScale += scaleStep * delta;
- }
- }
- }
-
- }
- package pixilab.gp.slic.game.rebound;
-
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.SlickException;
-
- import pixilab.gp.slic.game.rebound.Field.FieldType;
- import pixilab.gp.slic.game.rebound.Fuzzy.Orientation;
- import pixilab.gp.slic.game.rebound.Map.Border;
-
- public class CollisionsDetection {
-
- //Input input = container.getInput();
- reflect(fuzzy, border);
-
- reflect(fuzzy, field);
-
- fenceReflect(fuzzy, map, 0);
-
- end(fuzzy, map, container);
-
- }
-
- if(getFieldType(fuzzy, map) == FieldType.END){
- container.exit();
- }
- }
-
-
- if(border[0] != border[1]) {
- if(border[0] != null) {
- // Rand rechts/links
- switch(border[0]) {
- case RIGHT :
- // Eintrittswinkel = Austrittswinkel
- switch(fuzzy.getCourse()) {
- case SO : fuzzy.setCourse(Orientation.SW); break;
- case NO : fuzzy.setCourse(Orientation.NW); break;
- case O : fuzzy.setCourse(Orientation.W); break;
- }
- break;
-
- case LEFT :
- // Eintrittswinkel = Austrittswinkel
- switch(fuzzy.getCourse()) {
- case SW : fuzzy.setCourse(Orientation.SO); break;
- case NW : fuzzy.setCourse(Orientation.NO); break;
- case W : fuzzy.setCourse(Orientation.O); break;
- }
- break;
- }
- }
-
- if(border[1] != null) {
- switch(border[1]) {
- case TOP :
- // Eintrittswinkel = Austrittswinkel
- switch(fuzzy.getCourse()) {
- case NO : fuzzy.setCourse(Orientation.SO); break;
- case NW : fuzzy.setCourse(Orientation.SW); break;
- case N : fuzzy.setCourse(Orientation.S); break;
- }
- break;
- case BOTTOM :
- // Eintrittswinkel = Austrittswinkel
- switch(fuzzy.getCourse()) {
- case SO : fuzzy.setCourse(Orientation.NO); break;
- case SW : fuzzy.setCourse(Orientation.NW); break;
- case S : fuzzy.setCourse(Orientation.N); break;
- }
- break;
- }
- }
- }
- }
-
- // Kollision mit Fence --------------------------------------------------------------------
-
- int[] position = fuzzy.getPosition();
- int[] matPosition = cartMatConvert(position);
-
- try {
- switch(getFenceField(matPosition, map).getFenceOrientation()) {
- case W :
- switch(fuzzy.getCourse()) {
- case O : fuzzy.setCourse(Orientation.W); break;
- case W : fuzzy.setCourse(Orientation.O); break;
- case NO : fuzzy.setCourse(Orientation.NW); break;
- case SO : fuzzy.setCourse(Orientation.SW); break;
- case NW : fuzzy.setCourse(Orientation.NO); break;
- case SW : fuzzy.setCourse(Orientation.SO); break;
- }
- break;
-
- case N :
- switch(fuzzy.getCourse()) {
- case N : fuzzy.setCourse(Orientation.S); break;
- case S : fuzzy.setCourse(Orientation.N); break;
- case NO : fuzzy.setCourse(Orientation.SO); break;
- case SO : fuzzy.setCourse(Orientation.NO); break;
- case NW : fuzzy.setCourse(Orientation.SW); break;
- case SW : fuzzy.setCourse(Orientation.NW); break;
- }
- break;
-
- case NW :
- switch(fuzzy.getCourse()) {
- case O : fuzzy.setCourse(Orientation.N); break;
- case S : fuzzy.setCourse(Orientation.W); break;
- case SO : fuzzy.setCourse(Orientation.NW); break;
- case W : fuzzy.setCourse(Orientation.S); break;
- case N : fuzzy.setCourse(Orientation.O); break;
- case NW : fuzzy.setCourse(Orientation.SO); break;
- }
- break;
-
- case NO :
- switch(fuzzy.getCourse()) {
- case O : fuzzy.setCourse(Orientation.S); break;
- case S : fuzzy.setCourse(Orientation.O); break;
- case NO : fuzzy.setCourse(Orientation.SW); break;
- case W : fuzzy.setCourse(Orientation.N); break;
- case N : fuzzy.setCourse(Orientation.W); break;
- case SW : fuzzy.setCourse(Orientation.NO); break;
- }
- break;
- }
- e.getMessage();
- }
-
- }
-
-
- if(field != null && field.getThisField() == null){
- return (Fence)field;
- } else {
- return null;
- }
- }
-
- // Kollision mit Fensterrand --------------------------------------------------------------
-
- /**
- * Überprüft, ob der äußere Spielrand berührt wurde
- * @param fuzzy
- * @param map
- * @return linker oder rechter / oberer oder unterer Rand
- */
-
- int x = fuzzy.getPosition()[0];
- int y = fuzzy.getPosition()[1];
-
-
- }
- if(x <= 0) {
- }
- }
- if(y <= 0) {
- }
-
- }
-
- // Kollision mit Standardfeldern der Map -------------------------------------------------
-
- /**
- * Überprüft üb ein Objekt auf dem Spielfeld berührt wurde
- * @param fuzzy Sprite
- * @param map Map
- * @return linker oder rechter / oberer oder unterer Rand
- */
-
- if(getFieldType(fuzzy, map) != null) {
- FieldType field = getFieldType(fuzzy, map);
- //System.out.println(fieldBorder(fuzzy)[0]+"-"+fieldBorder(fuzzy)[1]);
- switch(field) {
- case ROCK : return fieldBorder(fuzzy);
- case TREE : return fieldBorder(fuzzy);
- }
- }
- }
-
- /**
- * Bordererkennung Eintrittswinkel != Austrittswinkel
- * (Schnell, da Orientierung bereits vor der Kollision bekannt ist)
- * @param fuzzy Sprite-Objekt
- * @return Rand
- */
- @SuppressWarnings("unused")
-
- switch(fuzzy.getCourse()) {
- }
-
- }
-
- /**
- * Bordererkennung (Etwas langsamer)
- * @param fuzzy Sprite-Objekt
- * @return Rand
- */
-
- int x = fuzzy.getPosition()[0];
- int y = fuzzy.getPosition()[1];
-
- int[] matrix = cartMatConvert(fuzzyDiveIn(fuzzy, 100));
-
- int fuzzyOffsetX = (x - fieldOffsetX);
- int fuzzyOffsetY = (y - fieldOffsetY);
-
- boolean commingFromLeft = fuzzyOffsetX < 0 ? true : false;
- boolean commingFromTop = fuzzyOffsetY < 0 ? true : false;
-
- if(commingFromLeft) {
- }
-
- if(commingFromTop) {
- }
-
- return fieldBorder(new int[] {fieldOffsetX + fuzzyOffsetX, fieldOffsetY + fuzzyOffsetY},
- new int[] {fieldOffsetX, fieldOffsetY});
- }
-
- /**
- * Ermittelt für alle Felder den berührten Rand.
- * (Errechnete 4 Pizzafelder: oben, unten, rechts, links)
- * @param position Position des Sprite als Kartesischer Vektor
- * @param offset Position des Feldes als kartesischer Vektor
- * @return Rand (Pizzafeld), der berührt wurde
- */
- int x = position[0];
- int y = position[1];
-
- int offX = offset[0];
- int offY = offset[1];
-
- int nx = (x-offX);
- int ny = (y-offY);
-
-
- if(x<=(a+offX) && x>offX && y<=(a+offY) && y>offY) {
- if(nx>ny && nx<(a-ny)) {
- //System.out.println("top");
- }
- if(nx<ny && nx>(a-ny)) {
- //System.out.println("botom");
- }
- if(ny<nx && ny>(a-nx)) {
- //System.out.println("right");
- }
- if(ny>nx && ny<(a-nx)) {
- //System.out.println("left");
- }
- // Am Rand
- //System.out.println("links oben");
- }
- //System.out.println("rechts unten");
- }
- //System.out.println("rechts oben");
- }
- //System.out.println("links unten");
- }
-
- }
- }
-
- /**
- * Gibt den Typ des Feldes, über dem sich das Sprite gerade befindet zurück
- * @param fuzzy Das Sprite
- * @param map Die Map
- * @return Feld-Typ
- */
-
- int[] matrix = cartMatConvert(fuzzyDiveIn(fuzzy, 100));
-
- if(matrix != null && map.getFields()[matrix[0]][matrix[1]] != null) {
- return map.getFields()[matrix[0]][matrix[1]].getThisField();
- } else {
- return null;
- }
- }
-
- /**
- * Konfiguration, wie weit das Sprite in ein Block eintauchen darf, damit es als
- * Wechsel von einem Block zum anderen erkannt wird.
- * @param fuzzy Das Sprite
- * @param sensibility Prozentualler Wert:
- * 0: Das Sprite taucht bis zur Feldmitte ein.
- * 100: Das Sprite berührt nur den Rand
- * @return neue [x,y] Koordinaten
- */
- private int[] fuzzyDiveIn(Fuzzy fuzzy, int sensibility) {
- int x = fuzzy.getPosition()[0];
- int y = fuzzy.getPosition()[1];
-
-
- switch(fuzzy.getCourse()) {
- case N : y -= distance; break;
- case NO : y -= distance;
- x += distance; break;
- case O : x += distance; break;
- case SO : x += distance;
- y += distance; break;
- case S : y += distance; break;
- case SW : y += distance;
- x -= distance; break;
- case W : x -= distance; break;
- case NW : x -= distance;
- y -= distance; break;
- }
-
- return new int[] {x, y};
- }
-
- /**
- * Konvertiert Karthesische Kordinaten des Sprites in Matrix-Kordinaten
- * (NICHT IDENTISCH MIT DEM KONVERTER FÜR MAUSKOORDINATEN!!!)
- * @param position Kartesische [x,y] Koordinaten auf der Map
- * @param fieldDimension Diemsion eines Feldes in der Map
- * @return Matrix [x,y] Koordinaten
- * Wenn die Koordinaten außerhalb des Sichtbaren Feldes sind ist matrix = null !!!
- */
- private int[] cartMatConvert(int[] position) {
- int x = position[0];
- int y = position[1];
-
-
- matrixX < 0 || matrixY < 0) {
- return null;
- }
- return new int[] {matrixX, matrixY};
- }
-
- }
- package pixilab.gp.slic.game.rebound;
-
- public class Const {
-
- public final static boolean debug = true;
- }
- package pixilab.gp.slic.game.rebound;
-
- import org.newdawn.slick.Image;
- import org.newdawn.slick.SlickException;
- import org.newdawn.slick.tiled.TiledMap;
-
- import pixilab.gp.slic.game.rebound.Fuzzy.Orientation;
-
-
- private int[] matPos;
- private int curImg = 0;
-
- public Fence(FieldType thisField, TiledMap grassMap) {
- super(thisField, grassMap);
-
- }
-
- public Fence(int[] matPos) {
- super(matPos);
- this.matPos = matPos;
- }
-
- }
-
- public void rotate() {
- if(curImg >= 3) {
- curImg = 0;
- } else {
- curImg++;
- }
- }
-
- public Orientation getFenceOrientation() {
-
- switch(curImg) {
- case 0 : return Orientation.W;
- case 1 : return Orientation.NW;
- case 2 : return Orientation.N;
- case 3 : return Orientation.NO;
- }
-
- return null;
- }
- }
- package pixilab.gp.slic.game.rebound;
-
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.Image;
- import org.newdawn.slick.Input;
- import org.newdawn.slick.SlickException;
-
- import pixilab.gp.slic.game.rebound.Field.FieldType;
-
- public class FenceManager {
-
- private boolean fenseSettable;
- private Fence fence;
-
- public FenceManager() {
- // TODO Auto-generated constructor stub
- }
-
- public void init() throws SlickException {
- }
-
- try {
- ((Fence)field).render(fenceBG);
- e.getMessage();
- }
- }
- }
- }
-
- Input input = container.getInput();
- int matPos[] = cartMatConvert(new int[] {input.getAbsoluteMouseX(),
- input.getAbsoluteMouseY()});
-
- // Bedingung, nur wenn Raster an, dürfen Fenses gesetzt werden
- if(menu.getFenseButton().isPressed()) {
- fenseSettable = fenseSettable ? false : true;
- map.setRenderRaster(fenseSettable ? true : false);
- }
-
- // Fence setzen
- if(input.isMousePressed(Input.MOUSE_LEFT_BUTTON) && fenseSettable) {
- setFence(matPos, map);
- }
-
- //Fence entfernen
- if(input.isMousePressed(Input.MOUSE_RIGHT_BUTTON) && fenseSettable) {
- resetFence(matPos, map);
- }
- }
-
- if(getfieldType(matPos, map) == null) {
- if(map.getFields()[matPos[0]][matPos[1]] != null) {
- map.setFields(matPos, null);
- }
- }
- }
-
-
- if(getfieldType(matPos, map) == null) {
- if(map.getFields()[matPos[0]][matPos[1]] == null) {
- map.setFields(matPos, new Fence(matPos));
- fence = ((Fence) map.getFields()[matPos[0]][matPos[1]]);
- } else {
- fence = ((Fence) map.getFields()[matPos[0]][matPos[1]]);
- fence.rotate();
- }
- }
- }
-
- /**
- * Gibt den TypDes Feldes zurück
- * @param mousePos Matrix- Mausposition
- * @param map Map
- * @return Feld- Typ
- */
- try {
- return map.getFields()[matPos[0]][matPos[1]].getThisField();
- return null;
- }
- }
-
- /**
- * Kartesisch/Matrix Wandler
- * @param pos Kartesische Mausposition
- * @return Matrix-Position
- */
- private int[] cartMatConvert(int[] pos) {
- return new int[] {x, y};
- }
- }
- package pixilab.gp.slic.game.rebound;
-
- import org.newdawn.slick.tiled.TiledMap;
-
- static enum FieldType{ROCK, TREE, LAKE, START, END};
-
- private FieldType thisField;
-
- this.thisField = thisField;
- }
-
-
- /**
- * @return the thisField
- */
- public FieldType getThisField() {
- return thisField;
- }
-
- /**
- * @param thisField the thisField to set
- */
- public void setThisField(FieldType thisField) {
- this.thisField = thisField;
- }
-
- }
- package pixilab.gp.slic.game.rebound;
-
- import org.newdawn.slick.Animation;
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.Image;
- import org.newdawn.slick.Input;
- import org.newdawn.slick.SlickException;
-
- public class Fuzzy {
-
- enum Orientation {
- N, NO, O, SO, S, SW, W, NW
- }
-
- private Animation fuzzySprite, fuzzyStay, fuzzyMove;
-
- private float rx = 3f, ry = 1f;
- private float x = rx, y = ry;
-
- private static int fuzzyWidth, fuzzyHeight;
-
- private boolean start, reset;
- private Orientation course;
-
- public void init() throws SlickException {
- fuzzyWidth = fuzzyBG.getWidth();
- fuzzyHeight = fuzzyBG.getHeight();
-
- fuzzyStay = fuzzyStayAnimation();
- fuzzyMove = fuzzyMoveAnimation();
-
- // At Start
- fuzzySprite = fuzzyStay;
- setCourse(Orientation.O);
- }
-
- public void render() throws SlickException {
- fuzzyBG.draw((int)x, (int)y);
- fuzzySprite.draw((int)x+10, (int)y-5);
- }
-
- public void update(GameContainer container, int delta) throws SlickException {
-
- Input input = container.getInput();
-
- fuzzySprite.update(delta);
- int velocity = 50;
- fuzzySprite = fuzzyStay;
-
- if(Const.debug) {
- if(input.isKeyDown(Input.KEY_D)) {
- setCourse(Orientation.O);
- move(getCourse(), delta, velocity);
- }
- if(input.isKeyDown(Input.KEY_S)) {
- setCourse(Orientation.S);
- move(getCourse(), delta, velocity);
- }
- if(input.isKeyDown(Input.KEY_A)) {
- setCourse(Orientation.W);
- move(getCourse(), delta, velocity);
- }
- if(input.isKeyDown(Input.KEY_W)) {
- setCourse(Orientation.N);
- move(getCourse(), delta, velocity);
- }
- if(input.isKeyDown(Input.KEY_Q)) {
- setCourse(Orientation.NW);
- move(getCourse(), delta, velocity);
- }
- if(input.isKeyDown(Input.KEY_E)) {
- setCourse(Orientation.NO);
- move(getCourse(), delta, velocity);
- }
- if(input.isKeyDown(Input.KEY_C)) {
- setCourse(Orientation.SO);
- move(getCourse(), delta, velocity);
- }
- if(input.isKeyDown(Input.KEY_Y)) {
- setCourse(Orientation.SW);
- move(getCourse(), delta, velocity);
- }
- if(input.isKeyDown(Input.KEY_SPACE)){
- start = start ? false : true;
- }
- }
-
- if(start) {
- move(getCourse(), delta, velocity);
- }
- if(reset){
- setPosition(rx, ry);
- }
-
- }
-
- public void setOrientation(Orientation orientation) {
- switch(orientation) {
- case N : setRotation(0); break;
- case NO : setRotation(45); break;
- case O : setRotation(90); break;
- case SO : setRotation(135); break;
- case S : setRotation(180); break;
- case SW : setRotation(225); break;
- case W : setRotation(270); break;
- case NW : setRotation(315); break;
- }
- }
-
- public void move(Orientation orientation, int delta, int velocity) {
-
- fuzzySprite = fuzzyMove;
-
- setOrientation(orientation);
-
- switch(orientation) {
- case N : y -= speed; break;
- case NO : y -= speed;
- x += speed; break;
- case O : x += speed; break;
- case SO : x += speed;
- y += speed; break;
- case S : y += speed; break;
- case SW : y += speed;
- x -= speed; break;
- case W : x -= speed; break;
- case NW : x -= speed;
- y -= speed; break;
- }
- }
-
- /**
- * @return the start
- */
- public boolean isStart() {
- return start;
- }
-
- /**
- * @param start the start to set
- */
- public void setStart(boolean start) {
- this.start = start;
- }
-
- public void setReset(boolean reset) {
- this.reset = reset;
-
- }
-
- public void setPosition(float rx2, float ry2) {
- this.x = rx2;
- this.y = ry2;
- }
-
- public int[] getPosition() {
- return new int[] {(int) this.x, (int) this.y};
- }
-
- /**
- * @return the course
- */
- public Orientation getCourse() {
- return course;
- }
-
- /**
- * @param course the course to set
- */
- public void setCourse(Orientation course) {
- this.course = course;
- }
-
- /**
- * @return the fuzzyWidth
- */
- public static int getFuzzyWidth() {
- return fuzzyWidth;
- }
-
- /**
- * @return the fuzzyHeight
- */
- public static int getFuzzyHeight() {
- return fuzzyHeight;
- }
-
- // --
- private Animation fuzzyStayAnimation() throws SlickException {
-
- int [] duration = {2000, 50};
-
- return new Animation(fuzzy, duration, false);
- }
-
- private Animation fuzzyMoveAnimation() throws SlickException {
-
- int [] duration = {1000, 500};
-
- return new Animation(fuzzy, duration, false);
- }
-
- private void setRotation(float r) {
- fuzzyBG.setCenterOfRotation(fuzzyBG.getWidth()/2f, fuzzyBG.getHeight()/2f-5);
- fuzzyBG.setRotation(r);
- for(int i = 0; i < fuzzySprite.getFrameCount(); i++) {
- fuzzySprite.getImage(i).setCenterOfRotation(fuzzySprite.getImage(i).getWidth()/2f,
- fuzzySprite.getImage(i).getHeight()/2f+5);
- fuzzySprite.getImage(i).setRotation(r);
- }
- }
-
- }
- package pixilab.gp.slic.game.rebound;
-
- import org.newdawn.slick.AppGameContainer;
- import org.newdawn.slick.BasicGame;
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.Graphics;
- import org.newdawn.slick.SlickException;
-
- public class FuzzyGame extends BasicGame{
-
- private Fuzzy fuzzy;
- private State state;
-
- public FuzzyGame() {
- super("Fuzzy-Game");
- fuzzy = new Fuzzy();
- state = new State();
- }
-
- @Override
- public void init(GameContainer container) throws SlickException {
- map.init();
- menu.init();
- fuzzy.init();
- state.init();
- }
-
- @Override
- map.render();
- state.render(map);
- menu.render();
- fuzzy.render();
-
- }
-
- @Override
- public void update(GameContainer container, int delta) throws SlickException {
- menu.update(container, delta);
- fuzzy.update(container, delta);
- state.update(container, map, menu, fuzzy);
- }
-
-
- try {
- FuzzyGame fuzzyGame = new FuzzyGame();
-
- AppGameContainer app = new AppGameContainer(fuzzyGame);
- app.setShowFPS(false);
-
- app.setDisplayMode(750, 750, false);
-
- app.start();
- } catch (SlickException e) {
- e.printStackTrace();
- }
- }
- }
- package pixilab.gp.slic.game.rebound;
-
- import org.newdawn.slick.Image;
- import org.newdawn.slick.SlickException;
- import org.newdawn.slick.tiled.TiledMap;
-
- import pixilab.gp.slic.game.rebound.Field.FieldType;
-
-
- public static final int BLOCK_DIMENSION = 50;
- public static final int NUMBER_OF_FIELDS = 15;
- private static int mapWidth, mapHeight;
- private boolean renderRaster;
-
- private TiledMap grassMap;
-
- public void init() throws SlickException {
- grassMap = new TiledMap("/data/MAP/map1.tmx");
- mapWidth = grassMap.getWidth();
- mapHeight = grassMap.getHeight();
-
- setMapMatrix();
- }
-
- public void render() throws SlickException {
- grassMap.render(0, 0);
- if(renderRaster) {
- raster.draw(0, 0);
- }
- }
-
- //--
-
- /**
- * @return the fields
- */
- return fields;
- }
-
- /**
- * @param fields the fields to set
- * @param matPos Matrixposition
- * @param fields Feld
- */
- this.fields[matPos[0]][matPos[1]] = fields;
- }
-
- /**
- * @return the mapWidth
- */
- public int getMapWidth() {
- return mapWidth*BLOCK_DIMENSION;
- }
-
- /**
- * @return the mapHeight
- */
- public int getMapHeight() {
- return mapHeight*BLOCK_DIMENSION;
- }
-
- // --
-
- private void setMapMatrix() {
-
- // // Layer mit dem Gegenstand
- // int indexStart = grassMap.getLayerIndex("start");
- // int indexEnd = grassMap.getLayerIndex("end");
- // int indexRock = grassMap.getLayerIndex("rock");
- // int indexTree = grassMap.getLayerIndex("tree");
- // int indexLake = grassMap.getLayerIndex("lake");
-
- FieldType[] fieldType = FieldType.values();
-
- int layerIndexLength = FieldType.values().length;
- int[] layerIndex = new int[layerIndexLength];
-
- for(int j = 0; j < grassMap.getLayerCount(); j++) {
-
- @SuppressWarnings("unused")
-
- for( int h = 0; h < mapHeight; h++) {
- for(int w = 0; w < mapWidth; w++) {
-
- if(grassMap.getTileId(w, h, j) != 0) {
- for(int i = 0; i < layerIndexLength; i++){
- layerIndex[i] = grassMap.getLayerIndex(fieldType[i].toString().toLowerCase());
- if(j == layerIndex[i]) {
- }
- }
- }
- }
- }
- }
-
- //String name = grassMap.getLayerProperty(tileID, "block", "true");
- //System.out.println("Picture ID: "+tileID +" Blocked: "+name );
- //getMapMatrix();
- }
-
- @SuppressWarnings("unused")
- private void getMapMatrix() {
- for( int h = 0; h < mapHeight; h++) {
- for(int w = 0; w < mapWidth; w++) {
- if(fields[w][h] != null)
- else
- }
- }
- }
-
- /**
- * @return the renderRaster
- */
- public boolean isRenderRaster() {
- return renderRaster;
- }
-
- /**
- * @param renderRaster the renderRaster to set
- */
- public void setRenderRaster(boolean renderRaster) {
- this.renderRaster = renderRaster;
- }
-
- }
- package pixilab.gp.slic.game.rebound;
-
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.SlickException;
-
- Button startButton, resetButton, fenseButton;
-
- }
-
- public void init() throws SlickException {
- startButton.init();
- resetButton.init();
- fenseButton.init();
- }
-
- public void render() throws SlickException {
- startButton.render();
- resetButton.render();
- fenseButton.render();
- }
-
- public void update(GameContainer container, int delta) throws SlickException {
- startButton.update(container, delta);
- resetButton.update(container, delta);
- fenseButton.update(container, delta);
- }
-
- // --
-
- /**
- * @return the startButton
- */
- return startButton;
- }
-
- // --
-
- /**
- * @return the resetButton
- */
- return resetButton;
- }
-
- /**
- * @return the fenseButton
- */
- return fenseButton;
- }
-
- /**
- * @param fenseButton the fenseButton to set
- */
- this.fenseButton = fenseButton;
- }
- }
- package pixilab.gp.slic.game.rebound;
-
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.SlickException;
-
- public class State {
-
- private boolean exit;
- private CollisionsDetection cd;
- private FenceManager fm;
-
- public State() {
- cd = new CollisionsDetection();
- fm = new FenceManager();
- }
-
- public void init() throws SlickException {
- fm.init();
- }
-
- fm.render(map);
- }
-
- menuStates(container, menu, fuzzy);
- cd.update(container, map, fuzzy);
- fm.update(container, map, menu);
- }
-
- // --
- if(menu.getStartButton().isPressed()) {
- if(!fuzzy.isStart()) {
- fuzzy.setStart(true);
- } else if(Const.debug) {
- fuzzy.setStart(false);
- }
- exit = false;
- }
- if(menu.getResetButton().isPressed()) {
- fuzzy.setStart(false);
-
- if(exit) {
- container.exit();
- }else {
- exit = true;
- }
- }
- fuzzy.setReset(menu.getResetButton().isPressed());
- }
-
- }