-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
96 lines (82 loc) · 3.54 KB
/
index.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
<html>
<head>
<!-- Pull the engine from the Quintus CDN or load it locally -->
<!-- (use quintus-all.min.js for production) -->
<script src='http://cdn.html5quintus.com/v0.2.0/quintus-all.js'></script>
<style>
</style>
</head>
<body>
<canvas id='Geede5' width="800" height="600"></canvas>
<script>
// Now set up your game (most games will load a separate .js file)
var Q = Quintus() // Create a new engine instance
.include("Sprites, Scenes, Input, 2D, Touch, UI") // Load any needed modules
.setup("Geede5") // Add a canvas element onto the page
.controls() // Add in default controls (keyboard, buttons)
.touch(); // Add in touch support (for the UI)
Q.Sprite.extend("Player",{
init: function(p) {
this._super(p, { sheet: "player", x: 410, y: 90 });
this.add('2d, platformerControls');
this.on("hit.sprite",function(collision) {
if(collision.obj.isA("Tower")) {
Q.stageScene("endGame",1, { label: "You Won!" });
this.destroy();
}
});
}
});
Q.Sprite.extend("Tower", {
init: function(p) {
this._super(p, { sheet: 'tower' });
}
});
Q.Sprite.extend("Enemy",{
init: function(p) {
this._super(p, { sheet: 'enemy', vx: 100 });
this.add('2d, aiBounce');
this.on("bump.left,bump.right,bump.bottom",function(collision) {
if(collision.obj.isA("Player")) {
Q.stageScene("endGame",1, { label: "You Died" });
collision.obj.destroy();
}
});
this.on("bump.top",function(collision) {
if(collision.obj.isA("Player")) {
this.destroy();
collision.obj.p.vy = -300;
}
});
}
});
Q.scene("level1",function(stage) {
stage.collisionLayer(new Q.TileLayer({ dataAsset: 'level.json', sheet: 'tiles' }));
var player = stage.insert(new Q.Player());
stage.add("viewport").follow(player);
stage.insert(new Q.Enemy({ x: 700, y: 0 }));
stage.insert(new Q.Enemy({ x: 800, y: 0 }));
stage.insert(new Q.Tower({ x: 180, y: 50 }));
});
Q.scene('endGame',function(stage) {
var box = stage.insert(new Q.UI.Container({
x: Q.width/2, y: Q.height/2, fill: "rgba(0,0,0,0.5)"
}));
var button = box.insert(new Q.UI.Button({ x: 0, y: 0, fill: "#CCCCCC",
label: "Play Again" }))
var label = box.insert(new Q.UI.Text({x:10, y: -10 - button.p.h,
label: stage.options.label }));
button.on("click",function() {
Q.clearStages();
Q.stageScene('level1');
});
box.fit(20);
});
Q.load("sprites.png, sprites.json, level.json, tiles.png", function() {
Q.sheet("tiles","tiles.png", { tilew: 32, tileh: 32 });
Q.compileSheets("sprites.png","sprites.json");
Q.stageScene("level1");
});
</script>
</body>
</html>