/** * This method inizializes map, images, animations and sounds * @param container * @throws SlickException */ @Override public void init(GameContainer container) throws SlickException { ready = new Image("data/ready.jpg"); gameOver = new Image("data/gameover.png"); youWin = new Image("data/youwin.png"); mazeMap = new TiledMap("data/maze/Maze.tmx"); initMapProperty(); initAnimations(); begin = new Sound("data/pacmanSound/begin.wav"); begin.play(); eatFruit = new Sound("data/pacmanSound/eatFruit.wav"); pacmanGame.initMaze(mazeMap,this); }
/** * @param mazeMap * @param mazeView * @throws SlickException */ public MazeModality(TiledMap mazeMap,MazeView mazeView) throws SlickException { this.addObserver(mazeView); tileWidth = mazeMap.getTileWidth(); tileHeight = mazeMap.getTileHeight(); mazeWidth = mazeMap.getWidth(); mazeHeight = mazeMap.getHeight(); initializationTiles(mazeView); pacman = new PacMan(tileWidth, tileHeight, mazeWidth, tiles); clyde = new Clyde(tileWidth, tileHeight, mazeWidth, tiles); blinky = new Blinky(tileWidth, tileHeight, mazeWidth, tiles); inky = new Inky(tileWidth, tileHeight, mazeWidth, tiles); pinky = new Pinky(tileWidth, tileHeight, mazeWidth, tiles); eatGhost = new Sound("data/pacmanSound/eatGhost.wav"); death = new Sound("data/pacmanSound/death.wav"); eatSuperPill = new Sound("data/pacmanSound/eatSuperPill.wav"); }
/** * Metoda wywoła się przy przejściu przez portal * * @param gc Potrzebny do przeładowania camery */ public void updateGameStatus(GameContainer gc) { try { gs.map = new TiledMap("graphic/map/" + Integer.toString(GameStatus.levelID) + ".tmx"); camera = new core.Camera(gc, gs.map); //update entity fields: gs.updateEntityFieldList(gs.map); //update listy portali na mapie gs.updatePortalMapList(gs.portalMapList); //update miniMapy w rogu hud.frame.miniMapPath = "graphic/miniMap/" + String.valueOf(GameStatus.levelID) + ".png"; hud.frame.miniMap = new Image(hud.frame.miniMapPath); } catch (SlickException e) { System.out.println("B R A K minimapy dla tej mapy"); e.printStackTrace(); } needToMapUpdate = false; }
/** * Aktualizuje pola aktywne na mapie * Kolizje, NpcArea,MobsArea * @param map mapa */ public void updateEntityFieldList(TiledMap map) { for (int i = 8; i < 11; i++) { exist = new boolean[map.getWidth()][map.getHeight()]; testField = map.getTileId(0, 0, i); for (int j = 0; j < map.getWidth(); j++) { for (int k = 0; k < map.getHeight(); k++) { collisionTileID = map.getTileId(j, k, i); if (collisionTileID == testField) { exist[j][k] = true; } } } if (i == 8) { updateCollisionFields(map); } if (i == 9) { updateNpcFields(map); } if (i == 10) { updateMobsFields(map); } } }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { map = new TiledMap("testdata/testmap.tmx","testdata"); // read some properties from map and layer mapName = map.getMapProperty("name", "Unknown map name"); monsterDifficulty = map.getLayerProperty(0, "monsters", "easy peasy"); nonExistingMapProperty = map.getMapProperty("zaphod", "Undefined map property"); nonExistingLayerProperty = map.getLayerProperty(1, "beeblebrox", "Undefined layer property"); // store the original tileid of layer 0 at 10, 10 originalTileID = map.getTileId(10, 10, 0); }
@Override public void init(GameContainer container) throws SlickException { this.container = container; this.map = new TiledMap("/home/enzo/newmap.tmx"); SpriteSheet spriteSheet = new SpriteSheet("/home/enzo/SpriteSheetAnim.png", 64, 64); this.animations[0] = loadAnimation(spriteSheet, 0, 1, 0); this.animations[1] = loadAnimation(spriteSheet, 0, 1, 1); this.animations[2] = loadAnimation(spriteSheet, 0, 1, 2); this.animations[3] = loadAnimation(spriteSheet, 0, 1, 3); this.animations[4] = loadAnimation(spriteSheet, 1, 9, 0); this.animations[5] = loadAnimation(spriteSheet, 1, 9, 1); this.animations[6] = loadAnimation(spriteSheet, 1, 9, 2); this.animations[7] = loadAnimation(spriteSheet, 1, 9, 3); Font font = new Font("Verdana", Font.BOLD, 20); UnicodeFont uFont = new UnicodeFont(font, font.getSize(), font.isBold(), font.isItalic()); nameInput = new TextField(container, uFont, 150,20,500,35, new ComponentListener() { public void componentActivated(AbstractComponent source) { message = "Entered1: "+nameInput.getText(); nameInput.setFocus(true); } }); // ComponentListener listener = new ComponentListener(); // TextField nameInput = new TextField(arg0, truetypefont, 150,20,500,35, listener); // // { // public void componentActivated(AbstractComponent source) { // System.out.println("Entered1: "+nameInput.getText()); // } // }); }
/** * This method creates the mape based on the game modality * @param mazeMap * @param mazeView * @throws SlickException */ public void initMaze(TiledMap mazeMap, MazeView mazeView) throws SlickException{ if(mode.equals("single")) maze = new SinglePlayer(mazeMap, mazeView); if(mode.equals("multi")) maze = new MultiPlayer(mazeMap, mazeView); if(mode.equals("extreme")) maze = new Extreme(mazeMap, mazeView); }
/** Create a new World object. */ public World() throws SlickException { this.map = new TiledMap(Game.ASSETS_PATH + "/map.tmx", Game.ASSETS_PATH); this.player = new Player(1332, 13086, Angle.fromDegrees(0)); aiPlayerList = new ArrayList<AIPlayer>(); aiPlayerList.add(new Elephant(1260, 13086, Angle.fromDegrees(0))); aiPlayerList.add(new Dog(1404, 13086, Angle.fromDegrees(0))); aiPlayerList.add(new Octopus(1476, 13086, Angle.fromDegrees(0))); itemList = new ArrayList<Item>(); itemList.add(new OilCan(1350, 12438)); itemList.add(new OilCan(864, 7614)); itemList.add(new OilCan(1962, 6498)); itemList.add(new OilCan(1314, 3690)); itemList.add(new Tomato(990, 11610)); itemList.add(new Tomato(1206, 5130)); itemList.add(new Tomato(1206, 3690)); itemList.add(new Tomato(1422, 2322)); itemList.add(new Boost(990, 10242)); itemList.add(new Boost(1818, 6534)); itemList.add(new Boost(990, 4302)); itemList.add(new Boost(1926, 3510)); panel = new Panel(); hazardList = new ArrayList<Hazard>(); }
public Level(String level, Player player) throws SlickException { map = new TiledMap("ressources/level/" + level + ".tmx"); background = new Image("ressources/background/" + map.getMapProperty("back.png", "back.png")); characters = new ArrayList<Character>(); levelObjects = new ArrayList<LevelObject>(); this.player = player; addCharacter(player); loadTileMap(); loadLimite(); loadEnd(); }
public GameStatus() throws SlickException { musicOn = true; //ustawianie pozycji startu gry this.levelID = 100; mapPath = "graphic/map/" + Integer.toString(levelID) + ".tmx"; map = new TiledMap(mapPath); spriteNumber = 1; this.sprite = new Sprite(); this.x = 238; this.y = 200; //czysty bohater this.hero = new Hero(); this.itemsInBag = new HashMap<>(); this.equipInBag = new HashMap<>(); this.itemsInGame = new HashMap<>(); this.equipInGame = new HashMap<>(); this.quest = new ArrayList<>(); this.skills = new ArrayList<>(); this.money = 0; //na pierwszej mapie nie ma mobów czy npc - więc kolekcje puste this.npc = gameUtils.NpcData.dataSeeder(); this.enemy = gameUtils.EnemyData.enemyData(); this.portalMapList = new ArrayList<model.Portal>(); //wczytanie danych o mapie updateEntityFieldList(map); updatePortalMapList(portalMapList); loadAllItemsInGame(itemsInGame); loadAllEquipInGame(equipInGame); }
/** * Metoda znajdująca pola kolizyjne * @param map Aktualna mapa */ public void updateCollisionFields(TiledMap map) { collisions = new ArrayList<>(); for (int i = 0; i < map.getWidth(); i++) { for (int j = 0; j < map.getHeight(); j++) { if (exist[i][j] == true) { recField = new Rectangle(i * 32, j * 32, 32, 32); collisions.add(recField); } } } collisions.trimToSize(); }
public void updateNpcFields(TiledMap map) { npc = new ArrayList<>(); for (int i = 0; i < map.getWidth(); i++) { for (int j = 0; j < map.getHeight(); j++) { if (exist[i][j] == true) { recField = new Rectangle(i * 32, j * 32, 32, 32); npc.add(recField); } } } }
public void updateMobsFields(TiledMap map) { mobs = new ArrayList<>(); for (int i = 0; i < map.getWidth(); i++) { for (int j = 0; j < map.getHeight(); j++) { if (exist[i][j] == true) { recField = new Rectangle(i * 32, j * 32, 32, 32); mobs.add(recField); } } } }
/** * The constructor. Takes the path for the .tmx and the x and y coordinates. * * @param path The path of the .tmx file * @param x The x coordinate * @param y The y coordinate * @throws SlickException */ public TileMap(String path, float x, float y) throws SlickException{ super(x, y, 0, 0); theTileMap = new TiledMap(path); this.setX(x); this.setY(y); this.setWidth(theTileMap.getWidth() * theTileMap.getTileWidth()); this.setHeight(theTileMap.getHeight() * theTileMap.getTileHeight()); TileSet theTileSet = theTileMap.getTileSet(0); SpriteSheet sheet = theTileSet.tiles; }
@Override public void init(GameContainer gc, StateBasedGame sbg)throws SlickException { levelMap1 = new TiledMap("/res/hmmm.tmx"); background = new Image("/res/Background.png"); Image [] movementUp = {new Image("/res/wmg1_bk1.png"), new Image("/res/wmg1_bk2.png")}; Image [] movementDown = {new Image("/res/wmg1_fr1.png"), new Image("/res/wmg1_fr2.png")}; Image [] movementLeft = {new Image("/res/wmg1_lf1.png"), new Image("/res/wmg1_lf2.png")}; Image [] movementRight = {new Image("/res/wmg1_rt1.png"), new Image("/res/wmg1_rt2.png")}; int [] duration = {300, 300}; up = new Animation(movementUp, duration, false); down = new Animation(movementDown, duration, false); left = new Animation(movementLeft, duration, false); right = new Animation(movementRight, duration, false); sprite = right; blocked = new boolean[levelMap1.getWidth()][levelMap1.getHeight()]; for (int xAxis=0;xAxis<levelMap1.getWidth(); xAxis++) { for (int yAxis=0;yAxis<levelMap1.getHeight(); yAxis++) { int tileID = levelMap1.getTileId(xAxis, yAxis, 0); String value = levelMap1.getTileProperty(tileID, "blocked", "false"); if ("true".equals(value)) { blocked[xAxis][yAxis] = true; } } } }
/** * Method for setting the map to be used in the room. * * @param mapPath * Path in filesystem to the tmx file representing a tiled map. */ public void setMap(String mapPath) { try { this.map = new TiledMap(mapPath); int layerCount = map.getLayerCount(); blockedLayerID = -1; for (int i = 0; i < layerCount; i++) { if (map.getLayerProperty(i, "blocked", "false").equals("true")) { blockedLayerID = i; } } staticBounds.clear(); // add static collision bounds for (int i = 0; i < map.getWidth(); i++) { for (int j = 0; j < map.getHeight(); j++) { int tileID = map.getTileId(i, j, blockedLayerID); String property = map.getTileProperty(tileID, "blocked", "false"); if (property.equals("true")) { staticBounds.add(new Rectangle2D.Float(i * 32, j * 32, 32, 32)); } } } } catch (SlickException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void init(GameContainer container) throws SlickException { tilemap = new TiledMap("testdata/isoexample.tmx", "testdata/"); }
public Extreme(TiledMap mazeMap, MazeView mazeView) throws SlickException { super(mazeMap, mazeView); }
public SinglePlayer(TiledMap mazeMap, MazeView mazeView) throws SlickException { super(mazeMap, mazeView); }
public MultiPlayer(TiledMap mazeMap, MazeView mazeView) throws SlickException { super(mazeMap, mazeView); }
public TiledMap getMap() { return map; }
public boolean checkCollision(BoundingShape bv, TiledMap map) { if (bv instanceof AABoundingRect) return checkCollision((AABoundingRect) bv, map); return false; }
/** * Create a new camera * * @param gc the GameContainer, used for getting the size of the GameCanvas * @param map the TiledMap used for the current scene */ public Camera(GameContainer gc, TiledMap map) { this.map = map; this.numTilesX = map.getWidth(); this.numTilesY = map.getHeight(); this.tileWidth = map.getTileWidth(); this.tileHeight = map.getTileHeight(); this.mapHeight = this.numTilesX * this.tileWidth; this.mapWidth = this.numTilesY * this.tileHeight; this.gc = gc; }
public TiledMap getTiledMap() { return mTiledMap; }
public Map(String path) throws SlickException { mTiledMap = new TiledMap("./" + path); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { // load the sprites and tiles, note that underneath the texture // will be shared between the sprite sheet and tilemap SpriteSheet sheet = new SpriteSheet("testdata/scroller/sprites.png",32,32); // load the tilemap created the TileD tool map = new TiledMap("testdata/scroller/map.tmx"); // build a collision map based on tile properties in the TileD map blocked = new boolean[map.getWidth()][map.getHeight()]; for (int x=0;x<map.getWidth();x++) { for (int y=0;y<map.getHeight();y++) { int tileID = map.getTileId(x, y, 0); String value = map.getTileProperty(tileID, "blocked", "false"); if ("true".equals(value)) { blocked[x][y] = true; } } } // caculate some layout values for rendering the tilemap. How many tiles // do we need to render to fill the screen in each dimension and how far is // it from the centre of the screen widthInTiles = container.getWidth() / TILE_SIZE; heightInTiles = container.getHeight() / TILE_SIZE; topOffsetInTiles = heightInTiles / 2; leftOffsetInTiles = widthInTiles / 2; // create the player sprite based on a set of sprites from the sheet loaded // above (tank tracks moving) player = new Animation(); for (int frame=0;frame<7;frame++) { player.addFrame(sheet.getSprite(frame,1), 150); } player.setAutoUpdate(false); // update the vector of movement based on the initial angle updateMovementVector(); Log.info("Window Dimensions in Tiles: "+widthInTiles+"x"+heightInTiles); }
@Override public boolean checkCollision(AABoundingRect rect, TiledMap map) { return !(rect.x > this.x + width || rect.x + rect.width < this.x || rect.y > this.y + height || rect.y + rect.height < this.y); }