Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.91 KB | None | 0 0
  1. import org.lwjgl.Sys;
  2. import org.lwjgl.input.Keyboard;
  3. import org.lwjgl.opengl.Display;
  4. import org.lwjgl.opengl.GL11;
  5. import java.util.ArrayList;
  6. import java.util.*;
  7.  
  8. public class LWJGL{
  9.     static ArrayList<red> list = new ArrayList<red>();
  10.     static int var;
  11.     static float[] reds = new float[36];
  12.     static boolean pop=true;
  13.     static boolean pop1=true;
  14.     static float speedx=0;
  15.     static float speedy=0;
  16.     static final int width = Display.getDisplayMode().getWidth();
  17.     static final int height = Display.getDisplayMode().getHeight();
  18.     static int x=Display.getDisplayMode().getWidth() / 2;
  19.     static int y=Display.getDisplayMode().getHeight() / 2;
  20.     public static final String GAME_TITLE = "TOM IS SO PR0";
  21.     private static final int FRAMERATE = 60;
  22.     private static boolean finished;
  23.     private static float angle;
  24.    
  25.     public static void main(String[] args) {
  26.         boolean fullscreen = (args.length == 1 && args[0].equals("-fullscreen"));
  27.         fullscreen=true;
  28.         try{
  29.             init(fullscreen);run();
  30.             }catch(Exception e){
  31.                 e.printStackTrace(System.err);
  32.                 Sys.alert(GAME_TITLE, "An error occured and the game will exit.");
  33.                 }
  34.             finally{cleanup();}
  35.         System.exit(0);
  36.   }
  37.   private static void lose(){
  38.     Sys.alert(GAME_TITLE, "You've lost with a score of "+list.size()+", NIIIICE!");
  39.   }
  40.   private static void init(boolean fullscreen) throws Exception {
  41.     Display.setTitle(GAME_TITLE);
  42.     Display.setFullscreen(fullscreen);
  43.     Display.setVSyncEnabled(true);
  44.     Display.create();
  45.     GL11.glMatrixMode(GL11.GL_PROJECTION);
  46.     GL11.glDisable(GL11.GL_DEPTH_TEST);
  47.     GL11.glLoadIdentity();
  48.     GL11.glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
  49.     GL11.glMatrixMode(GL11.GL_MODELVIEW);
  50.     GL11.glLoadIdentity();
  51.     GL11.glViewport(0, 0, width, height);
  52.   }
  53.  
  54.   /**
  55.    * Runs the game (the "main loop")
  56.    */
  57. private static void run() {
  58.     int sub =0;
  59.     boolean gg = false;
  60.     while (!gg){
  61.     while (!finished) {
  62.       // Always call Window.update(), all the time - it does some behind the
  63.       // scenes work, and also displays the rendered output
  64.       Display.update();
  65.  
  66.       // Check for close requests
  67.       if (Display.isCloseRequested()) {
  68.         finished = true;
  69.       }
  70.  
  71.       // The window is in the foreground, so we should play the game
  72.       else if (Display.isActive()) {
  73.         logic();
  74.         render(sub);sub++;if(sub==FRAMERATE)sub=0;
  75.         Display.sync(FRAMERATE);
  76.       }
  77.  
  78.       // The window is not in the foreground, so we can allow other stuff to run and
  79.       // infrequently update
  80.       else {
  81.         try {
  82.           Thread.sleep(100);
  83.         } catch (InterruptedException e) {
  84.         }
  85.         logic();
  86.  
  87.         // Only bother rendering if the window is visible or dirty
  88.         if (Display.isVisible() || Display.isDirty()) {
  89.           render(sub);sub++;if(sub==FRAMERATE)sub=0;
  90.         }
  91.       }
  92.     }
  93.     lose();gg=true;
  94.     }
  95.   }
  96. private static void cleanup() {
  97.     Display.destroy();
  98.   }
  99. private static void logic() {
  100.     if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
  101.       finished = true;
  102.     }
  103.     angle += 2.0f % 360;
  104.     if(collide(list, (int)y, (int)x, 8, 8)){
  105.         finished = true;
  106.     }
  107.   }
  108. private static boolean collide(ArrayList<red> list, int y, int x, int w, int h){
  109.     for(int q=0;q < list.size();q++){
  110.         if(list.get(q).dir){
  111.             if(colbox(list.get(q).off,list.get(q).oth,list.get(q).REDSIZE,list.get(q).REDSIZE,x,y,w,h)){
  112.                 return true;
  113.             }
  114.         }else{
  115.             if(colbox(list.get(q).oth,list.get(q).off,list.get(q).REDSIZE,list.get(q).REDSIZE,x,y,w,h)){
  116.                 return true;
  117.             }
  118.         }
  119.        
  120.     }
  121.     //System.out.println("YOU LOSE, BUT YOUR GONNA HAVE TO ALT TAB TO FIGURE IT OUT!!!");
  122.     return false;
  123.   }
  124. public static boolean colbox(int x1,int y1,int x1w,int y1h,int x2,int y2,int x2w,int y2h)
  125.   {
  126.     if(x1+x1w<x2)
  127.       return false;
  128.     if(x1>x2+x2w)
  129.       return false;
  130.     if(y1+y1h<y2)
  131.       return false;
  132.     if(y1>y2+y2h)
  133.       return false;
  134.     return true;
  135. }
  136. private static void keys(){
  137.     if (Keyboard.isKeyDown(Keyboard.KEY_DOWN))y-=7;
  138.     if (Keyboard.isKeyDown(Keyboard.KEY_UP))y+=7;
  139.     if (Keyboard.isKeyDown(Keyboard.KEY_LEFT))x-=7;
  140.     if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT))x+=7;
  141.     x%=Display.getDisplayMode().getWidth();
  142.     y%=Display.getDisplayMode().getHeight();
  143.     if(x<=0)x=Display.getDisplayMode().getWidth();
  144.     if(y<=0)y=Display.getDisplayMode().getHeight();
  145.     if (Keyboard.isKeyDown(Keyboard.KEY_Q)&&pop)mkdot();
  146.     if (Keyboard.isKeyDown(Keyboard.KEY_W))for(int q = 0; q< 4;q++)mkdot();
  147.     if (Keyboard.isKeyDown(Keyboard.KEY_A)&&pop)rmdot();
  148.     if (Keyboard.isKeyDown(Keyboard.KEY_S))for(int q = 0;q< 4;q++)rmdot();
  149.     if (!Keyboard.isKeyDown(Keyboard.KEY_A))pop1=true;
  150.     if (!Keyboard.isKeyDown(Keyboard.KEY_Q))pop=true;
  151. }
  152. private static void you(){
  153.         GL11.glBegin(GL11.GL_POLYGON);
  154.         double temp = 2*Math.PI/5;
  155.         GL11.glVertex3i((int)(6*Math.sin(temp)), (int)(6*Math.cos(temp)),1);
  156.         GL11.glVertex3i((int)(8*Math.sin(temp*2)), (int)(8*Math.cos(temp*2)),1);
  157.         GL11.glVertex3i((int)(6*Math.sin(temp*3)), (int)(6*Math.cos(temp*3)),1);
  158.         GL11.glVertex3i((int)(8*Math.sin(temp*4)), (int)(8*Math.cos(temp*4)),1);
  159.         GL11.glVertex3i((int)(6*Math.sin(temp*5)), (int)(6*Math.cos(temp*5)),1);
  160.         GL11.glVertex3i((int)(8*Math.sin(temp)), (int)(8*Math.cos(temp)),1);
  161.         GL11.glVertex3i((int)(6*Math.sin(temp*2)), (int)(6*Math.cos(temp*2)),1);
  162.         GL11.glVertex3i((int)(8*Math.sin(temp*3)), (int)(8*Math.cos(temp*3)),1);
  163.         GL11.glVertex3i((int)(6*Math.sin(temp*4)), (int)(6*Math.cos(temp*4)),1);
  164.         GL11.glVertex3i((int)(8*Math.sin(temp*5)), (int)(8*Math.cos(temp*5)),1);
  165.         //GL11.glScaled(.3,.3,.6);
  166.       GL11.glEnd();
  167.      
  168.       // render the square
  169.      
  170.       GL11.glColor3d(.3,0,1);
  171.       GL11.glBegin(GL11.GL_QUADS);
  172.         GL11.glVertex2i(-2, -2);
  173.         GL11.glVertex2i(2, -2);
  174.         GL11.glVertex2i(2, 2);
  175.         GL11.glVertex2i(-2, 2);
  176.       GL11.glEnd();
  177. }
  178. private static void render(int sub) {
  179.     if(sub==0){
  180.         mkdot();
  181.     }
  182.     GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
  183.     GL11.glPushMatrix();
  184.     GL11.glColor3d(1,1,1);
  185.     GL11.glBegin(GL11.GL_QUADS);
  186.     GL11.glVertex3f(0.0f, (float)height,0.0f);
  187.     GL11.glVertex3f(0.0f, 0.0f,0.0f);
  188.     GL11.glVertex3f((float)width, 0.0f,0.0f);
  189.     GL11.glVertex3f((float)width, (float)height,0.0f);
  190.     GL11.glEnd();
  191.     bg(sub);
  192.     for(int x=0;x<list.size();x++)list.get(x).tick();
  193.     GL11.glTranslatef((float) (x % width),(float) (y % height), 0.0f);
  194.     keys();
  195.     GL11.glRotatef(-angle, 0, 0, 1.0f);
  196.     //PENTAGON MOD
  197.     GL11.glColor3d(0,1,.2);
  198.     you();
  199.     GL11.glPopMatrix();
  200.    
  201. }
  202. public static void bg(int sub){
  203.     if(sub%20==0){
  204.         for(int q = 0;q<reds.length;q++){
  205.             reds[q]=(float)Math.random();
  206.         }
  207.     }
  208.     int q = 0;
  209.     for(int a = 0;a<6;a++){
  210.         for(int b = 0;b<6;b++){
  211.             if(reds[q]<.3){
  212.                 GL11.glColor3d(1,1,1);
  213.             }else{
  214.                 GL11.glColor3d(reds[q%reds.length],0,0);
  215.             }
  216.             GL11.glBegin(GL11.GL_QUADS);
  217.             GL11.glVertex3f(a*width/6,b*height/6,0.0f);
  218.             GL11.glVertex3f((a+1)*width/6,b*height/6,0.0f);
  219.             GL11.glVertex3f((a+1)*width/6,(b+1)*height/6,0.0f);
  220.             GL11.glVertex3f(a*width/6,(b+1)*height/6,0.0f);
  221.             GL11.glEnd();
  222.             q++;
  223.         }
  224.     }
  225. }
  226. public static void mkdot(){
  227.     int temp = (int)Math.round(Math.random());
  228.     double a=0;
  229.     double b=0;
  230.     double c=0;
  231.     int d=(int)(int)Math.round(Math.random()*9);
  232.         if(d==9){
  233.             a=0;b=0;c=0;
  234.         }else{
  235.             if(d>=5){
  236.                 b=.7;c=.7;
  237.             }else{
  238.                 b=.4;c=.5;
  239.             }
  240.         }
  241.         if(temp==1)list.add(new red(true,(int)Math.round(Display.getDisplayMode().getWidth()*Math.random()),a,b,c));
  242.         if(temp==0)list.add(new red(false,(int)Math.round(Display.getDisplayMode().getHeight()*Math.random()),a,b,c));
  243.         pop=false;
  244.   }
  245. public static void rmdot(){
  246.     if(list.size()>=1)list.remove((int)Math.round((list.size()-1)*Math.random()));
  247.         pop1=false;
  248.   }
  249. }
  250. class red{
  251.         public boolean dir;
  252.         public boolean otd=true;
  253.         public int off;
  254.         public int oth=0;
  255.         public int max;
  256.         public int REDSIZE=8;
  257.         public double r,g,b;
  258.         public red(boolean direction, int offset,double a, double b1, double c){
  259.                 dir=direction;
  260.                 off=offset;
  261.                 if(dir){
  262.                         max=Display.getDisplayMode().getHeight();
  263.                 }else{
  264.                         max=Display.getDisplayMode().getWidth();
  265.                 }
  266.                 r=a;g=b1;b=c;
  267.         }
  268.         public boolean getDir(){
  269.             return dir;
  270.         }
  271.         public int getOth(){
  272.             return oth;
  273.         }
  274.         public int getOff(){
  275.             return off;
  276.         }
  277.         public int REDSIZE(){
  278.             return REDSIZE;
  279.         }
  280.         public void set(){
  281.                 if(dir){
  282.                         GL11.glTranslatef(off, oth,0);
  283.                 }
  284.                 if(!dir){
  285.                         GL11.glTranslatef(oth,off,0);
  286.                 }
  287.         }
  288.         public void reset(){
  289.                 if(dir){
  290.                         GL11.glTranslatef(-off, -oth,0);
  291.                 }
  292.                 if(!dir){
  293.                         GL11.glTranslatef(-oth,-off,0);
  294.                 }
  295.         }
  296.         public void othmod(){
  297.                 if(otd)oth+=3;
  298.                 if(!otd)oth-=3;
  299.                 if(oth>max){
  300.                         otd=!otd;
  301.                 }
  302.                 if(oth<0){
  303.                         otd=!otd;
  304.                 }
  305.         }
  306.         public void tick(){
  307.                 othmod();
  308.                 set();
  309.                 GL11.glColor3d(r,g,b);
  310.         GL11.glBegin(GL11.GL_QUADS);
  311.         GL11.glVertex2i(0, 0);
  312.         GL11.glVertex2i(REDSIZE, 0);
  313.         GL11.glVertex2i(REDSIZE, REDSIZE);
  314.         GL11.glVertex2i(0,REDSIZE);
  315.         GL11.glEnd();
  316.         reset();
  317.         }
  318. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement