Skip to content

Instantly share code, notes, and snippets.

@itsjoekent
Created December 24, 2012 15:14
Show Gist options
  • Save itsjoekent/4369604 to your computer and use it in GitHub Desktop.
Save itsjoekent/4369604 to your computer and use it in GitHub Desktop.
Bouncing Ball Thing
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package me.thedeadlybutter.timeflip;
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.Random;
/**
*
* @author Butters
*/
public class StateMainMenu implements State {
Location l = new Location(20, 20);
Vector v = new Vector(2, 2);
int length = 16;
Random r = new Random();
public StateMainMenu() {
}
@Override
public void init(Main main) {
}
@Override
public void update(Main main, double delta) {
l.subVector(v);
if(l.getX() >= main.getW() || (l.getX() <= 0)){
v.setX(v.getX() * -1);
}
if((l.getY() >= main.getH()) || (l.getY() <= 0)){
v.setY(v.getY() * -1);
}
}
@Override
public void render(Main main, Graphics2D g) {
//g.setColor(Color.white);
//g.fillRect(0, 0, main.getWidth(), main.getHeight());
g.setColor(new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)));
if(r.nextBoolean()){
g.fillRect(l.getX(), l.getY(), length, length);
}
else{
g.fillOval(l.getX(), l.getY(), length, length);
}
}
@Override
public int getID() {
return StateManager.MAIN_MENU_STATE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment