This wiki is out of date, use the continuation of this wiki instead

Get angle

From FenixWiki

Revision as of 11:02, 11 July 2007 by Sandman (Talk | contribs)
Jump to: navigation, search


Contents

Definition

INT get_angle ( <INT processID> )

Returns the angle between the coordinates of a certain process and the process calling get_angle().

Parameters

INT processID - The other process.

Returns

INT : The wanted angle.

-1 - An error may have occurred.
 !-1 - The wanted angle.

Example

Program angling;
Const
    screen_width = 320;
    screen_height = 200;
    screen_depth = 8;
Begin

    // Set the screen mode
    set_mode(screen_width,screen_height,screen_depth);

    // Create mouse graph and start moisepointer
    x = new_map(20,20,screen_depth);
    map_clear(0,x,rgb(255,0,0));
    mousepointer(0,x);

    // Create arrow, assign to graph
    graph = new_map(30,30,screen_depth);
    drawing_map(0,graph);
    drawing_color(rgb(0,255,0));
    draw_line( 0,29,29,30/2);
    draw_line( 0, 0,30,30/2);

    // Set position
    x = screen_width /2;
    y = screen_height/2;

    // Always point to the mouse
    Repeat
        // Get the angle between this process' coordinates and those of mousegraph. We can use TYPE
        // and get_id() here, because usually there would only be one mousepointer and one always.
        angle = get_angle(get_id(type mousepointer));
        frame;
    Until(key(_esc))

End

/**
 * Follows the mouse coordinates. x is always mouse.x and y is always mouse.y
 * for processes with priority <1. The graphic of this process will be a certain graphic.
 * int file     - The fileID of the file where the graphic is located
 * int graph    - The graphID of the graphic to be used for this process
 */
Process mousepointer(int file,int graph)
Begin
    // Set the priority to 1, because we first want to have the correct coordinates of
    // the mouse set in this process. Then after that other process can use those coordinates.
    priority = 1;
    Loop
        x = mouse.x;
        y = mouse.y;
        frame;
    End
End

Used in example: set_mode(), new_map(), map_clear(), drawing_map(), drawing_color(), draw_line(), mouse, graph, x, y, angle, priority

This example could also be done with fget_angle(), which is easier and doesn't require an extra process.

Personal tools