• 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
mepis

Critique my code please

7 posts in this topic

Good evening everyone,

 

Would anyone mind please critiquing my code? Any help would be very appreciated.

 

Background:

I'm in school for computer science and am casually playing around with various languages coding different things. I decided to program a Pong clone in Java as a learning experience. This experiment has less to do with making an actual game and more to do with designing code really well. I designed my code with a lot of forward thought to make future changes and UI settings very easy to do later on. With that said, my code is probably a lot more complicated than it needs to be. But I did it for practice and learning.

 

I still have to add a point system and UI to change settings later on. I see those as more trivial things at this point though. 

 

I'm putting in two links to the code. One is to my Github account where the files are located. I am also putting a link to my personal blog page (not intending on plugging here) because I put all the code on a single page. I figured it might be easier to follow back and fourth between the various classes that way.

 

So, if anyone wouldn't mind, please tear into my code. I can't learn more if I have no idea what I messed up or what I could be doing better. I appreciate any opinions any person might have.

 

GitHub

 

Personal Blog Page

1

Share this post


Link to post
Share on other sites

In some of your boolean logic, change this:

public boolean isBallGreaterThanWindowWidth(){
    if (xPosition > (windowWidth - (xRadius * 1.5)))
      return true;
    else 
      return false;
  }

to this:

public boolean isBallGreaterThanWindowWidth(){
    return(xPosition > (windowWidth - (xRadius * 1.5)));
}
Edited by Cosmic314
0

Share this post


Link to post
Share on other sites
It makes no sense for an abstract game object like the Ball class to be aware of characteristics of the program window.

If you like, it could have functions that return the edge coordinates of the ball, which can then be compared to window coordinates elsewhere.
0

Share this post


Link to post
Share on other sites
  1. Every time you add a new item, you have to change the GameWindow.paint method.
  2. You have a lot of hardcoded magic numbers. Like 16666666..., (userInput == 38), (userInput == 40), etc.
  3. Some objects are not encapsulated very well. Ball is just a bag of data which doesn't do anything, just holds values. It also holds values not specific to ball, like window measurements.
  4. What is the purpose of GameLoopTimer? It looks like it could be used to make movement framerate independent, but it is not used for that. Is the frequency of GameWindow.paint calls fixed in Java, or does it vary with the speed of the machine?
  5. What is the purpose of the isHard boolean?
  6. GameWindow has too many responsibilities - drawing, input detection and response, general initialization, object creation, object movement. It should delegate a lot more to other classes. 
1

Share this post


Link to post
Share on other sites

mepis, I've sumitted a couple of pull requests that address one or two of the points I mentioned above.

1

Share this post


Link to post
Share on other sites

mepis, I've sumitted a couple of pull requests that address one or two of the points I mentioned above.

 

Awesome. Thank you!

 

I've taken note of everything everyone is saying. For my purposes, I think it might be best to scrap what I have and start over again. It'll be a better learning experience that way.

 

I always figured the GameWindow class did to much. But I wasn't sure how to break it down and make it be in better form. But this is all practice and learning so it work out. It makes me go back and look at it again.

 

The whole point of the ball class was only to make it conceptually easier to see what was going on. I can see how I messed that up though. Correct me if I am wrong, but it would be alright for that class just to hold number pertaining to the ball itself but the rest is completely not needed and better handled somewhere else?

 

Part of the problem with the GameWindow class doing to much is that I'm still getting used to the Java GUI classes (Eg. Swing). I'm still learning and figuring out how to handle all of those classes. I have a hard time understanding the Java classes because there are just so bloody freaking many of them. It seems like half of them are capable of doing the same thing as another class. But I'm still learning. That's the way these things go.

 

Thanks a lot guys. I'm going to hold out for a couple of days longer and see if anyone else has any other input. Then I'm going to start over so I can figure out a way to better handle that GameWindow class.

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