trying to write 2d snake game in java just for fun. i have tile map as 2d array.
the problem is that its is not drawing player in level 2d loop.
let me know if there is better way to do this. only thing i have to use 2d array tile map.
Player.java
Level.java
Main.java
the problem is that its is not drawing player in level 2d loop.
let me know if there is better way to do this. only thing i have to use 2d array tile map.
Player.java
Code:
//player class is just a green fill rect.
public void paint(Graphics g)
{
g.setColor(Color.green);
g.fillRect(x, y, width, height);
}
Level.java
Code:
2d array:
000000
000000
010000
public void paint(Graphics g, Player p){
for(int y = 0; y < map01.length; y++){
for(int x = 0; x < map01[y].length; x++){
if(map01[y][x] == 0) //BACKGROUND
{
g.setColor(Color.black);
g.fillRect(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
}
if(map01[y][x] == 1) //PLAYER
{
p = new Player(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
}
}
}
}
Main.java
Code:
....
//start level
public void start(){
levelObject = new Level();
...
//paint method
public void paint(Graphics g){
levelObject.paint(g, playerObject);
...
Comment