Commit a1198376 authored by Matyáš Latner's avatar Matyáš Latner

#83 Zvvýraznění kroků v tutoriálu

parent 0723a198
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
......@@ -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;
......@@ -83,7 +84,7 @@ import cz.nic.tablexia.game.manager.GameManager;
*/
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),
......@@ -138,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;
......@@ -167,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;
......@@ -259,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() {
......@@ -386,8 +390,11 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
actionsStripWidget = showActionsStripWidget(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);
......@@ -405,7 +412,6 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
goToPlanningMode();
super.showGame();
actionsWidget.showActions();
showStartArrowInfo();
}
/* //////////////////////////////////////////// BACKGROUND */
......@@ -537,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;
......@@ -789,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() {
......
......@@ -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();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment