diff options
Diffstat (limited to 'core/src/ch/asynk')
6 files changed, 49 insertions, 164 deletions
| diff --git a/core/src/ch/asynk/tankontank/engine/gfx/AbstractDrawable.java b/core/src/ch/asynk/tankontank/engine/gfx/AbstractDrawable.java deleted file mode 100644 index bfafb38..0000000 --- a/core/src/ch/asynk/tankontank/engine/gfx/AbstractDrawable.java +++ /dev/null @@ -1,93 +0,0 @@ -package ch.asynk.tankontank.engine.gfx; - -import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; - -public abstract class AbstractDrawable implements Drawable -{ -    protected float w; -    protected float h; -    protected float x; -    protected float y; -    protected int r; -    protected float s; -    protected Color color; - -    public AbstractDrawable() -    { -        this.w = 0f; -        this.h = 0f; -        this.x = 0f; -        this.y = 0f; -        this.r = 0; -        this.s = 1f; -        this.color = new Color(1, 1, 1, 1); -    } - -    @Override -    public void drawDebug(ShapeRenderer debugShapes) {} - -    @Override -    public float getWidth() -    { -        return w; -    } - -    @Override -    public float getHeight() -    { -        return h; -    } - -    @Override -    public float getX() -    { -        return x; -    } - -    @Override -    public float getY() -    { -        return y; -    } - -    @Override -    public int getRotation() -    { -        return r; -    } - -    @Override -    public void setRotation(int r) -    { -        this.r = r; -    } - -    @Override -    public void setScale(float s) -    { -        this.s = s; -    } - -    @Override -    public void setPosition(float x, float y) -    { -        this.x = x; -        this.y = y; -    } - -    @Override -    public void moveBy(float dx, float dy) -    { -        this.x += dx; -        this.y += dy; -    } - -    @Override -    public void setCoords(float x, float y, int r) -    { -        this.x = x; -        this.y = y; -        this.r = r; -    } -} diff --git a/core/src/ch/asynk/tankontank/engine/gfx/Drawable.java b/core/src/ch/asynk/tankontank/engine/gfx/Drawable.java index 075c33d..8f39e87 100644 --- a/core/src/ch/asynk/tankontank/engine/gfx/Drawable.java +++ b/core/src/ch/asynk/tankontank/engine/gfx/Drawable.java @@ -14,9 +14,9 @@ public interface Drawable extends Disposable      public float getY(); -    public   int getRotation(); +    public float getRotation(); -    public void setRotation(int r); +    public void setRotation(float r);      public void setScale(float s); @@ -24,7 +24,7 @@ public interface Drawable extends Disposable      public void moveBy(float dx, float dy); -    public void setCoords(float x, float y, int r); +    public void setCoords(float x, float y, float r);      public void draw(Batch batch, float parentAlpha); diff --git a/core/src/ch/asynk/tankontank/engine/gfx/Node.java b/core/src/ch/asynk/tankontank/engine/gfx/Node.java index 4c94e50..982e022 100644 --- a/core/src/ch/asynk/tankontank/engine/gfx/Node.java +++ b/core/src/ch/asynk/tankontank/engine/gfx/Node.java @@ -1,6 +1,8 @@  package ch.asynk.tankontank.engine.gfx;  import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer;  import ch.asynk.tankontank.engine.Layer; diff --git a/core/src/ch/asynk/tankontank/engine/gfx/SpriteNode.java b/core/src/ch/asynk/tankontank/engine/gfx/SpriteNode.java new file mode 100644 index 0000000..f714203 --- /dev/null +++ b/core/src/ch/asynk/tankontank/engine/gfx/SpriteNode.java @@ -0,0 +1,44 @@ +package ch.asynk.tankontank.engine.gfx; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; + +public abstract class SpriteNode extends Sprite implements Node +{ +    public SpriteNode(Texture texture) +    { +        super(texture); +    } + +    public SpriteNode(TextureRegion region) +    { +        super(region); +    } + +    @Override +    public void dispose() +    { +        // FIXME : what to do with dispose in SpriteNode +    } + +    @Override +    public void moveBy(float dx, float dy) +    { +        translate(dx, dy); +    } + +    @Override +    public void setCoords(float x, float y, float r) +    { +        setPosition(x, y); +        setRotation(r); +    } + +    @Override +    public void drawDebug(ShapeRenderer shapes) +    { +        shapes.rect(getX(), getY(), (getWidth() / 2f), (getHeight() / 2f), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation()); +    } +} diff --git a/core/src/ch/asynk/tankontank/engine/gfx/TextureDrawable.java b/core/src/ch/asynk/tankontank/engine/gfx/TextureDrawable.java deleted file mode 100644 index 3803d15..0000000 --- a/core/src/ch/asynk/tankontank/engine/gfx/TextureDrawable.java +++ /dev/null @@ -1,39 +0,0 @@ -package ch.asynk.tankontank.engine.gfx; - -import com.badlogic.gdx.Gdx; - -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.Batch; - -public class TextureDrawable extends AbstractDrawable -{ -    private Texture texture; - -    public TextureDrawable(Texture texture) -    { -        this.texture = texture; -        this.w = texture.getWidth(); -        this.h = texture.getHeight(); -    } - -    @Override -    public void dispose() -    { -        texture.dispose(); -    } - -    @Override -    public void draw(Batch batch, float parentAlpha) -    { -        batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); - -        if (r != 0f) -            batch.draw(texture, x, y, (w / 2f), (h / 2f), w, h, s, s, r, (int) x, (int) y, (int) w, (int) h, false, false); -        else { -            if (s == 1f) -                batch.draw(texture, x, y); -            else -                batch.draw(texture, x, y, getWidth() * s, getHeight() * s); -        } -    } -} diff --git a/core/src/ch/asynk/tankontank/engine/gfx/TextureRegionDrawable.java b/core/src/ch/asynk/tankontank/engine/gfx/TextureRegionDrawable.java deleted file mode 100644 index afb54d9..0000000 --- a/core/src/ch/asynk/tankontank/engine/gfx/TextureRegionDrawable.java +++ /dev/null @@ -1,29 +0,0 @@ -package ch.asynk.tankontank.engine.gfx; - -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.TextureRegion; - -public class TextureRegionDrawable extends AbstractDrawable -{ -    private TextureRegion region; - -    public TextureRegionDrawable(TextureRegion region) -    { -        this.region = region; -        this.w = region.getRegionWidth(); -        this.h = region.getRegionHeight(); -    } - -    @Override -    public void dispose() -    { -    } - -    @Override -    public void draw(Batch batch, float parentAlpha) -    { -        batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); - -        batch.draw(region, x, y, (w / 2f), (h / 2f), w, h, s, s, r, true); -    } -} | 
