Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.lwjgl.Sys;
- import org.lwjgl.input.Keyboard;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.GL11;
- import java.util.ArrayList;
- import java.util.*;
- public class LWJGL{
- static ArrayList<red> list = new ArrayList<red>();
- static int var;
- static float[] reds = new float[36];
- static boolean pop=true;
- static boolean pop1=true;
- static float speedx=0;
- static float speedy=0;
- static final int width = Display.getDisplayMode().getWidth();
- static final int height = Display.getDisplayMode().getHeight();
- static int x=Display.getDisplayMode().getWidth() / 2;
- static int y=Display.getDisplayMode().getHeight() / 2;
- public static final String GAME_TITLE = "TOM IS SO PR0";
- private static final int FRAMERATE = 60;
- private static boolean finished;
- private static float angle;
- public static void main(String[] args) {
- boolean fullscreen = (args.length == 1 && args[0].equals("-fullscreen"));
- fullscreen=true;
- try{
- init(fullscreen);run();
- }catch(Exception e){
- e.printStackTrace(System.err);
- Sys.alert(GAME_TITLE, "An error occured and the game will exit.");
- }
- finally{cleanup();}
- System.exit(0);
- }
- private static void lose(){
- Sys.alert(GAME_TITLE, "You've lost with a score of "+list.size()+", NIIIICE!");
- }
- private static void init(boolean fullscreen) throws Exception {
- Display.setTitle(GAME_TITLE);
- Display.setFullscreen(fullscreen);
- Display.setVSyncEnabled(true);
- Display.create();
- GL11.glMatrixMode(GL11.GL_PROJECTION);
- GL11.glDisable(GL11.GL_DEPTH_TEST);
- GL11.glLoadIdentity();
- GL11.glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
- GL11.glMatrixMode(GL11.GL_MODELVIEW);
- GL11.glLoadIdentity();
- GL11.glViewport(0, 0, width, height);
- }
- /**
- * Runs the game (the "main loop")
- */
- private static void run() {
- int sub =0;
- boolean gg = false;
- while (!gg){
- while (!finished) {
- // Always call Window.update(), all the time - it does some behind the
- // scenes work, and also displays the rendered output
- Display.update();
- // Check for close requests
- if (Display.isCloseRequested()) {
- finished = true;
- }
- // The window is in the foreground, so we should play the game
- else if (Display.isActive()) {
- logic();
- render(sub);sub++;if(sub==FRAMERATE)sub=0;
- Display.sync(FRAMERATE);
- }
- // The window is not in the foreground, so we can allow other stuff to run and
- // infrequently update
- else {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
- logic();
- // Only bother rendering if the window is visible or dirty
- if (Display.isVisible() || Display.isDirty()) {
- render(sub);sub++;if(sub==FRAMERATE)sub=0;
- }
- }
- }
- lose();gg=true;
- }
- }
- private static void cleanup() {
- Display.destroy();
- }
- private static void logic() {
- if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
- finished = true;
- }
- angle += 2.0f % 360;
- if(collide(list, (int)y, (int)x, 8, 8)){
- finished = true;
- }
- }
- private static boolean collide(ArrayList<red> list, int y, int x, int w, int h){
- for(int q=0;q < list.size();q++){
- if(list.get(q).dir){
- if(colbox(list.get(q).off,list.get(q).oth,list.get(q).REDSIZE,list.get(q).REDSIZE,x,y,w,h)){
- return true;
- }
- }else{
- if(colbox(list.get(q).oth,list.get(q).off,list.get(q).REDSIZE,list.get(q).REDSIZE,x,y,w,h)){
- return true;
- }
- }
- }
- //System.out.println("YOU LOSE, BUT YOUR GONNA HAVE TO ALT TAB TO FIGURE IT OUT!!!");
- return false;
- }
- public static boolean colbox(int x1,int y1,int x1w,int y1h,int x2,int y2,int x2w,int y2h)
- {
- if(x1+x1w<x2)
- return false;
- if(x1>x2+x2w)
- return false;
- if(y1+y1h<y2)
- return false;
- if(y1>y2+y2h)
- return false;
- return true;
- }
- private static void keys(){
- if (Keyboard.isKeyDown(Keyboard.KEY_DOWN))y-=7;
- if (Keyboard.isKeyDown(Keyboard.KEY_UP))y+=7;
- if (Keyboard.isKeyDown(Keyboard.KEY_LEFT))x-=7;
- if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT))x+=7;
- x%=Display.getDisplayMode().getWidth();
- y%=Display.getDisplayMode().getHeight();
- if(x<=0)x=Display.getDisplayMode().getWidth();
- if(y<=0)y=Display.getDisplayMode().getHeight();
- if (Keyboard.isKeyDown(Keyboard.KEY_Q)&&pop)mkdot();
- if (Keyboard.isKeyDown(Keyboard.KEY_W))for(int q = 0; q< 4;q++)mkdot();
- if (Keyboard.isKeyDown(Keyboard.KEY_A)&&pop)rmdot();
- if (Keyboard.isKeyDown(Keyboard.KEY_S))for(int q = 0;q< 4;q++)rmdot();
- if (!Keyboard.isKeyDown(Keyboard.KEY_A))pop1=true;
- if (!Keyboard.isKeyDown(Keyboard.KEY_Q))pop=true;
- }
- private static void you(){
- GL11.glBegin(GL11.GL_POLYGON);
- double temp = 2*Math.PI/5;
- GL11.glVertex3i((int)(6*Math.sin(temp)), (int)(6*Math.cos(temp)),1);
- GL11.glVertex3i((int)(8*Math.sin(temp*2)), (int)(8*Math.cos(temp*2)),1);
- GL11.glVertex3i((int)(6*Math.sin(temp*3)), (int)(6*Math.cos(temp*3)),1);
- GL11.glVertex3i((int)(8*Math.sin(temp*4)), (int)(8*Math.cos(temp*4)),1);
- GL11.glVertex3i((int)(6*Math.sin(temp*5)), (int)(6*Math.cos(temp*5)),1);
- GL11.glVertex3i((int)(8*Math.sin(temp)), (int)(8*Math.cos(temp)),1);
- GL11.glVertex3i((int)(6*Math.sin(temp*2)), (int)(6*Math.cos(temp*2)),1);
- GL11.glVertex3i((int)(8*Math.sin(temp*3)), (int)(8*Math.cos(temp*3)),1);
- GL11.glVertex3i((int)(6*Math.sin(temp*4)), (int)(6*Math.cos(temp*4)),1);
- GL11.glVertex3i((int)(8*Math.sin(temp*5)), (int)(8*Math.cos(temp*5)),1);
- //GL11.glScaled(.3,.3,.6);
- GL11.glEnd();
- // render the square
- GL11.glColor3d(.3,0,1);
- GL11.glBegin(GL11.GL_QUADS);
- GL11.glVertex2i(-2, -2);
- GL11.glVertex2i(2, -2);
- GL11.glVertex2i(2, 2);
- GL11.glVertex2i(-2, 2);
- GL11.glEnd();
- }
- private static void render(int sub) {
- if(sub==0){
- mkdot();
- }
- GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
- GL11.glPushMatrix();
- GL11.glColor3d(1,1,1);
- GL11.glBegin(GL11.GL_QUADS);
- GL11.glVertex3f(0.0f, (float)height,0.0f);
- GL11.glVertex3f(0.0f, 0.0f,0.0f);
- GL11.glVertex3f((float)width, 0.0f,0.0f);
- GL11.glVertex3f((float)width, (float)height,0.0f);
- GL11.glEnd();
- bg(sub);
- for(int x=0;x<list.size();x++)list.get(x).tick();
- GL11.glTranslatef((float) (x % width),(float) (y % height), 0.0f);
- keys();
- GL11.glRotatef(-angle, 0, 0, 1.0f);
- //PENTAGON MOD
- GL11.glColor3d(0,1,.2);
- you();
- GL11.glPopMatrix();
- }
- public static void bg(int sub){
- if(sub%20==0){
- for(int q = 0;q<reds.length;q++){
- reds[q]=(float)Math.random();
- }
- }
- int q = 0;
- for(int a = 0;a<6;a++){
- for(int b = 0;b<6;b++){
- if(reds[q]<.3){
- GL11.glColor3d(1,1,1);
- }else{
- GL11.glColor3d(reds[q%reds.length],0,0);
- }
- GL11.glBegin(GL11.GL_QUADS);
- GL11.glVertex3f(a*width/6,b*height/6,0.0f);
- GL11.glVertex3f((a+1)*width/6,b*height/6,0.0f);
- GL11.glVertex3f((a+1)*width/6,(b+1)*height/6,0.0f);
- GL11.glVertex3f(a*width/6,(b+1)*height/6,0.0f);
- GL11.glEnd();
- q++;
- }
- }
- }
- public static void mkdot(){
- int temp = (int)Math.round(Math.random());
- double a=0;
- double b=0;
- double c=0;
- int d=(int)(int)Math.round(Math.random()*9);
- if(d==9){
- a=0;b=0;c=0;
- }else{
- if(d>=5){
- b=.7;c=.7;
- }else{
- b=.4;c=.5;
- }
- }
- if(temp==1)list.add(new red(true,(int)Math.round(Display.getDisplayMode().getWidth()*Math.random()),a,b,c));
- if(temp==0)list.add(new red(false,(int)Math.round(Display.getDisplayMode().getHeight()*Math.random()),a,b,c));
- pop=false;
- }
- public static void rmdot(){
- if(list.size()>=1)list.remove((int)Math.round((list.size()-1)*Math.random()));
- pop1=false;
- }
- }
- class red{
- public boolean dir;
- public boolean otd=true;
- public int off;
- public int oth=0;
- public int max;
- public int REDSIZE=8;
- public double r,g,b;
- public red(boolean direction, int offset,double a, double b1, double c){
- dir=direction;
- off=offset;
- if(dir){
- max=Display.getDisplayMode().getHeight();
- }else{
- max=Display.getDisplayMode().getWidth();
- }
- r=a;g=b1;b=c;
- }
- public boolean getDir(){
- return dir;
- }
- public int getOth(){
- return oth;
- }
- public int getOff(){
- return off;
- }
- public int REDSIZE(){
- return REDSIZE;
- }
- public void set(){
- if(dir){
- GL11.glTranslatef(off, oth,0);
- }
- if(!dir){
- GL11.glTranslatef(oth,off,0);
- }
- }
- public void reset(){
- if(dir){
- GL11.glTranslatef(-off, -oth,0);
- }
- if(!dir){
- GL11.glTranslatef(-oth,-off,0);
- }
- }
- public void othmod(){
- if(otd)oth+=3;
- if(!otd)oth-=3;
- if(oth>max){
- otd=!otd;
- }
- if(oth<0){
- otd=!otd;
- }
- }
- public void tick(){
- othmod();
- set();
- GL11.glColor3d(r,g,b);
- GL11.glBegin(GL11.GL_QUADS);
- GL11.glVertex2i(0, 0);
- GL11.glVertex2i(REDSIZE, 0);
- GL11.glVertex2i(REDSIZE, REDSIZE);
- GL11.glVertex2i(0,REDSIZE);
- GL11.glEnd();
- reset();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement