summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/engine/Tile.java
blob: 85987d69f13376b985490d268659fb625909d474 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package ch.asynk.tankontank.engine;

import java.util.List;
import java.util.ArrayDeque;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;

import ch.asynk.tankontank.engine.gfx.BasicDrawable;
import ch.asynk.tankontank.engine.gfx.StackedImages;

public abstract class Tile implements BasicDrawable
{
    private StackedImages overlays;
    private ArrayDeque<Pawn> stack;

    public abstract Tile getNewAt(float x, float y);

    public Tile(TextureAtlas atlas)
    {
        this.stack = null;
        this.overlays = new StackedImages(atlas);
    }

    public int push(Pawn pawn)
    {
        if (stack == null) stack = new ArrayDeque<Pawn>();
        stack.push(pawn);
        return stack.size();
    }

    public int remove(Pawn pawn)
    {
        stack.remove(pawn);
        return stack.size();
    }

    public Pawn getTopPawn()
    {
        if ((stack == null) || (stack.size() == 0)) return null;
        return stack.getFirst();
    }

    public boolean mustBeDrawn()
    {
        if (occupied()) return true;
        return hasOverlayEnabled();
    }

    public boolean occupied()
    {
        if (stack == null) return false;
        return (stack.size() != 0);
    }

    public boolean clearOverlays()
    {
        overlays.clear();
        return occupied();
    }

    public boolean hasOverlayEnabled()
    {
        return overlays.isEnabled();
    }

    public boolean enableOverlay(int i, boolean enable)
    {
        overlays.enable(i, enable);
        if (enable) return true;
        return mustBeDrawn();
    }

    public List<Tile> adjacents()
    {
        // FIXME
        System.err.println("adjacents() Not implemented yet");
        return null;
    }

    @Override
    public void translate(float x, float y)
    {
        overlays.translate(x, y);
    }

    @Override
    public void setPosition(float x, float y, float z)
    {
        overlays.setPosition(x, y, z);
    }

    @Override
    public void draw(Batch batch, float parentAlpha)
    {
        overlays.draw(batch, parentAlpha);
        Pawn pawn = getTopPawn();
        if (pawn != null)
            pawn.draw(batch, parentAlpha);
    }

    @Override
    public void drawDebug(ShapeRenderer debugShapes)
    {
        overlays.drawDebug(debugShapes);
        Pawn pawn = getTopPawn();
        if (pawn != null)
            pawn.drawDebug(debugShapes);
    }
}