Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Pong Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
upthescale




PostPosted: 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
Sponsor
sponsor
[Gandalf]




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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 Smile
[Gandalf]




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: