Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Coin{
- float jumpValue, grav, magvalue;
- boolean jump = true;
- float coinPositionX, coinPositionY, directionX, directionY;
- Image coinImage;
- public Coin(float directionX, float jumpValue)
- {
- this.directionX = directionX;
- this.directionY = jumpValue;
- this.jumpValue = jumpValue;
- doInitializations();
- }
- public void doInitializations()
- {
- coinPositionX = 285;
- coinPositionY = 455;
- grav = 2f;
- magvalue = 1.8f;
- coinImage = Toolkit.getDefaultToolkit().createImage("coinBoxCoinKlein.png");
- }
- public void Update()
- {
- if (jump)
- {
- directionY = -directionY * 4;
- jump = false;
- }
- coinPositionY += directionY;
- coinPositionX += directionX;
- directionY += grav;
- if (coinPositionY >= 270)
- {
- grav = 1190f;
- }
- if (coinPositionY <= 270)
- {
- grav += 50f;
- }
- if (coinPositionY >= 400)
- {
- //change direction!
- coinPositionY = 400;
- directionY = -directionY / 40 * 25;
- if (directionY >= -80)
- {
- directionX = 0;
- directionY = 0;
- }
- }
- }
- public void Draw(Graphics g, ImageExample ie)
- {
- g.drawImage(coinImage, (int)coinPositionY, (int)coinPositionX, ie);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement