So I’ve decided to make a 2d hack and slash tile game…
I’ve decided to go on with a model view control pattern for my “gui hook” into the game…
I can draw the game like snake would do. Gameworld static, and player moves around the screen.
I want to draw my game with the player fixed in the middle, and the world moving “under” the player.
until now my drawing method is like this:
public void draw(){
Graphics g = getGraphics();
Graphics bbg = this.backBuffer.getGraphics();
BufferedImage image = null;
bbg.setColor(Color.BLACK);
bbg.fillRect(0, 0, windowWidth, windowHeight);
Player player = game.getTileMap().getPlayer();
for(int y = 0; y < 12; y++){
for(int x = 0; x < 20; x++){
Position position = new Position(x,y);
//Draw tiles
Tile tile = game.getTileMap().getTileAt(position);
if(tile != null){
image = tile.getImage();
}
//Draw items
Item item = game.getTileMap().getItemAt(position);
if(item != null){
image = item.getImage();
}
//Draw units
Unit unit = game.getTileMap().getUnitAt(position);
if(unit != null && !(unit instanceof Player)){
image = unit.getImage();
}
bbg.drawImage(image, x*40, y*40, this);
}
}
bbg.drawImage(player.getImage(), player.getPosition().getX()*40, player.getPosition().getY()*40, this);
g.drawImage(this.backBuffer, 0, 0, this);
}
So my question is: How do I draw the world calculated from the player position, and not fixed like the code is now?