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

Username:   Password: 
 RegisterRegister   
 Math.Distance/Moving on an Arc Problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
StarGateSG-1




PostPosted: Mon May 30, 2005 1:40 pm   Post subject: Math.Distance/Moving on an Arc Problem

This require a diagram: see attachment!

A: That is how the line moves along right now.

B: Is how I want to to move, That trouble is I am not sure how, and it has boggled my brain for like 3 days now.

Here is the whole code
code:

% Sets the Screen
View.Set ("graphics:640;480,nobuttonbar,offscreenonly")
% Declaration of Variables,
var x, y, xRadius, yRadius, initialAngle, finalAngle : int := 0 % Values for Trajectory
var xAngle, yAngle : int := 0 % Line values
var windspeed, Power : int := 0 % Windspeed and power Values
var MoveArrow : array char of boolean % Value for when a key has been pressed
var Adjust : int
% Declaration of Procedures,
forward procedure Main
forward procedure Trajectory
forward procedure MoveTurret
% Variable Values,
xAngle := maxx - 20
yAngle := 20
% This is the arc distance that needs to be maintain while the
% Line moves up and down,
var Distance : int := Math.Distance (maxx, 0, yAngle,xAngle)
% This is the main procedure which controls the whole program,
% Main Program,
body procedure Main
    % Main loop
    loop
        % Slows the program down so you have more control over were you palce the turret
        delay (50)
        % Gets Movemnet from turret
        MoveTurret
        View.Update
        cls
    end loop
end Main

body procedure Trajectory
    % Draws the trajectory line
    drawarc (x, y, xRadius, yRadius, initialAngle, finalAngle, black)
end Trajectory

body procedure MoveTurret
    % Draws the Turret
   
    drawfilloval (maxx, 0, 20, 20, 7)
    drawline (maxx, 0, xAngle, yAngle, black)
    % Checks if Up,Down or Enter was pressed
    Input.KeyDown (MoveArrow)
    % What happens when Up key is pressed
    if MoveArrow (KEY_UP_ARROW) then
        % If the line is at a 90 then stop it
        if xAngle >= 0 and yAngle >= 40 then
            xAngle := xAngle
            yAngle := yAngle
            % Otherwise continue
        else
            xAngle := xAngle + +1
            yAngle := yAngle - -1
            % This is for making the line move along a arc pattern
            if Math.Distance (maxx, 0, xAngle, yAngle) >= Distance then
                Adjust := Math.Distance (maxx, 0, xAngle, yAngle) - Distance
                yAngle := yAngle - Adjust
            else

            end if
        end if
        % What happens when Down key is pressed
    elsif MoveArrow (KEY_DOWN_ARROW) then
        % If line is at 180 then stop it
        if xAngle <= maxx and yAngle <= 0 then
            xAngle := xAngle
            yAngle := yAngle
            % Otherwise continue

        else
            xAngle := xAngle + -1
            yAngle := yAngle - +1
            % This is for making the line move along a arc pattern
            if Math.Distance (maxx, 0, xAngle, yAngle) >= Distance then

            else

            end if
        end if
        % What happens if Enter key is pressed
    elsif MoveArrow (KEY_ENTER) then
        Trajectory
    end if
end MoveTurret
Main


I could really use some help with this any ideas welcome.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Mon May 30, 2005 4:30 pm   Post subject: (No subject)

You should fix the errors in your code before you post it.

To do this, you need some simple trig, my friend.


Here you go. Study hard. Wink
Turing:

View.Set ("offscreenonly")
var timeLast := Time.Elapsed

var barrel :
    record
        angle : real
        rotationSpeed : real
        length_ : real
        endX, endY : real
        power : real
    end record

barrel.angle := 45
barrel.rotationSpeed := 0.2
barrel.length_ := 40
barrel.endX := cosd (barrel.angle) * barrel.length_
barrel.endY := sind (barrel.angle) * barrel.length_
barrel.power := 2

var proj : flexible array 1 .. 0 of
    record
        x, y, vx, vy : real
    end record

const gravity := 0.015

var keys : array char of boolean


function cooldown (timeDelay : int) : boolean
    if Time.Elapsed - timeLast >= timeDelay then
        timeLast := Time.Elapsed
        result true
    end if
    result false
end cooldown

loop
    Input.KeyDown (keys)
    if keys (KEY_UP_ARROW) then
        barrel.angle += barrel.rotationSpeed
        barrel.endX := cosd (barrel.angle) * barrel.length_
        barrel.endY := sind (barrel.angle) * barrel.length_
    end if
    if keys (KEY_DOWN_ARROW) then
        barrel.angle -= barrel.rotationSpeed
        barrel.endX := cosd (barrel.angle) * barrel.length_
        barrel.endY := sind (barrel.angle) * barrel.length_
    end if
    if keys (KEY_ENTER) then
        if cooldown (200) then
            new proj, upper (proj) + 1
            proj (upper (proj)).x := barrel.endX
            proj (upper (proj)).y := barrel.endY
            proj (upper (proj)).vx := cosd (barrel.angle) * barrel.power
            proj (upper (proj)).vy := sind (barrel.angle) * barrel.power
        end if
    end if

    for i : 1 .. upper (proj)
        proj (i).vy -= gravity
        proj (i).x += proj (i).vx
        proj (i).y += proj (i).vy
    end for

    for i : 1 .. upper (proj)
        if proj (i).x > maxx or proj (i).y < 0 or proj (i).x < 0 then
            proj (i) := proj (upper (proj))
            new proj, upper (proj) - 1
            exit
        end if
    end for

    cls
    Draw.FillOval (0, 0, 30, 30, black)
    Draw.Line (0, 0, round (barrel.endX), round (barrel.endY), black)
    for i : 1 .. upper (proj)
        Draw.FillOval (round (proj (i).x), round (proj (i).y), 4, 4, black)
    end for
    View.Update
    Time.DelaySinceLast (5)
end loop
StarGateSG-1




PostPosted: Mon May 30, 2005 7:33 pm   Post subject: (No subject)

Thank you I will study, its not errors I just forgot to comment.

Edit:

Thank you so much it was right in fornt of me the whole time, I was looking at arc's in the help file, when you search they come up to. I got it working and making mine better by adding more keys and also creating editable factors, gravity and power, you can do kool things with them.
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: