Skip to content

Commit

Permalink
Added simple renderers for board and players.
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Sep 23, 2012
1 parent ac38858 commit 227cace
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions Mazebuilder/src/com/mazebuilder/gameplay/players/Player.java
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions Mazebuilder/src/com/mazebuilder/renderer/BoardRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.newdawn.slick.Graphics;

import com.mazebuilder.gameplay.players.Player;

public interface BoardRenderer {

int tileHeight();
Expand Down Expand Up @@ -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);
}
13 changes: 13 additions & 0 deletions Mazebuilder/src/com/mazebuilder/renderer/ChaserPlayerRenderer.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
4 changes: 2 additions & 2 deletions Mazebuilder/src/com/mazebuilder/renderer/Renderable.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.newdawn.slick.Graphics;

public interface Renderable {

void render(Graphics g, int xOffset, int yOffset);

}
13 changes: 13 additions & 0 deletions Mazebuilder/src/com/mazebuilder/renderer/RunnerPlayerRenderer.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
59 changes: 59 additions & 0 deletions Mazebuilder/src/com/mazebuilder/renderer/SimpleBoardRenderer.java
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit 227cace

Please sign in to comment.