File: directional_movement.md

package info (click to toggle)
surgescript 0.5.4.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,876 kB
  • sloc: ansic: 13,674; makefile: 16
file content (69 lines) | stat: -rw-r--r-- 1,715 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Directional Movement
====================

The Directional Movement [behavior](/engine/behavior) makes the associated [entity](/engine/entity) perform a directional movement on the 2D plane. It features:

* A direction [vector](/engine/vector2) that specifies the direction of the movement
* A movement speed, a scalar value given in pixels per second

You may control the direction of the movement using the [direction vector](#direction) or an [angle](#angle) given in degrees. Additionally, you may control the [speed](#speed) of the movement simply by changing its value.

Directional Movement is very versatile. You can use it to implement many things: different types of baddies, flying objects, racing cars viewed from a top-down view, simple projectiles, and much more.

*Example*

```
//
// The example below shows how to make an entity move to the
// right of the screen at a rate of 60 pixels per second
//
using SurgeEngine.Actor;
using SurgeEngine.Vector2;
using SurgeEngine.Behaviors.DirectionalMovement;

object "Simple Ball" is "entity"
{
    actor = Actor("Simple Ball");
    movement = DirectionalMovement();

    state "main"
    {
        movement.direction = Vector2.right;
        movement.speed = 60;
    }
}
```

Factory
-------

#### Behaviors.DirectionalMovement

`DirectionalMovement()`

Spawns a DirectionalMovement.

*Returns*

A DirectionalMovement object.

Properties
----------

#### speed

`speed`: number.

The speed of the movement, in pixels per second.

#### direction

`direction`: [Vector2](/engine/vector2) object.

The direction of the movement.

#### angle

`angle`: number.

The counterclockwise angle of the direction vector, in degrees. 0 means right, 90 means up, etc.