Created
September 21, 2011 21:51
-
-
Save homelinen/1233427 to your computer and use it in GitHub Desktop.
drawPlayer class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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