-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathActor.js
65 lines (48 loc) · 1.48 KB
/
Actor.js
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
'use strict';
// Should make Meteor not aware of scoring?
var createSubClass = require('../util/create_subclass')
, collisionService = require('../collisions')
, hudService = require('../hud')
, rules = require('../rules')
, config = require('../config')
, world = config.world
, Container = createjs.Container;
var Actor = module.exports = createSubClass(Container, 'Actor', {
initialize: Actor$initialize,
destroy: Actor$destroy,
isDestroyed: Actor$isDestroyed,
tick: Actor$tick,
collision: Actor$collision
});
function Actor$initialize(x, y) {
if (this.constructor == Actor)
return console.error('This is an abstract class and should be subclassed');
Container.prototype.initialize.apply(this, arguments);
this.x = x;
this.y = y;
this.on('collision', this.collision);
this.on('tick', this.tick);
}
function Actor$destroy() {
if (this.parent) {
rules.events.dispatchEvent({
type: 'destroyed',
data: { self: this }
});
collisionService.removeActor(this);
this.parent.removeChild(this);
this._destroyed = true;
}
}
function Actor$isDestroyed() {
return this._destroyed;
}
function Actor$tick() {
if (this.x > world.width) this.x = 0;
if (this.x < 0) this.x = world.width;
if (this.y > world.height) this.y = 0;
if (this.y < 0) this.y = world.height;
}
function Actor$collision(event) {
// To be implemented in subclass
}