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

Username:   Password: 
 RegisterRegister   
 How would I simulate the function "degtorad" in tu
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
s_climax




PostPosted: Mon May 03, 2004 3:15 pm   Post subject: How would I simulate the function "degtorad" in tu

How would I go about converting this into Turing?
code:
y+=sin(degtorad(360-dir))*speed
x+=cos(degtorad(360-dir))*speed
[/code]
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon May 03, 2004 3:22 pm   Post subject: (No subject)

Just a quick thought:

by default sin, cos, and tan all return radian values. sind, cosd, and tand return degree values. May be of some help.
Mazer




PostPosted: Mon May 03, 2004 4:58 pm   Post subject: (No subject)

Delos, you meant to say that sin and cos take radian values and sind and cosd take degree values, right?

Anyways, s_climax if you can use trig you should probably already know how to convert from degrees to radians, but if not I believe it was pi / 180 = r / d. Or something... I never use radians (they're for sissies Wink ).
s_climax




PostPosted: Mon May 03, 2004 4:58 pm   Post subject: (No subject)

Thanks. One more question then. Why is it that in my code, when the direction is 180 the character does not move straight up?

code:

var chars : array char of boolean
var x, y, dir, speed, timer : int
speed := 2
dir := 0
x := maxx div 2
y := maxy div 2
timer := 0
loop
    timer += 1

    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        y += round (sin (360 - dir) * speed)
        x += round (cos (360 - dir) * speed)
    end if
    if chars (KEY_DOWN_ARROW) then
        y += round (sin ((360 - dir)) * -speed)
        x += round (cos ((360 - dir)) * -speed)
    end if
    if chars (KEY_LEFT_ARROW) and timer mod 10 = 0 then
        dir += 1
    end if
    if chars (KEY_RIGHT_ARROW) and timer mod 10 = 0 then
        dir -= 1
    end if
    drawfilloval (x, y, 5, 5, 2)
    delay (10)
    cls

    if x > maxx then
        x := 1
    elsif x < 0 then
        x := maxx - 1
    end if

    if y > maxy then
        y := 1
    elsif y < 0 then
        y := maxy - 1
    end if
    put dir
end loop


By the way, the part about the timer being mod 10 is only necessary as a tempory fix. I should not need it. However, without it my character turns too quick. Any help?
zylum




PostPosted: Mon May 03, 2004 7:29 pm   Post subject: (No subject)

i didnt want to alter your code too much but this should help:

code:

var chars : array char of boolean
var ang, speed : int
var x, y, dx, dy : real
ang := 0
speed := 2
x := maxx div 2
y := maxy div 2
loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        speed := 2
    elsif chars (KEY_DOWN_ARROW) then
        speed := -1
    else
        speed := 0
    end if
    if chars (KEY_LEFT_ARROW) then
        ang += 3
    end if
    if chars (KEY_RIGHT_ARROW) then
        ang -= 3
    end if
    dx := cosd (ang) * speed
    dy := sind (ang) * speed
    x += dx
    y += dy
    drawfilloval (round (x), round (y), 5, 5, 2)
    delay (10)
    cls

    if x > maxx then
        x := 1
    elsif x < 0 then
        x := maxx - 1
    end if

    if y > maxy then
        y := 1
    elsif y < 0 then
        y := maxy - 1
    end if
end loop


-zylum
s_climax




PostPosted: Mon May 03, 2004 9:02 pm   Post subject: (No subject)

Thanks.

Judging from the differences, I see two main things I did wrong. First it was cosd and sind instead of just sin and cos. Second I should have rounded at the end to prevent jerkiness. Can you tell me if this is correct?
djlenny_3000




PostPosted: Tue May 04, 2004 1:53 pm   Post subject: (No subject)

hey not bad but i have one coment y not put a triangle or somesort of marker to show the front and make a car driving program cuz what u have so far is very cool
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: