Permalink
Browse files

Lesson 27: Arrow buttons for android devices

  • Loading branch information...
vladimirslav committed Jan 2, 2017
1 parent 223be4e commit 183f5b02b8ddeff08ad71c7681e1ef766ecb50c1
@@ -13,7 +13,7 @@ attack
index: -1
base
rotate: false
xy: 20, 32
xy: 38, 16
size: 16, 4
orig: 16, 4
offset: 0, 0
@@ -32,93 +32,121 @@ coin
orig: 16, 16
offset: 0, 0
index: -1
ghost
darrow
rotate: false
xy: 2, 74
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
ground
ghost
rotate: false
xy: 20, 92
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
ground
rotate: false
xy: 38, 110
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
health
rotate: false
xy: 38, 58
xy: 38, 22
size: 14, 14
orig: 14, 14
offset: 0, 0
index: -1
larrow
rotate: false
xy: 2, 56
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
player
rotate: false
xy: 38, 110
xy: 20, 74
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
rarrow
rotate: false
xy: 38, 92
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
skeleton
rotate: false
xy: 2, 56
xy: 2, 38
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
slime
rotate: false
xy: 20, 74
xy: 20, 56
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
sound0
rotate: false
xy: 38, 92
xy: 38, 74
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
sound1
rotate: false
xy: 2, 38
xy: 2, 20
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
sound2
rotate: false
xy: 20, 56
xy: 2, 2
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
sound3
rotate: false
xy: 38, 74
xy: 20, 38
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
spider
rotate: false
xy: 2, 20
xy: 38, 56
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
uarrow
rotate: false
xy: 20, 20
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
wall
rotate: false
xy: 2, 2
xy: 20, 2
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
warning
rotate: false
xy: 20, 38
xy: 38, 38
size: 16, 16
orig: 16, 16
offset: 0, 0
Binary file not shown.
@@ -42,6 +42,12 @@
public TextureRegionDrawable soundBtn[];
public TextureRegionDrawable leftArrowBtn;
public TextureRegionDrawable rightArrowBtn;
public TextureRegionDrawable upArrowBtn;
public TextureRegionDrawable downArrowBtn;
public static final int TILE_SIZE = 16;
public Resources()
@@ -80,6 +86,11 @@ public Resources()
{
soundBtn[i] = new TextureRegionDrawable(gameSprites.findRegion("sound" + i));
}
leftArrowBtn = new TextureRegionDrawable(gameSprites.findRegion("larrow"));
rightArrowBtn = new TextureRegionDrawable(gameSprites.findRegion("rarrow"));
upArrowBtn = new TextureRegionDrawable(gameSprites.findRegion("uarrow"));
downArrowBtn = new TextureRegionDrawable(gameSprites.findRegion("darrow"));
}
public void dispose()
@@ -1,34 +1,33 @@
package com.coldwild.dodginghero.screens;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.coldwild.dodginghero.DodgingHero;
import com.coldwild.dodginghero.Resources;
import com.coldwild.dodginghero.SoundManager;
import com.coldwild.dodginghero.graph.Background;
import com.coldwild.dodginghero.graph.SizeEvaluator;
import com.coldwild.dodginghero.graph.effects.WarningEffect;
import com.coldwild.dodginghero.logic.GameLogic;
import com.coldwild.dodginghero.logic.GameProgress;
import com.coldwild.dodginghero.logic.objects.Bonus;
import com.coldwild.dodginghero.logic.objects.Player;
import sun.security.provider.SHA;
/**
* Created by comrad_gremlin on 9/6/2016.
*/
@@ -53,6 +52,8 @@
private Player player;
private ImageButton sndBtn;
private Group controlGroup;
public static final float GAME_END_FADEOUT = 0.5f;
public static final float GAME_START_FADEIN = 0.25f;
@@ -116,16 +117,16 @@ public boolean keyDown(InputEvent event, int keycode) {
switch (keycode)
{
case Input.Keys.UP:
AttempMove(0, 1);
AttemptMove(0, 1);
break;
case Input.Keys.DOWN:
AttempMove(0, -1);
AttemptMove(0, -1);
break;
case Input.Keys.LEFT:
AttempMove(-1, 0);
AttemptMove(-1, 0);
break;
case Input.Keys.RIGHT:
AttempMove(1, 0);
AttemptMove(1, 0);
break;
};
return false;
@@ -134,6 +135,44 @@ public boolean keyDown(InputEvent event, int keycode) {
gameStage.getCamera().update();
batch.setProjectionMatrix(gameStage.getCamera().combined);
controlGroup = new Group();
gameStage.addActor(controlGroup);
//if (Gdx.app.getType() == Application.ApplicationType.Android)
{
prepareDirectionButtons();
}
}
private void prepareDirectionButton(final int dx,
final int dy,
TextureRegionDrawable img,
float x,
float y)
{
ImageButton btn = new ImageButton(img);
btn.setPosition(x, y);
btn.addListener(new ClickListener() {
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button)
{
AttemptMove(dx, dy);
super.touchUp(event, x, y, pointer, button);
}
});
controlGroup.addActor(btn);
}
private void prepareDirectionButtons() {
// up-down
prepareDirectionButton(0, 1, game.res.upArrowBtn, 2, gameStage.getHeight() / 2 + 2);
prepareDirectionButton(0, -1, game.res.downArrowBtn, 2, gameStage.getHeight() / 2 - 16);
// left-right
prepareDirectionButton(-1, 0, game.res.leftArrowBtn, gameStage.getWidth() - 36, gameStage.getHeight() / 2 - 9);
prepareDirectionButton(1, 0, game.res.rightArrowBtn, gameStage.getWidth() - 18, gameStage.getHeight() / 2 - 9);
}
public void update(float delta)
@@ -292,7 +331,7 @@ public void resize(int width, int height)
sizeEvaluator.setRightSideX(gameStage.getWidth());
}
public void AttempMove(int dx, int dy)
public void AttemptMove(int dx, int dy)
{
if (player.getLives() > 0 &&
logic.getEnemy().getLives() > 0 &&
@@ -306,6 +345,7 @@ public void AttempMove(int dx, int dy)
boolean playerWon;
@Override
public void OnGameEnd(final boolean playerWon) {
controlGroup.remove();
this.playerWon = playerWon;
gameStage.addAction(
Actions.sequence(

0 comments on commit 183f5b0

Please sign in to comment.