This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
baseClass.js
58 lines (51 loc) · 1.49 KB
/
baseClass.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
'use strict';
/* this is the base definition of an object for our game */
var Base = module.exports = function () {
var that = this;
// the bounds will be managed by the server
// we will need to send and receive changes to the player's location
this.bounds = {
// these values tell us where the object is located
x: 0,
y: 0,
// these tell us how big the object is
// these probably won't change much during the game
width: 0,
height: 0
};
// render is local data that we need to put the player on the map
this.render = {
// these are the offsets from the bounding box
// they are static and probably based on the images
offsets: {
x: 0,
y: 0,
width: 0,
height: 0
},
// these values need to be re computed when the bounds change
x: 0,
y: 0,
height: 0,
width: 0
};
// TODO is there a better base sprite?
this.sprite = {
sheet: undefined,
action: undefined,
dir: undefined,
frame: 0,
max_frame: 0,
nextFrame: function() {
that.sprite.frame++;
if(that.sprite.frame > that.sprite.max_frame)
that.sprite.frame = 0;
}
};
};
Base.prototype.update = function () {
this.render.x = this.bounds.x + this.render.offsets.x;
this.render.y = this.bounds.y + this.render.offsets.y;
this.render.width = this.bounds.width + this.render.offsets.width;
this.render.height = this.bounds.height + this.render.offsets.height;
};