From 58f02682e0af500ba510eefcf023ae70e28e780d Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 7 Dec 2018 01:39:16 +0100 Subject: Add initial impl for sprites --- src/subconscious/graphics/MapScene.java | 18 ++++++++++++++++-- src/subconscious/graphics/Sprite.java | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/subconscious/graphics/Sprite.java diff --git a/src/subconscious/graphics/MapScene.java b/src/subconscious/graphics/MapScene.java index fb590ac..8e2933b 100644 --- a/src/subconscious/graphics/MapScene.java +++ b/src/subconscious/graphics/MapScene.java @@ -5,6 +5,8 @@ import subconscious.Map; import subconscious.Tile; import subconscious.Actor; +import java.util.ArrayList; + import java.awt.Canvas; import java.awt.Point; import java.awt.Rectangle; @@ -55,6 +57,8 @@ public abstract class MapScene extends Scene { protected boolean zooming = false; protected boolean panning = false; + protected ArrayList sprites = new ArrayList<>(); + public MapScene(Game g, String uniqueName) { super(g, uniqueName); @@ -154,7 +158,17 @@ public abstract class MapScene extends Scene { g.drawRect(0, 0, maxBound, maxBound); } - protected void renderActors(Graphics2D g) { + protected void renderSprites(Graphics2D g) { + + for (Sprite sprite : this.sprites) { + Rectangle rect = sprite.getRect(); + Graphics2D spriteGraphics = (Graphics2D) g.create( + rect.x, rect.y, rect.width, rect.height + ); + + sprite.render(spriteGraphics); + } + // Draw actors g.setFont(g.getFont().deriveFont(g.getFont().getSize()*2.0F)); @@ -251,7 +265,7 @@ public abstract class MapScene extends Scene { g.transform(this.applyZoomTx); g.transform(this.applyPanTx); this.renderTiles(g); - this.renderActors(g); + this.renderSprites(g); g.transform(this.undoPanTx); g.transform(this.undoZoomTx); } diff --git a/src/subconscious/graphics/Sprite.java b/src/subconscious/graphics/Sprite.java new file mode 100644 index 0000000..ed048da --- /dev/null +++ b/src/subconscious/graphics/Sprite.java @@ -0,0 +1,33 @@ +package subconscious.graphics; + +import subconscious.Actor; + +import java.awt.Graphics2D; +import java.awt.Rectangle; + + +public class Sprite { + + protected Actor actor; + + protected int x, y; + protected int width, height; + protected int dx, dy; + + public Sprite(Actor actor) { + this.actor = actor; + } + + public void render(Graphics2D g) { + + } + + public void update() { + x += dx; + y += dy; + } + + public Rectangle getRect() { + return new Rectangle(x, y, width, height); + } +} -- cgit v1.2.1