geh.Geh.java Source code

Java tutorial

Introduction

Here is the source code for geh.Geh.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package geh;

import geh.objects.Player;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;

/**
 *
 * @author rplu1618
 */
public class Geh {

    public int WIDTH = 800;
    public int HEIGHT = 680;

    private Player[] players;

    public void start() {
        initGL();

        players = new Player[4];

        for (int i = 0; i < 4; i++) {
            players[i] = new Player(i * 100, 20, i);
        }

        while (!Display.isCloseRequested()) {
            input();
            render();
            Display.setVSyncEnabled(true);
        }

        Display.destroy();
    }

    public void input() {

    }

    public void initGL() {
        try {
            Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
            Display.create();
        } catch (LWJGLException ex) {
            ex.printStackTrace();
            System.exit(0);
        }
        Mouse.setGrabbed(false);
        GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        GL11.glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0, WIDTH, HEIGHT, 0.0, -1.0, 10.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

    }

    public void render() {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        for (Player player : players) {
            player.render();

            player.setDirection((float) Math.random() * 10, (float) Math.random() * 10);

            player.update();
        }

        Display.update();
    }

    public void sendToServer() {

    }

    public static void main(String[] args) {
        Geh g = new Geh();
        g.start();
    }

}