Skip to content

Instantly share code, notes, and snippets.

@homelinen
Created September 21, 2011 21:51
Show Gist options
  • Save homelinen/1233427 to your computer and use it in GitHub Desktop.
Save homelinen/1233427 to your computer and use it in GitHub Desktop.
drawPlayer class
/**
* Draw the player
*/
public void drawPlayer(Graphics2D g2d, Dimension playerSize) {
//Get the players position in terms of cell co-ords
int playerxmin = (teddy.getxPos() + teddy.getChangex()) / cellWidth;
int playerymin = (teddy.getyPos() + teddy.getChangey()) / cellHeight;
//Get the max player x and y
int playerxmax = (playerxmin + (int)teddy.getSize().getWidth()) / cellWidth;
int playerymax = (playerymin + (int)teddy.getSize().getHeight()) / cellHeight;
System.out.println("Playerxmax: " + playerxmax + " ymax: " + playerymax);
System.out.println("Playerxmixn " + playerxmin + " yin: " + playerymin);
boolean lowerBound = maze[playerxmin][playerymin] != null && maze[playerxmin][playerymin].isPassable();
boolean borderBoundx = playerxmin > 0 && playerxmax < (maze.length * cellWidth);
boolean borderBoundy = playerymin > 0 && playerymax < (maze[0].length * cellWidth);
if (lowerBound && borderBoundx && borderBoundy) {
teddy.move();
}
g2d.setColor(Color.GREEN);
g2d.fillOval(teddy.getxPos(), teddy.getyPos(), (int)playerSize.getWidth(), (int)playerSize.getHeight());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment