forked from robertkleffner/mariohtml5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtitleState.js
More file actions
executable file
·82 lines (61 loc) · 2.4 KB
/
Copy pathtitleState.js
File metadata and controls
executable file
·82 lines (61 loc) · 2.4 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
/**
Displays the title screen and menu.
Code by Rob Kleffner, 2011
*/
Mario.TitleState = function() {
this.drawManager = null;
this.camera = null;
this.logoY = null;
this.bounce = null;
this.font = null;
};
Mario.TitleState.prototype = new Enjine.GameState();
Mario.TitleState.prototype.Enter = function() {
this.drawManager = new Enjine.DrawableManager();
this.camera = new Enjine.Camera();
var bgGenerator = new Mario.BackgroundGenerator(2048, 15, true, Mario.LevelType.Overground);
var bgLayer0 = new Mario.BackgroundRenderer(bgGenerator.CreateLevel(), 320, 240, 2);
bgGenerator.SetValues(2048, 15, false, Mario.LevelType.Overground);
var bgLayer1 = new Mario.BackgroundRenderer(bgGenerator.CreateLevel(), 320, 240, 1);
this.title = new Enjine.Sprite();
this.title.Image = Enjine.Resources.Images["title"];
this.title.X = 0, this.title.Y = 120;
this.logo = new Enjine.Sprite();
this.logo.Image = Enjine.Resources.Images["logo"];
this.logo.X = 0, this.logo.Y = 0;
this.font = Mario.SpriteCuts.CreateRedFont();
this.font.Strings[0] = { String: "Press S to Start", X: 96, Y: 120 };
this.logoY = 20;
this.drawManager.Add(bgLayer0);
this.drawManager.Add(bgLayer1);
this.bounce = 0;
Mario.GlobalMapState = new Mario.MapState();
//set up the global main character variable
Mario.MarioCharacter = new Mario.Character();
Mario.MarioCharacter.Image = Enjine.Resources.Images["smallMario"];
Mario.PlayTitleMusic();
};
Mario.TitleState.prototype.Exit = function() {
Mario.StopMusic();
this.drawManager.Clear();
delete this.drawManager;
delete this.camera;
delete this.font;
};
Mario.TitleState.prototype.Update = function(delta) {
this.bounce += delta * 2;
this.logoY = 20 + Math.sin(this.bounce) * 10;
this.camera.X += delta * 25;
this.drawManager.Update(delta);
};
Mario.TitleState.prototype.Draw = function(context) {
this.drawManager.Draw(context, this.camera);
context.drawImage(Enjine.Resources.Images["title"], 0, 120);
context.drawImage(Enjine.Resources.Images["logo"], 0, this.logoY);
this.font.Draw(context, this.Camera);
};
Mario.TitleState.prototype.CheckForChange = function(context) {
if (Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.S)) {
context.ChangeState(Mario.GlobalMapState);
}
};