public static boolean collision(int xCord, int yCord, boolean b) { if (GameData.isValid(xCord, yCord) && GameData.instance().blockMap[xCord][yCord] != null) { return true; } if (b) { Point p = Frame.game.m.cordToPos(xCord, yCord); Rectangle r1 = new Rectangle(p.x, p.y, 60, 60); for (int i = 0; i < GameData.instance().entityList.size(); i++) { Entity e = GameData.instance().entityList.get(i); if (e.isSolid()) { Rectangle r2 = e.getBounds(); if (r1.intersects(r2)) { return true; } } } } return false; }
/** * @param gd * @param peer * @throws IOException * @throws EncodeException * @throws JSONException */ @OnMessage public void broadCastMessage(GameData gd, Session peer) throws IOException, EncodeException, JSONException, Exception { System.out.println("JSON RECEIVED"); String gameID = gd.getJson().get("gameId").toString(); String playername = gd.getJson().getString("playerName"); // we may not need these lines GameBoard board = cache.getBoard(); board.addPlayerToBoard(new Player(playername)); JSONObject jSONObject = new JSONObject(); jSONObject.put("players", board.getPlayersOnBoard()); jSONObject.put("gameId", gameID); jSONObject.put("type", "notify"); jSONObject.put("playerName", playername); if (board.getPlayersOnBoard().size() == 3) { jSONObject.put("startGame", true); } gd.setJson(jSONObject); System.out.println("JSON : " + gd.getJson()); for (Session currPeer : peers) { currPeer.getBasicRemote().sendObject(gd); } System.out.println("JSON SENT"); }
// Returns block at given coords. public static Block getBlock(int x, int y) { if (GameData.isValid(x, y)) { return GameData.instance().blockMap[x][y]; } else { return null; } }
public void run() { if (!mBoard.gameOver()) ++mGameData.seconds_elapsed; int seconds = (int) (mGameData.seconds_elapsed); int minutes = (int) (seconds / 60); seconds -= 60 * minutes; int hours = (int) (minutes / 60); minutes -= 60 * hours; int days = (int) (hours / 24); hours -= 24 * days; String s = ""; if (days > 0) s += String.format("%dd ", days); if (hours > 0) s += String.format("%dh ", hours); s += String.format("%d:%02d", minutes, seconds); if (!mBoardData.challenge_mode && mGameData.mistake_count > 0) s += String.format( ", %d %s", mGameData.mistake_count, mGameData.mistake_count > 1 ? "misses" : "miss"); mTimeLabel.setText(s); if (mBoard.gameOver()) { mGameData.seconds_elapsed = -1; mGameData.mistake_count = 0; } else mTimerHandler.postDelayed(this, 1000); }
/* */ public static void main(String[] argv) /* */ throws SlickXMLException /* */ { /* 22 */ ObjectTreeParser parser = new ObjectTreeParser("org.newdawn.slick.tests.xml"); /* 23 */ parser.addElementMapping("Bag", ItemContainer.class); /* */ /* 25 */ GameData parsedData = (GameData) parser.parse("testdata/objxmltest.xml"); /* 26 */ parsedData.dump(""); /* */ }
@Override public void update() { if (GameData.getphase() == PHASE.TWO || GameData.getphase() == PHASE.THREE) { bonus.setActive(true); bonus.update(); } if (blinking) { long elapsed = (System.nanoTime() - blinkTimer) / 1000000; if (elapsed > 1000) { blinking = false; } } // set boundaries of the ship (player): // on X axis if (x <= GamePanel.WIDTH - playerImage.getWidth(null) / 2) { x = GamePanel.WIDTH - playerImage.getWidth(null) / 2; } if (x > GamePanel.PWIDTH + playerImage.getWidth(null) / 2) { x = GamePanel.PWIDTH + playerImage.getWidth(null) / 2; } // on Y axis if (y < GamePanel.HEIGHT - playerImage.getHeight(null) / 2) { y = GamePanel.HEIGHT - playerImage.getHeight(null) / 2; } if (y > GamePanel.PHEIGHT - playerImage.getHeight(null) / 2) { y = GamePanel.PHEIGHT - playerImage.getHeight(null) / 2; } }
@Override public void render(Graphics g) { if (blinking) { long elapsed = (System.nanoTime() - blinkTimer) / 1000000; if (elapsed / 100 % 2 == 0) { return; } } g.drawImage(playerImage, (int) x, (int) y, null); if (GameData.getphase() == PHASE.TWO || GameData.getphase() == PHASE.THREE) { bonus.render(g); // render the bonus system } }
static { try { terrainMap = ImageIO.read(GameData.instance().getClass().getResource("/Resources/TerrainMap.png")); } catch (Exception e) { } }
public void updateLight() { byte temp = lightValue; if (this.isTop()) { lightValue = GameData.instance().sunLight; } else { lightValue = 0; } for (int a = -1; a < 2; a++) { for (int b = -1; b < 2; b++) { if (getBlock(a, b, this) != null && getBlock(a, b, this).getLightValue() / 3 > lightValue) { lightValue = (byte) (getBlock(a, b, this).getLightValue() / 3); } BlockAir b1 = BlockAir.getBlock(getXCord() + a, getYCord() + b); if (b1 != null && b1.getLightValue() / 2 > lightValue) { lightValue = (byte) (b1.getLightValue() / 2); } } } if (lightValue != temp) { for (int i1 = -1; i1 < 2; i1++) { for (int i2 = -1; i2 < 2; i2++) { if (getBlock(i1, i2, this) != null) { getBlock(i1, i2, this).updateLight(); } } } } updateNeighbourValues(); }
@Override public void onResume() { super.onResume(); btnResume.setEnabled(GameData.savedGameExist()); btnStart.setBackgroundResource(R.drawable.button); btnResume.setBackgroundResource(R.drawable.button); btnExit.setBackgroundResource(R.drawable.button); }
public boolean isTop() { for (int i = yCord + 1; i < GameData.worldHeight; i++) { if (GameData.instance().blockMap[xCord][i] != null) { return false; } } return true; }
public void updateState() { if (state == STATE_TRAVELING) { double distance = target.distance(getX2(), getY2()); boolean targetReached = distance <= 6.0 ? true : false; if (targetReached) { state = STATE_DONE; gameData.getHealth().decrementHealth(); } } }
private ArrayList<SpellWrapper> getSpells(String duration) { GameData data = getGameObject().getGameData(); ArrayList ids = new ArrayList(); if (duration == null) { ids.addAll(getList(PERMANENT_SPELLS)); ids.addAll(getList(DAY_SPELLS)); ids.addAll(getList(COMBAT_SPELLS)); ids.addAll(getList(PHASE_SPELLS)); ids.addAll(getList(MOVE_SPELLS)); } else { ids.addAll(getList(duration)); } ArrayList<SpellWrapper> ret = new ArrayList<SpellWrapper>(); for (Iterator i = ids.iterator(); i.hasNext(); ) { String id = (String) i.next(); GameObject go = data.getGameObject(Long.valueOf(id)); ret.add(new SpellWrapper(go)); } return ret; }
public void run() { TouchListener.getInstance().addTouchEvent(this); while (run) { GameData.getInstance().changeDrawing(2); // Change drawing style to msg DrawMsg.drawMsg("Nie udalo sie nawiazac polaczenia", 10); try { sleep(15); } catch (Exception e) { Log.e(TAG, "[Sleep] WaitThread: " + e.getMessage()); } } }
protected void initLight() { if (getBlock(0, 1, this) != null) { getBlock(0, 1, this).updateLight(); } else if (BlockAir.getBlock(xCord, yCord + 1) != null) { BlockAir.getBlock(xCord, yCord + 1).updateLight(); } if (getBlock(0, -1, this) != null) { getBlock(0, -1, this).updateLight(); } else if (BlockAir.getBlock(xCord, yCord - 1) != null) { BlockAir.getBlock(xCord, yCord - 1).updateLight(); if (BlockAir.getBlock(xCord, yCord - 1).isDirectLight()) { BlockAir.getBlock(xCord, yCord - 1).setDirectLight(false); } } if (getBlock(1, 0, this) != null) { getBlock(1, 0, this).updateLight(); } else if (BlockAir.getBlock(xCord + 1, yCord) != null) { BlockAir.getBlock(xCord + 1, yCord).updateLight(); } if (getBlock(-1, 0, this) != null) { getBlock(-1, 0, this).updateLight(); } else if (BlockAir.getBlock(xCord - 1, yCord) != null) { BlockAir.getBlock(xCord - 1, yCord).updateLight(); } if (isTop()) { for (int i = 0; i < GameData.worldHeight; i++) { Block b = GameData.instance().blockMap[getXCord()][i]; if (b != null && b.lightValue == GameData.instance().sunLight) { b.updateLight(); } } } }
public static SpellMasterWrapper getSpellMaster(GameData data) { // System.out.println("MASTER_ID = "+MASTER_ID+", dataid = "+data.dataid); if (MASTER_ID == null) { // System.out.println(data.toIdentifier()+": MASTER_ID is null"); GamePool pool = new GamePool(data.getGameObjects()); ArrayList list = pool.find(SPELL_MASTER_KEY); GameObject gm = null; if (list != null && list.size() == 1) { gm = (GameObject) list.iterator().next(); // System.out.println(data.toIdentifier()+": Found a SpellMaster!"); } if (gm == null) { gm = data.createNewObject(); gm.setName(SPELL_MASTER_KEY); gm.setThisAttribute(SPELL_MASTER_KEY); // System.out.println(data.toIdentifier()+": Creating a new SpellMaster!"); } MASTER_ID = new Long(gm.getId()); return new SpellMasterWrapper(gm); } else { return new SpellMasterWrapper(data.getGameObject(MASTER_ID)); } }
@Override public boolean closeRequested() { int id = this.getCurrentStateID(); // intercept close requests in game-related states and return to song menu if (id == STATE_GAME || id == STATE_GAMEPAUSEMENU || id == STATE_GAMERANKING) { // start playing track at preview position SongMenu songMenu = (SongMenu) this.getState(Opsu.STATE_SONGMENU); if (id == STATE_GAMERANKING) { GameData data = ((GameRanking) this.getState(Opsu.STATE_GAMERANKING)).getGameData(); if (data != null && data.isGameplay()) { songMenu.resetGameDataOnLoad(); songMenu.resetTrackOnLoad(); } } else { songMenu.resetGameDataOnLoad(); if (id == STATE_GAME) { MusicController.pause(); MusicController.resume(); } else songMenu.resetTrackOnLoad(); } if (UI.getCursor().isSkinned()) UI.getCursor().reset(); this.enterState( Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); return false; } // show confirmation dialog if any downloads are active if (DownloadList.get().hasActiveDownloads() && UI.showExitConfirmation(DownloadList.EXIT_CONFIRMATION)) return false; if (Updater.get().getStatus() == Updater.Status.UPDATE_DOWNLOADING && UI.showExitConfirmation(Updater.EXIT_CONFIRMATION)) return false; return true; }
/** * Turns a JSON object into a User. * * @param o JSON object */ public void fromJSONObject(JSONObject o) { try { setFirstName((String) o.remove(KEY_FIRST_NAME)); setLastName((String) o.remove(KEY_LAST_NAME)); setID((String) o.remove(KEY_ID)); setPoints(Utils.numToInt(o.remove(KEY_POINTS))); String id = (String) o.remove(KEY_WEEKLY_PICK_ID); Contestant c = null; GameData g = GameData.getCurrentGame(); if (id.equals(Contestant.NULL_ID)) { c = new Contestant(); c.setNull(); } else { c = g.getContestant(id); } setWeeklyPick(c); id = (String) o.remove(KEY_ULT_PICK_ID); if (id.equals(Contestant.NULL_ID)) { c = new Contestant(); c.setNull(); } else { c = g.getContestant(id); } setUltimatePick(c); setUltimatePoints(Utils.numToInt(o.remove(KEY_WIN_PICK_POINTS))); setNumBonusAnswer(((Number) o.remove(KEY_NUM_BONUS_ANSWER)).intValue()); } catch (InvalidFieldException e) { System.out.println("Warning: InvalidFieldException in fromJSONObject"); e.printStackTrace(); } }
public void remove() { GameData.instance().blockList.remove(this); GameData.instance().blockMap[xCord][yCord] = null; for (int a = -1; a < 2; a++) { for (int b = -1; b < 2; b++) { if (getBlock(a, b, this) != null) { getBlock(a, b, this).updateLight(); } } } if (isTop()) { for (int i = 0; i < GameData.worldHeight; i++) { if (GameData.instance().blockMap[xCord][i] != null && GameData.instance().blockMap[xCord][i].isTop()) { GameData.instance().blockMap[xCord][i].updateLight(); } } } BlockAir.create(xCord, yCord, true); BlockAir.getBlock(xCord, yCord).updateLight(); }
private GameController(GameData data) { this.dice = data.getDice(); this.board = new Board(data.getFields(), data.getCards()); this.moveController = new MoveController(data.getDice()); this.fieldController = new FieldController(board); this.playerQueue = new LinkedList<Player>(); for (int i = 0; i < data.getPlayers().length; i++) { playerQueue.add(data.getPlayers()[i]); } this.currentPlayer = playerQueue.remove(); }
/** * setWinPick sets the users choice for which contestant will win the competition. Also determines * how many points the user will receive if that player wins * * @param winner contestant choice * @throws InvalidFieldException If null, throws exception. */ public void setUltimatePick(Contestant winner) throws InvalidFieldException { setUltimatePickNoSetPts(winner); if (!winner.isNull()) ultPoints = 2 * GameData.getCurrentGame().weeksLeft(); }
/** Not very useful but required to check we do not broke API. */ @Test public void testToString() { String string = gameData.toString(); assertTrue(string.contains(gameData.getId())); }
static { try { BufferedImage spriteMap = ImageIO.read(GameData.instance().getClass().getResource("/Resources/jimmyMap.png")); for (int b = 0; b < 3; b++) { bodySprite[b] = new BufferedImage(bodyWidth, bodyHeight, spriteMap.getType()); Graphics2D g = bodySprite[b].createGraphics(); g.drawImage( spriteMap, 0, 0, bodyWidth, bodyHeight, bodyWidth * b, 0, bodyWidth * b + bodyWidth, bodyHeight, null); g.dispose(); } for (int b = 0; b < 6; b++) { headSprite[b] = new BufferedImage(headWidth, headHeight, spriteMap.getType()); Graphics2D g = headSprite[b].createGraphics(); g.drawImage( spriteMap, 0, 0, headWidth, headHeight, headWidth * b, bodyHeight, headWidth * b + headWidth, bodyHeight + headHeight, null); g.dispose(); } for (int b = 0; b < 5; b++) { headSprite[b + 6] = new BufferedImage(headWidth, headHeight, spriteMap.getType()); Graphics2D g = headSprite[b + 6].createGraphics(); g.drawImage( spriteMap, 0, 0, headWidth, headHeight, headWidth * b, bodyHeight + headHeight, headWidth * b + headWidth, bodyHeight + headHeight * 2, null); g.dispose(); } armSprite = new BufferedImage(armWidth, armHeight, spriteMap.getType()); Graphics2D g = armSprite.createGraphics(); g.drawImage( spriteMap, 0, 0, armWidth, armHeight, (bodyWidth * 3), 0, armWidth + (bodyWidth * 3), armHeight, null); g.dispose(); legSprite = new BufferedImage(legWidth, legHeight, spriteMap.getType()); g = legSprite.createGraphics(); g.drawImage( spriteMap, 0, 0, legWidth, legHeight, bodyWidth * 3 + armWidth, 0, legWidth + armWidth + (bodyWidth * 3), legHeight, null); g.dispose(); footSprite = new BufferedImage(footWidth, footHeight, spriteMap.getType()); g = footSprite.createGraphics(); g.drawImage( spriteMap, 0, 0, footWidth, footHeight, armWidth + legWidth + (bodyWidth * 3), 0, armWidth + legWidth + footWidth + (bodyWidth * 3), footHeight, null); g.dispose(); } catch (Exception e) { System.err.println(e.getMessage()); } }
public Block() { setSize(60, 60); GameData.instance().blockList.add(this); setPaintLevel((byte) 3); }
public Block(short xCord, short yCord) { this(); setCoordinates(xCord, yCord); GameData.instance().blockMap[xCord][yCord] = this; }