-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnewlevel.html
151 lines (128 loc) · 4.78 KB
/
newlevel.html
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
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Mario the game</title>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<canvas id="canvas" width="640" height="480">
<p>Your browser does not support the canvas element.</p>
</canvas>
<script type="text/javascript" src="enjine.js"></script>
<script type="text/javascript" src="code/setup.js"></script>
<script type="text/javascript" src="code/level.js"></script>
<script type="text/javascript" src="code/loadingState.js"></script>
<script type="text/javascript" src="code/backgroundGenerator.js"></script>
<script type="text/javascript" src="code/backgroundRender.js"></script>
<script type="text/javascript" src="level1.json"></script>
<script type="text/javascript" src="code/levelLoading.js"></script>
<script type="text/javascript" src="code/levelRender.js"></script>
<script type="text/javascript" src="code/sparkle.js"></script>
<script type="text/javascript" src="code/character.js"></script>
<script>
Game.LoadingState.prototype.CheckForChange = function(context) {
if (this.ImagesLoaded) {
context.ChangeState(new Game.newLevelTest());
}
};
Game.newLevelTest = function(){
this.drawManager = null;
this.camera = null;
this.mario = null;
this.font = null;
this.wasKeyDown = false;
this.Level = null;
this.Layer = null;
this.BgLayer = [];
this.Paused = false;
};
//gs={_proto_={enter,exit,...}}
Game.newLevelTest.prototype = new Enjine.GameState();
//gs={enter,...,_proto_={}}
Game.newLevelTest.prototype.Enter = function(){
var levelGenerator = new Game.LevelLoading();
this.Level = levelGenerator.CreateLevel(0, 1);//type, difficulty
this.Layer = new Game.LevelRender(this.Level, 320, 240);
this.drawManager = new Enjine.DrawableManager();
this.camera = new Enjine.Camera();
for(i = 0; i < 2; i++){
scrollSpeed = 4 >> i;
w = ((((320 * 16) - 320) / scrollSpeed) | 0) + 320;
h = ((((240 * 16) - 240) / scrollSpeed) | 0) + 240;
bgLevelGenerator = new Game.BackgoundGenerator(w / 32 + 1, h / 32 + 1, i === 0, levelGenerator.Type);
this.BgLayer[i] = new Game.BackgroundRender(bgLevelGenerator.CreateLevel(), 320, 240, scrollSpeed);
}
this.mario = new Game.Character(this);
this.mario.SetLarge(false, false);
this.drawManager.Add(this.mario);
};
Game.newLevelTest.prototype.AddSprite = function(sp){
this.drawManager.Add(sp);
};
Game.newLevelTest.prototype.RemoveSprite = function(sp){
this.drawManager.Remove(sp);
};
Game.newLevelTest.prototype.Exit = function(){
this.drawManager.Clear();
delete this.drawManager;
delete this.camera;
delete this.mario;
delete this.Level;
delete this.Layer;
};
Game.newLevelTest.prototype.Update = function(delta){
this.camera.X = this.mario.X - 160;
if (this.camera.X < 0) {
this.camera.X = 0;
}
if (this.camera.X > this.Level.Width * 16 - 320) {
this.camera.X = this.Level.Width * 16 - 320;
}
this.Layer.Update(delta);
this.Level.Update();
this.camera.X = (this.mario.XOld + (this.mario.X - this.mario.XOld) * delta) - 160;
this.camera.Y = (this.mario.YOld + (this.mario.Y - this.mario.YOld) * delta) - 120;
for (i = 0; i < this.drawManager.Objects.length; i++) {
if (this.drawManager.Objects[i] !== this.mario) {
this.drawManager.Objects[i].Update(delta);
}
}
this.mario.Update(delta);
if(Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Right) ||
Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.Left)){
//sprite.update(t)
this.wasKeyDown = true;
}
};
Game.newLevelTest.prototype.Draw = function(context){
if (this.camera.X < 0) {
this.camera.X = 0;
}
if (this.camera.Y < 0) {
this.camera.Y = 0;
}
if (this.camera.X > this.Level.Width * 16 - 320) {
this.camera.X = this.Level.Width * 16 - 320;
}
if (this.camera.Y > this.Level.Height * 16 - 240) {
this.camera.Y = this.Level.Height * 16 - 240;
}
for (i = 0; i < 2; i++) {
this.BgLayer[i].Draw(context, this.camera);
}
this.Layer.Draw(context, this.camera);
context.save();
context.translate(-this.camera.X, -this.camera.Y);
this.drawManager.Draw(context, this.camera);//sprite.draw(a,b), b as origin
context.restore();
};
Game.newLevelTest.prototype.CheckForChange = function(context){
if(this.wasKeyDown && !Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.F))
return;//context.ChangeState(new Game.LoadingState());
};
//GameState::enter,exit,update,draw,checkforchange
$(document).ready(function() { new Enjine.Application().Initialize(new Game.LoadingState(), 320, 240) });//w,h
</script>
</body>
</html>