After typing this all out, I got an error with the uploader, it reads "Upload Skipped(Error503)". Any idea what this means? I'd like to get some input on this project.
Just post the code here. It'll be easier on everyone.
Main Class:
import java.util.Random;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
public class BreakoutMain extends BasicGame {
static AppGameContainer app;
Brick[] bricks;
Paddle paddle;
Ball ball;
boolean gameOver = false;
Item item;
public BreakoutMain() {
super("Breakout");
}
public void init(GameContainer container) throws SlickException {
paddle = new Paddle(Mouse.getX());
bricks = new Brick[60];
ball = new Ball(Mouse.getX());
item = new Item(1000, 0);
int brickx = 5;
int bricky = 5;
for (int c = 0; c < 5; c++) {
for (int i = 0; i < 12; i++) {
bricks[(c * 12) + i] = new Brick(brickx, bricky);
brickx += 65;
}
bricky += 35;
brickx = 5;
}
}
public void update(GameContainer container, int delta)
throws SlickException {
if (!gameOver) {
Input input = app.getInput();
if (input.isMousePressed(0) && !ball.isFree()) {
ball.setFree(true);
}
paddle.update(Mouse.getX());
ball.update(Mouse.getX());
item.update();
collision();
} else {
if (Mouse.isButtonDown(0)) {
System.exit(0);
}
}
}
public void render(GameContainer container, Graphics g)
throws SlickException {
if (!gameOver) {
paddle.paint(g);
ball.paint(g);
item.paint(g);
for (Brick b : bricks) {
b.paint(g);
}
} else {
g.drawString("Game Over", 350, 280);
}
}
public static void main(String[] args) throws SlickException {
app = new AppGameContainer(new BreakoutMain());
app.setDisplayMode(785, 600, false);
app.start();
}
public void collision() {
// Ball-Brick
for (Brick currentBrick : bricks) {
if (ball.ballCircle.intersects(currentBrick.brickRect)) {
ball.setDy(-ball.getDy());
Random rand = new Random();
// 10% chance to drop item on broken brick
switch (rand.nextInt(49)) {
case 0:
item = new ItemBigPaddle(
currentBrick.brickRect.getCenterX(),
currentBrick.brickRect.getCenterY());
break;
case 1:
item = new ItemSmallPaddle(
currentBrick.brickRect.getCenterX(),
currentBrick.brickRect.getCenterY());
break;
case 2:
item = new ItemFastBall(
currentBrick.brickRect.getCenterX(),
currentBrick.brickRect.getCenterY());
break;
case 3:
item = new ItemSlowBall(
currentBrick.brickRect.getCenterX(),
currentBrick.brickRect.getCenterY());
break;
}
currentBrick.brickRect.setX(1000);
}
}
// Ball-Right Wall
if (ball.ballCircle.getMaxX() >= 785) {
ball.setDx(-ball.getDx());
}
// Ball-Left Wall
if (ball.ballCircle.getMinX() <= 0) {
ball.setDx(-ball.getDx());
}
// Ball-Top Wall
if (ball.ballCircle.getMinY() <= 0) {
ball.setDy(-ball.getDy());
}
// Ball-Bottom Wall
if (ball.ballCircle.getMaxY() >= 600) {
gameOver = true;
}
// Ball-paddle
if (ball.ballCircle.intersects(paddle.paddleRect)) {
ball.setDy(-ball.getDy());
}
// Paddle-Item
if (paddle.paddleRect.intersects(item.itemCircle)) {
item.performAction(ball, paddle);
item.itemCircle.setCenterX(1000);
}
}
}
Ball Class:
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Circle;
public class Ball {
private float dx = .2f;
private float dy = .2f;
private boolean isFree = false;
Circle ballCircle;
public Ball(int mouseX) {
ballCircle = new Circle(mouseX, 550, 10);
}
public void update(int mouseX) {
if (!isFree) {
ballCircle.setCenterX(mouseX);
} else {
ballCircle.setCenterX(ballCircle.getCenterX() + dx);
ballCircle.setCenterY(ballCircle.getCenterY() - dy);
}
}
public void paint(Graphics g) {
g.setColor(Color.white);
g.fillOval(ballCircle.getX(), ballCircle.getY(),
ballCircle.getHeight(), ballCircle.getWidth());
}
// Getters and setters
public boolean isFree() {
return isFree;
}
public void setFree(boolean isFree) {
this.isFree = isFree;
}
public float getDx() {
return dx;
}
public void setDx(float dx) {
this.dx = dx;
}
public float getDy() {
return dy;
}
public void setDy(float dy) {
this.dy = dy;
}
}
Paddle Class:
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;
public class Paddle {
Rectangle paddleRect;
public Paddle(float MouseX) {
paddleRect = new Rectangle(MouseX, 560, 60, 15);
}
public void paint(Graphics g) {
g.setColor(Color.white);
g.fillRect(paddleRect.getX(), paddleRect.getY(), paddleRect.getWidth(),
paddleRect.getHeight());
}
public void update(int mouseX) {
paddleRect.setCenterX(mouseX);
if (paddleRect.getMaxX() >= 785)
paddleRect.setX(785 - paddleRect.getWidth());
if (paddleRect.getX() <= 0)
paddleRect.setX(0);
}
}
Brick Class:
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;
public class Brick {
private boolean destroyed = false;
Rectangle brickRect;
public Brick(float x, float y) {
brickRect = new Rectangle(x, y, 60, 30);
}
public void paint(Graphics g) {
g.setColor(Color.white);
g.fillRect(brickRect.getX(), brickRect.getY(), brickRect.getWidth(),
brickRect.getHeight());
}
}
Item Class:
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Circle;
public class Item {
Circle itemCircle;
float dy = .15f;
Color color;
public Item(float x, float y) {
itemCircle = new Circle(x, y, 7);
}
public void update() {
if (itemCircle.getCenterX() != 1000) {
itemCircle.setCenterY(itemCircle.getCenterY() + dy);
}
}
public void performAction(Ball ball, Paddle paddle) {}
public void paint(Graphics g) {
g.setColor(color);
g.fillOval(itemCircle.getCenterX(), itemCircle.getCenterY(),
itemCircle.getWidth(), itemCircle.getHeight());
}
}
There are other classes for the various items I've made, they're pretty basic though. Only thing different in them is that I change color and add stuff into the action performed method. The only items I've made are Speed up, Speed down, Bigger paddle and Smaller paddle.