package ru.dmitriymx.game; import org.lwjgl.LWJGLException; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; import org.lwjgl.opengl.GL11; public class Main { private Foxy foxy; private void init_display(int width, int height){ try { Display.setDisplayMode(new DisplayMode(width, height)); Display.setVSyncEnabled(true); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); System.exit(-1); } } private void init_opengl(int width, int height) { GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glClearColor(0, 0, 0.3f, 0); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, width, height, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); } private void render(){ while(Keyboard.next()){ if(Keyboard.getEventKey() == Keyboard.KEY_LEFT){ foxy.setInverse(true); if(Keyboard.getEventKeyState()){ foxy.setState(1); } else { foxy.setState(0); } } else if (Keyboard.getEventKey() == Keyboard.KEY_RIGHT){ foxy.setInverse(false); if(Keyboard.getEventKeyState()){ foxy.setState(1); } else { foxy.setState(0); } } } final int speed = 5 * 4; if(foxy.getState() == 1){ if(foxy.getInverse()){ foxy.setX(foxy.getX() - speed); } else { foxy.setX(foxy.getX() + speed); } } foxy.render(); } public void start(int width, int height){ init_display(width, height); init_opengl(width, height); foxy = new Foxy(); foxy.setY(Display.getHeight() - (34*4)); while(!Display.isCloseRequested()){ GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); render(); Display.update(); Display.sync(15); } Display.destroy(); } public static void main(String[] args){ new Main().start(800,600); } }