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

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




PostPosted: Wed May 24, 2006 6:34 pm   Post subject: Moving Ball

I would like to move a ball with te up and down key, while with the arrow keys, the line inside the ball will rotate 360 degrees, im sure u have seen this b4, and im sure u no wut i meen, if not here is the
code:
code:

setscreen ("offscreenonly;graphics:700;600;nobuttonbar;position:truemiddle;center")
var x, y : int := 200
var aimx, aimy : int := 200
var chars : array char of boolean
aimx mod= 360
loop
    colorback (7)
    Input.KeyDown (chars)
    cls
    drawfilloval (x, y, 20, 20, red)
    Draw.ThickLine (aimx, aimy, aimx, round (aimy) + 35, 4, red)


    if chars (KEY_RIGHT_ARROW) then

        Draw.ThickLine (aimx + round (cosd (x)), aimy - 170 + round (y), aimx, round (aimy) + 35, 4, red)

    end if


    delay (12)
    View.Update
end loop


yopu prolly thinkng...wow that is off, yes it is because i dont really know wut to do, i would like it so wheni hit the left arrow key, or right, the line in the ball will spine.. lol so anyhelp wud be great thanks!
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Wed May 24, 2006 7:20 pm   Post subject: (No subject)

Again, you'll need to know trigonometry.

code:

    if chars (KEY_RIGHT_ARROW) then

        Draw.ThickLine (aimx + round (cosd (x)), aimy - 170 + round (y), aimx, round (aimy) + 35, 4, red)

    end if

This makes no sense. Why would you draw a line between these two points when you press the right arrow key? I think what you want to do is decriment the angle.

To draw your line:
code:

Draw.Line (round (ball.x), round (ball.y), round (ball.x + cosd (ball.angle) * line_length, round (ball.y + sind (ball.angle) * line_length), black)


You should be able to get it working with that. Please, give it a reasonable try.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: