Commit aa80ade5 authored by Luboš Horáček's avatar Luboš Horáček

Merge branch 'devel' of gitlab.labs.nic.cz:labs/tablexia into devel

parents 87e73080 0d1a9a67
obb/potme/gfx/info/start_arrow.png

37.3 KB | W: | H:

obb/potme/gfx/info/start_arrow.png

36.5 KB | W: | H:

obb/potme/gfx/info/start_arrow.png
obb/potme/gfx/info/start_arrow.png
obb/potme/gfx/info/start_arrow.png
obb/potme/gfx/info/start_arrow.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -23,6 +23,7 @@
<string name="game_potme_loading_text_2">Přetahuj správné úkony do pásu vpravo a dávej pozor na všechny překážky. Teprve až budeš mít naplánovanou celou trasu, stiskni tlačítko HOTOVO.</string>
<string name="game_potme_start">HOTOVO</string>
<string name="game_potme_floor">Patro</string>
<string name="game_potme_victory_tutorial">Gratuluji! A teď to zkus sám&#8230;</string>
<string name="game_potme_victory_0">Au au, tolik chyb! To muselo bolet.</string>
<string name="game_potme_victory_1">Krůček za krůčkem. To chce klid, soustředit se a úspěchy se brzy dostaví.</string>
<string name="game_potme_victory_2">Chybička se vždycky vloudí, ale dobrému detektivovi by se to stávat nemělo.</string>
......
......@@ -116,6 +116,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
protected boolean afterResume = false;
protected boolean paused = false;
private boolean playVictorySpeech = false;
private boolean useGameManager = true;
private static final int STEPS_PER_SECOUND = 60;
protected static final int VICTORY_SCREEN_STARS_COUNT = 3;
......@@ -169,6 +170,10 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
public boolean isGameActive(GamesDefinition gameDefinitionToCheck) {
return (gamesDefinition == gameDefinitionToCheck) && (gameState == GameState.STARTED);
}
protected void disableGameManagerForCurrentGame() {
useGameManager = false;
}
/* //////////////////////////////////////////// TABLEXIA LIFECYCLE */
......@@ -220,6 +225,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
scene.clearTouchAreas();
clearScene();
useGameManager = true;
gameManager = null;
}
......@@ -252,7 +258,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
*/
protected void initGame() {
getTablexiaContext().showScreenContent(null);
if (gameManager == null) {
if (gameManager == null && useGameManager) {
gameManager = new GameManager(gamesDefinition, getTablexiaContext().getSelectedUser(), getDifficulty());
}
}
......@@ -302,8 +308,11 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
if (gameTrophy == null) {
gameTrophy = GameTrophy.createGameTrophyAndSave(userId, gameNumber);
}
List<TrophyEnum> trophies = gameTrophy.nextGameComplete(getDifficulty(), score);
trophies.addAll(UserTrophyDefinition.processUserTrophies(selectedUser));
List<TrophyEnum> trophies = null;
if (score >= 0) {
trophies = gameTrophy.nextGameComplete(getDifficulty(), score);
trophies.addAll(UserTrophyDefinition.processUserTrophies(selectedUser));
}
showVictoryScreen(score, trophies);
GameTrophy.logAllGameTrophysForUser(userId);
}
......@@ -906,7 +915,9 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
@Override
public void run() {
if (playVictorySpeech == true) {
soundControl.playSound(getVictorySpeech()[score], false);
if (score >= 0 && score < getVictorySpeech().length) {
soundControl.playSound(getVictorySpeech()[score], false);
}
}
}
......@@ -952,12 +963,13 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
* @param trophies game trophies
*/
private void showTrophies(List<TrophyEnum> trophies) {
for (int i = 0; i < trophies.size(); i++) {
if (i < VICTORY_SCREEN_TROPHIES_LAYOUTS.length) {
showTrophyImage(VICTORY_SCREEN_TROPHIES_LAYOUTS[i], trophies.get(i));
}
}
if (trophies != null) {
for (int i = 0; i < trophies.size(); i++) {
if (i < VICTORY_SCREEN_TROPHIES_LAYOUTS.length) {
showTrophyImage(VICTORY_SCREEN_TROPHIES_LAYOUTS[i], trophies.get(i));
}
}
}
}
/**
......@@ -1008,15 +1020,24 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
* @param score score to show in victory screen (number of stars)
*/
private void setVictoryScreenScore(int score) {
if (score > 0) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar1), SfxSounds.VICTORYSCREEN_STAR1_SOUND, VICTORYSCREEN_STAR1_DELAY);
}
if (score > 1) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar2), SfxSounds.VICTORYSCREEN_STAR2_SOUND, VICTORYSCREEN_STAR2_DELAY);
}
if (score > 2) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar3), SfxSounds.VICTORYSCREEN_STAR3_SOUND, VICTORYSCREEN_STAR3_DELAY);
}
if (score < 0) {
victoryLayout.findViewById(R.id.victoryscreen_ratingstar1).setVisibility(View.GONE);
victoryLayout.findViewById(R.id.victoryscreen_ratingstar2).setVisibility(View.GONE);
victoryLayout.findViewById(R.id.victoryscreen_ratingstar3).setVisibility(View.GONE);
} else {
victoryLayout.findViewById(R.id.victoryscreen_ratingstar1).setVisibility(View.VISIBLE);
victoryLayout.findViewById(R.id.victoryscreen_ratingstar2).setVisibility(View.VISIBLE);
victoryLayout.findViewById(R.id.victoryscreen_ratingstar3).setVisibility(View.VISIBLE);
if (score > 0) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar1), SfxSounds.VICTORYSCREEN_STAR1_SOUND, VICTORYSCREEN_STAR1_DELAY);
}
if (score > 1) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar2), SfxSounds.VICTORYSCREEN_STAR2_SOUND, VICTORYSCREEN_STAR2_DELAY);
}
if (score > 2) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar3), SfxSounds.VICTORYSCREEN_STAR3_SOUND, VICTORYSCREEN_STAR3_DELAY);
}
}
}
/**
......@@ -1074,14 +1095,14 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
* @param score score to show on victory screen
*/
public void setVictoriousTextsAndProgress(int score) {
TextView txtvVictory = (TextView) victoryLayout.findViewById(R.id.victoryscreen_message);
txtvVictory.setText(getVictoryText(score));
TextView tvStats = (TextView) victoryLayout.findViewById(R.id.victoryscreen_result);
tvStats.setText(getStatsText());
resetVictoryScreenScore();
setVictoryScreenScore(score);
TextView txtvVictory = (TextView) victoryLayout.findViewById(R.id.victoryscreen_message);
txtvVictory.setText(getVictoryText(score));
TextView tvStats = (TextView) victoryLayout.findViewById(R.id.victoryscreen_result);
tvStats.setText(getStatsText());
resetVictoryScreenScore();
setVictoryScreenScore(score);
}
/**
......
......@@ -21,6 +21,7 @@ package cz.nic.tablexia.game.games.potme;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -74,6 +75,7 @@ import cz.nic.tablexia.game.games.potme.map.mapobject.MapObjectType;
import cz.nic.tablexia.game.games.potme.map.tile.Tile;
import cz.nic.tablexia.game.games.potme.map.widget.MapWidget;
import cz.nic.tablexia.game.games.potme.map.widget.MapWidget.TileMapClickListener;
import cz.nic.tablexia.game.manager.GameManager;
/**
* Activity for "Potmě" game
......@@ -82,7 +84,7 @@ import cz.nic.tablexia.game.games.potme.map.widget.MapWidget.TileMapClickListene
*/
public class PotmeActivity extends GameActivity implements TileMapClickListener {
public enum GameLayer {
public static enum GameLayer {
BACKGROUND_TEXTURE_LAYER (0),
BACKGROUND_DRAWING_LAYER (1),
BUTTON_LAYER (2),
......@@ -137,6 +139,11 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
scene.sortChildren();
}
}
public static final List<ActionType> TUTORIAL_STEPS = Arrays.asList(new ActionType[]{ActionType.GO,
ActionType.RIGHT,
ActionType.DOOR,
ActionType.GO});
private static final boolean SHOW_DEBUGINFO_RULE = true;
......@@ -166,8 +173,6 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
private static final int GAME_INFO_FINISH_ALPHA = 1;
private static final int GAME_INFO_START_ALPHA = 0;
private static final float GAME_INFO_APPEAR_DURATION = 0.3f;
private static final float GAME_INFO_ARROW_APPEAR_DURATION = 1f;
private static final int GAME_INFO_ARROW_APPEAR_DELAY = 2;
public static int TILE_SIZE;
public static int MAP_START_POSITION_X;
......@@ -176,7 +181,10 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
public static int ACTION_SIZE_SMALLER;
private int planningStartTime = 0;
private PotmeDifficulty potmeDifficulty;
private boolean currentFirstPlay = true;
private RandomAccess randomAccess;
private ActionsStripWidget actionsStripWidget;
private ActionsWidget actionsWidget;
......@@ -255,13 +263,13 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
textPressedPositionY = unpressedButtonSprite.getHeight() / 8;
buttonText = new Text(textUnpressedPositionX, textUnpressedPositionY, ResourceManager.getInstance().getFont(), getString(R.string.game_potme_start), getVertexBufferObjectManager());
textLayer.attachChild(buttonText);
disable();
}
public void enable() {
enabled = true;
changeActualButtonSprite(unpressedButtonSprite);
buttonText.setPosition(textUnpressedPositionX, textUnpressedPositionY);
hideStartArrowInfo();
}
public void disable() {
......@@ -335,6 +343,8 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
protected void resetGame() {
super.resetGame();
potmeDifficulty = null;
randomAccess = null;
mapWidgets = null;
......@@ -348,6 +358,10 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
@Override
protected void initGame() {
if (!getPotmeDifficulty().hasResults()) {
disableGameManagerForCurrentGame();
currentFirstPlay = false;
}
super.initGame();
// calculate widgets sizes
......@@ -359,8 +373,7 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
TILE_SIZE = (int)(((displaySize.x - actionStripWidgetWidth - actionPanelWidth) / MAP_X_SIZE) * TILE_SIZE_RATIO);
MAP_START_POSITION_X = (int)(TILE_SIZE * MAP_START_X_TILE_SIZE_RATIO);
MAP_START_POSITION_Y = (int)(displaySize.y - (TILE_SIZE * MAP_START_Y_TILE_SIZE_RATIO));
PotmeDifficulty potmeDifficulty = PotmeDifficulty.getPotmeDifficultyForGameDifficulty(getDifficulty());
mapWidgets = new ArrayList<MapWidget>();
errorCount = 0;
......@@ -371,14 +384,17 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
GameLayer.attachLayersToScene(scene);
showMapWidgets(potmeDifficulty);
showMapWidgets(getPotmeDifficulty());
prepareBackground();
actionsStripWidget = showActionsStripWidget(actionStripWidgetWidth);
actionsWidget = showActionsWidget(potmeDifficulty, actionStripWidgetWidth);
actionsWidget = showActionsWidget(getPotmeDifficulty(), actionStripWidgetWidth);
startButton = showStartButton((int)actionsWidget.getX());
//TODO remove and use event bus
actionsStripWidget.setStartButton(startButton);
actionsWidget.setStartButton(startButton);
player = showPlayer();
prepareGameInfos(actionStripWidgetWidth);
......@@ -396,7 +412,6 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
goToPlanningMode();
super.showGame();
actionsWidget.showActions();
showStartArrowInfo();
}
/* //////////////////////////////////////////// BACKGROUND */
......@@ -491,34 +506,34 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
private void showMapWidgets(PotmeDifficulty potmeDifficulty) {
try {
Tile lastFinishPosition = null;
int floorCount = potmeDifficulty.getFloorCount();
boolean hasKey = potmeDifficulty.hasDifficultyActionType(ActionType.KEY);
for (int i = 0; i < floorCount; i++) {
MapObjectType finishMapObjetcMapObjectType;
if (i == (floorCount - 1)) {
finishMapObjetcMapObjectType = MapObjectType.SAFE;
} else {
finishMapObjetcMapObjectType = MapObjectType.STAIRS;
}
boolean floorHasKey = hasKey && ((floorCount - 1) / 2) == i;
MapWidget mapWidget = new MapWidget(lastFinishPosition, finishMapObjetcMapObjectType, i, floorCount > 1, MAP_START_POSITION_X, MAP_START_POSITION_Y, MAP_X_SIZE, MAP_Y_SIZE, floorHasKey, randomAccess, getResources().getText(R.string.game_potme_floor).toString(), getVertexBufferObjectManager());
mapWidgets.add(mapWidget);
if (i == 0) {
mapWidget.setInFront();
} else {
mapWidget.setInBottom();
}
mapWidget.setClickable(scene, this);
GameLayer.MAP_LAYER.getLayerEntity().attachChild(mapWidget);
lastFinishPosition = mapWidget.getTileMap().getTileAtPosition(mapWidget.getTileMap().getMapFinishPosition());
}
Tile lastFinishPosition = null;
int floorCount = potmeDifficulty.getFloorCount();
boolean hasKey = potmeDifficulty.hasDifficultyActionType(ActionType.KEY);
for (int i = 0; i < floorCount; i++) {
MapObjectType finishMapObjetcMapObjectType;
if (i == (floorCount - 1)) {
finishMapObjetcMapObjectType = MapObjectType.SAFE;
} else {
finishMapObjetcMapObjectType = MapObjectType.STAIRS;
}
boolean floorHasKey = hasKey && ((floorCount - 1) / 2) == i;
MapWidget mapWidget = new MapWidget(potmeDifficulty.getMapProviderNewInstance(randomAccess), lastFinishPosition, finishMapObjetcMapObjectType, i, floorCount > 1, MAP_START_POSITION_X, MAP_START_POSITION_Y, MAP_X_SIZE, MAP_Y_SIZE, floorHasKey, getResources().getText(R.string.game_potme_floor).toString(), getVertexBufferObjectManager());
mapWidgets.add(mapWidget);
if (i == 0) {
mapWidget.setInFront();
} else {
mapWidget.setInBottom();
}
mapWidget.setClickable(scene, this);
GameLayer.MAP_LAYER.getLayerEntity().attachChild(mapWidget);
lastFinishPosition = mapWidget.getTileMap().getTileAtPosition(mapWidget.getTileMap().getMapFinishPosition());
}
} catch (Throwable t) {
throw new RuntimeException("Error during generating map with random seed: " + randomAccess.getRandomSeed(), t);
}
......@@ -528,12 +543,14 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
Sprite actionStripBackground = new Sprite(displaySize.x - (actionStripWidgetWidth / 2), displaySize.y - (displaySize.y / 2), actionStripWidgetWidth, displaySize.y, ResourceManager.getInstance().getTexture(ResourceManager.BACKGROUND_ACTIONSTRIP_TEXTURE), getVertexBufferObjectManager());
GameLayer.BACKGROUND_TEXTURE_LAYER.getLayerEntity().attachChild(actionStripBackground);
ActionsStripWidget actionStripWidget = new ActionsStripWidget(displaySize.x, displaySize.y, actionStripWidgetWidth, displaySize.y, scene, getVertexBufferObjectManager());
actionStripWidget.enableActionSorting(getPotmeDifficulty() != PotmeDifficulty.TUTORIAL);
actionStripWidget.enableStartButtonControl(getPotmeDifficulty() != PotmeDifficulty.TUTORIAL);
GameLayer.ACTION_STRIP_LAYER.getLayerEntity().attachChild(actionStripWidget);
return actionStripWidget;
}
private ActionsWidget showActionsWidget(PotmeDifficulty potmeDifficulty, int actionStripWidgetWidth) {
ActionsWidget widget = new ActionsWidget(displaySize.x - actionStripWidgetWidth - (2 * ACTION_SIZE_SMALLER), displaySize.y - ACTION_SIZE_SMALLER, potmeDifficulty, scene, actionsStripWidget, getVertexBufferObjectManager());
ActionsWidget widget = new ActionsWidget(displaySize.x - actionStripWidgetWidth - (2 * ACTION_SIZE_SMALLER), displaySize.y - ACTION_SIZE_SMALLER, displaySize.x, displaySize.y, potmeDifficulty, scene, actionsStripWidget, actionStripWidgetWidth, getVertexBufferObjectManager());
GameLayer.ACTIONS_LAYER.getLayerEntity().attachChild(widget);
return widget;
......@@ -615,7 +632,9 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
}
private void goToPlayMode() {
getGameManager().setExtraInt1(getGameManager().getExtraInt1() + ((int)scene.getSecondsElapsedTotal() - planningStartTime));
if (getGameManager() != null) {
getGameManager().setExtraInt1(getGameManager().getExtraInt1() + ((int)scene.getSecondsElapsedTotal() - planningStartTime));
}
startButton.disable();
actionsWidget.disableActions();
actionsStripWidget.disableControl();
......@@ -728,7 +747,7 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
}
MapObject mapObject = tileMap.getTileAtPosition(player.getActualTileMapPosition()).getMapObject();
if ((mapObject != null) &&
(!PotmeDifficulty.getPotmeDifficultyForGameDifficulty(getDifficulty()).hasDifficultyActionType(ActionType.KEY) || player.hasKey()) &&
(!getPotmeDifficulty().hasDifficultyActionType(ActionType.KEY) || player.hasKey()) &&
(mapObject.getMapObjectType() == MapObjectType.SAFE) &&
(selectedActionPosition == selectedActions.size() - 1)) {
......@@ -739,7 +758,9 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
player.registerEntityModifier(new DelayModifier(FINISH_ACTION_DELAY, new EntityModifierListenerAdapter() {
@Override
public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
getGameManager().setCounterAndSave(errorCount);
if (getGameManager() != null) {
getGameManager().setCounterAndSave(errorCount);
}
gameComplete();
}
}));
......@@ -776,27 +797,6 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
createInfoSprite(GameLayer.INFO_LAYER, ResourceManager.INFO_CRASH, gameInfoPositionX, gameInfoPositionY, gameInfoWidth, gameInfoHeight);
createInfoSprite(GameLayer.INFO_LAYER, ResourceManager.INFO_SAFE1, gameInfoPositionX, gameInfoPositionY, gameInfoWidth, gameInfoHeight);
createInfoSprite(GameLayer.INFO_LAYER, ResourceManager.INFO_SAFE2, gameInfoPositionX, gameInfoPositionY, gameInfoWidth, gameInfoHeight);
float startArrowWidth = TILE_SIZE * 1.5f;
float startArrowHeight = TILE_SIZE * 1.5f;
float startPositionX = displaySize.x - actionStripWidgetWidth - ACTION_SIZE_SMALLER + (startArrowWidth * 2/3);
float startPositionY = MAP_START_POSITION_Y - mapWidgets.get(0).getHeight() + startArrowHeight;
createInfoSprite(GameLayer.BACKGROUND_DRAWING_LAYER, ResourceManager.INFO_START_ARROW, startPositionX, startPositionY, startArrowWidth, startArrowHeight);
}
private void showStartArrowInfo() {
scene.registerEntityModifier(new DelayModifier(GAME_INFO_ARROW_APPEAR_DELAY) {
@Override
protected void onModifierFinished(IEntity pItem) {
showGameInfo(ResourceManager.INFO_START_ARROW, true, GAME_INFO_ARROW_APPEAR_DURATION, null);
}
});
}
private void hideStartArrowInfo() {
hideGameInfo(ResourceManager.INFO_START_ARROW, true, null);
}
public void showCrashInfo() {
......@@ -901,24 +901,36 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
seedTextView.setPadding(0, 0, 200, 0);
}
}
/* //////////////////////////////////////////// POTME DIFFICULTY */
public PotmeDifficulty getPotmeDifficulty() {
if (potmeDifficulty == null) {
boolean firstPlay = currentFirstPlay && (getTablexiaContext().getSelectedUser() != null) && (GameManager.getGamePlayCountForUser(getTablexiaContext().getSelectedUser(), getGameDefinition()) == 0);
potmeDifficulty = PotmeDifficulty.getPotmeDifficultyForGameDifficulty(getDifficulty(), firstPlay);
}
return potmeDifficulty;
}
/* //////////////////////////////////////////// VICTORY SCREEN CALLBACKS */
@Override
public CharSequence getVictoryText(int progress) {
switch (progress) {
case 0:
return getString(R.string.game_potme_victory_0);
case 1:
return getString(R.string.game_potme_victory_1);
case 2:
return getString(R.string.game_potme_victory_2);
case 3:
return getString(R.string.game_potme_victory_3);
default:
throw new IllegalStateException("Unknown progress");
}
switch (progress) {
case -1:
return getString(R.string.game_potme_victory_tutorial);
case 0:
return getString(R.string.game_potme_victory_0);
case 1:
return getString(R.string.game_potme_victory_1);
case 2:
return getString(R.string.game_potme_victory_2);
case 3:
return getString(R.string.game_potme_victory_3);
default:
throw new IllegalStateException("Unknown progress");
}
}
@Override
public String[] getVictorySpeech() {
......@@ -927,12 +939,14 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
@Override
public CharSequence getStatsText() {
return Html.fromHtml(getString(R.string.game_potme_error_count, errorCount));
return !getPotmeDifficulty().hasResults() ? "" : Html.fromHtml(getString(R.string.game_potme_error_count, errorCount));
}
@Override
public int countProgress() {
if (errorCount < 1) {
if (!getPotmeDifficulty().hasResults()) {
return -1;
} else if (errorCount < 1) {
return 3;
} else if (errorCount < 3) {
return 2;
......
......@@ -3,8 +3,13 @@ package cz.nic.tablexia.game.games.potme;
import java.util.Arrays;
import java.util.List;
import android.util.Log;
import cz.nic.tablexia.game.common.RandomAccess;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.potme.action.ActionType;
import cz.nic.tablexia.game.games.potme.map.IMapProvider;
import cz.nic.tablexia.game.games.potme.map.MapGenerator;
import cz.nic.tablexia.game.games.potme.map.MapTutorial;
/**
* Game potme difficulty definition and mapping to game difficulty
......@@ -14,18 +19,27 @@ import cz.nic.tablexia.game.games.potme.action.ActionType;
*/
public enum PotmeDifficulty {
EASY (GameDifficulty.EASY, 1, Arrays.asList(new ActionType[]{})),
MEDIUM (GameDifficulty.MEDIUM, 1, Arrays.asList(new ActionType[]{ActionType.KEY})),
HARD (GameDifficulty.HARD, 2, Arrays.asList(new ActionType[]{ActionType.KEY}));
TUTORIAL(null, false, MapTutorial.class, 1, Arrays.asList(new ActionType[]{})),
EASY (GameDifficulty.EASY, true, MapGenerator.class, 1, Arrays.asList(new ActionType[]{})),
MEDIUM (GameDifficulty.MEDIUM, true, MapGenerator.class, 1, Arrays.asList(new ActionType[]{ActionType.KEY})),
HARD (GameDifficulty.HARD, true, MapGenerator.class, 2, Arrays.asList(new ActionType[]{ActionType.KEY}));
private GameDifficulty gameDifficulty;
private int floorCount;
private List<ActionType> difficultyActionTypes;
private Class<? extends IMapProvider> mapProviderClass;
private boolean hasResults;
private PotmeDifficulty(GameDifficulty gameDifficulty, int floorCount, List<ActionType> difficultyActionTypes) {
this.gameDifficulty = gameDifficulty;
this.floorCount = floorCount;
this.difficultyActionTypes = difficultyActionTypes;
private PotmeDifficulty(GameDifficulty gameDifficulty, boolean hasResults, Class<? extends IMapProvider> mapProviderClass, int floorCount, List<ActionType> difficultyActionTypes) {
this.gameDifficulty = gameDifficulty;
this.hasResults = hasResults;
this.mapProviderClass = mapProviderClass;
this.floorCount = floorCount;
this.difficultyActionTypes = difficultyActionTypes;
}
public boolean hasResults() {
return hasResults;
}
public int getFloorCount() {
......@@ -36,7 +50,10 @@ public enum PotmeDifficulty {
return difficultyActionTypes.contains(actionType);
}
public static PotmeDifficulty getPotmeDifficultyForGameDifficulty(GameDifficulty gameDifficulty) {
public static PotmeDifficulty getPotmeDifficultyForGameDifficulty(GameDifficulty gameDifficulty, boolean isFirstGame) {
if (isFirstGame) {
return TUTORIAL;
}
for (PotmeDifficulty potmeDifficulty : PotmeDifficulty.values()) {
if (potmeDifficulty.gameDifficulty == gameDifficulty) {
return potmeDifficulty;
......@@ -45,4 +62,13 @@ public enum PotmeDifficulty {
return null;
}
public IMapProvider getMapProviderNewInstance(RandomAccess randomAccess) {
try {
return mapProviderClass.getConstructor(RandomAccess.class).newInstance(randomAccess);
} catch (Exception e) {
Log.e(PotmeDifficulty.class.getCanonicalName(), "Cannot create instance for IMapProvider class: " + mapProviderClass, e);
}
return null;
}
}
......@@ -167,13 +167,16 @@ public class Action extends Sprite {
/* //////////////////////////////////////////// ACTION STATE */
public void setEnbaled(boolean enabled) {
clickable = enabled;
}
public void disable() {
clickable = false;
setEnbaled(false);
}
public void enable() {
clickable = true;
setEnbaled(true);
}
......
......@@ -38,9 +38,9 @@ import org.andengine.util.modifier.ease.EaseBackOut;
import org.andengine.util.modifier.ease.EaseLinear;
import cz.nic.tablexia.game.games.potme.PotmeActivity;
import cz.nic.tablexia.game.games.potme.PotmeActivity.StartButton;
import cz.nic.tablexia.game.games.potme.ResourceManager;
import cz.nic.tablexia.game.games.potme.UtilityAccess;
import cz.nic.tablexia.game.games.potme.PotmeActivity.StartButton;
import cz.nic.tablexia.game.games.potme.action.Action;
import cz.nic.tablexia.game.games.potme.action.Action.ActionListener;
import cz.nic.tablexia.game.games.potme.action.ActionContainer;
......@@ -79,6 +79,8 @@ public class ActionsStripWidget extends Entity implements ActionListener {
private MoveModifier nextActionFieldMoveModifier;
private MoveModifier scrollPaneMoveModifier;
private int actionOffsetX;
private boolean startButtonControl;
private boolean enableActionSorting;
public ActionsStripWidget(int positionX,
int positionY,
......@@ -95,6 +97,9 @@ public class ActionsStripWidget extends Entity implements ActionListener {
this.vertexBufferObjectManager = vertexBufferObjectManager;
this.actionOffsetX = width / 8;
enableActionSorting = true;
startButtonControl = true;
actualSelectedActionPosition = NO_SELECTED_POSITION;
selectedActions = new ArrayList<ActionContainer>();
......@@ -130,6 +135,14 @@ public class ActionsStripWidget extends Entity implements ActionListener {
return selectedActions.size() < MAXIMUM_ACTIONS_COUNT;
}
public void enableStartButtonControl(boolean startButtonControl) {
this.startButtonControl = startButtonControl;
}
public void enableActionSorting(boolean enableActionSorting) {
this.enableActionSorting = enableActionSorting;
}
/* //////////////////////////////////////////// BACKGROUND AND SCROLLING */
......@@ -382,7 +395,7 @@ public class ActionsStripWidget extends Entity implements ActionListener {
}
public void performCollisionWithNumberStart(int collisionNumber) {
if (isNotFull()) {
if (isNotFull() && enableActionSorting) {
if (collisionNumber > 0 && collisionNumber < selectedActions.size()) {
moveNextActionTemporalyHalfUp();
moveActionsFromPositionHalfDown(collisionNumber);
......@@ -421,10 +434,12 @@ public class ActionsStripWidget extends Entity implements ActionListener {
}
public void setStartButtonState() {
if (selectedActions.size() > 0) {
enableStartButton();
} else {
disableStartButton();
if (startButtonControl) {
if (selectedActions.size() > 0) {
enableStartButton();
} else {
disableStartButton();
}
}
}
......@@ -458,7 +473,8 @@ public class ActionsStripWidget extends Entity implements ActionListener {
// add new action
ActionContainer actionContainer = createActionContainer(createAction(selectedActionType, selectedActionPosition));
if (selectedActionPosition > selectedActions.size()) {
actionContainer.getAction().setEnbaled(enableActionSorting);
if (selectedActionPosition > selectedActions.size() || !enableActionSorting) {
selectedActions.add(actionContainer);
} else {
selectedActions.add(selectedActionPosition, actionContainer);
......
......@@ -23,13 +23,17 @@ import java.util.ArrayList;
import java.util.List;
import org.andengine.entity.Entity;
import org.andengine.entity.IEntity;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.adt.color.Color;
import android.os.Handler;
import cz.nic.tablexia.game.games.potme.PotmeActivity;
import cz.nic.tablexia.game.games.potme.PotmeActivity.StartButton;
import cz.nic.tablexia.game.games.potme.PotmeDifficulty;
import cz.nic.tablexia.game.games.potme.ResourceManager;
import cz.nic.tablexia.game.games.potme.action.Action;
......@@ -43,28 +47,85 @@ import cz.nic.tablexia.game.games.potme.action.ActionType;
*
*/
public class ActionsWidget extends Entity implements ActionListener {
public enum ActionLayer {
BACKGROUND_LAYER (0),
ACTIONS_LAYER (1),
INFO_LAYER (2);
private Entity layerEntity;
private int layerZIndex;
private ActionLayer(int layerZIndex) {
this.layerZIndex = layerZIndex;
}
private void setLayerEntity(Entity layerEntity) {
this.layerEntity = layerEntity