BlockBasher - My first game in Java 2D.

I have gone from Showcase to WIP with this as I’ve completely taken it apart as I couldn’t fix bugs as it was. The links below aren’t available at the moment but should be back and better shortly.


My first game in Java 2D. No external dependencies or libraries. Made following trial and error, some reading up on here, and other places. If anyone’s kind enough to look at the source to see if I’ve gone badly wrong it’s here:

https://github.com/danieldean/BlockBasher

The commenting is a little verbose but that’s to help me for now. My hit detection is also a little dodgy and I may have a go at fixing that in the future. You can download a complied and ready to go JAR here:

https://github.com/danieldean/BlockBasher/releases

I’m also learning to use Git and Semantic Versioning. This as a warm up and refresh for distance learning as I’ll be doing Java after summer. I’m not that new to Java but I am new to painting and games in Java.

Thanks!

I danieldean i played your game and you should fix some things:

  • You should put the windows size dinamic because its too big in my laptop
  • The player rectangle or something ehh (dont know the name) should collide on sides of the game window
  • When the ball touches the sides of the rectangle, it enters the rectangle (sorry for my bad english)
  • Put the arrow keys because it easier to play

And i think it all i found
Nice game
Keep it up :smiley:

-death

Thanks for your feedback.

I didn’t realise the window size is a problem, as I’m using FHD, I fixed it because I had difficulties with getting the blocks to fit the screen with integer arithmetic if I allowed it to be changed. I’d need to change everything to use doubles, Graphics2D and Rectangle2D.Double, etc., which could be a lot to do now. I think I can allow anything with 4:3 as the aspect ratio without problems. I’ll look into this.

I guess you mean the paddle can go off the play area. I didn’t think about this but easily fixed. If you release the ball whilst the paddle is out of the play area it causes even more problems. :o Collision detection needs fixing. I know this but I’m trying to figure out what might be better.

I can change the key bindings easily enough, maybe I can make them and the window size be set by the player somehow.

The game is now able to be resized, but for now you must change the constants. I haven’t made a way to do this after compilation so I’ve yet to make a release with JAR.

Hi! Nice game. I played it for a bit, and now I have some feedback for you. :slight_smile:

I could not see my score throughout the game, even though the picture you posted shows it in the corner. That bummed me out a bit.
It seems that the controls offer no aim, making the ball go in the same pattern throughout the entire game. I suggest finding the ball’s new direction based on where it hit on the paddle. While on the subject of the ball’s direction, I noticed in your code that the ball does not posses a velocity - only a position. I think you could simplify your code by introducing a velocity vector to the ball, instead of storing this information in temporary variables in the main class. This change would also make changing the balls direction much easier. Everyone wins. :smiley:

If you do the same thing to your paddle, you could make it control very differently. Right now it’s very tight, and responds with immediate effect. A velocity vector could add a heavier feel to it, making the paddle more difficult to stop, or change direction. This would make the game a bit more challenging.

Your code looks really neat, although there are some things I do not quite understand. One of these things, is the need for x2 and y2 variables. They could easily be replaced by a getter, adding only an extra calculation. I think that is worth the saved complexity.

The black background is a little bit dull, and I think it would be a shame not to generate at least something. Even a gradient would make it no much prettier. Remember bubble struggle? That game only had some gradients for backgrounds and it worked perfectly, making each level memorable.

There are tons of ways to improve a game like yours, but I think you did a good job. Your code does what you meant it to do, and it does so in a clear fashion. Good job on the game. :slight_smile:

Hi there. Thanks for trying. :slight_smile:

I’m a little confused why you don’t see the score. Do you see the splash screens for the game start, over and levels? It’s all the same font so if you do I thinks that’s very strange. My painting code for this is very straightforward and I don’t think it should go wrong unless I have sync issues.

Point taken on the velocity vector, I can probably add this to my Sprite and have it across the board. The only reason for having x2 and y2 is that it made the intersection code a bit simpler but in something else I’ve started I’ve gone with getters instead. They are unneeded variables because they’re just x + width so I’ll get rid of them.

Edit: I have given the paddle velocity, using vx, vy and made a tick() method, limiting it’s speed by the magnitude. Clearly it only works in one dimension with the paddle. Can you try it? http://www.java-gaming.org/user-generated-content/members/295784/blockbasher.jar, I think it’s what you mean.

Sure. I do see the splash with the title and directions. I still don’t see the score, though.

If I make the paddle move before shooting the ball, it glitches out a little. I also seems that the paddle once again can go through the sides.
It looks like you implemented what I described, however it feels weird. It may just be a too high maximum velocity, or too much velocity given when pressing a button. :slight_smile:

Thanks, that’s kind of the idea and why I’ve kept the contrasting colours in to give it that look.

For the moment this isn’t available on GitHub as I’ve gone completely back to the drawing board with it to give it separate tick and render along with vectors and reflection. So when it comes back you should really be a player not just going through the motions! :persecutioncomplex: As it was you’d play the same game each time if you didn’t move at the start and the random ball start was the same.

In the mean time this https://github.com/danieldean/Bounce is serving as a demo of my bouncing so I can get it right and finish the game. You can download a JAR under releases.