Page 1 of 1

Pong

Posted: Mon Jan 13, 2014 9:34 pm
by jgordon
We are creating a two player pong game. We have gotten both paddles to move up and down, and now we are beginning to program the ball. What type of code should be used to make a shape move at different angles and bounce off paddles?

Re: Pong

Posted: Mon Jan 13, 2014 9:42 pm
by FourthWorld
In the IDE, click the Resources button - there, see the last Tutorial in the list, "Bouncy".

That example does with a stack against your monitor edges what you want to do with a ball within your window, so I suspect at least some of that code may be a good starting point.

Re: Pong

Posted: Tue Jan 14, 2014 1:01 am
by Simon
Here is a complete write up;
http://livecodegamedev.net/Techniques/livecode-pong/

Simon

Re: Pong

Posted: Sun Mar 01, 2020 10:46 am
by kelyanok
hello
im from the future and im trying to make a pong too, but im stuck. im a begginner and i already made a few really simple games, and i tried to make one a little bit more difficult. ive made the render of the pong, and now im trying to use collisions but it doesnt work. here's the code for he button "start"

Code: Select all

on mouseUp
   hide me
   collision
   startAll
end mouseUp

on startAll
   move graphic "ball" to 0,5+random(310) in 50 tick
end startAll

on collision
   if intersect(graphic "ball",graphic "paddle")
   then
      answer "working"
   end if
end collision
the "answer working" is only to test if the collision is working. but its nooooooottttt :(
can someone help me? thanks!

Re: Pong

Posted: Sun Mar 01, 2020 6:54 pm
by jacque
For one thing, the mouseUp handler is checking for the collision before the ball has moved. It would fail unless you've already set the ball position over the paddle before clicking the button.

Re: Pong

Posted: Sun Mar 01, 2020 6:57 pm
by kelyanok
thats true, i changed it. but it still doesnt work... ill try to change all my code and ill post it when i finish it. anyway thank you for your answer

Re: Pong

Posted: Mon Mar 02, 2020 7:09 am
by dunbarx
Hi.

I do not want to go too fast for you, but try this. Make three buttons on a new card. Name one of them "ball" and one of them "paddle". Name the other one "Start" Set the loc of btn "ball" to "100,100". Set the loc of btn "paddle" somewhere to the lower right of btn "ball" In the script of btn "start":

Code: Select all

on mouseUp
   startTheBallMoving
end mouseUp

on startTheBallMoving
   set the loc of btn "ball" to item 1 of the loc of btn "ball" +2 & "," & item 2 of the loc of btn "ball" +2
   if the right of btn "ball" > item 3 of the rect of this cd or the bottom of btn "ball" > item 4 of the rect of this cd then
      set the loc of btn "ball" to "100,100"
         answer "A Miss"
      exit to top
   end if
   if intersect(btn "ball",btn"paddle") then
      set the loc of btn "ball" to "100,100"
      answer "A hit!"
      exit to top
   end if
   
   send "startTheBallMoving" to me in 1
end startTheBallMoving
Click btn "start". Btn "ball will move until it either hits btn "paddle" or the edge of the card. This should give you some ideas on the sequence of events that you must keep in mind. It also uses an entirely different method than the "move" command, and you will need to do that in order to test the state of your game on the fly. The "move" command does not easily allow for that, since it is generally used for animation, and you need more control over your environment.

Craig