Computer Science Canada Pong ball |
Author: | Salman [ Fri Jan 11, 2013 2:11 pm ] | ||
Post subject: | Pong ball | ||
What is it you are trying to achieve? <Replace all the <> with your answers/code and remove the <>> Make the ball hit the paddles. What is the problem you are having? <Answer Here> Describe what you have tried to solve this problem <Answer Here> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using <Answer Here> 4.1 |
Author: | Insectoid [ Fri Jan 11, 2013 2:18 pm ] |
Post subject: | RE:Pong ball |
Look at any one of the dozens of collision detection tutorials available in the Turing Tutorials section. The Turing Walkthrough is a great place to start. |
Author: | Salman [ Mon Jan 14, 2013 12:52 pm ] |
Post subject: | RE:Pong ball |
I tried this, still doesn't work import GUI var x2, y2, xChange, yChange : int := 1 const radius : int := 10 var font : int var option : string var movement1 : int := 0 var movement2 : int := 0 var keys : array char of boolean var x := 175 var y := 0 colorback (black) for i : 1 .. 25 %Counted loop makes the background stay black for j : 1 .. 80 put " " .. end for end for setscreen ("nocursor,offscreenonly") font := Font.New ("Arial Black:18") Font.Draw ("Pong", 280, 320, font, red) put whatdotcolor (x, y) procedure startGame cls Draw.FillBox (0, 600, maxx, 360, brightred) Draw.FillBox (0, 00, maxx, 45, brightred) Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred) Draw.FillBox (630, x + movement2, maxx, 225 + movement2, brightred) Input.KeyDown (keys) if keys ('w') then Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred) if movement1 <= 360 - 175 - 50 then movement1 := movement1 + 2 end if end if if keys ('s') then Draw.FillBox (0, 175 + movement1, 10, 225 + movement1, brightred) if movement1 >= 45 - 175 then movement1 := movement1 - 2 end if end if if keys (KEY_UP_ARROW) then Draw.FillBox (630, 175 + movement2, maxx, 225 + movement2, brightred) if movement2 <= 360 - 175 - 50 then movement2 := movement2 + 2 end if end if if keys (KEY_DOWN_ARROW) then Draw.FillBox (630, 175 + movement2, maxx, 225 + movement2, brightred) if movement2 >= 45 - 175 then movement2 := movement2 - 2 end if end if x := maxx div 2 y := maxy div 2 loop Draw.FillOval (x2, y2, radius, radius, brightblue) x +=xChange y +=yChange if View.WhatDotColour (x,y+radius)=brightred then yChange*=-1 elsif View.WhatDotColour (x,y-radius)=brightred then yChange *=-1 end if if View.WhatDotColour (x+radius,y)=brightred then xChange*=-1 elsif View.WhatDotColour (x-radius,y)=brightred then xChange*=-1 end if end loop end startGame var startButton : int := GUI.CreateButton (maxx div 2 - 30, 60, 60, "Start Game", startGame) procedure helpGame cls Font.Draw ("Refer to the instruction manual", 100, 320, font, red) end helpGame var helpButtom : int := GUI.CreateButton (maxx div 2 - 200, 60, 60, "Help", helpGame) loop startGame View.Update exit when GUI.ProcessEvent end loop |
Author: | Insectoid [ Mon Jan 14, 2013 1:06 pm ] | ||
Post subject: | RE:Pong ball | ||
Will this loop ever exit? |
Author: | Salman [ Tue Jan 15, 2013 1:29 pm ] |
Post subject: | RE:Pong ball |
it will exit when the ball goes off the screen |
Author: | Tony [ Tue Jan 15, 2013 2:23 pm ] |
Post subject: | RE:Pong ball |
ok, followup question: from what line of the code will that loop "exit when the ball goes off the screen"? |