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

First Pong Game - Code review

4 posts in this topic

Hello everyone,

 

it would be nice if some of you guys can review my code for my pong game. this is the first game i have ever written, i used this tutorial but i adapted it to pong instead,  so there will be a lot of code that is similar if not the same to the tutorial but i fully understand the code. i also found a FPS class online and used that with a some minor changes.

 

thank you

 

p.s. if the images dont display, add them to the Pong\bin\com\pyro\sprite\

 

[attachment=14419:Pyro_pong.zip]

 

 

1

Share this post


Link to post
Share on other sites

Yeah I imported your project into eclipse and I found a few problems at the start.

On starting, it gave me an error with loading the images from the project. I found that this was because you were loading the image by reading from a URL instead of the folder that you're running from (might be because it's an applet but I'm not sure). Anyway, I found a bunch load of junk-code when you're importing images. I'm just going to make the assumption that this isn't meant to be an applet (because if it isn't then you don't need ALL the image load code that you have).

 

Ok so I can't remember what your image loading code was but it was in the SpriteStore class in the getSprite function.

The entire block can either be shortened by one of two ways.

1.

		try{
			System.out.println("Importing Image:" + ref);
			Image image = ImageIO.read(new File(ref));
			
			Sprite sprite = new Sprite(image);
			sprites.put(ref, sprite);

			return sprite;
		}catch(Exception e){
			System.out.println(ref + " does not exist");
		}
		
		System.exit(0);
		return null;

 

or if you want just 3 lines:

 

2.


Sprite sprite = new Sprite(new ImageIcon(ref).getImage());
sprites.put(ref, sprite);
return sprite;

 

 

 

Also, Ball.png was corrupt when I downloaded it. Might just be my WinRar but I thought I should tell you just in case.

 

All in all, I think the code is pretty good and well commented. It's very easy to see what's going on in the code which is a very good thing.

 

My tips for future games:

I see that you have all of your game logic code, window code and window animation code in one class. My tip for the future would be to write the game logic in its own class. This class could extend an abstract class called State which has 3 abstract methods init(), update(), and render(Graphics g). Then you could have an application holder class which would be created by passing an instance of a class extends from the State class. Sooo for example:


EDIT: this isn't supposed to be a quote.

public class Pong extends State{

     @Override 
     public void init(){
              //Initialize crap in here
     }
     @Override 
     public void update(){
           //All of the update logic EG checking for collisions and resolving
     }
     @Override 
     public void render(Graphics G){
           //Do all your drawing code here
     }

}
public class AppHolder extends JPanel implements Runnable {

     State state;

     public AppHolder(State state){
          state.init();
          this.state = state;
          Thread thread = new Thread(this);
          thead.start();
     }

     public void run(){
          while(true){
                  state.update();
                  repaint();
                  thread.sleep(1000/FPSYOUWANT)
          }
     }
  
     @Override
     public void paint(Graphics g){
             state.render(g);
     }
}

 

Then you can just initialize a JFrame and add a new instance of AppHolder and it'll do the crap.

The reason that this is better (not necessarily this but the general structure) is because you'll have to re-write a bunch of crap-ass initialization code if you want something like a main screen. Or, if you just put it all in the Game class then the game class will begin to be cluttered and ugly. Having this structure means you can just access the AppHolder class and set the state object to a new one such as MainScreen that extends state and do all the mainscreen logic and drawing in there. 

After you get more advanced you can start using the more complicated, flexible game architecture types. This is just one that will make the work easier in the long run.

 

Anyway, I'm bored of writing, hope this helps!

Also, sorry if I made any mistakes, it's pretty late.

Edited by CryoGenesis
1

Share this post


Link to post
Share on other sites

Also, I checked your other post about where to go from here. 

I see that you're an experienced coder so you're pretty much sorted. There is just one thing you'll probably need to get your head over though. Coding games (or simulations in general) is pretty much coding your own universe, that's how I see it anyway.

To make your game more realistic you'll need to learn physics (laws of motion, etc). To add functionality you'll need to learn mathematics (trigonometry, pythag, basically the stuff you learn in high school). For instance, if you wanted to draw a simple line from point A to point B, pixel by pixel, you'll either need to know trigonometry or how to work out the gradient of a line to do so. You'd actually be surprised how much trig and geometry stuff you use in game programming.

Anyway, I would recommend you to go get some game physics books then use the things you learn from the books to enhance your games to make them more interesting. For instance, about 2 years ago I learnt the equation to gravity and made an asteroids game where all the asteroids would start chasing after you because they were being pulled towards you due to their gravity.

Good luck with your game devving!

0

Share this post


Link to post
Share on other sites

Why do you have Player1Bar and Player2Bar when they are the same except for the name? Having the same code in more than one place is very bad.

0

Share this post


Link to post
Share on other sites

thank you all

 

CryoGenesis - thanks, i will look into replacing the sprite loading code, and separating the code a bit more. i will also looking into getting a book on game programming math and physics.

tufflax - yes i do realize that they do pretty much the same stuff - will change it.
 

thank you both.

Edited by Pyrotemplar
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