-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcercise_1.7_motion101_moverClass.js
More file actions
59 lines (49 loc) · 1.14 KB
/
excercise_1.7_motion101_moverClass.js
File metadata and controls
59 lines (49 loc) · 1.14 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
"use strict";
// Require the max-api module to connect to Max via node.script
const maxAPI = require("max-api");
var Victor = require("victor");
const random = require("random");
var location1 = new Victor(random.float(0, 600), random.float(0, 200));
var velocity1 = new Victor(random.float( -2, 2), random.float(-2, 2));
class Mover {
constructor(location, velocity, width, height)
{
this.location = location;
this.velocity = velocity;
this.width = width;
this.height = height;
}
update()
{
this.location.add(this.velocity);
}
display()
{
maxAPI.outlet("newLocationOutput", this.location.x, this.location.y);
}
checkEdges() {
if (this.location.x > this.width) {
this.location.x = 0;
}
else if (this.location.x < 0) {
this.location.x = this.width;
}
if (this.location.y > this.height) {
this.location.y = 0;
}
else if (this.location.y < 0) {
this.location.y = this.height;
}
}
}
maxAPI.addHandler("motion", (...args) =>
{
var mover = new Mover();
mover.width = 600;
mover.height = 400;
mover.location = location1;
mover.velocity = velocity1;
mover.update();
mover.checkEdges();
mover.display();
});