/** * Update all game elements. Consider update methods execution dependencies. Currently there are * none. */ @Override public void update() { if (getGameState() == GameState.RUNNING) { updateTime(); mBackground.update(); mDeathEffectContainer.update(); mNpcContainer.update(); } }
/** * On touch remove top touched npc and create a death effect on the touched spot. Trigger * GameState.END if the last Demon or Human was killed * * @param touchX * @param touchY * @return enum value that shows if some game element was actually touched or not */ public TouchedElement onTouchEvent(float touchX, float touchY) { TouchedElement result = TouchedElement.NONE; if (mGameState == GameState.RUNNING) { Npc touchedNpc = mNpcContainer.removeTopTouchedNpc(touchX, touchY); if (touchedNpc != null) { boolean isDemon = touchedNpc.getNpcType().isEnemy(); updateScore(touchedNpc); // Create a new death effect at the location of the killed npc mDeathEffectContainer.createDeathEffect( touchedNpc.getCenterX(), touchedNpc.getCenterY(), isDemon); if (isDemon) { result = TouchedElement.DEMON; } else { result = TouchedElement.HUMAN; } } checkForGameEnd(); } return result; }
/** * Render all game elements. Order of rendering affects the order on the Z axis. First things * rendered are on the back. Last things rendered are on the front. */ @Override public void render(Canvas canvas) { mBackground.render(canvas); mDeathEffectContainer.render(canvas); mNpcContainer.render(canvas); }