File: platformer.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 (229 lines) | stat: -rw-r--r-- 4,368 bytes parent folder | download | duplicates (2)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
Platformer
==========

The Platformer [behavior](/engine/behavior) makes the associated [entity](/engine/entity) perform a simple platform movement (with gravity, etc). Used mostly by NPCs and baddies, this behavior is supposed to be lightweight for the CPU and is not designed to support 360°-physics.

**Important:** for best results, the hot spot of the entity should be placed on its feet.

*Example*

```
//
// In the example below, we create a dummy that
// walks around the level (left and right)
//
using SurgeEngine.Actor;
using SurgeEngine.Behaviors.Enemy;
using SurgeEngine.Behaviors.Platformer;

object "My Baddie" is "entity", "enemy"
{
    actor = Actor("My Baddie"); // give it graphics
    enemy = Enemy(); // make it behave like a baddie
    platformer = Platformer(); // give it a platform movement

    state "main"
    {
        platformer.speed = 60; // 60 pixels per second
        platformer.walk(); // make it walk
    }
}
```

Factory
-------

#### Behaviors.Platformer

`Platformer()`

Spawns a Platformer.

*Returns*

The behavior object.

Properties
----------

#### speed

`speed`: number.

Walking speed, in pixels per second.

#### jumpSpeed

`jumpSpeed`: number.

Jump speed, in pixels per second. The higher the value, the more intense the jump.

#### direction

`direction`: number, read-only.

Direction will be +1 if the platformer is facing right or -1 is it's facing left.

#### walking

`walking`: boolean, read-only.

Is the platformer walking?

#### walkingLeft

`walkingLeft`: boolean, read-only.

Is the platformer walking to the left?

#### walkingRight

`walkingRight`: boolean, read-only.

Is the platformer walking to the right?

#### midair

`midair`: boolean, read-only.

Is the platformer midair?

#### falling

`falling`: boolean, read-only.

Is the platformer falling down?

#### leftWall

`leftWall`: boolean, read-only.

Is the platformer touching a wall on its left side?

#### rightWall

`rightWall`: boolean, read-only.

Is the platformer touching a wall on its right side?

#### leftLedge

`leftLedge`: boolean, read-only.

Is the platformer standing on a ledge located on its left side?

#### rightLedge

`rightLedge`: boolean, read-only.

Is the platformer standing on a ledge located on its right side?

Functions
---------

#### walk

`walk()`

Enables automatic walking. The platformer will walk left and right automatically.

*Returns*

Returns the platformer itself.

#### walkLeft

`walkLeft()`

Makes the platformer walk to the left.

*Returns*

Returns the platformer itself.

#### walkRight

`walkRight()`

Makes the platformer walk to the right.

*Returns*

Returns the platformer itself.

#### stop

`stop()`

Makes the platformer stop walking.

*Returns*

Returns the platformer itself.

#### jump

`jump()`

Makes the platformer jump. It will only jump if it's touching the ground.

*Returns*

Returns the platformer itself.

*Example*

```
//
// In the example below, we create a jumping
// dummy that walks left and right
//
using SurgeEngine.Actor;
using SurgeEngine.Behaviors.Enemy;
using SurgeEngine.Behaviors.Platformer;

object "My Jumping Baddie" is "entity", "enemy"
{
    actor = Actor("My Jumping Baddie"); // handles the graphics
    enemy = Enemy(); // make it behave like a baddie
    platformer = Platformer().walk(); // make it walk

    state "main"
    {
        platformer.speed = 60; // 60 pixels per second
        if(timeout(3.0)) // jump every 3 seconds
            state = "jump";
    }

    state "jump"
    {
        platformer.jump();
        state = "main";
    }
}
```

#### forceJump

`forceJump()`

Makes the platformer jump, regardless if it's touching the ground or not.

*Returns*

Returns the platformer itself.

#### setSensorBox

`setSensorBox(width, height)`

The platformer spawns invisible [sensors](/engine/sensor) to detect collisions. Together, these sensors are thought to form a box which size is related to the size of the individual sensors. This function sets the size of this box. That size should be compatible with the size of the sprite and a size too small may break the platformer. The size of the sensor box is computed automatically, so normally you don't need to modify it.

*Arguments*

* `width`: number. The width of the box, in pixels.
* `height`: number. The height of the box, in pixels.

*Returns*

Returns the platformer itself.