package utm.csc492.diamondfire.models;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;

/**
 * Created by yasith on 2/12/2014.
 */
public abstract class Unit extends Actor {

    protected String name;
    protected char shortName;
    protected int range;
    protected int move;
    protected int health;

    private Sprite sprite;

    // Positions on the battleground
    private int posX;
    private int posY;

    private float size = 32.0f;

    public Unit(Sprite sprite) {
        this.sprite = sprite;
    }


    /**
     * Reset the position of the sprite, then draw
     */
    @Override
    public void draw(SpriteBatch batch, float parentAlpha) {
        // Prepare the sprite before drawing
        sprite.setPosition(posY * size, posX * size);
        sprite.setScale(this.getScaleX(), this.getScaleY());
        sprite.draw(batch, parentAlpha);
    }

    /**
     * Touch detection for the units.
     *
     * Not implemented yet
     */
    public Actor hit(float x, float y) { return null;}

    /**
     * Gets called before draw, should update the states of the Actor here.
     */
    @Override
    public abstract void act(float delta);


    /**
     * Sets the position on the battleground
     */
    public void setPosition(int x, int y){
        this.posX = x;
        this.posY = y;
    }

    public int getHealth() {
        return health;
    }

    public void setHealth(int health) {
        this.health = health;
    }

    public String getName() {
        return name;
    }

    public int getRange() {
        return range;
    }

    public int getMove() {
        return move;
    }

    public int getPosX() {
        return posX;
    }

    public int getPosY() {
        return posY;
    }

    public char getShortName() {
        return shortName;
    }
}

@@ -173,16 +173,121 @@
 d.Actor;
+%0Aimport com.badlogic.gdx.scenes.scene2d.InputEvent;%0Aimport com.badlogic.gdx.scenes.scene2d.InputListener;
 %0A%0A/**%0A *
@@ -706,21 +706,297 @@
 sprite;%0A
-    %7D
+%0A%0A        this.addListener(new InputListener() %7B%0A            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) %7B%0A                onTouchDown();%0A                return true;%0A            %7D%0A        %7D);%0A    %7D%0A%0A    public abstract void onTouchDown();
 %0A%0A%0A    /
@@ -1207,17 +1207,17 @@
 tion(pos
-Y
+X
  * size,
@@ -1220,17 +1220,17 @@
 ize, pos
-X
+Y
  * size)
@@ -1472,21 +1472,34 @@
 y) %7B
- return null;
+%0A        return this;%0A    
 %7D%0A%0A 
@@ -1797,16 +1797,217 @@
 osY = y;
+%0A%0A        // Update the bounds for this unit, in screen position coordinates%0A        float boundX = posX * size;%0A        float boundY = posY * size;%0A%0A        this.setBounds(boundX, boundY, size, size);
 %0A    %7D%0A%0A

Add touch detection for Units.