• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
stein102

Critique/tips on first breakout attempt?

9 posts in this topic

I have followed the advice given by Alpha_ProgDes and made a pong game, followed by a breakout game. I made the game in Java with Slick as my game library. It's pretty basic and has a few errors, but I'm fairly happy with the overall result. There is still work to be done, the errors I need to fix right now are:

 

1) When ball collides with the paddle on the side it still changes the balls dy, not the dx. I feel like it would be easy enough to make another shape and add it onto the ends of the paddle for the ball to collide with.

2) Sometimes when the ball collides with the bricks, instead of bouncing off and destroying the brick, it continues through that brick and destroys another. I'm not sure what causes this but I feel like it has something to do with the order I've set up the collision in.

 

Possibly features to add:

1) Music and sound - This should be easy enough, it's just a matter of finding some sounds to use

2) A menu

3) Actual game levels - Read from a text file, instead of 5 solid lines of brick

4) A level editor - Probably something I'd come back to after gaining more experience

5) Player lives - After #3

6) A score - After #3

 

What do you guys think? Any suggestions of things I can do differently?

 

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.

2

Share this post


Link to post
Share on other sites

The proper attachment

 

[attachment=14372:Breakout.rar]

Edited by Gaiiden
double-post from thread merge
1

Share this post


Link to post
Share on other sites

I'd consider (2) unacceptable. I'm not sure about (1) either.

I strongly suggest to use sweeping collision checking.

I also suggest to do (5) and (6) before (3) as I expect those to be easier. Do easy things first.

 

As a side note, I don't suggest to use text files. Their inability to be "natively set up in columns" makes them hard to deal with in my opinion.

Consider .csv instead: this way, you can edit them in (say) openoffice calc, export it (it's basically a txt anyway) but you gain the explicit aligned cells of a spreadsheet.

In the past, I've experimented with this for a maze-oriented game. The fact each cell can contain nearly arbitrary data without messing up the layout (at least in calc) was a serious bonus for me.

 

No idea about the upload error. I'm fairly sure other people have uploaded executables in the past.

2

Share this post


Link to post
Share on other sites

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.
0

Share this post


Link to post
Share on other sites

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.

2

Share this post


Link to post
Share on other sites

Have you looked at what happens if you try to hit a block from on top of it?
If you look at

 

ball.setDy(-ball.getDy()); 

 

 

You should consider using vectors to represent the balls velocity.

2

Share this post


Link to post
Share on other sites

How would I represent a vector in Java? What would I use to store say V = 20m/s[N45E]? Or would I just use the components and have like Vx and Vy?

0

Share this post


Link to post
Share on other sites

Also, fixed the problem where the ball continues through multiple bricks. Just added a break after

currentBrick.brickRect.setX(1000);

 In the Collision method

0

Share this post


Link to post
Share on other sites

So how would I use a vector to represent the balls velocity? When the ball hits a stationary object, it's velocity just reverses, so that's simple. When the object hits the paddle though, would I reverse the velocity of the ball and add on the velocity of the paddle?

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0