Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.unh0lytigg.lhc;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.input.Keyboard;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- import org.lwjgl.opengl.GL11;
- import org.newdawn.slick.Color;
- @SuppressWarnings("unused")
- public class LHC {
- public static boolean DRAW_DEBUG = false;
- private int width, height;
- private int gridspace_size;
- private int[][] levels;
- private boolean gameOver = false;
- private float go_alpha = 0.0F;
- private long alpha_timer = 500;
- public LHC() {
- width = 800;
- height = 800;
- gridspace_size = width / 5;
- levels = new int[4][4];
- int level = -1;
- for (int x = 0; x < 4; x++) {
- for (int y = 0; y < 4; y++) {
- levels[x][y] = level;
- level++;
- level %= 11;
- }
- }
- }
- private static int[] color_levels = {0xEEE4DA,0xEDE0C8,0xF2B179,0xF59563,0xF67C5F,0xF65E38,0xEDCF72,0xEDCC61,0xEDC850,0xEDC53F,0xEDC22E};
- private static String[] text_levels = {"electron", "electron neutrino", "muon", "muon neutrino", "tau", "tau neutrino", "gluon", "photon", "Z boson", "W boson", "Higgs boson"};
- private static Color[] text_colors = {Color.darkGray, Color.white};
- private static int tileColors(int level) {
- if (level == -1)
- return 0xCCC0B3;
- return color_levels[level];
- }
- private static String texts(int level) {
- if (level == -1)
- return "";
- return text_levels[level];
- }
- private static Color textColor(int level) {
- if (level == -1 || level == 0 || level == 1)
- return text_colors[0];
- return text_colors[1];
- }
- private static float[] convertRGB(int rgb) {
- int r = (rgb >> 16) & 0xFF;
- int g = (rgb >> 8) & 0xFF;
- int b = (rgb >> 0) & 0xFF;
- float[] f = new float[3];
- f[0] = (float)((float)r / (float)0xFF);
- f[1] = (float)((float)g / (float)0xFF);
- f[2] = (float)((float)b / (float)0xFF);
- return f;
- }
- private void keyboard() {
- while (Keyboard.next()) {
- if (gameOver) continue;
- char c = Keyboard.getEventCharacter();
- if (c == 'd') {
- DRAW_DEBUG = !DRAW_DEBUG;
- continue;
- }
- int key = Keyboard.getEventKey();
- if (Keyboard.getEventKeyState()) {
- boolean moved = false;
- if (key == Keyboard.KEY_UP) {
- moved = up();
- } else if (key == Keyboard.KEY_DOWN) {
- moved = down();
- } else if (key == Keyboard.KEY_LEFT) {
- moved = left();
- } else if (key == Keyboard.KEY_RIGHT) {
- moved = right();
- }
- if (moved) checkGrid();
- }
- }
- }
- private void doLogicUpdates() {
- if (gameOver) {
- if (go_alpha < 0.8F) {
- if (alpha_timer == 0) {
- go_alpha += 0.01F;
- alpha_timer = 500;
- } else {
- alpha_timer -= 1;
- }
- }
- }
- }
- private void checkGrid() {
- gameOver = true;
- }
- private boolean up() {
- System.out.println("up");
- return false;
- }
- private boolean down() {
- System.out.println("down");
- return false;
- }
- private boolean left() {
- System.out.println("left");
- return false;
- }
- private boolean right() {
- System.out.println("right");
- return true;
- }
- public void run() {
- try {
- Display.setDisplayMode(new DisplayMode(width,height));
- Display.create();
- Display.setTitle("LHC");
- } catch (LWJGLException e) {
- e.printStackTrace();
- System.exit(0);
- }
- GL11.glMatrixMode(GL11.GL_PROJECTION);
- GL11.glLoadIdentity();
- GL11.glOrtho(0, width, height, 0, 1, -1);
- GL11.glMatrixMode(GL11.GL_MODELVIEW);
- while (!Display.isCloseRequested()) {
- keyboard();
- doLogicUpdates();
- GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
- drawRect(0, 0, width, height, 0xBBADA0);
- for (int x = 0; x < 4; x++) {
- int xOffset = (gridspace_size / 5) + (gridspace_size * x) + ((gridspace_size / 5) * x);
- for (int y = 0; y < 4; y++) {
- int yOffset = (gridspace_size / 5) + (gridspace_size * y) + ((gridspace_size / 5) * y);
- drawRoundRect(xOffset, yOffset, xOffset + gridspace_size, yOffset + gridspace_size, gridspace_size / 8, tileColors(levels[x][y]));
- }
- }
- if (gameOver) {
- GL11.glEnable(GL11.GL_BLEND);
- GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_SRC_ALPHA);
- GL11.glColor4f(0.5f, 0.0f, 0.0f, go_alpha);
- GL11.glBegin(GL11.GL_QUADS);
- GL11.glVertex2i(width, 0);
- GL11.glVertex2i(0, 0);
- GL11.glVertex2i(0, height);
- GL11.glVertex2i(width, height);
- GL11.glEnd();
- }
- Display.sync(30);
- Display.update();
- }
- Display.destroy();
- }
- private static void drawRoundRect(int x, int y, int x1, int y1, int radius, int color) {
- int newX = Math.abs(x+radius);
- int newY = Math.abs(y+radius);
- int newX1 = Math.abs(x1-radius);
- int newY1 = Math.abs(y1-radius);
- drawRect(newX, newY, newX1, newY1, color);
- drawRect(x, newY, newX, newY1, color);
- drawRect(newX1, newY, x1, newY1, color);
- drawRect(newX, y, newX1, newY, color);
- drawRect(newX, newY1, newX1, y1, color);
- drawQuarterCircle(newX,newY,radius,0,color);
- drawQuarterCircle(newX1,newY,radius,3,color);
- drawQuarterCircle(newX,newY1,radius,1,color);
- drawQuarterCircle(newX1,newY1,radius,2,color);
- }
- private static void drawRect(int x, int y, int x1, int y1, int color) {
- drawRectModed(x, y, x1, y1, color, GL11.GL_QUADS);
- if (DRAW_DEBUG)
- drawRectModed(x, y, x1, y1, 0x000000, GL11.GL_LINE_LOOP);
- }
- private static void drawRectModed(int x, int y, int x1, int y1, int color, int mode) {
- float[] f = convertRGB(color);
- GL11.glColor3f(f[0],f[1],f[2]);
- GL11.glBegin(mode);
- GL11.glVertex2i(x1, y);
- GL11.glVertex2i(x, y);
- GL11.glVertex2i(x, y1);
- GL11.glVertex2i(x1, y1);
- GL11.glEnd();
- }
- private static void drawQuarterCircle(int x, int y, int radius, int quadriant, int color) {
- drawQuarterCircleModed(x, y, radius, quadriant, color, GL11.GL_POLYGON);
- if (DRAW_DEBUG)
- drawQuarterCircleModed(x, y, radius, quadriant, 0x000000, GL11.GL_LINE_LOOP);
- }
- private static void drawQuarterCircleModed(int x, int y, int radius, int quadriant, int color, int mode) {
- float[] f = convertRGB(color);
- GL11.glColor3f(f[0],f[1],f[2]);
- GL11.glBegin(mode);
- GL11.glVertex2d(x, y);
- if (quadriant == 0) {
- for (int i = 0; i <= 90; i++)
- GL11.glVertex2d(x + (Math.sin((i * Math.PI / 180)) * (radius*-1)), y + (Math.cos((i * Math.PI / 180)) * (radius*-1)));
- } else if (quadriant == 1) {
- for (int i = 90; i <= 180; i++)
- GL11.glVertex2d(x + (Math.sin((i * Math.PI / 180)) * (radius*-1)), y + (Math.cos((i * Math.PI / 180)) * (radius*-1)));
- } else if (quadriant == 2) {
- for (int i = 180; i <= 270; i++)
- GL11.glVertex2d(x + (Math.sin((i * Math.PI / 180)) * (radius*-1)), y + (Math.cos((i * Math.PI / 180)) * (radius*-1)));
- } else if (quadriant == 3) {
- for (int i = 270; i <= 360; i++)
- GL11.glVertex2d(x + (Math.sin((i * Math.PI / 180)) * (radius*-1)), y + (Math.cos((i * Math.PI / 180)) * (radius*-1)));
- }
- GL11.glEnd();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement