Im trying to move a shape, an octagon, in my game but I dont know how. Here is what I have so far
import java.awt.Container;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Circle;
import org.newdawn.slick.geom.Polygon;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;
public class ShapesAndCollisionTest extends BasicGame{
private Shape circle;
private boolean collides = false;
private float x = 300;
private float y = 100;
float speed = .25f;
private Shape octagon;
public ShapesAndCollisionTest(String title) {
super(title);
}
public void init(GameContainer gc) throws SlickException {
circle = new Circle(100, 100, 50);// x, y, radius
octagon = new Circle(x, y, 30, 8);//x, y, radius, number of segments
}
public void render(GameContainer gc, Graphics g) throws SlickException {
//set the color
g.setColor(new Color(0, 255, 255));//inside color
g.fill(circle);
g.setColor(new Color(255, 0, 0));//red, green, blue OUTLINE of circle
g.draw(circle);
g.setColor(Color.magenta);
g.draw(octagon);
//just show whether the collision is changing or not
g.drawString("Collides " + collides, 350, 30);
}
public void update(GameContainer gc, int delta) throws SlickException {
Input input = gc.getInput();
//control octogon
//up
if(input.isKeyDown(Input.KEY_UP)){
y = y - speed * delta;//delta makes the speed run the same on ANY computer
}
//down
if(input.isKeyDown(Input.KEY_DOWN)){
y = y + speed * delta;
}
//left
if(input.isKeyDown(Input.KEY_LEFT)){
x = x - speed * delta;
}
//right
if(input.isKeyDown(Input.KEY_RIGHT)){
x = x + speed * delta;
}
//check if it collides
collides = circle.intersects(octagon);
}