I am making a game in LWJGL (2) and slick-util (I think).
I am trying to move my map (It is a double int array that uses numbers to get the textures), but my code only moves the first texture to be drawn on the screen (top-left). how can I move ALL of my map at the same time? Here is my code:
package Window;
import static org.lwjgl.opengl.GL11.*;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import controls.TileChanger;
import Functions.renderer;
import Window.GridHandler;
public class Main {
public static void main(String[] args) {
renderer.begin();
int[][] map = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
GridHandler grid = new GridHandler(map);
TileChanger changer = new TileChanger(grid);
String mapSave = map.toString();
float translate_x = 0;
float translate_y = 0;
int speed = 5;
while (!Keyboard.isKeyDown(Keyboard.KEY_Q)) {
// while(Keyboard.next()){
if (Keyboard.getEventKey() == Keyboard.KEY_P && Keyboard.getEventKeyState()) {
System.out.println(mapSave);
/* Writer wr;
try {
wr = new FileWriter("map.txt");
wr.write(mapSave);
wr.close();
} catch (IOException e) {
e.printStackTrace();
} */
}
// }
if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
translate_x += speed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
translate_x -= speed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
translate_y += speed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
translate_y -= speed;
}
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(translate_x, translate_y, 0);
glEnable(GL_TEXTURE_2D);
changer.Update();
grid.draw();
glPopMatrix();
Display.update();
Display.sync(60);
}
Display.destroy();
System.exit(0);
}
}
Can anyone help me out? (I need the map to move correctly when I push any of the WASD keys (W = up, A = left, S = down, D = right).
changer.Update();
, however, it's not displayed here. Could you edit your question and add what seems to be that important piece of code? \$\endgroup\$