ForumsProgramming ForumThe Open Source Coding Challenge #1 - "Pong!" - Discussion

22 7780
IQAndreas
offline
IQAndreas
299 posts
Peasant

For the Glory and Honor, we bring you;
The First Even Open Source Coding Challenge!

This challenge's theme is Pong and is due January 16th, 2009.

THE DISCUSSION
Are you having any problems writing your code? Ask for help here before submitting your final project.

Was there anything you liked or would like to point out about your own or someone else's code?

Who do you think deserves to win so far, and why?

Do not post any of this information in the Submissions thread! Instead, post here. Non developers are more than welcome to join in the discussion.

JUDGING
Players may judge even if they submitted a game, and even if they are not programmers. Please keep an open mind, and to not be too overly obsessed with your own code to accept anyone else's success.

Unless no agreement can be made, there is no official voting. Instead, the winner will be selected based on a general consensus. The real discussion will be done on the 17th and 18th (but feel free to post your opinions before that), and a winner will be selected on the 19th.

OTHER CONCERNS
Also, should we allow developers to submit more than one game, since there are perhaps not very many developers?

Also, can anyone get ahold of some experienced developers who would be willing to join in the challenge?

I will be setting up an official site somewhere where you can view all submitted content from past challenges which you can learn from.

  • 22 Replies
dank
offline
dank
986 posts
Peasant

I can get you somewhere to host if you need it. The best way to get more developers is going to be by publicity. Maybe some nice prizes will boost their willingness.

Qwerty001
offline
Qwerty001
422 posts
Nomad

@dank

Do you think you could pull some strings for a merit for the winner?

Thx!

dank
offline
dank
986 posts
Peasant

Depends on if there are a decent number of submissions.

Awoogamuffin
offline
Awoogamuffin
19 posts
Nomad

Hey everyone!

thought I'd show my progress so far, but this time without the source code, in the interests of healthy competition. Don't worry, come the deadline, all will be revealed!

So now I have the ball bouncing around. Check it out here:

http://awoogamuffinagpc.blogspot.com/

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

I'm having a lot of trouble with hitTest

How are you guys doing so far?

IQAndreas
offline
IQAndreas
299 posts
Peasant

I'm having a lot of trouble with hitTest

Send some sample code, and I can try to help you out with it.
Don't worry, I won't steal your code. I am trying to avoid using hitTest as much as possible.
Awoogamuffin
offline
Awoogamuffin
19 posts
Nomad

You don't want to use hitTest

The problem is that sometimes the ball will be moving faster than the width of your paddles. So on one frame the ball is to the left of the paddle, but on the next frame it is on the right of the paddle. This means no collision is detected.

You need to do a sweep test. That is, you check the position of the ball before and after moving, to see if it went through the paddle during the frame. It can be a bit tricky. In the interests of keeping this fun, shall I put up some code to help with collision detection? Or should I wait until submission time?

Sssssnnaakke
offline
Sssssnnaakke
1,036 posts
Scribe

http://www.howstuffworks.com/question435.htm

I posted this for the people that don't know how to do open sourcing.

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Could anyone provide an example or a link? I found a lot of hitTest == evil on Google, but none giving an alternative for it

Awoogamuffin
offline
Awoogamuffin
19 posts
Nomad

Ok guys, I've got the collision more or less working. it's a bit messy, but at least it works...

I'm using my Vector2D class (you can see it on my blog here) to define the velocity of both the ball and the paddles. This is the function for detecting collision between the ball and a paddle:

public function checkPaddleCollision(paddle:Paddle)
{
var hitHorizontal:Boolean = false;
var hitVertical:Boolean = false;
var fromHorizontal:Boolean = false;
var fromVertical:Boolean = false;
//trace("collision"
//calculate the previous positions of ball and paddle
var paddlePrevX:Number = paddle.x - paddle.velocity.x;
var paddlePrevY:Number = paddle.y - paddle.velocity.y;

var relativeVelocity:Vector2D = new Vector2D();

relativeVelocity.x = x - prevX - paddle.velocity.x;
relativeVelocity.y = y - prevY - paddle.velocity.y;

//SWEEP TESTS:

//check horizontal
if(relativeVelocity.x < 0)
{
//ball coming from right, so check with right hand side of paddle
if(prevX - ballRadius >= paddlePrevX + paddle.paddleWidth && x - ballRadius <= paddle.x + paddle.paddleWidth)
{
hitHorizontal = true;
fromHorizontal = true;
}
}

if(relativeVelocity.x > 0)
{
//ball coming from left, so check with right hand side of paddle
if(prevX + ballRadius <= paddlePrevX && x + ballRadius >= paddle.x)
{
hitHorizontal = true;
fromHorizontal = true;
}
}

//check vertical
if(relativeVelocity.y < 0)
{
//ball coming from below, so check with bottom of paddle
if(prevY - ballRadius >= paddlePrevY + paddle.paddleHeight && y - ballRadius <= paddle.y + paddle.paddleHeight)
{
hitVertical = true;
fromVertical = true;
}
}

if(relativeVelocity.y > 0)
{
//ball coming from above, so check with top of paddle
if(prevY + ballRadius <= paddlePrevY && y + ballRadius >= paddle.y)
{
hitVertical = true;
fromVertical = true;
}
}

//BASIC TESTS:
if(x - ballRadius <= paddle.x + paddle.paddleWidth && x + ballRadius >= paddle.x) hitHorizontal = true;
if(y - ballRadius <= paddle.y + paddle.paddleHeight && y + ballRadius >= paddle.y) hitVertical = true;

if(hitHorizontal && hitVertical) //collision has occurred
{
if (fromHorizontal)
{
relativeVelocity.x < 0 ? x = paddle.x + paddle.paddleWidth + ballRadius : x = paddle.x - ballRadius;
velocity.x *= -1;
if(Math.abs(velocity.x) < Math.abs(paddle.velocity.x)) velocity.x = paddle.velocity.x * 1.4;
else velocity.x += paddle.velocity.x/8;
velocity.y += paddle.velocity.y/((Math.random() + 1) * 3);
}
if (fromVertical)
{
relativeVelocity.y < 0 ? y = paddle.y + paddle.paddleHeight + ballRadius : y = paddle.y - ballRadius;
velocity.y *= -1;
if(Math.abs(velocity.y) < Math.abs(paddle.velocity.y)) velocity.y = paddle.velocity.y * 1.4;
else velocity.y += paddle.velocity.y/8;
velocity.x += paddle.velocity.x/((Math.random() + 1) * 3);
}
}
}

Awoogamuffin
offline
Awoogamuffin
19 posts
Nomad

Sorry, it isn't commented much yet - It will be fully commented soon

I'll be happy to answer any questions or queries you have...

IQAndreas
offline
IQAndreas
299 posts
Peasant

Just thinking, it seems a bit slow this week. How many people will have submissions done by Friday?

Anyone want to extend the competition one more week, perhaps making it a monthly contest instead?

Awoogamuffin
offline
Awoogamuffin
19 posts
Nomad

I think I'll be finished by Friday, but if people want more time that's fine - It would give me time to try to write a computer AI for the game...

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Maybe we should submit with whatever we have, let's just take points out for being incomplete

IQAndreas
offline
IQAndreas
299 posts
Peasant

If Awoogamuffin is the only one that has something done so far, I think one more week might be good.

Are there any others that are planning on submitting anything?

Showing 1-15 of 22