Turing pong help
Author |
Message |
Metaxu
|
Posted: Sun Dec 30, 2012 1:26 pm Post subject: Turing pong help |
|
|
What is it you are trying to achieve?
Ball to work on hitting the left side paddle and bouncing off. Works on the right side. Also need ball to bounce off of top and bottom. Works on the top but not on the bottom
What is the problem you are having?
Wont bounce
Describe what you have tried to solve this problem
Tried alot, but any help would be much appreciated.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
What i have so far
Turing: |
var x, y, x2, y2, x22, y22, x222, y222, ballx, bally : int
x := 10
y := 270
x2 := 20
y2 := 175
x22 := 620
y22 := 270
x222 := 630
y222 := 175
ballx := maxx div 2
bally := maxy div 2
var rad1, rad2 : int := 6
var DX, DY : int := 4
colourback (black)
var chars : array char of boolean
loop
ballx := ballx + DX %w
bally := bally + DY %z
Input.KeyDown (chars )
if chars ('w') then
y := y + 5
y2 := y2 + 5
end if
if chars ('s') then
y2 := y2 - 5
y := y - 5
end if
if chars (KEY_UP_ARROW) then
y22 := y22 + 5
y222 := y222 + 5
end if
if chars (KEY_DOWN_ARROW) then
y222 := y222 - 5
y22 := y22 - 5
end if
if y > 395 then
y := y - 5
y2 := y - 95
end if
if y2 <= 1 then
y := y2 + 95
y2 := y2 + 5
end if
if y22 > 395 then
y22 := y22 - 5
y222 := y22 - 95
end if
if y222 <= 1 then
y22 := y222 + 95
y222 := y222 + 5
end if
if ballx + 6 >= 10 and ballx - 6 <= 20 and bally >= y - 85 and bally <= y + 85 then
DX := (- 1) * DX
end if
if ballx + 6 >= 620 and ballx - 6 <= 630 and bally >= y - 30 and bally <= y + 30 then
DX := (- 1) * DX
end if
if ballx >= maxx - 6 then
DX := - 3
end if
if bally >= maxy - 6 then
DY := - 3
end if
drawfilloval (ballx, bally, rad1, rad2, white)
drawfillbox (x, y, x2, y2, 0)
delay (10)
cls
drawfilloval (ballx, bally, rad1, rad2, black)
drawfillbox (x22, y22, x222, y222, 0)
end loop
|
Please specify what version of Turing you are using
The good one. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sun Dec 30, 2012 1:56 pm Post subject: RE:Turing pong help |
|
|
code: | var x, y, x2, y2, x22, y22, x222, y222, ballx, bally : int |
This is a problem. I have no idea what any of these variables are supposed to be. Your variable names should describe themselves. All I know is these represent the X and Y coordinates of...things. Without comments, I haven't got a clue. In fact, I didn't read past that line, for exactly this reason. Fix this first, and then maybe I'll give you a hand. |
|
|
|
|
![](images/spacer.gif) |
Panphobia
![](http://compsci.ca/v3/uploads/user_avatars/62033050050c6b61548706.png)
|
Posted: Sun Dec 30, 2012 10:18 pm Post subject: RE:Turing pong help |
|
|
I think those variables are for the paddles |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Mon Dec 31, 2012 12:04 am Post subject: RE:Turing pong help |
|
|
He could probably figure it out, he's trying to teach a lesson in proper variable naming.
Or he's lazy. Either way.
For small projects like this naming your variables incoherent names is annoying, but still usable. However if you work in anything bigger this will not do. Get into the habit of naming your variables something more relevant and/or specific. |
|
|
|
|
![](images/spacer.gif) |
|
|