Pong issues

Just started using Construct 2? Post your questions here

Post » Fri Mar 06, 2015 10:07 pm

Hi,

Last night i started to recreate the game pong, after seeing a tutorial series on youtube. All went quite well besides that im trying to figure out what causes the cpu paddle to start moving upwards every time the ball is destroyed. Im guessing that the program thinks the CPU paddle Y value is greater than the balls since that is the only code that moves the cpu paddle up. But how could this be as the ball is destroyed?

Another thing is that i'd like to try to make an exact copy of the original pong, and i noticed that it releases the ball from the middle from that Y value where the ball went to the goal. How would i fix it so id get my pong to do this as well. Also, i now have it set so that it shoots the ball just randomly, how would i make it to shoot at the player who just lost?

capx file as attachment.
You do not have the required permissions to view the files attached to this post.
B
7
S
1
Posts: 93
Reputation: 632

Post » Sat Mar 07, 2015 7:10 am

As for why your paddle is traveling up, yes the program thinks the Y position of the ball is higher than the paddle. If there is no ball to get a position from, the value is always 0. You could solve this by adding a condition to the motion of the paddle that checks to see if at ball is in the layout. If one isn't, don't move the paddle.

To get the ball to spawn at the same Y position where it left the board, just add a global variable and store the Y position when the ball is destroyed. Then use this value as the Y position when the ball is spawned.
B
38
S
12
G
11
Posts: 329
Reputation: 7,708

Post » Sun Mar 08, 2015 3:42 pm

Big thanks FargFAther, got it to work just great.Paddle stops and resets in the middle after a match, and I didn't even need to use global variables as i got the ball to spawn where i want it to by ordering the spawn point to move its Y position to the same as the ball where it got destroyed. Simple.
However i dont really get it how can the spawnpoint know the correct Y position if the ball is allready destroyed? kinda strange even if it works. Any insight to this?

Pretty much the last dilemma i have with this is how can i set it so that it randomly shoots the ball on both directions in start of the game. I have it set on random (180) degrees, but this has a few flaws, the bigger being that if the ball launches from 90 degrees, it will just keep bouncing between the ceiling, another would be that it only launces downwards when it would be better if it could launch also upwards. So i basically need a contained random launch for both directions somehow like "on start of layout-> ball> set bullet rotation random (-60,60 or 120,240). How would i do this correctly? Also the ball sometimes bounces at a very steep angle so it hakea forever to reach the other player, OR actually start to turn backwards Like a boomerang, very odd. Would be happy if someone coule enlighten me a bit with these.
You do not have the required permissions to view the files attached to this post.
B
7
S
1
Posts: 93
Reputation: 632

Post » Tue Mar 10, 2015 3:40 pm

Bump in the hope for an answer.
B
7
S
1
Posts: 93
Reputation: 632

Post » Tue Mar 10, 2015 6:24 pm

Hi ya,

Please see provided attachment.
You do not have the required permissions to view the files attached to this post.
B
34
S
16
G
16
Posts: 141
Reputation: 10,644

Post » Tue Mar 10, 2015 6:42 pm

Hi. What you can do is that when the ball contacts with the object in the wall, the system creates a new instance of the ball and then sets the direction in a random number between 0 and 180 (if you set it that appears in the upper centre).
B
4
Posts: 5
Reputation: 210

Post » Wed Mar 11, 2015 6:02 pm

bernivic135 wrote:Hi. What you can do is that when the ball contacts with the object in the wall, the system creates a new instance of the ball and then sets the direction in a random number between 0 and 180 (if you set it that appears in the upper centre).


You dont even need a new instance. Just set the ball to stop, move to the center, turn in the new direction, and then start moving again.

If I were making a pong clone my solution to do it in as few events as possable would be to simply use the math expressions

A = Current angle the ball is moving Ball.angle
B = random(-60,60) <-this is absolute and not depended on the balls current angle ie 0deg is pointing right. depending on the min/max angel you want your ball to move

When the game starts or the Ball hits a paddle simply enter the new angle of movement as
(90+(90(Ball.angle-(Ball.angle+1))+random(-60,60)

there are four quadrants that a angel falls into, this equation will tell the ball to turn ether true left or right 0deg vs 180deg depending on which direction it was moving to begin with. Then pick a new angel between what range you wish the ball to move.

For hitting the wall just make change it to Ball.angle(Ball.angel-(Ball.angel+1)) which will bounce the ball in the same angle but reversed in positive or negative. A ball hitting the bottom wall at -30deg will then move at +30deg

There is probably a less mathy way tough events but I love my one step events.

And for starting a new round just have a boolen var for "YouScore"=True. If the ball scores a point for you leave it true and if true start the ball moveing to the right. And if the Ai scores turn it False and move it left. +/- any random angle, just instead of the expreshion Ball.angle just use 180 to move it to you or 0 to move it to the Ai. In just 3 or 4 events

Vulcan
#TrigLife

ps you need two events for when the ball hits a wall and for when it hits a paddle
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
6
S
2
Posts: 113
Reputation: 1,220

Post » Wed Mar 11, 2015 10:32 pm

Thanks for the replys! wonderful ideas. Got it to work just fine :)
B
7
S
1
Posts: 93
Reputation: 632


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest