-
Notifications
You must be signed in to change notification settings - Fork 94
/
tiles.js
164 lines (116 loc) · 5.22 KB
/
tiles.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
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
(function() {
/**
*
* Backbone Game Engine - An elementary HTML5 canvas game engine using Backbone.
*
* Copyright (c) 2014 Martin Drapeau
* https://github.com/martindrapeau/backbone-game-engine
*
*/
Backbone.Tile = Backbone.Sprite.extend({
defaults: {
type: "tile",
width: 32,
height: 32,
spriteSheet: "tiles",
state: "idle",
static: true,
persist: true
},
initialize: function(attributes, options) {
options || (options = {});
this.world = options.world;
this.lastSequenceChangeTime = 0;
}
});
function extendSprite(cls, name, attributes, animations) {
var newCls = _.classify(name);
Backbone[newCls] = Backbone[cls].extend({
defaults: _.extend(
_.deepClone(Backbone[cls].prototype.defaults),
{name: name},
attributes || {}
),
animations: _.extend(
_.deepClone(Backbone[cls].prototype.animations),
animations || {}
)
});
return Backbone[newCls];
}
extendSprite("Tile", "land1", {collision: true}, {idle: {sequences: [353]}});
extendSprite("Tile", "land2", {collision: true}, {idle: {sequences: [354]}});
extendSprite("Tile", "land3", {collision: true}, {idle: {sequences: [355]}});
extendSprite("Tile", "land4", {collision: true}, {idle: {sequences: [237]}});
extendSprite("Tile", "land5", {collision: true}, {idle: {sequences: [238]}});
extendSprite("Tile", "land6", {collision: true}, {idle: {sequences: [239]}});
extendSprite("Tile", "land7", {collision: true}, {idle: {sequences: [208]}});
extendSprite("Tile", "land8", {collision: true}, {idle: {sequences: [34]}});
extendSprite("Tile", "mush1", {collision: true}, {idle: {sequences: [382]}});
extendSprite("Tile", "mush2", {collision: true}, {idle: {sequences: [383]}});
extendSprite("Tile", "mush3", {collision: true}, {idle: {sequences: [384]}});
extendSprite("Tile", "mush4", {collision: true}, {idle: {sequences: [266]}});
extendSprite("Tile", "mush5", {collision: true}, {idle: {sequences: [267]}});
extendSprite("Tile", "mush6", {collision: true}, {idle: {sequences: [268]}});
extendSprite("Tile", "ground", {collision: true}, {idle: {sequences: [0]}});
extendSprite("Tile", "ground2", {collision: true}, {idle: {sequences: [31]}});
extendSprite("Tile", "block", {collision: true}, {idle: {sequences: [3]}});
extendSprite("Tile", "block2", {collision: true}, {idle: {sequences: [29]}});
extendSprite("Tile", "cloud-small", {collision: true}, {idle: {sequences: [613]}});
extendSprite("Tile", "water1", {collision: false}, {idle: {sequences: [583]}});
extendSprite("Tile", "water2", {collision: false}, {idle: {sequences: [612]}});
extendSprite("Tile", "cloud1", {collision: false}, {idle: {sequences: [580]}});
extendSprite("Tile", "cloud2", {collision: false}, {idle: {sequences: [581]}});
extendSprite("Tile", "cloud3", {collision: false}, {idle: {sequences: [582]}});
extendSprite("Tile", "cloud-happy1", {collision: false}, {idle: {sequences: [585]}});
extendSprite("Tile", "cloud-happy2", {collision: false}, {idle: {sequences: [586]}});
extendSprite("Tile", "cloud-happy3", {collision: false}, {idle: {sequences: [587]}});
extendSprite("Tile", "cloud4", {collision: false}, {idle: {sequences: [609]}});
extendSprite("Tile", "cloud5", {collision: false}, {idle: {sequences: [610]}});
extendSprite("Tile", "cloud6", {collision: false}, {idle: {sequences: [611]}});
extendSprite("Tile", "cloud-happy4", {collision: false}, {idle: {sequences: [614]}});
extendSprite("Tile", "cloud-happy5", {collision: false}, {idle: {sequences: [615]}});
extendSprite("Tile", "cloud-happy6", {collision: false}, {idle: {sequences: [616]}});
extendSprite("Tile", "cloud-platform1", {collision: true}, {idle: {sequences: [588]}});
extendSprite("Tile", "cloud-platform2", {collision: true}, {idle: {sequences: [589]}});
extendSprite("Tile", "cloud-platform3", {collision: true}, {idle: {sequences: [590]}});
extendSprite("Tile", "cloud-platform4", {collision: true}, {idle: {sequences: [704]}});
extendSprite("Tile", "cloud-platform5", {collision: true}, {idle: {sequences: [705]}});
extendSprite("Tile", "cloud-platform6", {collision: true}, {idle: {sequences: [706]}});
Backbone.Platform = Backbone.Character.extend({
defaults: {
type: "character",
name: "platform",
width: 96,
height: 32,
spriteSheet: "tiles",
tileX: 256,
tileY: 640,
state: "idle",
static: false,
collision: true
},
initialize: function(attributes, options) {
options || (options = {});
this.world = options.world;
},
update: function(dt) {
return true;
},
draw: function(context, options) {
options || (options = {});
var x = this.get("x") + (options.offsetX || 0),
y = this.get("y") + (options.offsetY || 0),
tileX = this.get("tileX"),
tileY = this.get("tileY"),
tileWidth = this.get("width"),
tileHeight = this.get("height");
context.drawImage(
this.spriteSheet.img,
tileX, tileY, tileWidth, tileHeight,
Math.round(x), Math.round(y), tileWidth, tileHeight
);
return this;
}
});
}).call(this);