-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackground.html
86 lines (76 loc) · 2.92 KB
/
background.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
<!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/backgroundGenerator.js"></script>
<script type="text/javascript" src="code/backgroundRender.js"></script>
<script>
Game.BackgroundTest = function(){
this.drawManager = null;
this.camera = null;
this.flip = null;
this.font = null;
this.wasKeyDown = false;
this.Layer = null;
this.BgLayer = [];
};
//gs={_proto_={enter,exit,...}}
Game.BackgroundTest.prototype = new Enjine.GameState();
//gs={enter,...,_proto_={}}
Game.BackgroundTest.prototype.Enter = function(){
Enjine.Resources.AddImage("flip","images/gameovergost.gif", 864, 64);
Enjine.Resources.AddImage("background","images/bgsheet.png",256, 320);
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, Game.LevelType.Castle);
this.BgLayer[i] = new Game.BackgroundRender(bgLevelGenerator.CreateLevel(), 320, 240, scrollSpeed);
}
this.flip = new Enjine.AnimatedSprite();
this.flip.Image = Enjine.Resources.Images["flip"];
this.flip.SetColumnCount(9);
this.flip.SetRowCount(1);
this.flip.AddNewSequence("loop", 0, 0, 0, 8);
this.flip.PlaySequence("loop", true);
this.flip.FramesPerSecond = 1/15;
this.drawManager.Add(this.flip);
};
Game.BackgroundTest.prototype.Exit = function(){
this.drawManager.Clear();
delete this.drawManager;
delete this.camera;
delete this.flip;
};
Game.BackgroundTest.prototype.Update = function(delta){
this.drawManager.Update(delta);//sprite.update(t)
if(Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.S))
this.wasKeyDown = true;
};
Game.BackgroundTest.prototype.Draw = function(context){
for (i = 0; i < 2; i++) {
this.BgLayer[i].Draw(context, this.camera);
}
this.drawManager.Draw(context, this.camera);//sprite.draw(a,b), b as origin
};
Game.BackgroundTest.prototype.CheckForChange = function(context){
if(this.wasKeyDown && !Enjine.KeyboardInput.IsKeyDown(Enjine.Keys.S))
return;//context.ChangeState(new Game.TitleState());//gameState
};
//GameState::enter,exit,update,draw,checkforchange
$(document).ready(function() { new Enjine.Application().Initialize(new Game.BackgroundTest(), 320, 240) });//w,h
</script>
</body>
</html>