Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Pongclone - constructive criticism please  (Read 984 times)
0 Members and 1 Guest are viewing this topic.
Offline ado

Senior Newbie





« Posted 2012-11-11 08:15:03 »

Hi all
I've been lurking around for quite a while whilst learning the basics of java and have just finished thenewbostons java game dev tuts and made a pong clone earlier today. Attached is both the runnable .jar, which starts in fullscreen, and the source.
Any constructive criticism or pointers would be much appreciated.
Known issue: pressing space while ball is moving will re-randomize ball velocity(direction).

Fullscreen Mode: http://www.mediafire.com/?98qobp777zf6jrb,22qohsmvefvnif8

EDIT: Windowed mode version(working): http://www.mediafire.com/?c7sg1cvft9qe47j,d2yeaa1lqihxfhs

enjoy,  
Ado
Offline matheus23

JGO Kernel


Medals: 113
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2012-11-11 09:20:30 »

You did this in one day? This is fast for a first game Wink

Fullscreen works perfectly...

But it somehow looks non-smooth.
I downloaded the source,
looked at the game loop: Seems okey, checked.
let the code print the fps, compiled and started: FPS is a constant 62.

I guess your problem lies in the famous spikes.
Spikes are some frames which just accedently take much more time than they should. Then it appears like it would be slower, but it isn't.
*looks at code again*
It seems like your "draw()" method in mainPong.java is "synchronized". Remove this keyword, it propably doesn't does what you want it to do.

One more thing:
To answer your question about random ball-launching:
Replace this:
1  
2  
3  
4  
5  
6  
        //launch ball
        if(keyCode == KeyEvent.VK_SPACE){
           ball.setVelocityX(3f);
            ball.setVelocityY(3f);
            startMsg = false;
        }

With this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
        //launch ball
        if(keyCode == KeyEvent.VK_SPACE){
       // We create a "rand" instance for generating random stuff.
       // It would be a better practice, if you store the rand
       // in this class's fields.
       Random rand = new Random();
       // rand.nextBoolean() returns randomly either true or false
       if (rand.nextBoolean() == true) {
      // If it's true, then the X-Velocity is positive, else it's negative.
      ball.setVelocityX(3f);
       } else {
      ball.setVelocityX(-3f);
       }
       if (rand.nextBoolean() == true) {
      ball.setVelocityY(3f);
       } else {
      ball.setVelocityY(-3f);
       }
            startMsg = false;
        }


I think I don't have to explain it, as it should already be done in the comments.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline masteryoom

JGO Coder


Medals: 5
Projects: 2


If you look closely, you might see it turning...


« Reply #2 - Posted 2012-11-11 09:26:46 »

I think you should either put in AI or make it clearer that it is two player.  Cheesy

Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ado

Senior Newbie





« Reply #3 - Posted 2012-11-11 09:58:44 »

@master oops. I forgot to mention that. Just made the actual main pong class today and that's right off the end of bucky's tutorials, so I don't know enough to implement Ai and I don't want the 2nd paddle to just follow the ball exactly. Might as well not even have it Tongue

@matheus I made the mainPong class today and used the other classes from bucky's tutorials, with some modification(which is where that sync in draw comes from, wasn't sure if I should keep or discard it. From what I understand it has to do with letting a particular thread do its thing before allowing others to run(?)).
I have started reading killer game programming in java and used neither its nor bucky's loops, instead using the variable timestep loop from the game loops post in the articles section of this forum.
Thanks for that random function. I think I will use that as I didn't know it could randomize booleans.
Offline ado

Senior Newbie





« Reply #4 - Posted 2012-11-12 09:49:51 »

Just an update.
I have been working today to add the option to switch between full screen and windowed mode. I think I am almost there as I can successfully switch between the two(via windowedMode boolean in ScreenManager, not ingame yet though I will bind setWindowedMode() to F3 or something later) but I am having issues with updating the canvas. I am not sure if this is an issue with my buffer strategy but I think I have narrowed it down to somewhere in getGraphics() or the ScreenManager update() method.
I have a feeling that Canvas buffering doesn't work the same way as Window buffering but maybe I'm wrong, I don't know a whole lot about Canvas or even Window at this point.
If someone would be so kind as to have a look at my code and help me out it would be much appreciated.
The new link is in the OP.
Offline ado

Senior Newbie





« Reply #5 - Posted 2012-11-13 09:56:10 »

@master: not sure if you are being serious or not but just to clarify I was saying 'oops' as in 'oh no I made a mistake'.

On another note, I have fixed switching between windowed and fullscreen. Embasassing mistake where I didn't rename some constructors in the draw method. It was still trying to get the fullscreen window height/width and not the canvas  Roll Eyes
Will upload the new source later.
Offline masteryoom

JGO Coder


Medals: 5
Projects: 2


If you look closely, you might see it turning...


« Reply #6 - Posted 2012-11-13 10:15:01 »

I'm going to compile your code *compiling code*. It appears you don't need the
1  
2  
import java.awt.Graphics;
import java.awt.Graphics2D;

inports. Your ball dropping at the start wasn't even random. I could place my paddle in exactly the same place, and the paddle would hit it. You should include a random class between maybe 1 and 36 (for 360 degrees).

Smiley
Offline ado

Senior Newbie





« Reply #7 - Posted 2012-11-13 13:17:59 »

I hadn't uploaded the new source at that time. new source is up for windowed mode. I have implemented matheus's random code but thats about as much work I'm going to do on the randomness of the ball.
The last thing I'm doing with this before I move onto a new project is to bind the window switching to the F3 key which has been giving me troubles. I'm having trouble cleanly killing the windowed canvas and launching fullscreen during the game. I'm trying to do this by just toggling the windowedMode boolean but I have a feeling it's either not switching fast enough, which doesn't sound likely, or there's something else happening but I'm just too tired and aren't picking up on it.
Offline ReBirth
« Reply #8 - Posted 2012-11-13 13:23:42 »

Shouldn't it be posted on WIP section?

Offline ado

Senior Newbie





« Reply #9 - Posted 2012-11-13 13:35:10 »

Possibly but as I have just finished working through learning the basics of java and some other tutorials I was more after advice on code structure, anything that could be done better or more efficently, getting help problem solving etc etc. Newbie stuff.
I have no plans for this beyond adding in the ability to toggle between window modes and thought some other newbies might like to check out the code. I have been collecting any other java game source code other people have put out to learn from and either couldn't find much in the way of basic(pong, mario, tetris, pacman) beginner level game source available or had to do alot of digging to find it.
   
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

SHC (24 views)
2014-11-25 12:00:59

SHC (22 views)
2014-11-25 11:53:45

Norakomi (19 views)
2014-11-25 11:26:43

Gibbo3771 (22 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (41 views)
2014-11-12 21:09:33

kovacsa (67 views)
2014-11-07 19:57:14
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!