summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/game/Map.java
blob: 9eef409759ecbc7543e1e3c178e5278b1fa8af62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package ch.asynk.tankontank.game;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.GridPoint2;

import ch.asynk.tankontank.engine.Board;
import ch.asynk.tankontank.engine.Pawn;

public class Map extends Board
{
    private Pawn currentPawn;
    private GridPoint2 currentHex = new GridPoint2(-1, -1);

    public Map(Board.Config cfg, Hex[][] board, Texture texture)
    {
        super(cfg, board, texture);
    }

    public boolean drag(float dx, float dy)
    {
        if (currentPawn == null) return false;
        currentPawn.translate(dx, dy);
        return true;
    }

    public void touchDown(float x, float y)
    {
        getHexAt(currentHex, x, y);
        if (currentHex.x != -1) {
            currentPawn = getTopPawnAt(currentHex);
        }
    }

    public void touchUp(float x, float y)
    {
        getHexAt(currentHex, x, y);
        if (currentPawn != null) {
            movePawnTo(currentPawn, currentHex);
        }
    }
}