Advertisement
Guest User

Ball.class

a guest
Mar 29th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1.  
  2. import java.awt.Image;
  3. import java.awt.event.KeyEvent;
  4.  
  5. import javax.swing.ImageIcon;
  6.  
  7.  
  8. public class Ball {
  9.     int x,y;
  10.     float dx,dy,gravity = 0.40f;
  11.     Image img;
  12.     boolean left = false, right = true, up = true, down = false;
  13.    
  14.     public Ball(){
  15.         ImageIcon ball = new ImageIcon(getClass().getResource("/resources/Ball.png"));
  16.         img = ball.getImage();
  17.        
  18.         x = 400;
  19.         y = 400;
  20.     }
  21.    
  22.     public void move(){
  23.         dy+=gravity;
  24.         x = x + dx;
  25.         y = y +dx;
  26.        
  27.         if(x <= 750 && right == true){
  28.             dx = 1;
  29.            
  30.         }else{
  31.             dx = -1;
  32.             right = false;
  33.             left = true;
  34.            
  35.         }
  36.         if(x<=0 && left == true){
  37.             dx = 1;
  38.             right = true;
  39.         }
  40.        
  41.         if(y >= 300 && up == true){
  42.             dy = -1;
  43.         }else{
  44.             dy = 1;
  45.             up = false;
  46.             down = true;
  47.         }
  48.        
  49.         if (y >= 500 && down == true){
  50.             dy = -1;
  51.             up = true;
  52.         }
  53.        
  54.        
  55.        
  56.        
  57.     }
  58.    
  59.     public float getX(){
  60.         return x;
  61.     }
  62.    
  63.     public float getY(){
  64.         return y;
  65.     }
  66.    
  67.     public Image getImage(){
  68.         return img;
  69.     }
  70.    
  71.    
  72.     public void keyPressed(KeyEvent e){
  73.         int key = e.getKeyCode();
  74.     }
  75.    
  76.     public void keyReleased(KeyEvent e){
  77.         int key = e.getKeyCode();
  78.         }
  79.    
  80.  
  81.    
  82.    
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement