I want to create a map in a game I'm making. Right now I have already made a texture for the map, but I want the map to be cut up in 50 * 50 blocks of pixels. Every block will be of a certain type of land. For example there will be plains, forest, water etc. I also want to be able to set certain settings for all the blocks like who owns the area.
Right now this is my code:
The code i have doesn't really work, because it simply draws the grid textures on the screen, but I want them on the map texture (tutorial.png). I want those squares to stay in position when I move the map around my screen with the arrows and be able to set certain properties to those grid blocks. One being for example water and the other being ground.import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import org.lwjgl.input.Mouse; import org.newdawn.slick.*; import org.newdawn.slick.state.*; public class GameScreen extends BasicGameState { int day = 1; int month = 1; int year = 2012; static boolean paused = false; ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor(); Image optionButton, tutorial, grid; float mapX = 0; float mapY = 0; int heightgrid, lengthgrid; public GameScreen(int state) { timer.scheduleAtFixedRate(new Runnable() { public void run() { if(Main.playing && !paused) { day++; } } }, 0, 1, TimeUnit.SECONDS); } public void init(GameContainer container, StateBasedGame state) throws SlickException { container.setShowFPS(Main.fpsCounter); optionButton = new Image("res/gui/buttons/smalloptionbutton.png"); tutorial = new Image("res/maps/tutorial.png"); grid = new Image("res/grid.png"); if(optionButton == null || tutorial == null || grid == null) { System.err.println("Image problems"); } heightgrid = tutorial.getHeight() / 50; lengthgrid = tutorial.getWidth() / 50; } public void render(GameContainer container, StateBasedGame state, Graphics graphics) throws SlickException { graphics.setBackground(Color.black); if(!paused) { tutorial.draw(mapX, mapY); graphics.setColor(Color.white); graphics.drawString("Day " +day, 100, 100); graphics.drawString("Month " +month, 100, 150); graphics.drawString("Year " +year, 100, 200); for(int j = 0; j <= heightgrid; j++) { for(int i = 0; i <= lengthgrid; i++) { grid.draw(i * 50, j * 50); } } } if(paused) { graphics.setColor(Color.white); graphics.drawString("Pause Screen", 100, 100); graphics.drawString("Press B to get back to playing.", 100, 150); optionButton.draw(200, 200); } } public void update(GameContainer container, StateBasedGame state, int delta) throws SlickException { Input input = container.getInput(); int posX = Mouse.getX(); int posY = Mouse.getY(); if(day > 30) { month++; day = 1; } if(month > 12) { year++; month = 1; } if(!paused) { if(Mouse.isInsideWindow() == false) { paused = true; } if(input.isKeyDown(Input.KEY_ESCAPE)) { paused = true; } if(input.isKeyDown(Input.KEY_DOWN)) { mapY-=5; } if(input.isKeyDown(Input.KEY_UP)) { mapY+=5; } if(input.isKeyDown(Input.KEY_LEFT)) { mapX+=5; } if(input.isKeyDown(Input.KEY_RIGHT)) { mapX-=5; } } if(paused) { if(input.isKeyDown(Input.KEY_B)) { paused = false; } if(posX > 200 && posX < 300 && posY > 370 && posY < 400) { if(Mouse.isButtonDown(0)) { state.enterState(3); OptionScreen.fromPause = true; } } } } public int getID() { return 4; } }
Does anyone know how to do that?