From 227cace405a3ca8d9fa72db2eb1a3c3c410de30f Mon Sep 17 00:00:00 2001 From: pgruevski Date: Sun, 23 Sep 2012 16:38:57 -0400 Subject: [PATCH] Added simple renderers for board and players. --- .../gameplay/board/DefaultBoard.java | 3 +- .../gameplay/players/ChaserPlayer.java | 4 +- .../mazebuilder/gameplay/players/Player.java | 6 +- .../gameplay/players/RunnerPlayer.java | 4 +- .../mazebuilder/renderer/BoardRenderer.java | 6 -- .../renderer/ChaserPlayerRenderer.java | 13 ++++ .../mazebuilder/renderer/PlayerRenderer.java | 2 +- .../com/mazebuilder/renderer/Renderable.java | 4 +- .../renderer/RunnerPlayerRenderer.java | 13 ++++ .../renderer/SimpleBoardRenderer.java | 59 +++++++++++++++++++ 10 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 Mazebuilder/src/com/mazebuilder/renderer/ChaserPlayerRenderer.java create mode 100644 Mazebuilder/src/com/mazebuilder/renderer/RunnerPlayerRenderer.java create mode 100644 Mazebuilder/src/com/mazebuilder/renderer/SimpleBoardRenderer.java diff --git a/Mazebuilder/src/com/mazebuilder/gameplay/board/DefaultBoard.java b/Mazebuilder/src/com/mazebuilder/gameplay/board/DefaultBoard.java index e82ecc0..f0c0c22 100644 --- a/Mazebuilder/src/com/mazebuilder/gameplay/board/DefaultBoard.java +++ b/Mazebuilder/src/com/mazebuilder/gameplay/board/DefaultBoard.java @@ -85,7 +85,8 @@ public void render(Graphics g, int xOffset, int yOffset) { int row = e.getValue().getRow(); int column = e.getValue().getColumn(); e.getKey().render(g, xOffset + (column * renderer.tileWidth()) + ((column - 1) * renderer.wallShortSideLength()), - yOffset + (row * renderer.tileHeight()) + ((row - 1) * renderer.wallShortSideLength())); + yOffset + (row * renderer.tileHeight()) + ((row - 1) * renderer.wallShortSideLength()), renderer.tileWidth(), + renderer.tileHeight()); } } diff --git a/Mazebuilder/src/com/mazebuilder/gameplay/players/ChaserPlayer.java b/Mazebuilder/src/com/mazebuilder/gameplay/players/ChaserPlayer.java index adff19a..9dd72d5 100644 --- a/Mazebuilder/src/com/mazebuilder/gameplay/players/ChaserPlayer.java +++ b/Mazebuilder/src/com/mazebuilder/gameplay/players/ChaserPlayer.java @@ -31,8 +31,8 @@ public ChaserPlayer(PlayerRenderer renderer, String name) { } @Override - public void render(Graphics g, int xOffset, int yOffset) { - renderer.drawPlayer(g, xOffset, yOffset); + public void render(Graphics g, int x, int y, int tileWidth, int tileHeight) { + renderer.drawPlayer(g, x, y, tileWidth, tileHeight); } @Override diff --git a/Mazebuilder/src/com/mazebuilder/gameplay/players/Player.java b/Mazebuilder/src/com/mazebuilder/gameplay/players/Player.java index 1b26604..be64a2b 100644 --- a/Mazebuilder/src/com/mazebuilder/gameplay/players/Player.java +++ b/Mazebuilder/src/com/mazebuilder/gameplay/players/Player.java @@ -1,10 +1,11 @@ package com.mazebuilder.gameplay.players; +import org.newdawn.slick.Graphics; + import com.google.common.collect.Multiset; import com.mazebuilder.gameplay.Direction; -import com.mazebuilder.renderer.Renderable; -public interface Player extends Renderable { +public interface Player { String getName(); @@ -25,4 +26,5 @@ public interface Player extends Renderable { /** Removes a bonus from the player. Returns true if the bonus was successfully removed, or false otherwise. **/ boolean spendBonus(Direction d); + void render(Graphics g, int xOffset, int yOffset, int tileWidth, int tileHeight); } diff --git a/Mazebuilder/src/com/mazebuilder/gameplay/players/RunnerPlayer.java b/Mazebuilder/src/com/mazebuilder/gameplay/players/RunnerPlayer.java index b6f3d70..8fb0add 100644 --- a/Mazebuilder/src/com/mazebuilder/gameplay/players/RunnerPlayer.java +++ b/Mazebuilder/src/com/mazebuilder/gameplay/players/RunnerPlayer.java @@ -20,8 +20,8 @@ public RunnerPlayer(PlayerRenderer renderer, String name) { } @Override - public void render(Graphics g, int xOffset, int yOffset) { - renderer.drawPlayer(g, xOffset, yOffset); + public void render(Graphics g, int x, int y, int tileWidth, int tileHeight) { + renderer.drawPlayer(g, x, y, tileWidth, tileHeight); } @Override diff --git a/Mazebuilder/src/com/mazebuilder/renderer/BoardRenderer.java b/Mazebuilder/src/com/mazebuilder/renderer/BoardRenderer.java index 4abb65f..39e6074 100644 --- a/Mazebuilder/src/com/mazebuilder/renderer/BoardRenderer.java +++ b/Mazebuilder/src/com/mazebuilder/renderer/BoardRenderer.java @@ -2,8 +2,6 @@ import org.newdawn.slick.Graphics; -import com.mazebuilder.gameplay.players.Player; - public interface BoardRenderer { int tileHeight(); @@ -38,8 +36,4 @@ public interface BoardRenderer { */ void drawCorner(Graphics g, int x, int y); - /** - * Draw the sprite for the given player. - */ - void drawPlayer(Player p, Graphics g, int x, int y); } diff --git a/Mazebuilder/src/com/mazebuilder/renderer/ChaserPlayerRenderer.java b/Mazebuilder/src/com/mazebuilder/renderer/ChaserPlayerRenderer.java new file mode 100644 index 0000000..a32611d --- /dev/null +++ b/Mazebuilder/src/com/mazebuilder/renderer/ChaserPlayerRenderer.java @@ -0,0 +1,13 @@ +package com.mazebuilder.renderer; + +import org.newdawn.slick.Color; +import org.newdawn.slick.Graphics; + +public final class ChaserPlayerRenderer implements PlayerRenderer { + + @Override + public void drawPlayer(Graphics g, int x, int y, int tileWidth, int tileHeight) { + g.setColor(Color.red); + g.fillRoundRect(x, y, tileWidth, tileHeight, Math.min(tileHeight, tileWidth) / 2); + } +} diff --git a/Mazebuilder/src/com/mazebuilder/renderer/PlayerRenderer.java b/Mazebuilder/src/com/mazebuilder/renderer/PlayerRenderer.java index 2608d81..297109d 100644 --- a/Mazebuilder/src/com/mazebuilder/renderer/PlayerRenderer.java +++ b/Mazebuilder/src/com/mazebuilder/renderer/PlayerRenderer.java @@ -4,6 +4,6 @@ public interface PlayerRenderer { - void drawPlayer(Graphics g, int x, int y); + void drawPlayer(Graphics g, int x, int y, int tileWidth, int tileHeight); } diff --git a/Mazebuilder/src/com/mazebuilder/renderer/Renderable.java b/Mazebuilder/src/com/mazebuilder/renderer/Renderable.java index 8153eaa..af9899b 100644 --- a/Mazebuilder/src/com/mazebuilder/renderer/Renderable.java +++ b/Mazebuilder/src/com/mazebuilder/renderer/Renderable.java @@ -3,7 +3,7 @@ import org.newdawn.slick.Graphics; public interface Renderable { - + void render(Graphics g, int xOffset, int yOffset); - + } diff --git a/Mazebuilder/src/com/mazebuilder/renderer/RunnerPlayerRenderer.java b/Mazebuilder/src/com/mazebuilder/renderer/RunnerPlayerRenderer.java new file mode 100644 index 0000000..e515ec7 --- /dev/null +++ b/Mazebuilder/src/com/mazebuilder/renderer/RunnerPlayerRenderer.java @@ -0,0 +1,13 @@ +package com.mazebuilder.renderer; + +import org.newdawn.slick.Color; +import org.newdawn.slick.Graphics; + +public final class RunnerPlayerRenderer implements PlayerRenderer { + + @Override + public void drawPlayer(Graphics g, int x, int y, int tileWidth, int tileHeight) { + g.setColor(Color.green); + g.fillRoundRect(x, y, tileWidth, tileHeight, Math.min(tileHeight, tileWidth) / 2); + } +} diff --git a/Mazebuilder/src/com/mazebuilder/renderer/SimpleBoardRenderer.java b/Mazebuilder/src/com/mazebuilder/renderer/SimpleBoardRenderer.java new file mode 100644 index 0000000..e2e52b7 --- /dev/null +++ b/Mazebuilder/src/com/mazebuilder/renderer/SimpleBoardRenderer.java @@ -0,0 +1,59 @@ +package com.mazebuilder.renderer; + +import org.newdawn.slick.Color; +import org.newdawn.slick.Graphics; + +public final class SimpleBoardRenderer implements BoardRenderer { + + private static final int TILE_HEIGHT = 64; + private static final int TILE_WIDTH = 64; + private static final int WALL_SHORT_SIDE = 16; + + @Override + public int tileHeight() { + return TILE_HEIGHT; + } + + @Override + public int tileWidth() { + return TILE_WIDTH; + } + + @Override + public int wallShortSideLength() { + return WALL_SHORT_SIDE; + } + + @Override + public void drawTile(Graphics g, int x, int y) { + g.setColor(Color.cyan); + g.fillRect(x, y, TILE_WIDTH, TILE_HEIGHT); + } + + @Override + public void drawWall(Graphics g, int x, int y, boolean horizontal) { + g.setColor(Color.red); + if (horizontal) { + g.fillRoundRect(x, y, TILE_WIDTH, WALL_SHORT_SIDE, 4); + } else { + g.fillRoundRect(x, y, WALL_SHORT_SIDE, TILE_HEIGHT, 4); + } + } + + @Override + public void drawNoWall(Graphics g, int x, int y, boolean horizontal) { + g.setColor(Color.lightGray); + if (horizontal) { + g.fillRoundRect(x, y, TILE_WIDTH, WALL_SHORT_SIDE, 4); + } else { + g.fillRoundRect(x, y, WALL_SHORT_SIDE, TILE_HEIGHT, 4); + } + } + + @Override + public void drawCorner(Graphics g, int x, int y) { + g.setColor(Color.green); + g.fillRoundRect(x, y, WALL_SHORT_SIDE, WALL_SHORT_SIDE, 8); + } + +}