Skip to content

Commit

Permalink
Lines now drawn between prior locations, currently active player is a…
Browse files Browse the repository at this point in the history
…lso emphasised.
  • Loading branch information
RSteyn committed Dec 21, 2014
1 parent beb00d0 commit 9bb3612
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class Camera {
worldPos.y - position.y as float
)
}

Vector2f getScreenPos(Vector2f gridPos, int gridSize) {
return getScreenPos(getWorldPos(gridPos, gridSize))
}
/** Get world position from grid coordinates
*
* @author Riley Steyn
Expand Down
30 changes: 27 additions & 3 deletions src/main/groovy/io/github/nelsoncrosby/gprg/entity/Player.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Player extends Entity {

// Add to previous coordinates
if (vel.lengthSquared() > 0) {
prevCoordinates.add(0, pos.copy())
prevCoordinates.add(pos.copy())
}

Vector2f playerInitialPos = pos.copy()
Expand Down Expand Up @@ -200,12 +200,16 @@ class Player extends Entity {
// Get player's next location with no acceleration
int x = screenpos.x - SIZE
int y = screenpos.y - SIZE

// Create a ring around the currently active player
gx.color = new Color(color.r, color.g, color.b, 0.75f)
gx.drawOval(x-2, y-2, (SIZE+2)*2, (SIZE+2)*2)

x += vel.x * gridSize
y += vel.y * gridSize

// Draw all nine possible movement points
// Use half-transparency for the guide
gx.color = new Color(color.r, color.g, color.b, 0.75f)
for (i in -1..1) {
for (j in -1..1) {
gx.drawOval(
Expand All @@ -228,7 +232,11 @@ class Player extends Entity {
void renderPath(Graphics gx, Camera camera, Vector2f screenpos) {
// Draw previous locations
gx.color = new Color(color.r, color.g, color.b, 0.3)
for (Vector2f point: prevCoordinates) {

// Draw line between all prior turn's locations
for (int i=1; i < prevCoordinates.size(); i++) {
Vector2f point = prevCoordinates[i]
Vector2f prevPoint = prevCoordinates[i-1]
Vector2f sPos = camera.getScreenPos(
camera.getWorldPos(point, gridSize)
)
Expand All @@ -237,6 +245,22 @@ class Player extends Entity {
sPos.y - SIZE as int,
SIZE*2, SIZE*2
)
// Draw line between this and the previous point
Vector2f firstLineCoord = camera.getScreenPos(prevPoint, gridSize)
Vector2f secondLineCoord = camera.getScreenPos(point, gridSize)
gx.drawLine(
firstLineCoord.x, firstLineCoord.y,
secondLineCoord.x, secondLineCoord.y
)
}
if (prevCoordinates.size() > 0) {
Vector2f firstLineCoord = camera.getScreenPos(
prevCoordinates[prevCoordinates.size()-1],
gridSize)
Vector2f secondLineCoord = camera.getScreenPos(pos, gridSize)
gx.drawLine(
firstLineCoord.x, firstLineCoord.y,
secondLineCoord.x, secondLineCoord.y)
}
}

Expand Down

0 comments on commit 9bb3612

Please sign in to comment.