Advertisement
Guest User

Untitled

a guest
Apr 13th, 2016
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. //A massive thank-you to Oskar Veerhoek for showing me how to make a side-scrolling display.
  2.  
  3. package Window;
  4.  
  5. import static org.lwjgl.opengl.GL11.*;
  6.  
  7. import org.lwjgl.input.Keyboard;
  8. import org.lwjgl.opengl.Display;
  9. import org.lwjgl.opengl.DisplayMode;
  10. import org.lwjgl.LWJGLException;
  11.  
  12. import Window.GridHandler;
  13.  
  14. public class Main {
  15.  
  16. static 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},
  17. {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},
  18. {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},
  19. {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},
  20. {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},
  21. {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},
  22. {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},
  23. {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},
  24. {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},
  25. {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},
  26. {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},
  27. {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},
  28. {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}
  29. };
  30.  
  31. static GridHandler grid = new GridHandler(map);
  32.  
  33. public static void main(String[] args) {
  34.  
  35. try {
  36. Display.setDisplayMode(new DisplayMode(1600,832));
  37. Display.setTitle("Quest to save your house. DevStage 0");
  38. Display.create();
  39. } catch (LWJGLException e) {
  40. e.printStackTrace();
  41. Display.destroy();
  42. System.exit(1);
  43. }
  44.  
  45. glMatrixMode(GL_PROJECTION);
  46. glLoadIdentity();
  47. glOrtho(0, 1600, 832, 0, -1, 1);
  48. glMatrixMode(GL_MODELVIEW);
  49.  
  50. float translate_x = 0;
  51. float translate_y = 0;
  52. int speed = 5;
  53.  
  54. while(!Keyboard.isKeyDown(Keyboard.KEY_Q)) {
  55.  
  56. glClear(GL_COLOR_BUFFER_BIT);
  57.  
  58. glPushMatrix();
  59.  
  60. glTranslatef(translate_x, translate_y, 0);
  61.  
  62. if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
  63. translate_x += speed;
  64. }
  65.  
  66. if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
  67. translate_x -= speed;
  68. }
  69.  
  70. if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
  71. translate_y += speed;
  72. }
  73.  
  74. if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
  75. translate_y -= speed;
  76. }
  77.  
  78.  
  79.  
  80.  
  81. glPopMatrix();
  82.  
  83. Display.update();
  84. Display.sync(60);
  85. }
  86. Display.destroy();
  87. System.exit(0);
  88.  
  89.  
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement