forked from robertkleffner/mariohtml5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadingState.js
More file actions
executable file
·144 lines (129 loc) · 5.04 KB
/
Copy pathloadingState.js
File metadata and controls
executable file
·144 lines (129 loc) · 5.04 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
143
144
/**
State that loads all the resources for the game.
Code by Rob Kleffner, 2011
*/
Mario.LoadingState = function() {
this.Images = [];
this.ImagesLoaded = false;
this.ScreenColor = 0;
this.ColorDirection = 1;
this.ImageIndex = 0;
this.SoundIndex = 0;
};
Mario.LoadingState.prototype = new Enjine.GameState();
Mario.LoadingState.prototype.Enter = function() {
var i = 0;
for (i = 0; i < 15; i++) {
this.Images[i] = {};
}
this.Images[0].name = "background";
this.Images[1].name = "endScene";
this.Images[2].name = "enemies";
this.Images[3].name = "fireMario";
this.Images[4].name = "font";
this.Images[5].name = "gameOverGhost";
this.Images[6].name = "items";
this.Images[7].name = "logo";
this.Images[8].name = "map";
this.Images[9].name = "mario";
this.Images[10].name = "particles";
this.Images[11].name = "racoonMario";
this.Images[12].name = "smallMario";
this.Images[13].name = "title";
this.Images[14].name = "worldMap";
this.Images[0].src = "images/bgsheet.png";
this.Images[1].src = "images/endscene.gif";
this.Images[2].src = "images/enemysheet.png";
this.Images[3].src = "images/firemariosheet.png";
this.Images[4].src = "images/font.gif";
this.Images[5].src = "images/gameovergost.gif";
this.Images[6].src = "images/itemsheet.png";
this.Images[7].src = "images/logo.gif";
this.Images[8].src = "images/mapsheet.png";
this.Images[9].src = "images/mariosheet.png";
this.Images[10].src = "images/particlesheet.png";
this.Images[11].src = "images/racoonmariosheet.png";
this.Images[12].src = "images/smallmariosheet.png";
this.Images[13].src = "images/title.gif";
this.Images[14].src = "images/worldmap.png";
Enjine.Resources.AddImages(this.Images);
var testAudio = new Audio();
if (testAudio.canPlayType("audio/mp3")) {
Enjine.Resources.AddSound("1up", "sounds/1-up.mp3", 1)
.AddSound("breakblock", "sounds/breakblock.mp3")
.AddSound("bump", "sounds/bump.mp3", 4)
.AddSound("cannon", "sounds/cannon.mp3")
.AddSound("coin", "sounds/coin.mp3", 5)
.AddSound("death", "sounds/death.mp3", 1)
.AddSound("exit", "sounds/exit.mp3", 1)
.AddSound("fireball", "sounds/fireball.mp3", 1)
.AddSound("jump", "sounds/jump.mp3")
.AddSound("kick", "sounds/kick.mp3")
.AddSound("pipe", "sounds/pipe.mp3", 1)
.AddSound("powerdown", "sounds/powerdown.mp3", 1)
.AddSound("powerup", "sounds/powerup.mp3", 1)
.AddSound("sprout", "sounds/sprout.mp3", 1)
.AddSound("stagestart", "sounds/stagestart.mp3", 1)
.AddSound("stomp", "sounds/stomp.mp3", 2);
} else {
Enjine.Resources.AddSound("1up", "sounds/1-up.wav", 1)
.AddSound("breakblock", "sounds/breakblock.wav")
.AddSound("bump", "sounds/bump.wav", 2)
.AddSound("cannon", "sounds/cannon.wav")
.AddSound("coin", "sounds/coin.wav", 5)
.AddSound("death", "sounds/death.wav", 1)
.AddSound("exit", "sounds/exit.wav", 1)
.AddSound("fireball", "sounds/fireball.wav", 1)
.AddSound("jump", "sounds/jump.wav", 1)
.AddSound("kick", "sounds/kick.wav", 1)
.AddSound("message", "sounds/message.wav", 1)
.AddSound("pipe", "sounds/pipe.wav", 1)
.AddSound("powerdown", "sounds/powerdown.wav", 1)
.AddSound("powerup", "sounds/powerup.wav", 1)
.AddSound("sprout", "sounds/sprout.wav", 1)
.AddSound("stagestart", "sounds/stagestart.wav", 1)
.AddSound("stomp", "sounds/stomp.wav", 1);
}
//load the array of tile behaviors
Mario.Tile.LoadBehaviors();
};
Mario.LoadingState.prototype.Exit = function() {
delete this.Images;
};
Mario.LoadingState.prototype.Update = function(delta) {
if (!this.ImagesLoaded) {
this.ImagesLoaded = true;
var i = 0;
for (i = 0; i < this.Images.length; i++) {
if (Enjine.Resources.Images[this.Images[i].name].complete !== true) {
this.ImagesLoaded = false;
break;
}
}
}
this.ScreenColor += this.ColorDirection * 255 * delta;
if (this.ScreenColor > 255) {
this.ScreenColor = 255;
this.ColorDirection = -1;
} else if (this.ScreenColor < 0) {
this.ScreenColor = 0;
this.ColorDirection = 1;
}
};
Mario.LoadingState.prototype.Draw = function(context) {
if (!this.ImagesLoaded) {
var color = parseInt(this.ScreenColor, 10);
context.fillStyle = "rgb(" + color + "," + color + "," + color + ")";
context.fillRect(0, 0, 640, 480);
} else {
context.fillStyle = "rgb(0, 0, 0)";
context.fillRect(0, 0, 640, 480);
}
};
Mario.LoadingState.prototype.CheckForChange = function(context) {
if (this.ImagesLoaded) {
//set up the global map state variable
Mario.GlobalMapState = new Mario.MapState();
context.ChangeState(new Mario.NameInputState());
}
};