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

Merge branch 'feature-potme' into 'devel'

Feature potme

See merge request !45
parents 1e7006f3 3dc7a6e9
......@@ -214,7 +214,9 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
*/
public class StartButton extends Entity {
private boolean enabled = true;
private static final float BUTTON_BLINK_DELAY = 0.3f;
private boolean enabled = true;
private Entity backgroundLayer;
private Entity blinkerLayer;
......@@ -226,7 +228,6 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
private Sprite unpressedButtonSprite;
private Sprite disabledButtonSprite;
private Sprite blinkerButtonSprite;
private Text buttonText;
private float textUnpressedPositionX;
......@@ -249,10 +250,6 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
// backgrounds
unpressedButtonSprite = new Sprite(0, 0, ResourceManager.getInstance().getTexture(ResourceManager.CONTROL_START_UNPRESSED), vertexBufferObject);
disabledButtonSprite = new Sprite(0, 0, ResourceManager.getInstance().getTexture(ResourceManager.CONTROL_START_DISABLED), vertexBufferObject);
blinkerButtonSprite = new Sprite(0, 0, ResourceManager.getInstance().getTexture(ResourceManager.CONTROL_START_BLINKER), vertexBufferObject);
disablePulsing();
blinkerLayer.attachChild(blinkerButtonSprite);
// touch area
touchArea = new Rectangle(0, 0, unpressedButtonSprite.getWidth(), unpressedButtonSprite.getHeight(), vertexBufferObject) {
......@@ -294,22 +291,21 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
}
public void enablePulsing() {
FadeInModifier fadeIn = new FadeInModifier(1f);
FadeInModifier fadeIn = new FadeInModifier(BUTTON_BLINK_DELAY);
fadeIn.setAutoUnregisterWhenFinished(true);
FadeOutModifier fadeOut = new FadeOutModifier(1f);
FadeOutModifier fadeOut = new FadeOutModifier(BUTTON_BLINK_DELAY);
fadeOut.setAutoUnregisterWhenFinished(true);
SequenceEntityModifier sequenceModifier = new SequenceEntityModifier(fadeOut, fadeIn);
sequenceModifier.setAutoUnregisterWhenFinished(true);
blinkerModifier = new LoopEntityModifier(sequenceModifier);
blinkerButtonSprite.registerEntityModifier(blinkerModifier);
unpressedButtonSprite.registerEntityModifier(blinkerModifier);
}
public void disablePulsing() {
if (blinkerModifier != null) {
blinkerButtonSprite.unregisterEntityModifier(blinkerModifier);
unpressedButtonSprite.unregisterEntityModifier(blinkerModifier);
blinkerModifier = null;
}
blinkerButtonSprite.setAlpha(0);
}
public boolean isEnbleda() {
......
......@@ -84,7 +84,6 @@ public class ResourceManager {
public static final String CONTROL_NEXT = ASSET_CONTROL + "next.png";
public static final String CONTROL_START_UNPRESSED = ASSET_CONTROL + "start_button_unpressed.png";
public static final String CONTROL_START_DISABLED = ASSET_CONTROL + "start_button_disabled.png";
public static final String CONTROL_START_BLINKER = ASSET_CONTROL + "start_button_blinker.png";
public static final String CONTROL_ACTUAL = ASSET_CONTROL + "actual.png";
public static final String CONTROL_KEY = ASSET_CONTROL + "key_icon.png";
......@@ -104,7 +103,6 @@ public class ResourceManager {
public static final String INFO_SAFE1 = ASSET_INFO + "safe1.png";
public static final String INFO_SAFE2 = ASSET_INFO + "safe2.png";
public static final String INFO_START_ARROW = ASSET_INFO + "start_arrow.png";
public static final String INFO_START_ARROW_BLINKER = ASSET_INFO + "start_arrow_blinker.png";
private static final String ASSET_SFX_SOURCE = ASSET_GAME + "sfx/";
......@@ -207,7 +205,6 @@ public class ResourceManager {
loadTexture(engine, context, CONTROL_NEXT);
loadTexture(engine, context, CONTROL_START_UNPRESSED);
loadTexture(engine, context, CONTROL_START_DISABLED);
loadTexture(engine, context, CONTROL_START_BLINKER);
loadTexture(engine, context, CONTROL_ACTUAL);
loadTexture(engine, context, CONTROL_KEY);
......@@ -224,7 +221,6 @@ public class ResourceManager {
loadTexture(engine, context, INFO_SAFE1);
loadTexture(engine, context, INFO_SAFE2);
loadTexture(engine, context, INFO_START_ARROW);
loadTexture(engine, context, INFO_START_ARROW_BLINKER);
SoundFactory.setAssetBasePath(ASSET_SFX_SOURCE);
......
......@@ -19,7 +19,6 @@
package cz.nic.tablexia.game.games.potme.action.widget;
import java.util.ArrayList;
import java.util.List;
import org.andengine.entity.Entity;
......@@ -38,6 +37,7 @@ import org.andengine.util.adt.color.Color;
import org.andengine.util.modifier.IModifier;
import android.os.Handler;
import android.util.SparseArray;
import cz.nic.tablexia.game.common.EntityModifierListenerAdapter;
import cz.nic.tablexia.game.games.potme.PotmeActivity;
import cz.nic.tablexia.game.games.potme.PotmeActivity.StartButton;
......@@ -90,7 +90,7 @@ public class ActionsWidget extends Entity implements ActionListener {
}
}
private static final float TUTORIAL_INFO_ARROW_BLINK_DURATION = 1f;
private static final float TUTORIAL_INFO_ARROW_BLINK_DURATION = 0.3f;
private static final float TUTORIAL_INFO_ARROW_FADEIN_DELAY = 0.5f;
private static final int TOP_Z_INDEX = ActionType.values().length + 1;
private static final float BACKGROUND_WIDTH_RATIO = 1.3f;
......@@ -106,7 +106,7 @@ public class ActionsWidget extends Entity implements ActionListener {
private static final float START_ARROW_HEIGHT = PotmeActivity.TILE_SIZE;
private ActionsStripWidget actionsStripWidget;
private List<Action> actions;
private SparseArray<Action> actions;
private VertexBufferObjectManager vertexBufferObjectManager;
private final Scene scene;
private Rectangle dimmer;
......@@ -130,7 +130,7 @@ public class ActionsWidget extends Entity implements ActionListener {
this.scene = scene;
this.actionsStripWidget = actionsStripWidget;
this.vertexBufferObjectManager = vertexBufferObjectManager;
this.actions = new ArrayList<Action>();
this.actions = new SparseArray<Action>();
currentStepNumber = 0;
......@@ -159,8 +159,9 @@ public class ActionsWidget extends Entity implements ActionListener {
dimmer.setVisible(false);
ActionLayer.attachLayersToEntity(this);
for (ActionType actionType : actionTypes) {
createAction(actionType, actionType.ordinal(), false, scene);
for (int i = 0; i < actionTypes.size(); i++) {
ActionType actionType = actionTypes.get(i);
createAction(actionType, i, actionType.ordinal(), false, scene);
}
ActionLayer.ACTIONS_LAYER.getLayerEntity().attachChild(dimmer);
ActionLayer.BACKGROUND_LAYER.getLayerEntity().attachChild(actionsBackground);
......@@ -171,19 +172,19 @@ public class ActionsWidget extends Entity implements ActionListener {
this.startButton = startButton;
}
private Action createAction(ActionType actionType, int orderNumber, boolean visible, Scene scene) {
private Action createAction(ActionType actionType, int position, int orderNumber, boolean visible, Scene scene) {
Action action = new Action(actionType,
orderNumber,
PotmeActivity.ACTION_SIZE_SMALLER,
2 * ACTION_OFFSET + PotmeActivity.ACTION_SIZE_SMALLER / 2 + (orderNumber % NUMBER_OF_COLUMNS) * (PotmeActivity.ACTION_SIZE_SMALLER + ACTION_OFFSET),
- 2 * ACTION_OFFSET - (((int) (orderNumber / NUMBER_OF_COLUMNS)) * (PotmeActivity.ACTION_SIZE_SMALLER + ACTION_OFFSET)),
2 * ACTION_OFFSET + PotmeActivity.ACTION_SIZE_SMALLER / 2 + (position % NUMBER_OF_COLUMNS) * (PotmeActivity.ACTION_SIZE_SMALLER + ACTION_OFFSET),
- 2 * ACTION_OFFSET - (((int) (position / NUMBER_OF_COLUMNS)) * (PotmeActivity.ACTION_SIZE_SMALLER + ACTION_OFFSET)),
visible,
vertexBufferObjectManager);
action.addActionListener(this);
action.setClickable(scene);
ActionLayer.ACTIONS_LAYER.getLayerEntity().attachChild(action);
actions.add(action.getOrderNumber(), action);
actions.put(action.getOrderNumber(), action);
return action;
}
......@@ -199,7 +200,8 @@ public class ActionsWidget extends Entity implements ActionListener {
public void showActions() {
int actualDelay = 0;
for (final Action action : actions) {
for (int i = 0; i < actions.size(); i++) {
final Action action = actions.get(actions.keyAt(i));
(new Handler()).postDelayed(new Runnable() {
@Override
......@@ -226,14 +228,16 @@ public class ActionsWidget extends Entity implements ActionListener {
public void enableActions() {
if (potmeDifficulty != PotmeDifficulty.TUTORIAL) {
for (Action action : actions) {
for (int i = 0; i < actions.size(); i++) {
Action action = actions.get(actions.keyAt(i));
action.enable();
}
}
}
public void disableActions() {
for (Action action : actions) {
for (int i = 0; i < actions.size(); i++) {
Action action = actions.get(actions.keyAt(i));
action.disable();
}
}
......@@ -244,8 +248,7 @@ public class ActionsWidget extends Entity implements ActionListener {
@Override
public void onActionDrag(Action lastAction) {
PotmeActivity.GameLayer.ACTIONS_LAYER.sendToFront(scene);
actions.remove(lastAction);
Action action = createAction(lastAction.getActionType(), lastAction.getOrderNumber(), false, scene);
Action action = createAction(lastAction.getActionType(), actions.indexOfKey(lastAction.getOrderNumber()), lastAction.getOrderNumber(), false, scene);
action.showWithAnimation();
prepareActionsCollisionEntity(action);
disableActions();
......@@ -284,7 +287,8 @@ public class ActionsWidget extends Entity implements ActionListener {
private void tryDimmAllActions() {
if (potmeDifficulty == PotmeDifficulty.TUTORIAL) {
dimmer.setVisible(true);
for (Action action : actions) {
for (int i = 0; i < actions.size(); i++) {
Action action = actions.get(actions.keyAt(i));
action.setZIndex(action.getOrderNumber());
action.disable();
}
......@@ -313,17 +317,8 @@ public class ActionsWidget extends Entity implements ActionListener {
ResourceManager.getInstance().getTexture(ResourceManager.INFO_START_ARROW),
vertexBufferObjectManager);
final Sprite infoArrowBlinkerSprite = new Sprite(positionX + START_ARROW_X_OFFSET,
positionY - START_ARROW_Y_OFFSET,
START_ARROW_WIDTH,
START_ARROW_HEIGHT,
ResourceManager.getInstance().getTexture(ResourceManager.INFO_START_ARROW_BLINKER),
vertexBufferObjectManager);
infoArrowSprite.setAlpha(0);
infoArrowBlinkerSprite.setAlpha(0);
ActionLayer.INFO_LAYER.getLayerEntity().attachChild(infoArrowSprite);
ActionLayer.INFO_LAYER.getLayerEntity().attachChild(infoArrowBlinkerSprite);
FadeInModifier fadeIn = new FadeInModifier(TUTORIAL_INFO_ARROW_BLINK_DURATION);
fadeIn.setAutoUnregisterWhenFinished(true);
......@@ -338,10 +333,7 @@ public class ActionsWidget extends Entity implements ActionListener {
@Override
public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
FadeInModifier fadeInModifier = new FadeInModifier(TUTORIAL_INFO_ARROW_FADEIN_DELAY);
fadeInModifier.setAutoUnregisterWhenFinished(true);
infoArrowSprite.registerEntityModifier(fadeInModifier);
infoArrowBlinkerSprite.registerEntityModifier(new LoopEntityModifier(sequenceModifier));
infoArrowSprite.registerEntityModifier(new LoopEntityModifier(sequenceModifier));
}
});
......
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