Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cg2d.v7animation;
- import java.awt.Color;
- import java.awt.Graphics;
- @SuppressWarnings("serial")
- public class FuckedUpBall extends AnimationPanel {
- private static final float SPEED = 100.0f;
- private static final int SIZE = 50;
- //pass middle
- private boolean state1 = false;
- //end of cycle
- private boolean state2 = false;
- private float y;
- //ball first goes down
- private int dirY = 1;
- public FuckedUpBall(){}
- @Override
- protected boolean step(double elapsedTime) {
- float delta = (float) (elapsedTime * SPEED);
- y += dirY * delta;
- if(((y + SIZE) >= getHeight()) && !state2 && (dirY == 1)){
- state2 = true;
- dirY = -1;
- }else if((y >= getHeight()) && state2 && (dirY == 1)){
- y = 1 - SIZE;
- dirY = 1;
- state1 = false;
- state2 = false;
- }
- if((y <= getHeight() / 2) && !state1 && (dirY == -1)){
- dirY = 1;
- state1 = true;
- }
- return true;
- }
- @Override
- protected void draw(Graphics g) {
- g.setColor(Color.red);
- g.fillOval(getWidth()/2 - SIZE/2, (int) y, SIZE, SIZE);
- }
- public static void main(String[] args) {
- new FuckedUpBall().run(500, 300, "Bounce", true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement