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

Merge branch 'feature-potme' into 'devel'

Feature potme

See merge request !43
parents c35b70b5 a1198376
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);
}
/**
......
......@@ -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;
}
public Entity getLayerEntity() {
return layerEntity;
}
public int getLayerZIndex() {
return layerZIndex;
}
public static void attachLayersToEntity(IEntity conteinerEntity) {
for (ActionLayer actionLayer : ActionLayer.values()) {
Entity entity = new Entity();
actionLayer.setLayerEntity(entity);
conteinerEntity.attachChild(entity);
entity.setZIndex(actionLayer.getLayerZIndex());
}
conteinerEntity.sortChildren();
}
}
private static final int TOP_Z_INDEX = ActionType.values().length + 1;
private static final float BACKGROUND_WIDTH_RATIO = 1.3f;
private static final double BACKGROUND_Y_POSITION_RATIO = 0.9;
private static final int START_ANIMATION_DELAY = 200;
private static final int NUMBER_OF_COLUMNS = 2;
public static final int ACTION_OFFSET = PotmeActivity.ACTION_SIZE_SMALLER / 10;
private static final float DIMMER_ALPHA = 0.5f;
private static final Color DIMMER_COLOR = Color.BLACK;
private static final float START_ARROW_WIDTH = PotmeActivity.TILE_SIZE * 1.2f;
private static final float START_ARROW_HEIGHT = PotmeActivity.TILE_SIZE;
private ActionsStripWidget actionsStripWidget;
private List<Action> actions;
private VertexBufferObjectManager vertexBufferObjectManager;
private final Scene scene;
private Rectangle dimmer;
private PotmeDifficulty potmeDifficulty;
private int currentStepNumber;
private StartButton startButton;
public ActionsWidget(float positionX, float positionY, PotmeDifficulty potmeDifficulty, Scene scene, ActionsStripWidget actionsStripWidget, VertexBufferObjectManager vertexBufferObjectManager) {
public ActionsWidget(float positionX,
float positionY,
float displaySizeX,
float displaySizeY,
PotmeDifficulty potmeDifficulty,
Scene scene,
ActionsStripWidget actionsStripWidget,
float actionStripWidgetWidth,
VertexBufferObjectManager vertexBufferObjectManager) {
super(positionX, positionY);
this.potmeDifficulty = potmeDifficulty;
this.scene = scene;
this.actionsStripWidget = actionsStripWidget;
this.vertexBufferObjectManager = vertexBufferObjectManager;
this.actions = new ArrayList<Action>();
currentStepNumber = 0;
List<ActionType> actionTypes = ActionType.getActionTypesForGameDifficulty(potmeDifficulty);
// BACKGROUND
ITextureRegion backgroundTexture = ResourceManager.getInstance().getTexture(ResourceManager.BACKGROUND_ACTIONS_TEXTURE);
int backgroundWidth = (int)((NUMBER_OF_COLUMNS * PotmeActivity.ACTION_SIZE_SMALLER) * BACKGROUND_WIDTH_RATIO);
int backgroundHeight = (int)(backgroundWidth * (backgroundTexture.getHeight() / backgroundTexture.getWidth()));
......@@ -73,11 +134,31 @@ public class ActionsWidget extends Entity implements ActionListener {
backgroundWidth,
backgroundHeight,
backgroundTexture, vertexBufferObjectManager);
attachChild(actionsBackground);
for (int i = 0; i < actionTypes.size(); i++) {
createAction(actionTypes.get(i), i, false, scene);
// DIMMER
float actionStripWidgetOffset = (actionStripWidgetWidth / 2) * 0.95f;
dimmer = new Rectangle(-positionX + (displaySizeX / 2) - actionStripWidgetOffset,
-positionY + (displaySizeY / 2),
displaySizeX - actionStripWidgetOffset,
displaySizeY,
vertexBufferObjectManager);
dimmer.setColor(DIMMER_COLOR);
dimmer.setAlpha(DIMMER_ALPHA);
dimmer.setVisible(false);
ActionLayer.attachLayersToEntity(this);
for (ActionType actionType : actionTypes) {
createAction(actionType, actionType.ordinal(), false, scene);
}
ActionLayer.ACTIONS_LAYER.getLayerEntity().attachChild(dimmer);
ActionLayer.BACKGROUND_LAYER.getLayerEntity().attachChild(actionsBackground);
tryToPerformNextTutorialStep();
}
public void setStartButton(StartButton startButton) {
this.startButton = startButton;
}
private Action createAction(ActionType actionType, int orderNumber, boolean visible, Scene scene) {
......@@ -91,11 +172,12 @@ public class ActionsWidget extends Entity implements ActionListener {
action.addActionListener(this);
action.setClickable(scene);
attachChild(action);
actions.add(action);
ActionLayer.ACTIONS_LAYER.getLayerEntity().attachChild(action);
actions.add(action.getOrderNumber(), action);
return action;
}
/* //////////////////////////////////////////// COLLISIONS */
private void prepareActionsCollisionEntity(Action action) {
......@@ -125,8 +207,10 @@ public class ActionsWidget extends Entity implements ActionListener {
/* //////////////////////////////////////////// ACTION STATE */
public void enableActions() {
for (Action action : actions) {
action.enable();
if (potmeDifficulty != PotmeDifficulty.TUTORIAL) {
for (Action action : actions) {
action.enable();
}
}
}
......@@ -147,14 +231,73 @@ public class ActionsWidget extends Entity implements ActionListener {
action.showWithAnimation();
prepareActionsCollisionEntity(action);
disableActions();
hideArrowSprite();
}
@Override
public void onActionDrop(Action action, int collidesWithNumber) {
PotmeActivity.GameLayer.resetLayersZIndexes(scene);
enableActions();
if (collidesWithNumber != Action.NO_COLLISION_NUMBER) {
actionsStripWidget.addSelectedAction(action.getActionType(), collidesWithNumber);
currentStepNumber++;
}
tryToPerformNextTutorialStep();
}
/* //////////////////////////////////////////// TUTORIAL STEPS */
private void tryToPerformNextTutorialStep() {
if (potmeDifficulty == PotmeDifficulty.TUTORIAL) {
if (currentStepNumber < PotmeActivity.TUTORIAL_STEPS.size()) {
highliteAction(PotmeActivity.TUTORIAL_STEPS.get(currentStepNumber));
if (startButton != null) {
startButton.disable();
}
} else {
PotmeActivity.GameLayer.BUTTON_LAYER.sendToFront(scene);
if (startButton != null) {
startButton.enable();
}
}
} else {
enableActions();
}
}
private void dimmAllActions() {
dimmer.setVisible(true);
for (Action action : actions) {
action.setZIndex(action.getOrderNumber());
action.disable();
}
dimmer.setZIndex(actions.size());
ActionLayer.ACTIONS_LAYER.getLayerEntity().sortChildren();
}
private void highliteAction(ActionType actionType) {
if (actionType.ordinal() < actions.size()) {
dimmAllActions();
Action action = actions.get(actionType.ordinal());
action.setZIndex(TOP_Z_INDEX);
action.enable();
showArrowSprite(action.getX(), action.getY(), vertexBufferObjectManager);
ActionLayer.ACTIONS_LAYER.getLayerEntity().sortChildren();
}
}
private void showArrowSprite(float positionX, float positionY, VertexBufferObjectManager vertexBufferObjectManager) {
hideArrowSprite();
Sprite infoArrowSprite = new Sprite(positionX + (PotmeActivity.ACTION_SIZE_SMALLER * 1.2f),
positionY - (PotmeActivity.ACTION_SIZE_SMALLER / 2),
START_ARROW_WIDTH,
START_ARROW_HEIGHT,
ResourceManager.getInstance().getTexture(ResourceManager.INFO_START_ARROW),
vertexBufferObjectManager);
ActionLayer.INFO_LAYER.getLayerEntity().attachChild(infoArrowSprite);
}
private void hideArrowSprite() {
ActionLayer.INFO_LAYER.getLayerEntity().detachChildren();
}
}
package cz.nic.tablexia.game.games.potme.map;
import cz.nic.tablexia.game.games.potme.map.mapobject.MapObjectType;
import cz.nic.tablexia.game.games.potme.map.tile.Tile;
public interface IMapProvider {
public TileMap prepareMap(Tile lastFinishTile, int mapXSize, int mapYSize, MapObjectType finishMapObject, boolean hasKey);
}
......@@ -39,7 +39,7 @@ import cz.nic.tablexia.game.games.potme.map.tile.TileType;
* @author Matyáš Latner
*
*/
public class MapGenerator {
public class MapGenerator implements IMapProvider {
private static final double OBSTACLE_PROBABILITY = 0.4;
......@@ -82,7 +82,7 @@ public class MapGenerator {
this.randomAccess = randomAccess;
}
public TileMap generateRandomMap(Tile lastFinishTile, int mapXSize, int mapYSize, MapObjectType finishMapObject, boolean hasKey) {
public TileMap prepareMap(Tile lastFinishTile, int mapXSize, int mapYSize, MapObjectType finishMapObject, boolean hasKey) {
Log.d(MapGenerator.class.getCanonicalName(), "Start generating with random seed: " + randomAccess.getRandomSeed());
TileMap tileMap = new TileMap(mapXSize, mapYSize);
......@@ -103,7 +103,7 @@ public class MapGenerator {
// connect all tile groups
connectAllGroups(tileMap, Arrays.asList(new TileMapPosition[] {startPosition}));
// selects best tile for safe
// select best tile for safe
Tile finishTile = createFinishTile(tileMap, finishMapObject);
tileMap.setMapFinishPosition(finishTile.getTileMapPosition());
......
package cz.nic.tablexia.game.games.potme.map;
import android.util.Log;
import cz.nic.tablexia.game.common.RandomAccess;
import cz.nic.tablexia.game.games.potme.PotmeActivity;
import cz.nic.tablexia.game.games.potme.map.TileMap.TileMapPosition;
import cz.nic.tablexia.game.games.potme.map.mapobject.MapObjectType;
import cz.nic.tablexia.game.games.potme.map.mapobstacle.MapObstacleType;
import cz.nic.tablexia.game.games.potme.map.mapobstacle.MapObstacleType.MapObstaclePosition;
import cz.nic.tablexia.game.games.potme.map.tile.Tile;
import cz.nic.tablexia.game.games.potme.map.tile.TileType;
public class MapTutorial implements IMapProvider {
protected RandomAccess randomAccess;
public MapTutorial(RandomAccess randomAccess) {
this.randomAccess = randomAccess;
}
@Override
public TileMap prepareMap(Tile lastFinishTile, int mapXSize, int mapYSize, MapObjectType finishMapObject, boolean hasKey) {
Log.d(MapGenerator.class.getCanonicalName(), "Start preparing tutorial map with random seed: " + randomAccess.getRandomSeed());
TileMap tileMap = new TileMap(mapXSize, mapYSize);
TileMapPosition position1 = PotmeActivity.DEFAULT_MAP_START_POSITION;
TileMapPosition position2 = new TileMapPosition(position1.getPositionX() - 1, position1.getPositionY());
TileMapPosition position3 = new TileMapPosition(position1.getPositionX() - 1, position1.getPositionY() - 1);
tileMap.setMapStartPosition(position1);
tileMap.setMapFinishPosition(position3);
Tile tile1 = new Tile(TileType.TILE_2IH);
Tile tile2 = new Tile(TileType.TILE_2LA);
Tile tile3 = new Tile(TileType.TILE_1C);
tileMap.addTileAtPosition(position1, tile1);
tileMap.addTileAtPosition(position2, tile2);
tileMap.addTileAtPosition(position3, tile3);
tile3.setMapObstacle(MapObstaclePosition.BOTTOM_POSITION, MapObstacleType.DOOR_H);
tile3.setMapObject(finishMapObject);
// fill all map
for (int i = 0; i < tileMap.getMapXSize(); i++) {
for (int j = 0; j < tileMap.getMapYSize(); j++) {
if (!tileMap.isTileAtPosition(i, j)) {
Tile tile = new Tile(TileType.TILE_0);
tileMap.addTileAtPosition(i, j, tile);
}
}
}
return tileMap;
}
}
\ No newline at end of file
......@@ -30,10 +30,9 @@ import org.andengine.opengl.vbo.DrawType;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.adt.color.Color;
import cz.nic.tablexia.game.common.RandomAccess;
import cz.nic.tablexia.game.games.potme.PotmeActivity;
import cz.nic.tablexia.game.games.potme.ResourceManager;
import cz.nic.tablexia.game.games.potme.map.MapGenerator;
import cz.nic.tablexia.game.games.potme.map.IMapProvider;
import cz.nic.tablexia.game.games.potme.map.TileMap;
import cz.nic.tablexia.game.games.potme.map.mapobject.MapObject;
import cz.nic.tablexia.game.games.potme.map.mapobject.MapObjectType;
......@@ -100,7 +99,7 @@ public class MapWidget extends Entity {
}
public MapWidget(Tile lastFinishTile, MapObjectType finishMapObjetcType, int floorNumber, boolean hasBookmark, int positionX, int positionY, int mapXSize, int mapYSize, boolean hasKey, RandomAccess randomAccess, String buttonText, VertexBufferObjectManager vertexBufferObjectManager) {
public MapWidget(IMapProvider mapProvider, Tile lastFinishTile, MapObjectType finishMapObjetcType, int floorNumber, boolean hasBookmark, int positionX, int positionY, int mapXSize, int mapYSize, boolean hasKey, String buttonText, VertexBufferObjectManager vertexBufferObjectManager) {
super();
this.buttonText = buttonText;