@Override public void update() { GameplayManager.getInstance().update((Player) Level.getObjects().get(0)); gameOver = checkGameOver(); levelEnded = checkLevelEnded(); checkPause(); if (pause || gameOver || levelEnded) { manager.update(); } else { level.input(); level.update(); ParticleMaster.update(camera); } }
private void processMap() throws SlickException { // clears array of walls for (int x = 0; x < mapa.getWidth(); x++) { for (int y = 0; y < mapa.getHeight(); y++) { wallMap[x][y] = 0; } } // detects all objects in the tiled map, sets their position and adds them into level for (int i = 0; i < mapa.getObjectCount(0); i++) { switch (mapa.getObjectType(0, i)) { case "player": Player hrac = new Player(); hrac.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(hrac); level.setPlayer(hrac); break; case "blob": Blob blob = new Blob(); blob.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(blob); break; case "cron": Cron cron = new Cron(); cron.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(cron); break; case "broom": Broom broom = new Broom(); broom.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(broom); break; case "fantom": Fantom fantom = new Fantom(); fantom.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(fantom); break; case "bomb": BombsUp bomba = new BombsUp(); bomba.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(bomba); break; case "speed": SpeedUp speed = new SpeedUp(); speed.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(speed); break; case "kick": KickUp kick = new KickUp(); kick.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(kick); break; case "range": RangeUp range = new RangeUp(); range.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(range); break; case "portal": Portal portal = new Portal(); portal.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(portal); break; case "dragon": Dragon dragon = new Dragon(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); // dragon.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(dragon); break; } } // detects all walls in tiled map, sets their position and adds them // into list and array of walls int wallX; int wallY; for (int i = 0; i < mapa.getObjectCount(1); i++) { wallX = mapa.getObjectX(1, i); wallY = mapa.getObjectY(1, i); wallMap[wallX / 32][wallY / 32] = 1; switch (mapa.getObjectType(1, i)) { case "wall": Wall stena = new Wall(); Walls.add(stena); stena.setPosition(wallX, wallY); break; case "block": Block blok = new Block(); Walls.add(blok); blok.setPosition(wallX, wallY); break; } } }
/** @author Michal */ public class Map { private TiledMap mapa; private Level level = Level.getLevel(); private List<Walls> Walls; private int[][] wallMap; /** * saves instance of level to variable * * @param level */ public Map(Level level) { this.level = level; } /** * loads tiled map according to name of level | declares 2-dimensional array for walls | processes * map * * @param level string with name of level */ public void loadMap(String level) { try { mapa = new TiledMap("resources/map/" + level + ".tmx"); Walls = new ArrayList<Walls>(); wallMap = new int[mapa.getWidth()][]; for (int i = 0; i < mapa.getWidth(); i++) { wallMap[i] = new int[mapa.getHeight()]; } processMap(); } catch (SlickException ex) { ex.printStackTrace(); } } private void processMap() throws SlickException { // clears array of walls for (int x = 0; x < mapa.getWidth(); x++) { for (int y = 0; y < mapa.getHeight(); y++) { wallMap[x][y] = 0; } } // detects all objects in the tiled map, sets their position and adds them into level for (int i = 0; i < mapa.getObjectCount(0); i++) { switch (mapa.getObjectType(0, i)) { case "player": Player hrac = new Player(); hrac.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(hrac); level.setPlayer(hrac); break; case "blob": Blob blob = new Blob(); blob.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(blob); break; case "cron": Cron cron = new Cron(); cron.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(cron); break; case "broom": Broom broom = new Broom(); broom.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(broom); break; case "fantom": Fantom fantom = new Fantom(); fantom.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(fantom); break; case "bomb": BombsUp bomba = new BombsUp(); bomba.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(bomba); break; case "speed": SpeedUp speed = new SpeedUp(); speed.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(speed); break; case "kick": KickUp kick = new KickUp(); kick.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(kick); break; case "range": RangeUp range = new RangeUp(); range.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(range); break; case "portal": Portal portal = new Portal(); portal.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(portal); break; case "dragon": Dragon dragon = new Dragon(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); // dragon.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i)); level.addToLevel(dragon); break; } } // detects all walls in tiled map, sets their position and adds them // into list and array of walls int wallX; int wallY; for (int i = 0; i < mapa.getObjectCount(1); i++) { wallX = mapa.getObjectX(1, i); wallY = mapa.getObjectY(1, i); wallMap[wallX / 32][wallY / 32] = 1; switch (mapa.getObjectType(1, i)) { case "wall": Wall stena = new Wall(); Walls.add(stena); stena.setPosition(wallX, wallY); break; case "block": Block blok = new Block(); Walls.add(blok); blok.setPosition(wallX, wallY); break; } } } /** * gets instance of tiled map * * @return tiled map */ public TiledMap getTiledMap() { return this.mapa; } /** * gets List of Walls * * @return List of walls */ public List<Walls> getWalls() { return Walls; } /** * gets 2-dimensional array indicating position of walls * * @return array of walls */ public int[][] getWallMap() { return wallMap; } }
public void display() { GL11.glViewport(0, 0, width, height); GL11.glClearColor(0.5f, 0.5f, 0.5f, 0.1f); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); float widthHeightRatio = width / height; GLU.gluPerspective(45, widthHeightRatio, 1, 1000); GLU.gluLookAt( player.getX(), player.getY(), player.getZ(), player.getCamX(), player.getCamY(), player.getCamZ(), 0, 1, 0); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); // Level GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glEnable(GL11.GL_DEPTH_TEST); for (byte i = 0; i < level.getSizeX(); i += 1) { for (byte j = 0; j < level.getSizeY(); j += 1) { for (byte k = 0; k < level.getSizeZ(); k += 1) { if (level.getCubeName(i, j, k).equals(Cube.CUBE_BOMB)) { objects.DrawCubeBomb(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXPLOSION)) { objects.DrawCubeExplosion(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXPLOSION_HIDE_EXIT)) { objects.DrawCubeExplosion(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXPLOSION_HIDE_ITEM)) { objects.DrawCubeExplosion(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_HEALTH)) { objects.DrawCubeItemHealth(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_XTRA_BOMB)) { objects.DrawCubeItemXtraBomb(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_BOMB_RANGE)) { objects.DrawCubeItemBombRange(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_BOMB_STRENGTH)) { objects.DrawCubeItemBombStrength(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_PORTAL)) { objects.DrawCubeItemPortal(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_ITEM_DOUBLE_SCORE)) { objects.DrawCubeItemDoubleScore(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_SOLID)) { objects.DrawCubeSolid(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_OUTSIDE)) { objects.DrawCubeOutside(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_OBSTACLE)) { objects.DrawCubeObstacle(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_OBSTACLE_HIDE_EXIT)) { objects.DrawCubeObstacle(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_EXIT)) { objects.DrawCubeExit(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.CUBE_SOLID_RAMP)) { objects.DrawCubeRamp(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); // Menüwürfel } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_NEW_GAME)) { objects.DrawMenuCubeNewGame(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_NEW_GAME_GRAVITY)) { objects.DrawMenuCubeNewGameGravity( i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_EXIT_PROGRAM)) { objects.DrawMenuCubeExitProgram(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_MULTI)) { objects.DrawMenuCubeMulti(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_SERVER)) { objects.DrawMenuCubeServer(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_OPTIONS)) { objects.DrawMenuCubeOptions(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } else if (level.getCubeName(i, j, k).equals(Cube.MENU_CUBE_LOAD_LEVEL)) { objects.DrawMenuCubeLoadLevel(i * SIZE_OF_CUBE, j * SIZE_OF_CUBE, k * SIZE_OF_CUBE); } } } } if (listPlayer != null) { for (int i = 0; i < listPlayer.size(); i++) { if (listPlayer.get(i).getNumber() != player.getNumber()) { objects.DrawPlayer( listPlayer.get(i).getX() - (SIZE_OF_CUBE / 2), listPlayer.get(i).getY() - (SIZE_OF_CUBE / 2), listPlayer.get(i).getZ() - (SIZE_OF_CUBE / 2)); } } } GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); // GL11.glOrtho(-CLIPSIZE, +CLIPSIZE, -CLIPSIZE, +CLIPSIZE, -CLIPSIZE * // 100.0f, +CLIPSIZE * 100.0f); // GL11.glOrtho(-CLIPSIZE, +CLIPSIZE, -CLIPSIZE, +CLIPSIZE, -CLIPSIZE, // +CLIPSIZE); GL11.glOrtho( -Window.width / 2, +Window.width / 2, -Window.height / 2, +Window.height / 2, -CLIPSIZE, +CLIPSIZE); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); // GL11.glTranslatef(1f, 1f, 0.0f); GL11.glDisable(GL11.GL_DEPTH_TEST); hud.renderHUD(); GL11.glFlush(); }
@Override public void enter() { init(); game.getGameBackground().stop(); game.getGameBackground().play(level.playTheme()); }
@Override public void exit() { level.destroy(); }