Hello and thanks in advance!!
I am racking my brain ( as small as it is )
I have downloaded peaches example of PONG multi-player example.
In order to make it support 1 player mode
I am attempting to make the paddle follow the ball for paddle 1.
I have tried the enterframe event and doing a transition with a slight delay but, it seems to cause the dragging of paddle 2 to stop moving like the cpu it trying to catch up every now and again.
so my question is this what is the correct way to implement this type or game play in a pong type example?
And can someone - please oh please provide a small code example.
Thanks
Larry
DoubleSlashDesign.com
this is pseudo code. don't know about peaches example...
just a simple solution, but it should work.
1
2
3
4
5
6
7
8
9
10
11
| paddleSpeed = 1
function animation () -- enterFrame method
-- if the ball is above the paddle, move the paddle up
if ball.y < paddleCPU.y then
paddleSpeed = -1
else -- or else move it down
paddleSpeed = 1
end
paddleCPU.y = paddleCPU.y + paddleSpeed
end |
I had almost that exact same code in an enterFrame method but the problem is that Paddle 1 is always matching up with the ball, so player 2 would never have a chance to with against player 1.
So thats why I added a transition.to with a delay, capturing the handle of the transition, checking it to make sure I am not doing a bunch of them before the last one completed etc...
Any ideas on how to slow the ball down a little bit to give the other player a chance to win against the computer?
Maybe in your code above I should use try setting the paddle speed to 0.5 instead of 1.
so
paddleSpeed = 0.5
and
paddleSpeed = -0.5
Thoughts?
Larry
Thanks
Larry
exactly, make the paddle y-speed slower than the ball y-speed and the player will have a chance to score :)