Advertisement
seaney11

Phase Ludum Dare 26 Source Code

Apr 28th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 38.42 KB | None | 0 0
  1. Class - display
  2.  
  3. package com.semcom.lde;
  4. import java.awt.Canvas;
  5. import java.awt.Color;
  6. import java.awt.Dimension;
  7. import java.awt.Font;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.Toolkit;
  11. import java.awt.image.*;
  12.  
  13. import javax.swing.Icon;
  14. import javax.swing.ImageIcon;
  15. import javax.swing.JOptionPane;
  16. import javax.swing.UIManager;
  17.  
  18. import com.semcom.lde.input.Controller;
  19. import com.semcom.lde.input.inputhandler;
  20. import com.semcom.lde.GUI.Launcher;
  21. import com.semcom.lde.graphics.Animation;
  22. import com.semcom.lde.graphics.Sprite;
  23.  
  24. public class display extends Canvas implements Runnable {
  25.    
  26.  
  27.     static Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
  28.  
  29.     private static final long serialVersionUID = 1L;
  30.  
  31.     public static int width = 1280;
  32.     public static int height = 720;
  33.     public static Sprite[] platform = new Sprite[11];
  34.     public static Sprite dot;
  35.     public static Sprite end;
  36.     public static Sprite guard1;
  37.     public static Sprite guard2;
  38.     public static Sprite guard3;
  39.     public static int level;
  40.     public static Level[] levels = new Level[10];
  41.     public static Level[] levelsA = new Level[10];
  42.     public static boolean phased;
  43.     public static boolean paused;
  44.     public static boolean guard1Dead = false;
  45.     public static boolean guard2Dead = false;
  46.     public static boolean guard3Dead = false;
  47.     public static int guard1Limit1;
  48.     public static int guard1Limit2;
  49.     public static int guard2Limit1;
  50.     public static int guard2Limit2;
  51.     public static int guard3Limit1;
  52.     public static int guard3Limit2;
  53.     public static Image help;
  54.  
  55.     private Thread thread;
  56.     private boolean running = false;
  57.     private Game game;
  58.     private inputhandler input;
  59.     private Image back;
  60.     private Image dotI;
  61.     private Image platformI;
  62.     private Animation dotA;
  63.     private Animation platformA;
  64.     private long passedTime;
  65.     private float gravity;
  66.     private float gravitya;
  67.     private boolean gravityActive = true;
  68.     private Image endI;
  69.    
  70.     public display(int i)
  71.     {
  72.         Dimension size = new Dimension(width, height);
  73.         setPreferredSize(size);
  74.         setMinimumSize(size);
  75.         setMaximumSize(size);
  76.         game = new Game();
  77.        
  78.         level = i;
  79.        
  80.         input = new inputhandler();
  81.         addKeyListener(input);
  82.         addMouseListener(input);
  83.         addFocusListener(input);
  84.         addMouseMotionListener(input);
  85.         loadImages();
  86.         initialProcesses();
  87.     }
  88.    
  89.     public void loadImages(){
  90.         back = new ImageIcon("res\\images\\back.png").getImage();
  91.         dotI = new ImageIcon("res\\images\\dot.gif").getImage();
  92.         platformI = new ImageIcon("res\\images\\platform.png").getImage();
  93.         endI = new ImageIcon("res\\images\\end.png").getImage();
  94.         Image guardI = new ImageIcon("res\\images\\guard.gif").getImage();
  95.        
  96.         dotA = new Animation();
  97.         dotA.addScene(dotI, 250);
  98.         dot = new Sprite(dotA);
  99.        
  100.         platformA = new Animation();
  101.         platformA.addScene(platformI, 250);
  102.         for (int i = 0; i < platform.length; i++){
  103.         platform[i] = new Sprite(platformA);
  104.         }
  105.        
  106.         Animation guardA = new Animation();
  107.         guardA.addScene(guardI, 250);
  108.         guard1 = new Sprite(guardA);
  109.         guard2 = new Sprite(guardA);
  110.         guard3 = new Sprite(guardA);
  111.        
  112.         Animation endA = new Animation();
  113.         endA.addScene(endI, 250);
  114.         end = new Sprite(endA);
  115.        
  116.         guard1.setVelocityX(0.0000001f);
  117.         guard2.setVelocityX(0.0000001f);
  118.         guard3.setVelocityX(0.0000001f);
  119.     }
  120.    
  121.     private void initialProcesses(){
  122.         gravitya = 0.0000000000000000007f;
  123.        
  124.         levels[0] = new Level(50,300,30,400,130,400,230,400,400,400,510,300,630,400,630,200,730,400,900,600,1000,500,1100,400,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  125.         levels[1] = new Level(50,300,30,400,130,400,630,400,730,400,830,300,930,400,1030,200,1100,400,0,0,0,0,0,0,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  126.         levels[2] = new Level(50,300,30,400,230,200,350,600,500,400,650,500,800,300,900,400,1100,400,0,0,0,0,0,0,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  127.         levels[3] = new Level(50,300,30,400,130,400,430,400,530,400,830,400,930,400,0,0,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),930,400 - guard1.getHeight(),0,0,0,0,830,1030,0,0,0,0);
  128.         levels[4] = new Level(50,300,30,400,300,400,750,400,1150,400,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),350,400 - guard1.getHeight(),800,400 - guard1.getHeight(),0,0,300,400,750,850,0,0);
  129.         levels[5] = new Level(50,300,30,400,450,500,650,450,650,350,1100,400,0,0,0,0,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),650,450 - guard1.getHeight(),0,0,0,0,650,750,0,0,0,0);
  130.         levels[6] = new Level(50,300,30,400,400,500,700,600,500,200,750,200,1000,600,1000,470,1100,400,0,0,0,0,0,0,1150,400 - end.getHeight(),550,200 - guard1.getHeight(),1050,600 - guard1.getHeight(),0,0,500,600,1000,1100,0,0);
  131.         levels[7] = new Level(50,300,30,400,700,400,950,300,700,200,900,100,1100,100,0,0,0,0,0,0,0,0,0,0,1150,100 - end.getHeight(),1000,300 - guard1.getHeight(),950,100 - guard1.getHeight(),0,0,950,1050,900,1000,0,0);
  132.         levels[8] = new Level(50,300,30,400,300,200,550,350,600,600,800,225,950,350,1100,400,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),350,200 - guard1.getHeight(),850,225 - guard1.getHeight(),0,0,300,400,800,900,0,0);
  133.         levels[9] = new Level(50,300,30,400,300,200,800,500,900,300,1100,400,0,0,0,0,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),350,200 - guard1.getHeight(),850,500 - guard1.getHeight(),950,300 - guard1.getHeight(),300,400,800,900,900,1000);
  134.        
  135.         levelsA[0] = new Level(50,300,30,400,130,400,230,400,400,400,510,300,630,400,630,200,730,400,900,600,1000,500,1100,400,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  136.         levelsA[1] = new Level(50,300,30,400,130,400,230,400,400,400, 510,300,630,400,630,200,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  137.         levelsA[2] = new Level(50,300,130,300,425,500,525,500,650,350,775,450,1000,400,0,0,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  138.         levelsA[3] = new Level(50,300,230,400,330,400,630,400,730,400,1030,400,1130,400,0,0,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  139.         levelsA[4] = new Level(50,300,150,350,400,350,600,600,750,500,900,300,0,0,0,0,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  140.         levelsA[5] = new Level(50,300,240,450,500,250,700,200,800,200,900,400,0,0,0,0,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  141.         levelsA[6] = new Level(50,300,200,450,400,300,500,400,850,550,1100,535,0,0,0,0,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  142.         levelsA[7] = new Level(50,300,30,400,200,300,500,500,1000,400,900,200,0,0,0,0,0,0,0,0,0,0,0,0,1150,100 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  143.         levelsA[8] = new Level(50,300,150,300,300,500,400,400,650,275,800,450,0,0,0,0,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  144.         levelsA[9] = new Level(50,300,150,300,700,600,800,400,1000,200,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1150,400 - end.getHeight(),0,0,0,0,0,0,0,0,0,0,0,0);
  145.        
  146.         levels[level].activate();
  147.     }
  148.  
  149.     public void run()
  150.     {
  151.         int frames = 0;
  152.         double unprocessedSeconds = 0;
  153.         long previousTime = System.nanoTime();
  154.         double secondsPerTick = 1 / 60.0;
  155.         int tickCount = 0;
  156.         boolean ticked = false;
  157.         while(running)
  158.         {
  159.             long currentTime = System.nanoTime();
  160.             passedTime = currentTime - previousTime;
  161.             previousTime = currentTime;
  162.             unprocessedSeconds += passedTime / 1000000000.0;
  163.             requestFocus();
  164.            
  165.             while(unprocessedSeconds > secondsPerTick)
  166.             {
  167.                 tick();
  168.                 unprocessedSeconds -= secondsPerTick;
  169.                 ticked = true;
  170.                 tickCount++;
  171.                 if(tickCount % 60 == 0)
  172.                 {
  173.                     previousTime += 1000;
  174.                     frames = 0;
  175.                 }
  176.             }
  177.             if(ticked)
  178.             {
  179.                 render();
  180.                 frames++;
  181.             }
  182.             render();
  183.             frames++;
  184.             loop();
  185.         }
  186.     }
  187.     private void tick()
  188.     {
  189.         game.tick(input.key);
  190.     }
  191.    
  192.     public void loop(){
  193.        
  194.         if (!paused){
  195.  
  196.         gravityActive = true;
  197.         Controller.canJump = false;
  198.         for (int i = 0; i < platform.length; i++){
  199.         if (collision(dot,platform[i])){
  200.             if (dot.getVelocityY() > 0 && dot.getY() + dot.getHeight() < platform[i].getY() + 5){
  201.                 gravityActive = false;
  202.                 Controller.canJump = true;
  203.                 dot.setVelocityY(0);
  204.             }
  205.         }
  206.         }
  207.        
  208.         if (Controller.left){
  209.             if (Controller.runWalk){
  210.                 dot.setVelocityX(-0.0000003f);
  211.             }
  212.             else{
  213.                 dot.setVelocityX(-0.0000002f);
  214.             }
  215.         }
  216.         else if (Controller.right){
  217.             if (Controller.runWalk){
  218.                 dot.setVelocityX(0.0000003f);
  219.             }
  220.             else{
  221.                 dot.setVelocityX(0.0000002f);
  222.             }
  223.         }
  224.         else{
  225.             dot.setVelocityX(0);
  226.         }
  227.         if (Controller.jump){
  228.             gravity = 0;
  229.             dot.setVelocityY(-0.0000004f);
  230.             Controller.canJump = false;
  231.             Controller.jump = false;
  232.             gravityActive = true;
  233.         }
  234.         if (Controller.phase && level != 0){
  235.             if (phased){
  236.                 phased = false;
  237.             }
  238.             else if (!phased){
  239.                 phased = true;
  240.             }
  241.             Controller.canPhase = false;
  242.             Controller.phase = false;
  243.         }
  244.        
  245.         if (phased){
  246.             back = new ImageIcon("res\\images\\backI.png").getImage();
  247.             platformI = new ImageIcon("res\\images\\platformI.png").getImage();
  248.             endI = new ImageIcon("res\\images\\endI.png").getImage();
  249.             levelsA[level].phase();
  250.         }
  251.         else{
  252.             back = new ImageIcon("res\\images\\back.png").getImage();
  253.             platformI = new ImageIcon("res\\images\\platform.png").getImage();
  254.             endI = new ImageIcon("res\\images\\end.png").getImage();
  255.             levels[level].phase();
  256.         }
  257.        
  258.         if (dot.getY() > 800){
  259.             gravity = 0;
  260.             levels[level].reset();
  261.         }
  262.         if (gravityActive == true){
  263.             gravity += gravitya;
  264.         }
  265.         else{
  266.             gravity = 0;
  267.         }
  268.        
  269.         if (guard1.getX() < guard1Limit1){
  270.             guard1.setX(guard1Limit1);
  271.             guard1.setVelocityX(-guard1.getVelocityX());
  272.         }
  273.         if (guard1.getX() + guard1.getWidth() > guard1Limit2){
  274.             guard1.setX(guard1Limit2 - guard1.getWidth());
  275.             guard1.setVelocityX(-guard1.getVelocityX());
  276.         }
  277.         if (guard2.getX() < guard2Limit1){
  278.             guard2.setX(guard2Limit1);
  279.             guard2.setVelocityX(-guard2.getVelocityX());
  280.         }
  281.         if (guard2.getX() + guard2.getWidth() > guard2Limit2){
  282.             guard2.setX(guard2Limit2 - guard2.getWidth());
  283.             guard2.setVelocityX(-guard2.getVelocityX());
  284.         }
  285.         if (guard3.getX() < guard3Limit1){
  286.             guard3.setX(guard3Limit1);
  287.             guard3.setVelocityX(-guard3.getVelocityX());
  288.         }
  289.         if (guard3.getX() + guard3.getWidth() > guard3Limit2){
  290.             guard3.setX(guard3Limit2 - guard3.getWidth());
  291.             guard3.setVelocityX(-guard3.getVelocityX());
  292.         }
  293.         if (collision(dot,guard1)){
  294.             if (dot.getY() + dot.getHeight() < guard1.getY() + (guard1.getHeight()/2)&& dot.getVelocityY() > 0){
  295.                 guard1Dead = true;
  296.                 guard1.hidden = true;
  297.                 guard1.setVelocityX(0);
  298.             }
  299.             else{
  300.                 levels[level].reset();
  301.             }
  302.         }
  303.         if (collision(dot,guard2)){
  304.             if (dot.getY() + dot.getHeight() < guard2.getY() + (guard2.getHeight()/2)&& dot.getVelocityY() > 0){
  305.                 guard2Dead = true;
  306.                 guard2.hidden = true;
  307.             }
  308.             else{
  309.                 levels[level].reset();
  310.             }
  311.         }
  312.         if (collision(dot,guard3)){
  313.             if (dot.getY() + dot.getHeight() < guard3.getY() + (guard3.getHeight()/2)&& dot.getVelocityY() > 0){
  314.                 guard3Dead = true;
  315.                 guard3.hidden = true;
  316.             }
  317.             else{
  318.                 levels[level].reset();
  319.             }
  320.         }
  321.         if(level == 0){
  322.             help = new ImageIcon("res\\images\\help1.gif").getImage();
  323.         }
  324.         if(level == 1){
  325.             help = new ImageIcon("res\\images\\help2.gif").getImage();
  326.         }
  327.         if(level == 2){
  328.             help = new ImageIcon("res\\images\\help3.gif").getImage();
  329.         }
  330.         if(level == 3){
  331.             help = new ImageIcon("res\\images\\help4.gif").getImage();
  332.         }
  333.         if(level == 4){
  334.             help = new ImageIcon("res\\images\\help5.gif").getImage();
  335.         }
  336.         if(level == 5){
  337.             help = new ImageIcon("").getImage();
  338.         }
  339.         if (collision(dot,end) && dot.hidden == false){
  340.             levels[level].completed = true;
  341.             dot.hidden = true;
  342.            
  343.             UIManager.put("OptionPane.background", Color.black);
  344.             UIManager.put("Panel.background", Color.black);
  345.             UIManager.put("OptionPane.messageForeground", Color.red);
  346.            
  347.             if (level != 9){
  348.  
  349.             Object[] options = { "Select a level", "Continue" };
  350.             Icon face = new ImageIcon("res\\images\\face.png");
  351.             int option;
  352.             option = JOptionPane.showOptionDialog(null, "You completed the level, and are one step closer to freedom!!!", "Well Done", JOptionPane.DEFAULT_OPTION, JOptionPane.OK_CANCEL_OPTION,face, options, options[0]);
  353.             if (option == 0){
  354.                 Object[] optionsa = null;
  355.                 if (levels[0].completed == true){
  356.                 Object[] optionsb = { "1","2" };
  357.                 optionsa = optionsb;
  358.                 }
  359.                 if (levels[1].completed == true){
  360.                 Object[] optionsb = { "1","2","3" };
  361.                 optionsa = optionsb;
  362.                 }
  363.                 if (levels[2].completed == true){
  364.                 Object[] optionsb = { "1","2","3","4" };
  365.                 optionsa = optionsb;
  366.                 }
  367.                 if (levels[3].completed == true){
  368.                 Object[] optionsb = { "1","2","3","4","5" };
  369.                 optionsa = optionsb;
  370.                 }
  371.                 if (levels[4].completed == true){
  372.                 Object[] optionsb = { "1","2","3","4","5","6" };
  373.                 optionsa = optionsb;
  374.                 }
  375.                 if (levels[5].completed == true){
  376.                 Object[] optionsb = { "1","2","3","4","5","6","7" };
  377.                 optionsa = optionsb;
  378.                 }
  379.                 if (levels[6].completed == true){
  380.                 Object[] optionsb = { "1","2","3","4","5","6","7","8" };
  381.                 optionsa = optionsb;
  382.                 }
  383.                 if (levels[7].completed == true){
  384.                 Object[] optionsb = { "1","2","3","4","5","6","7","8","9" };
  385.                 optionsa = optionsb;
  386.                 }
  387.                 if (levels[8].completed == true){
  388.                 Object[] optionsb = { "1","2","3","4","5","6","7","8","9", "10" };
  389.                 optionsa = optionsb;
  390.                 }
  391.                 int leveli = JOptionPane.showOptionDialog(null, "Which level would you like to select", "Select a Level", JOptionPane.DEFAULT_OPTION, JOptionPane.OK_CANCEL_OPTION,face, optionsa, optionsa[0]);
  392.                 if (leveli < 10 && leveli > -1){
  393.                     level = leveli;
  394.                     }
  395.             }
  396.             if (option == 1){
  397.                 level++;
  398.             }
  399.             dot.hidden = false;
  400.             levels[level].activate();
  401.             System.out.println(guard1.getX());
  402.             guard1.setVelocityX(0.0000001f);
  403.             guard2.setVelocityX(0.0000001f);
  404.             guard3.setVelocityX(0.0000001f);
  405.             }
  406.             else{
  407.                 Object[] options = { "Select a level"};
  408.                 Icon face = new ImageIcon("res\\images\\face.png");
  409.                 int option;
  410.                 option = JOptionPane.showOptionDialog(null, "You have escaped and are free!!!", "Congradulations", JOptionPane.DEFAULT_OPTION, JOptionPane.OK_CANCEL_OPTION,face, options, options[0]);
  411.                 if (option == 0){
  412.                     Object[] optionsa = { "1","2","3","4","5","6","7","8","9", "10" };
  413.                    
  414.                     int leveli = JOptionPane.showOptionDialog(null, "Which level would you like to select", "Select a Level", JOptionPane.DEFAULT_OPTION, JOptionPane.OK_CANCEL_OPTION,face, optionsa, optionsa[0]);
  415.                     if (leveli < 10 && leveli > -1){
  416.                     level = leveli;
  417.                     }
  418.                 }
  419.                 dot.hidden = false;
  420.                 levels[level].activate();
  421.             }
  422.         }
  423.        
  424.         dot.setVelocityY(dot.getVelocityY() + (gravity * passedTime));
  425.         dot.update(passedTime);
  426.         guard1.update(passedTime);
  427.         guard2.update(passedTime);
  428.         guard3.update(passedTime);
  429.     }
  430.         if (Controller.pause){
  431.             if (paused){
  432.                 paused = false;
  433.             }
  434.             else if (!paused){
  435.                 paused = true;
  436.                 gravityActive = false;
  437.                 dot.setVelocityY(0);
  438.                
  439.                 UIManager.put("OptionPane.background", Color.black);
  440.                 UIManager.put("Panel.background", Color.black);
  441.                 UIManager.put("OptionPane.messageForeground", Color.red);
  442.                
  443.                 Object[] options = { "Select a level", "Continue" };
  444.                 Icon pause = new ImageIcon("res\\images\\pause.png");
  445.                 int option;
  446.                 option = JOptionPane.showOptionDialog(null, "You have paused the game, what would you like to do", "Paused", JOptionPane.DEFAULT_OPTION, JOptionPane.OK_CANCEL_OPTION,pause, options, options[0]);
  447.                
  448.                 if (option == 0){
  449.                     Object[] optionsa = null;
  450.                     if (levels[0].completed == true){
  451.                     Object[] optionsb = { "1","2" };
  452.                     optionsa = optionsb;
  453.                     }
  454.                     if (levels[1].completed == true){
  455.                     Object[] optionsb = { "1","2","3" };
  456.                     optionsa = optionsb;
  457.                     }
  458.                     if (levels[2].completed == true){
  459.                     Object[] optionsb = { "1","2","3","4" };
  460.                     optionsa = optionsb;
  461.                     }
  462.                     if (levels[3].completed == true){
  463.                     Object[] optionsb = { "1","2","3","4","5" };
  464.                     optionsa = optionsb;
  465.                     }
  466.                     if (levels[4].completed == true){
  467.                     Object[] optionsb = { "1","2","3","4","5","6" };
  468.                     optionsa = optionsb;
  469.                     }
  470.                     if (levels[5].completed == true){
  471.                     Object[] optionsb = { "1","2","3","4","5","6","7" };
  472.                     optionsa = optionsb;
  473.                     }
  474.                     if (levels[6].completed == true){
  475.                     Object[] optionsb = { "1","2","3","4","5","6","7","8" };
  476.                     optionsa = optionsb;
  477.                     }
  478.                     if (levels[7].completed == true){
  479.                     Object[] optionsb = { "1","2","3","4","5","6","7","8","9" };
  480.                     optionsa = optionsb;
  481.                     }
  482.                     if (levels[8].completed == true){
  483.                     Object[] optionsb = { "1","2","3","4","5","6","7","8","9", "10" };
  484.                     optionsa = optionsb;
  485.                     }
  486.                     else {
  487.                         Object[] optionsb = { "1" };
  488.                         optionsa = optionsb;
  489.                     }
  490.                     level = JOptionPane.showOptionDialog(null, "Which level would you like to select", "Select a Level", JOptionPane.DEFAULT_OPTION, JOptionPane.OK_CANCEL_OPTION,pause, optionsa, optionsa[0]);
  491.                     levels[level].activate();
  492.                     paused = false;
  493.                 }
  494.                 else {
  495.                     paused = false;
  496.                     System.out.println("work");
  497.                 }
  498.             }
  499.             Controller.canPause = false;
  500.             Controller.pause = false;
  501.         }
  502.     }
  503.    
  504.     private boolean collision(Sprite s1, Sprite s2){
  505.         if (s1.getX() < s2.getX() + s2.getWidth() && s1.getX() + s1.getWidth() > s2.getX() && s1.getY() < s2.getY() + s2.getHeight() && s1.getY() + s1.getHeight() > s2.getY() && s1.hidden == false && s2.hidden == false){
  506.             return true;
  507.         }
  508.         return false;
  509.     }
  510.    
  511.     private void render()
  512.     {
  513.         BufferStrategy bs = this.getBufferStrategy();
  514.         if(bs == null)
  515.         {
  516.             createBufferStrategy(3);
  517.             return;
  518.         }
  519.        
  520.         Graphics g = bs.getDrawGraphics();
  521.         g.drawImage(back, 0, 0,null);
  522.         for(int i = 0; i < platform.length; i++){
  523.             if (platform[i].hidden == false){
  524.             g.drawImage(platformI, Math.round(platform[i].getX()),Math.round(platform[i].getY()), null);
  525.             }
  526.         }
  527.         if (end.hidden == false){
  528.             g.drawImage(endI, Math.round(end.getX()),Math.round(end.getY()), null);
  529.         }
  530.         if (dot.hidden == false){
  531.             g.drawImage(dot.getImage(), Math.round(dot.getX()),Math.round(dot.getY()), null);
  532.         }
  533.         if (guard1.hidden == false){
  534.             g.drawImage(guard1.getImage(), Math.round(guard1.getX()),Math.round(guard1.getY()), null);
  535.         }
  536.         if (guard2.hidden == false){
  537.             g.drawImage(guard2.getImage(), Math.round(guard2.getX()),Math.round(guard2.getY()), null);
  538.         }
  539.         if (guard3.hidden == false){
  540.             g.drawImage(guard3.getImage(), Math.round(guard3.getX()),Math.round(guard3.getY()), null);
  541.         }
  542.         g.drawImage(help,10, 10, null);
  543.         g.setFont(new Font("Verdana", 0, 20));
  544.         g.setColor(Color.YELLOW);
  545.         g.dispose();
  546.         bs.show();
  547.     }
  548.    
  549.     public synchronized void start() {
  550.         if (running)
  551.         {
  552.             return;
  553.         }
  554.         running = true;
  555.         thread = new Thread(this);
  556.         thread.start();
  557.     }
  558.    
  559.     public synchronized void stop()
  560.     {
  561.         if (!running)
  562.         {
  563.             return;
  564.         }
  565.         running = false;
  566.         try
  567.         {
  568.             thread.join();
  569.         }
  570.         catch(Exception e)
  571.         {
  572.             e.printStackTrace();
  573.             System.exit(1);
  574.         }
  575.     }
  576.    
  577.  
  578.  
  579.     public static void main(String[] args) {
  580.         new Launcher();
  581.     }
  582.          
  583. }
  584.  
  585. class - Game
  586.  
  587. package com.semcom.lde;
  588.  
  589. import java.awt.event.KeyEvent;
  590.  
  591. import com.semcom.lde.input.Controller;
  592.  
  593. public class Game {
  594.    
  595.     public int time;
  596.     public Controller controls;
  597.    
  598.     public Game()
  599.     {
  600.         controls = new Controller();
  601.     }
  602.    
  603.     public void tick(boolean[] key)
  604.     {
  605.         time ++;
  606.         boolean right = key[KeyEvent.VK_RIGHT];
  607.         boolean left = key[KeyEvent.VK_LEFT];
  608.         boolean jump = key[KeyEvent.VK_UP];
  609.         boolean sprint = key[KeyEvent.VK_SHIFT];
  610.         boolean space = key[KeyEvent.VK_SPACE];
  611.         boolean pause = key[KeyEvent.VK_ESCAPE];
  612.        
  613.         controls.tick(left, right, jump, sprint, space, pause);
  614.        
  615.        
  616.     }
  617.  
  618. }
  619.  
  620. class - level
  621.  
  622. package com.semcom.lde;
  623.  
  624. import java.awt.Point;
  625.  
  626. import javax.swing.ImageIcon;
  627.  
  628. public class Level {
  629.    
  630.     public Point[] places = new Point[11];
  631.     public Point dotStart;
  632.     public Point end;
  633.     public Point guard1;
  634.     public Point guard2;
  635.     public Point guard3;
  636.     public int guard1Limit1;
  637.     public int guard1Limit2;
  638.     public int guard2Limit1;
  639.     public int guard2Limit2;
  640.     public int guard3Limit1;
  641.     public int guard3Limit2;
  642.     public boolean completed = false;
  643.  
  644.     public Level(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int x5,int y5,int x6,int y6,int x7,int y7,int x8,int y8,int x9,int y9,int x10,int y10,int x11,int y11,int x12,int y12,int x13,int y13,int x14,int y14,int x15,int y15,int x16,int y16,int x17,int x18,int x19,int x20,int x21,int x22){
  645.         dotStart = new Point(x1,y1);
  646.         places[0] = new Point(x2,y2);
  647.         places[1] = new Point(x3,y3);
  648.         places[2] = new Point(x4,y4);
  649.         places[3] = new Point(x5,y5);
  650.         places[4] = new Point(x6,y6);
  651.         places[5] = new Point(x7,y7);
  652.         places[6] = new Point(x8,y8);
  653.         places[7] = new Point(x9,y9);
  654.         places[8] = new Point(x10,y10);
  655.         places[9] = new Point(x11,y11);
  656.         places[10] = new Point(x12,y12);
  657.         end = new Point(x13,y13);
  658.         guard1 = new Point(x14,y14);
  659.         guard2 = new Point(x15,y15);
  660.         guard3 = new Point(x16,y16);
  661.         guard1Limit1 = x17;
  662.         guard1Limit2 = x18;
  663.         guard2Limit1 = x19;
  664.         guard2Limit2 = x20;
  665.         guard3Limit1 = x21;
  666.         guard3Limit2 = x22;
  667.     }
  668.     public void activate(){
  669.         display.dot.setX(dotStart.x);
  670.         display.dot.setY(dotStart.y);
  671.         for(int i = 0; i < places.length; i++){
  672.             if (places[i].x != 0 && places[i].y != 0){
  673.                 display.platform[i].setX(places[i].x);
  674.                 display.platform[i].setY(places[i].y);
  675.                 display.platform[i].hidden = false;
  676.             }
  677.             else{
  678.                 display.platform[i].hidden = true;
  679.             }
  680.         }
  681.         display.end.setX(end.x);
  682.         display.end.setY(end.y);
  683.         display.phased = false;
  684.         display.dot.hidden = false;
  685.         if (guard1.x != 0 && guard1.y != 0){
  686.             display.guard1.setX(guard1.x);
  687.             display.guard1.setY(guard1.y);
  688.             display.guard1.hidden = false;
  689.         }
  690.         else{
  691.             display.guard1.hidden = true;
  692.         }
  693.         if (guard2.x != 0 && guard2.y != 0){
  694.             display.guard2.setX(guard2.x);
  695.             display.guard2.setY(guard2.y);
  696.             display.guard2.hidden = false;
  697.         }
  698.         else{
  699.             display.guard2.hidden = true;
  700.         }
  701.         if (guard3.x != 0 && guard3.y != 0){
  702.             display.guard3.setX(guard3.x);
  703.             display.guard3.setY(guard3.y);
  704.             display.guard3.hidden = false;
  705.         }
  706.         else{
  707.             display.guard3.hidden = true;
  708.         }
  709.         display.guard1Limit1 = guard1Limit1;
  710.         display.guard1Limit2 = guard1Limit2;
  711.         display.guard2Limit1 = guard2Limit1;
  712.         display.guard2Limit2 = guard2Limit2;
  713.         display.guard3Limit1 = guard3Limit1;
  714.         display.guard3Limit2 = guard3Limit2;
  715.         display.guard1Dead = false;
  716.         display.guard2Dead = false;
  717.         display.guard3Dead = false;
  718.        
  719.         if(display.level == 0){
  720.             display.help = new ImageIcon("res\\images\\help1.gif").getImage();
  721.         }
  722.         if(display.level == 1){
  723.             display.help = new ImageIcon("res\\images\\help2.gif").getImage();
  724.         }
  725.         if(display.level == 2){
  726.             display.help = new ImageIcon("res\\images\\help3.gif").getImage();
  727.         }
  728.         if(display.level == 3){
  729.             display.help = new ImageIcon("res\\images\\help4.gif").getImage();
  730.         }
  731.         if(display.level == 4){
  732.             display.help = new ImageIcon("res\\images\\help5.gif").getImage();
  733.         }
  734.         else{
  735.             display.help = new ImageIcon("").getImage();
  736.         }
  737.     }
  738.     public void phase(){
  739.         for(int i = 0; i < places.length; i++){
  740.             if (places[i].x != 0 && places[i].y != 0){
  741.                 display.platform[i].setX(places[i].x);
  742.                 display.platform[i].setY(places[i].y);
  743.                 display.platform[i].hidden = false;
  744.             }
  745.             else{
  746.                 display.platform[i].hidden = true;
  747.             }
  748.         }
  749.         if (guard1.x != 0 && guard1.y != 0 && display.guard1Dead == false){
  750.             display.guard1.hidden = false;
  751.         }
  752.         else{
  753.             display.guard1.hidden = true;
  754.         }
  755.         if (guard2.x != 0 && guard2.y != 0 && display.guard2Dead == false){
  756.             display.guard2.hidden = false;
  757.         }
  758.         else{
  759.             display.guard2.hidden = true;
  760.         }
  761.         if (guard3.x != 0 && guard3.y != 0 && display.guard3Dead == false){
  762.             display.guard3.hidden = false;
  763.         }
  764.         else{
  765.             display.guard3.hidden = true;
  766.         }
  767.         display.end.setX(end.x);
  768.         display.end.setY(end.y);
  769.     }
  770.     public void reset(){
  771.         display.dot.setX(dotStart.x);
  772.         display.dot.setY(dotStart.y);
  773.         for(int i = 0; i < places.length; i++){
  774.             display.platform[i].setX(places[i].x);
  775.             display.platform[i].setY(places[i].y);
  776.         }
  777.         display.end.setX(end.x);
  778.         display.end.setY(end.y);
  779.  
  780.         if (guard1.x != 0 && guard1.y != 0 && (display.phased == true || display.guard1.hidden == false) ){
  781.             display.guard1.hidden = false;
  782.         }
  783.         else{
  784.             display.guard1.hidden = true;
  785.         }
  786.         if (guard2.x != 0 && guard2.y != 0){
  787.             display.guard2.hidden = false;
  788.         }
  789.         else{
  790.             display.guard2.hidden = true;
  791.         }
  792.         if (guard3.x != 0 && guard3.y != 0){
  793.             display.guard3.hidden = false;
  794.         }
  795.         else{
  796.             display.guard3.hidden = true;
  797.         }
  798.         display.phased = false;
  799.     }
  800.  
  801. }
  802.  
  803. class RunGame
  804.  
  805. package com.semcom.lde;
  806.  
  807. import javax.swing.JFrame;
  808.  
  809. public class RunGame {
  810.  
  811.  
  812.     public static final String title = "Phase";
  813.     public static JFrame frame = new JFrame();
  814.    
  815.     public RunGame(int i){
  816.        
  817.         display game = new display(i);
  818.         frame.add(game);
  819.         frame.setSize(display.width, display.height);
  820.         frame.setResizable(false);
  821.         frame.setVisible(true);
  822.         frame.setTitle(title);
  823.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  824.         frame.setLocationRelativeTo(null);
  825.        
  826.         game.start();
  827.     }
  828.    
  829. }
  830.  
  831. class - animation
  832.  
  833. package com.semcom.lde.graphics;
  834.  
  835. import java.util.ArrayList;
  836. import java.awt.Image;
  837.  
  838. public class Animation {
  839.  
  840.     private ArrayList<Onescene> scenes;
  841.     private int sceneIndex;
  842.     private long movieTime;
  843.     private long totalTime;
  844.  
  845.     public Animation() {
  846.         scenes = new ArrayList<Onescene>();
  847.         totalTime = 0;
  848.         start();
  849.     }
  850.  
  851.     public synchronized void addScene(Image i, long t) {
  852.         totalTime += t;
  853.         scenes.add(new Onescene(i, totalTime));
  854.     }
  855.  
  856.     public synchronized void start() {
  857.         movieTime = 0;
  858.         sceneIndex = 0;
  859.     }
  860.  
  861.     public synchronized void update(long timePassed) {
  862.  
  863.         if(scenes.size() > 1 ) {
  864.             movieTime += timePassed;
  865.  
  866.             if(movieTime >= totalTime) {
  867.                 movieTime = 0;
  868.                 sceneIndex = 0;
  869.             }
  870.             while(movieTime > getScene(sceneIndex).endTime) {
  871.                 sceneIndex++;
  872.             }
  873.         }
  874.     }
  875.  
  876.     public synchronized Image getImage() {
  877.  
  878.         if(scenes.size() == 0) {
  879.             return null;
  880.         }
  881.  
  882.         else {
  883.             return getScene(sceneIndex).pic;
  884.         }
  885.     }
  886.  
  887.     private Onescene getScene(int x) {
  888.         return (Onescene)scenes.get(x);
  889.     }
  890.  
  891.     public class Onescene{
  892.         Image pic;
  893.         long endTime;
  894.  
  895.         public Onescene(Image pic, long endTime) {
  896.             this.pic = pic;
  897.             this.endTime = endTime;
  898.         }
  899.     }
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906. }
  907.  
  908. class render
  909.  
  910. package com.semcom.lde.graphics;
  911.  
  912. public class render {
  913.    
  914.     public final int width;
  915.     public final int height;
  916.     public final int[] pixels;
  917.    
  918.     public render(int width, int height)
  919.     {
  920.         this.width = width;
  921.         this.height  = height;
  922.         pixels = new int[width * height];
  923.     }
  924.    
  925.     public void draw(render render, int xoffset, int yoffset)
  926.     {
  927.         for (int y = 0; y < render.height; y++)
  928.         {
  929.             int ypix = y + yoffset;
  930.             if(ypix < 0 || ypix >= height)
  931.             {
  932.                 continue;
  933.             }
  934.            
  935.             for (int x = 0; x < render.width; x++)
  936.             {
  937.                 int xpix = x + xoffset;
  938.                 if (xpix < 0 || xpix >= width)
  939.                 {
  940.                     continue;
  941.                 }
  942.                
  943.                 int alpha = render.pixels[x + y * render.width];
  944.                 if (alpha > 0){
  945.                 pixels[xpix + ypix *width] = alpha;
  946.                 }
  947.             }
  948.         }
  949.     }
  950.  
  951. }
  952. class sprite
  953.  
  954. package com.semcom.lde.graphics;
  955.  
  956. import java.awt.Image;
  957.  
  958. public class Sprite {
  959.  
  960.     private Animation a;
  961.     private float x;
  962.     private float y;
  963.     private float vx;
  964.     private float vy;
  965.    
  966.     public boolean hidden = false;
  967.  
  968.     public Sprite(Animation a) {
  969.         this.a = a;
  970.     }
  971.  
  972.     public void update(long timePassed) {
  973.         x += vx * timePassed;
  974.         y += vy * timePassed;
  975.         a.update(timePassed);
  976.     }
  977.  
  978.     public float getX() {
  979.         return x;
  980.     }
  981.  
  982.     public float getY() {
  983.         return y;
  984.     }
  985.  
  986.     public void setX(float x) {
  987.         this.x = x;
  988.     }
  989.  
  990.     public void setY(float y) {
  991.         this.y = y;
  992.     }
  993.  
  994.     public int getWidth() {
  995.         return a.getImage().getWidth(null);
  996.     }
  997.  
  998.     public int getHeight() {
  999.         return a.getImage().getHeight(null);
  1000.     }
  1001.  
  1002.     public float getVelocityX() {
  1003.         return vx;
  1004.     }
  1005.  
  1006.     public float getVelocityY() {
  1007.         return vy;
  1008.     }
  1009.  
  1010.     public void setVelocityX(float vx) {
  1011.         this.vx = vx;
  1012.     }
  1013.  
  1014.     public void setVelocityY(float vy) {
  1015.         this.vy = vy;
  1016.     }
  1017.  
  1018.     public Image getImage() {
  1019.         return a.getImage();
  1020.     }
  1021. }
  1022.  
  1023. class launcher
  1024.  
  1025. package com.semcom.lde.GUI;
  1026.  
  1027. import java.awt.Color;
  1028. import java.awt.Dimension;
  1029. import java.awt.Rectangle;
  1030. import java.awt.event.ActionEvent;
  1031. import java.awt.event.ActionListener;
  1032.  
  1033. import javax.swing.Icon;
  1034. import javax.swing.ImageIcon;
  1035. import javax.swing.JButton;
  1036. import javax.swing.JFrame;
  1037. import javax.swing.JOptionPane;
  1038. import javax.swing.JPanel;
  1039. import javax.swing.UIManager;
  1040.  
  1041.  
  1042. public class Launcher extends JFrame{
  1043.  
  1044.     private static final long serialVersionUID = 1L;
  1045.    
  1046.     protected JPanel window = new JPanel();
  1047.     private JButton play, howToPlay;
  1048.     private Rectangle rplay, rhelp;
  1049.    
  1050.     private int width = 240;
  1051.     private int height = 320;
  1052.     protected int button_width = 80;
  1053.     protected int button_height = 40;
  1054.    
  1055.     public Launcher(){
  1056.        
  1057.         setTitle("Phase");
  1058.         setSize (new Dimension(width, height));
  1059.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  1060.         getContentPane().add(window);
  1061.         setLocationRelativeTo(null);
  1062.         setResizable(false);
  1063.         setVisible(true);
  1064.         window.setLayout(null);
  1065.         window.setBackground(Color.black);
  1066.         play = new JButton("Play");
  1067.         rplay = new Rectangle(width/2 - button_width/2, 90, button_width, button_height);
  1068.         play.setBounds(rplay);
  1069.         play.setBackground(Color.gray);
  1070.         play.setForeground(Color.red);
  1071.         window.add(play);;
  1072.        
  1073.         howToPlay = new JButton("How to Play");
  1074.         rhelp = new Rectangle(width/2 - 120/2, 190, 120, button_height);
  1075.         howToPlay.setBounds(rhelp);
  1076.         howToPlay.setBackground(Color.gray);
  1077.         howToPlay.setForeground(Color.red);
  1078.         window.add(howToPlay);
  1079.        
  1080.         play.addActionListener(new ActionListener(){
  1081.             public void actionPerformed(ActionEvent e){
  1082.                 dispose();
  1083.                 new LevelSelector();
  1084.             }
  1085.         });
  1086.         howToPlay.addActionListener(new ActionListener(){
  1087.             public void actionPerformed(ActionEvent e){
  1088.                 UIManager.put("OptionPane.background", Color.black);
  1089.                 UIManager.put("Panel.background", Color.black);
  1090.                 UIManager.put("OptionPane.messageForeground", Color.red);
  1091.                
  1092.                 Icon dot = new ImageIcon("res\\images\\dot.gif");
  1093.                
  1094.                 JOptionPane.showMessageDialog(null, "You are this dot.\nYou have been trapped and your mission is to escape.\nSimple, or is it?\n\nGood luck\n\nControls:\nleft/right arrow keys - move\nup arrow key - jump\nshift - sprint\nspace - phase\nescape - pause", "How to Play", JOptionPane.INFORMATION_MESSAGE, dot);
  1095.             }
  1096.         });
  1097.     }
  1098.  
  1099. }
  1100.  
  1101. class LevelSelector
  1102.  
  1103. package com.semcom.lde.GUI;
  1104.  
  1105. import java.awt.Color;
  1106. import java.awt.Dimension;
  1107. import java.awt.Rectangle;
  1108. import java.awt.event.ActionEvent;
  1109. import java.awt.event.ActionListener;
  1110.  
  1111. import javax.swing.JButton;
  1112. import javax.swing.JFrame;
  1113. import javax.swing.JPanel;
  1114.  
  1115. import com.semcom.lde.RunGame;
  1116.  
  1117. public class LevelSelector extends JFrame{
  1118.    
  1119. private static final long serialVersionUID = 1L;
  1120.    
  1121.     protected JPanel window = new JPanel();
  1122.     private JButton[] buttons = new JButton[10];
  1123.     private Rectangle[] rButtons = new Rectangle[10];
  1124.    
  1125.     private int width = 650;
  1126.     private int height = 400;
  1127.     protected int button_width = 50;
  1128.     protected int button_height = 50;
  1129.    
  1130.     public LevelSelector(){
  1131.        
  1132.         setTitle("Select Level");
  1133.         setSize (new Dimension(width, height));
  1134.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  1135.         getContentPane().add(window);
  1136.         setLocationRelativeTo(null);
  1137.         setResizable(false);
  1138.         setVisible(true);
  1139.         window.setLayout(null);
  1140.         window.setBackground(Color.black);
  1141.        
  1142.         buttons[0] = new JButton("1");
  1143.        rButtons[0] = new Rectangle(100, 100, button_width, button_height);
  1144.         buttons[0].setBounds(rButtons[0]);
  1145.        
  1146.         buttons[0].addActionListener(new ActionListener(){
  1147.             public void actionPerformed(ActionEvent e){
  1148.                 dispose();
  1149.                 new RunGame(0);
  1150.             }
  1151.         });
  1152.  
  1153.         buttons[1] = new JButton("2");
  1154.        rButtons[1] = new Rectangle(200, 100, button_width, button_height);
  1155.         buttons[1].setBounds(rButtons[1]);
  1156.        
  1157.         buttons[1].addActionListener(new ActionListener(){
  1158.             public void actionPerformed(ActionEvent e){
  1159.                 dispose();
  1160.                 new RunGame(1);
  1161.             }
  1162.         });
  1163.  
  1164.         buttons[2] = new JButton("3");
  1165.        rButtons[2] = new Rectangle(300, 100, button_width, button_height);
  1166.         buttons[2].setBounds(rButtons[2]);
  1167.        
  1168.         buttons[2].addActionListener(new ActionListener(){
  1169.             public void actionPerformed(ActionEvent e){
  1170.                 dispose();
  1171.                 new RunGame(2);
  1172.             }
  1173.         });
  1174.  
  1175.         buttons[3] = new JButton("4");
  1176.        rButtons[3] = new Rectangle(400, 100, button_width, button_height);
  1177.         buttons[3].setBounds(rButtons[3]);
  1178.        
  1179.         buttons[3].addActionListener(new ActionListener(){
  1180.             public void actionPerformed(ActionEvent e){
  1181.                 dispose();
  1182.                 new RunGame(3);
  1183.             }
  1184.         });
  1185.  
  1186.         buttons[4] = new JButton("5");
  1187.        rButtons[4] = new Rectangle(500, 100, button_width, button_height);
  1188.         buttons[4].setBounds(rButtons[4]);
  1189.        
  1190.         buttons[4].addActionListener(new ActionListener(){
  1191.             public void actionPerformed(ActionEvent e){
  1192.                 dispose();
  1193.                 new RunGame(4);
  1194.             }
  1195.         });
  1196.  
  1197.         buttons[5] = new JButton("6");
  1198.        rButtons[5] = new Rectangle(100, 250, button_width, button_height);
  1199.         buttons[5].setBounds(rButtons[5]);
  1200.        
  1201.         buttons[5].addActionListener(new ActionListener(){
  1202.             public void actionPerformed(ActionEvent e){
  1203.                 dispose();
  1204.                 new RunGame(5);
  1205.             }
  1206.         });
  1207.  
  1208.         buttons[6] = new JButton("7");
  1209.        rButtons[6] = new Rectangle(200, 250, button_width, button_height);
  1210.         buttons[6].setBounds(rButtons[6]);
  1211.        
  1212.         buttons[6].addActionListener(new ActionListener(){
  1213.             public void actionPerformed(ActionEvent e){
  1214.                 dispose();
  1215.                 new RunGame(6);
  1216.             }
  1217.         });
  1218.  
  1219.         buttons[7] = new JButton("8");
  1220.        rButtons[7] = new Rectangle(300, 250, button_width, button_height);
  1221.         buttons[7].setBounds(rButtons[7]);
  1222.        
  1223.         buttons[7].addActionListener(new ActionListener(){
  1224.             public void actionPerformed(ActionEvent e){
  1225.                 dispose();
  1226.                 new RunGame(7);
  1227.             }
  1228.         });
  1229.  
  1230.         buttons[8] = new JButton("9");
  1231.        rButtons[8] = new Rectangle(400, 250, button_width, button_height);
  1232.         buttons[8].setBounds(rButtons[8]);
  1233.        
  1234.         buttons[8].addActionListener(new ActionListener(){
  1235.             public void actionPerformed(ActionEvent e){
  1236.                 dispose();
  1237.                 new RunGame(8);
  1238.             }
  1239.         });
  1240.  
  1241.         buttons[9] = new JButton("10");
  1242.        rButtons[9] = new Rectangle(500, 250, button_width, button_height);
  1243.         buttons[9].setBounds(rButtons[9]);
  1244.        
  1245.         buttons[9].addActionListener(new ActionListener(){
  1246.             public void actionPerformed(ActionEvent e){
  1247.                 dispose();
  1248.                 new RunGame(9);
  1249.             }
  1250.         });
  1251.        
  1252.         for (int i = 1; i < buttons.length; i++){
  1253.             buttons[i].setEnabled(false);
  1254.         }
  1255.        
  1256.         for (int i = 0; i < buttons.length; i++){
  1257.             window.add(buttons[i]);
  1258.         }
  1259.         for (int i = 0; i < buttons.length; i++){
  1260.             buttons[i].setBackground(Color.gray);
  1261.             buttons[i].setForeground(Color.red);
  1262.         }
  1263.  
  1264.     }
  1265.  
  1266. }
  1267. class controller
  1268.  
  1269. package com.semcom.lde.input;
  1270.  
  1271.  
  1272. public class Controller {
  1273.    
  1274.     public static boolean right = false;
  1275.     public static boolean left = false;
  1276.     public static boolean jump = false;
  1277.     public static boolean runWalk = false;
  1278.     public static boolean canJump = true;
  1279.     public static boolean phase = false;
  1280.     public static boolean canPhase = true;
  1281.     public static boolean pause = false;
  1282.     public static boolean canPause = true;
  1283.    
  1284.     public void tick(boolean left, boolean right, boolean jump, boolean sprint,boolean space, boolean esc)
  1285.     {
  1286.        
  1287.         if (left)
  1288.         {
  1289.             Controller.left = true;
  1290.         }
  1291.         if (right)
  1292.         {
  1293.             Controller.right = true;
  1294.         }
  1295.         if(sprint)
  1296.         {
  1297.             runWalk = true;
  1298.         }
  1299.         if(!left)
  1300.         {
  1301.             Controller.left = false;
  1302.         }
  1303.         if(!right)
  1304.         {
  1305.             Controller.right = false;
  1306.         }
  1307.         if(!sprint)
  1308.         {
  1309.             runWalk = false;
  1310.         }
  1311.         if(jump && canJump){
  1312.             Controller.jump = true;
  1313.         }
  1314.         if(!jump){
  1315.             Controller.jump = false;
  1316.         }
  1317.         if(space && canPhase){
  1318.             phase = true;
  1319.         }
  1320.         if(!space){
  1321.             phase = false;
  1322.             canPhase = true;
  1323.         }
  1324.         if(space && canPhase){
  1325.             phase = true;
  1326.         }
  1327.         if(!space){
  1328.             phase = false;
  1329.             canPhase = true;
  1330.         }
  1331.  
  1332.         if(esc && canPause){
  1333.             pause = true;
  1334.         }
  1335.         if(!esc){
  1336.             pause = false;
  1337.             canPause = true;
  1338.         }
  1339.     }
  1340. }
  1341.  
  1342. class input handler
  1343.  
  1344. package com.semcom.lde.input;
  1345.  
  1346. import java.awt.event.FocusEvent;
  1347. import java.awt.event.FocusListener;
  1348. import java.awt.event.KeyEvent;
  1349. import java.awt.event.KeyListener;
  1350. import java.awt.event.MouseEvent;
  1351. import java.awt.event.MouseListener;
  1352. import java.awt.event.MouseMotionListener;
  1353.  
  1354. public class inputhandler implements KeyListener, MouseListener, MouseMotionListener, FocusListener {
  1355.  
  1356.     public boolean[] key= new boolean[68836];
  1357.     public static int mouseX;
  1358.     public static int mouseY;
  1359.     public static int mouseButton;
  1360.     public static boolean clicked = false;
  1361.     int sTime;
  1362.     int oTime;
  1363.    
  1364.     @Override
  1365.     public void mouseDragged(MouseEvent e) {
  1366.         // TODO Auto-generated method stub
  1367.        
  1368.     }
  1369.  
  1370.     @Override
  1371.     public void mouseMoved(MouseEvent e) {
  1372.         // TODO Auto-generated method stub
  1373.         mouseX = e.getX();
  1374.         mouseY = e.getY();
  1375.     }
  1376.  
  1377.     @Override
  1378.     public void mouseClicked(MouseEvent e) {
  1379.         mouseButton = e.getButton();
  1380.        
  1381.         if (mouseButton == 1)
  1382.         {
  1383.             clicked = true;
  1384.         }
  1385.     }
  1386.  
  1387.     @Override
  1388.     public void mouseEntered(MouseEvent e) {
  1389.         // TODO Auto-generated method stub
  1390.        
  1391.     }
  1392.  
  1393.     @Override
  1394.     public void mouseExited(MouseEvent e) {
  1395.         // TODO Auto-generated method stub
  1396.        
  1397.     }
  1398.  
  1399.     @Override
  1400.     public void mousePressed(MouseEvent e) {
  1401.         // TODO Auto-generated method stub
  1402.        
  1403.     }
  1404.  
  1405.     @Override
  1406.     public void mouseReleased(MouseEvent e) {
  1407.         // TODO Auto-generated method stub
  1408.        
  1409.     }
  1410.  
  1411.     @Override
  1412.     public void keyPressed(KeyEvent e) {
  1413.         int keycode = e.getKeyCode();
  1414.         if (keycode > 0 && keycode < key.length)
  1415.         {
  1416.             key[keycode] = true;
  1417.         }
  1418.     }
  1419.  
  1420.     @Override
  1421.     public void keyReleased(KeyEvent e) {
  1422.         int keycode = e.getKeyCode();
  1423.         if (keycode > 0 && keycode < key.length)
  1424.         {
  1425.             key[keycode] = false;
  1426.         }
  1427.     }
  1428.  
  1429.     @Override
  1430.     public void keyTyped(KeyEvent e) {
  1431.         // TODO Auto-generated method stub
  1432.        
  1433.     }
  1434.  
  1435.     @Override
  1436.     public void focusGained(FocusEvent e) {
  1437.         // TODO Auto-generated method stub
  1438.        
  1439.     }
  1440.  
  1441.     @Override
  1442.     public void focusLost(FocusEvent e) {
  1443.         for (int i = 0; i < key.length; i++)
  1444.         {
  1445.             key[i] = false;
  1446.         }
  1447.     }
  1448.  
  1449. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement