Advertisement
Guest User

Coin.java

a guest
Aug 19th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. public class Coin{
  2.  
  3.     float jumpValue, grav, magvalue;
  4.     boolean jump = true;
  5.     float coinPositionX, coinPositionY, directionX, directionY;
  6.    
  7.     Image coinImage;
  8.    
  9.     public Coin(float directionX, float jumpValue)
  10.     {
  11.         this.directionX = directionX;
  12.         this.directionY = jumpValue;
  13.         this.jumpValue = jumpValue;
  14.        
  15.         doInitializations();
  16.     }
  17.    
  18.     public void doInitializations()
  19.     {
  20.         coinPositionX = 285;
  21.         coinPositionY = 455;
  22.         grav = 2f;
  23.         magvalue = 1.8f;
  24.        
  25.         coinImage = Toolkit.getDefaultToolkit().createImage("coinBoxCoinKlein.png");
  26.     }
  27.    
  28.    
  29.     public void Update()
  30.     {
  31.        
  32.         if (jump)
  33.         {
  34.             directionY = -directionY * 4;
  35.             jump = false;
  36.         }
  37.  
  38.        
  39.         coinPositionY += directionY;
  40.         coinPositionX += directionX;
  41.         directionY += grav;
  42.         if (coinPositionY >= 270)
  43.         {
  44.             grav = 1190f;
  45.         }
  46.         if (coinPositionY <= 270)
  47.         {
  48.             grav += 50f;
  49.         }
  50.        
  51.  
  52.         if (coinPositionY >= 400)
  53.         {
  54.             //change direction!
  55.             coinPositionY = 400;
  56.             directionY = -directionY / 40 * 25;
  57.             if (directionY >= -80)
  58.             {
  59.                 directionX = 0;
  60.                 directionY = 0;
  61.  
  62.             }
  63.         }
  64.     }
  65.    
  66.    
  67.     public void Draw(Graphics g, ImageExample ie)
  68.     {
  69.         g.drawImage(coinImage, (int)coinPositionY, (int)coinPositionX, ie);
  70.        
  71.     }
  72.    
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement