Pong Help
Author |
Message |
upthescale
|
Posted: Sat Mar 18, 2006 11:20 pm Post subject: Pong Help |
|
|
ok i can make a ball move easily
code: |
var x,y:int
x:=200
y:=100
loop
drawfilloval(x,y,20,20,7)
delay(20)
drawfilloval(x,y,20,20,0)
x:=x+2
end loop
|
what ever..he ball movs but when i do a square, it just extends and gets bigger...how do i make it so the whole square moves and not just get bigger? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
[Gandalf]

|
Posted: Sat Mar 18, 2006 11:43 pm Post subject: (No subject) |
|
|
Use cls to clear the screen every time it is executed.
So here's your current code improved using cls:
code: | var x, y : int
x := 200
y := 100
loop
cls
drawfilloval (x, y, 20, 20, 7)
x += 2 %this is the same as x := x + 2
delay (20)
end loop |
Now, I believe the problem with your box code is that you are mixing up the parameters. They are:
Quote: drawfillbox (x1, y1, x2, y2, Color : int)
As on a Cartesian plane.
Also, indent your code properly in the future. |
|
|
|
|
 |
upthescale
|
Posted: Sun Mar 19, 2006 12:17 am Post subject: (No subject) |
|
|
ok i got the saqure to move fine down the screen, i wana do it so if the mouse touchs any pixel of the square, the game wil say you lose, shud i use mousewhere? and how cuz the squae is moving |
|
|
|
|
 |
Flikerator
|
Posted: Sun Mar 19, 2006 12:37 am Post subject: (No subject) |
|
|
Use Mouse.Where, and look up whatdotcolor in the help file.
exit when whatdotcolor (Mx,My) = boxcolor
or
exit when Mx > ### and Mx < ### and My...
Mx and My are the mouse coordinates.
After the loop have the "You've been pwned" |
|
|
|
|
 |
Cervantes

|
Posted: Sun Mar 19, 2006 9:27 am Post subject: (No subject) |
|
|
Let's avoid whatdotcolour, shall we? It's a bad approach to collision detection, especially for newbies.
Go with the second approach:
Turing: |
% let mx = mouse x
% let my = my
% let blockx = x value for left side of block
% let blockwidth = width of block
% let blocky = y value for bottom of block
% let blockheight = height of block
if mx >= blockx & mx <= blockx + blockwidth & my >= blocky & my <= blocky + blockheight then
% collision!
end if
|
|
|
|
|
|
 |
MysticVegeta

|
Posted: Sun Mar 19, 2006 10:47 am Post subject: (No subject) |
|
|
If you have Turing >= 4.05 then, this can be achieved more simply by
code: | Math.Distance(x1, y1, x2, y2) | which is the same thing as the distance formula in the cartesian plane:
code: | distance = sqrt ( (y2-y1)^2 + (x2-x1)^2 ) |
All you need to do is check if the distance is < what ever you want it to be less than  |
|
|
|
|
 |
[Gandalf]

|
Posted: Sun Mar 19, 2006 6:06 pm Post subject: (No subject) |
|
|
Ehm... Why use Math.Distance to check collision on a box? It's just adding extra complications. |
|
|
|
|
 |
|
|