-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforce.js
More file actions
142 lines (122 loc) · 2.99 KB
/
Copy pathforce.js
File metadata and controls
142 lines (122 loc) · 2.99 KB
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
/*
* GDevelop JS Platform
* Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
*/
/**
* A Force is used to move objects.
*
* @namespace gdjs
* @class Force
* @constructor
* @param x The initial x component
* @param y The initial y component
* @param clearing The clearing
*/
gdjs.Force = function(x,y, clearing)
{
this._x = x || 0;
this._y = y || 0;
this._angle = Math.atan2(y,x)*180/3.14159;
this._length = Math.sqrt(x*x+y*y);
this._dirty = false;
this._clearing = clearing;
}
/**
* Returns the X component of the force.
* @method getX
*/
gdjs.Force.prototype.getX = function() {
return this._x;
}
/**
* Returns the Y component of the force.
* @method getY
*/
gdjs.Force.prototype.getY = function() {
return this._y;
}
/**
* Set the x component of the force.
* @method setX
* @param x {Number} The new X component
*/
gdjs.Force.prototype.setX = function(x) {
this._x = x;
this._dirty = true;
}
/**
* Set the y component of the force.
* @method setY
* @param y {Number} The new Y component
*/
gdjs.Force.prototype.setY = function(y) {
this._y = y;
this._dirty = true;
}
/**
* Set the angle of the force.
* @method setAngle
* @param angle {Number} The new angle
*/
gdjs.Force.prototype.setAngle = function(angle) {
if ( this._dirty ) {
this._length = Math.sqrt(this._x*this._x+this._y*this._y);
this._dirty = false;
}
this._angle = angle;
this._x = Math.cos(angle/180*3.14159)*this._length;
this._y = Math.sin(angle/180*3.14159)*this._length;
}
/**
* Set the length of the force.
* @method setLength
* @param len {Number} The length
*/
gdjs.Force.prototype.setLength = function(len) {
if ( this._dirty ) {
this._angle = Math.atan2(this._y, this._x)*180/3.14159;
this._dirty = false;
}
this._length = len;
this._x = Math.cos(this._angle/180*3.14159)*this._length;
this._y = Math.sin(this._angle/180*3.14159)*this._length;
}
/**
* Get the angle of the force
* @method getAngle
*/
gdjs.Force.prototype.getAngle = function() {
if ( this._dirty ) {
this._angle = Math.atan2(this._y, this._x)*180/3.14159;
this._length = Math.sqrt(this._x*this._x+this._y*this._y);
this._dirty = false;
}
return this._angle;
}
/**
* Get the length of the force
* @method getLength
*/
gdjs.Force.prototype.getLength = function() {
if ( this._dirty ) {
this._angle = Math.atan2(this._y, this._x)*180/3.14159;
this._length = Math.sqrt(this._x*this._x+this._y*this._y);
this._dirty = false;
}
return this._length;
};
/**
* Return true if the force is temporary, false if it is permanent.
* @method getClearing
*/
gdjs.Force.prototype.getClearing = function() {
return this._clearing;
};
/**
* Set if the force clearing.
* @method setClearing
*/
gdjs.Force.prototype.setClearing = function(clearing) {
this._clearing = clearing;
};