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

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




PostPosted: Mon Nov 01, 2004 9:22 am   Post subject: Direction by degree

I want my program to use directional rotation to move the character. the program i'm modifying isn't this one it's the ball game in submitted prgograms. i just need a code example hopefully based on this.


Keyboard controls.t
 Description:

Download
 Filename:  Keyboard controls.t
 Filesize:  828 Bytes
 Downloaded:  106 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Mon Nov 01, 2004 3:34 pm   Post subject: (No subject)

code:

var winID := Window.Open ("graphics:700;700,nobuttonbar,title:Moving Ball,offscreenonly")
var ball :
    record
        x, y : real
        dir : real
        forward_speed, backward_speed : int
        radius : int
    end record

ball.x := 100
ball.y := 100
ball.dir := 90
ball.forward_speed := 3
ball.backward_speed := 2
ball.radius := 6

var keys : array char of boolean

loop

    Input.KeyDown (keys)
    if keys (KEY_RIGHT_ARROW) then
        if ball.dir <= 0 then
            ball.dir += 360
        end if
        ball.dir -= 0.1
    end if
    if keys (KEY_LEFT_ARROW) then
        if ball.dir >= 360 then
            ball.dir -= 360
        end if
        ball.dir += 0.1
    end if
    if keys (KEY_UP_ARROW) then
        ball.x += cos (ball.dir) * ball.forward_speed
        ball.y += sin (ball.dir) * ball.backward_speed
    end if
    if keys (KEY_DOWN_ARROW) then
        ball.x -= cos (ball.dir) * ball.forward_speed
        ball.y -= sin (ball.dir) * ball.backward_speed
    end if

    cls
    drawline (round (ball.x), round (ball.y), round (ball.x) + round ((cos (ball.dir) * (ball.radius * 1.5))), round (ball.y) + round ((sin (ball.dir) * (ball.radius * 1.5))), black)
    drawfilloval (round (ball.x), round (ball.y), ball.radius, ball.radius, 12)
    View.Update
    delay (10)

    exit when keys (KEY_ESC)
end loop
Window.Close (winID)

something like that?
AsianSensation




PostPosted: Mon Nov 01, 2004 7:54 pm   Post subject: (No subject)

shameless plug!

anyways, I wrote a tutorial way back: http://www.compsci.ca/v2/viewtopic.php?t=3542

So you can check that out. I think I explained reasonably OK.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: