Computer Science Canada

Direction by degree

Author:  gigaman [ 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.

Author:  Cervantes [ Mon Nov 01, 2004 3:34 pm ]
Post 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?

Author:  AsianSensation [ Mon Nov 01, 2004 7:54 pm ]
Post 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.


: