Permalink
Browse files

split off games into separate URLs, create rooms

  • Loading branch information...
1 parent 4b4340c commit 1440df7c9a4fe7e0163e87762ba9e08c78a822e5 @jlongster committed Dec 1, 2012
Showing with 422 additions and 264 deletions.
  1. +164 −148 main.js
  2. +77 −0 room.js
  3. +10 −4 scene.js
  4. +7 −0 static/css/main.css
  5. +87 −0 static/game.html
  6. +22 −40 static/index.html
  7. +5 −0 static/js/landing.js
  8. +41 −62 static/js/main.js
  9. +2 −0 static/js/packets.js
  10. +7 −1 static/js/server-conn.js
  11. +0 −9 static/js/server.js
View
Oops, something went wrong.
View
@@ -0,0 +1,77 @@
+
+
+function Room(name, scene) {
+ this.name = name;
+ this.scene = scene;
+ this.players = [];
+}
+
+Room.prototype.start = function() {
+ this.scene.start(this);
+};
+
+Room.prototype.stop = function() {
+ this.scene.stop(this);
+};
+
+Room.prototype.addPlayer = function(player) {
+ this.players.push(player);
+ this.scene.addObject(player.entity);
+};
+
+Room.prototype.removePlayer = function(player) {
+ var idx = this.players.indexOf(player);
+ if(idx !== -1) {
+ this.players.splice(idx, 1);
+ }
+
+ var ent = this.scene.getObject(player.name);
+ if(ent) {
+ ent._parent.removeObject(ent);
+ }
+};
+
+Room.prototype.getPlayer = function(id) {
+ for(var i=0; i<this.players.length; i++) {
+ if(this.players[i].id == id) {
+ return this.players[i];
+ }
+ }
+}
+
+Room.prototype.count = function() {
+ return this.players.length;
+};
+
+Room.prototype.names = function() {
+ return this.players.map(function(user) { return user.name; });
+};
+
+Room.prototype.broadcast = function(user, packet) {
+ for(var i=0, l=this.players.length; i<l; i++) {
+ var player = this.players[i];
+
+ if(player != user) {
+ try {
+ player.stream.write(packet);
+ }
+ catch(e) {
+ console.log('send error: ' + e);
+ }
+ }
+ }
+};
+
+Room.prototype.lookupUser = function(entity) {
+ for(var i=0, l=this.players.length; i<l; i++) {
+ var player = this.players[i];
+
+ if(player.entity === entity) {
+ return player;
+ }
+ }
+
+ return null;
+};
+
+module.exports = Room;
View
@@ -41,15 +41,15 @@ module.exports = Scene.extend({
entity.sendDiff(packet.sequenceId);
},
- start: function(lookupUser, broadcast) {
+ start: function(room) {
var _this = this;
- setInterval(function() {
+ this._interval = setInterval(function() {
_this.traverse(function(ent) {
if(!(ent instanceof Entity)) {
return;
}
- var user = lookupUser(ent);
+ var user = room.lookupUser(ent);
var buffer = ent.flushPackets();
if(user) {
@@ -78,11 +78,17 @@ module.exports = Scene.extend({
user.stream.write(p.makePacket(state, p.statePacket));
state.from = user.id;
- broadcast(user, p.makePacket(state, p.statePacket));
+ room.broadcast(user, p.makePacket(state, p.statePacket));
ent.saveHistory(state);
}
}
});
}, 100);
+ },
+
+ stop: function() {
+ if(this._interval) {
+ clearInterval(this._interval);
+ }
}
});
View
@@ -75,6 +75,13 @@ canvas {
display: none;
}
+#intro .rules {
+ text-align: left;
+ width: 40em;
+ margin: 3em auto;
+ margin-top: 1em;
+}
+
body.intro #intro,
body.instructions #instructions,
body.ingame #ingame {
View
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>Github Game Off 2012</title>
+
+ <link rel="stylesheet" type="text/css" href="css/main.css" />
+ <link rel="stylesheet" type="text/css" href="css/ui.css" />
+ <style>
+ </style>
+ </head>
+ <body class="ingame">
+ <div id="ingame">
+ <canvas id="canvas"></canvas>
+
+ <div id="notification"></div>
+
+ <div id="chat" class="closed">
+ <div id="messages"></div>
+ <div class="type">
+ <div class="inner">
+ <input id="message-input" type="text" name="message" autocomplete="off" />
+ </div>
+ </div>
+ </div>
+
+ <div class="initialOverlay">
+ <p>Use WASD or arrow keys to move around, and space to jump.</p>
+
+ <p>
+ <strong>In fullscreen mode</strong>, use mouse to look around and click
+ shoot.
+ </p>
+
+ <p>
+ <strong>In windowed mode</strong>, click and drag to look around and hit E to
+ shoot.
+ </p>
+
+ <p>
+ Want to go fullscreen (recommended for pointer lock)?
+ <button class="start">Yes</button>
+ <button class="no">No</button>
+ </p>
+ </div>
+ </div>
+
+ <script>
+ window.sh = {};
+ window.sh.util = {};
+ </script>
+ <script src="js/shade/gl-matrix.js"></script>
+ <script src="js/shade/util.js"></script>
+ <script src="js/shade/object.js"></script>
+ <script src="js/shade/program.js"></script>
+ <script src="js/shade/resources.js"></script>
+ <script src="js/shade/scene.js"></script>
+ <script src="js/shade/scenenode.js"></script>
+ <script src="js/shade/mesh.js"></script>
+ <script src="js/shade/cube.js"></script>
+ <script src="js/shade/line.js"></script>
+ <script src="js/shade/square.js"></script>
+ <script src="js/shade/camera.js"></script>
+ <script src="js/shade/renderer.js"></script>
+ <script src="js/shade/mesh-loader.js"></script>
+ <script src="js/shade/collision.js"></script>
+ <script src="js/shade/quadtree.js"></script>
+ <script src="js/shade/aabb.js"></script>
+ <script src="js/shade/sound.js"></script>
+
+ <script src="js/zepto.min.js"></script>
+ <script src="js/lib/binary.js"></script>
+ <script src="js/packets.js"></script>
+ <script src="js/server-conn.js"></script>
+ <script src="js/server-events.js"></script>
+ <script src="js/messages.js"></script>
+
+ <script src="js/input.js"></script>
+ <script src="js/simplex-noise.js"></script>
+ <script src="js/terrain.js"></script>
+ <script src="js/level.js"></script>
+ <script src="js/entity.js"></script>
+ <script src="js/player.js"></script>
+ <script src="js/stats.min.js"></script>
+ <script src="js/main.js"></script>
+ </body>
+</html>
View
@@ -13,9 +13,28 @@
<div id="intro">
<h1>Octoshot</h1>
- <p>A 3d first person shooter for the web!</p>
+ <p><em>A 3d first person shooter for the web!</em></p>
- <button class="play">Play now!</button>
+ <h3>Rules</h3>
+
+ <ul class="rules">
+ <li>Games can have 2-8 players</li>
+ <li>Only headshots count -- but you have big heads!</li>
+ <li>Everyone has 3 points of health (3 shots kills somebody)</li>
+ <li>Use WASD or the arrow keys to move around</li>
+ <li>
+ If in fullscreen mode, shoot with a mouse click and look
+ around with the mouse
+ </li>
+ <li>
+ If in windowed mode, shoot with the E key and click and drag
+ to look around
+ </li>
+ <li>Get the most kills in 5 minutes!</li>
+ </ul>
+
+ <button class="play-find">Find a Game</button>
+ <button class="play-start">Start a Game</button>
</div>
<div id="instructions">
@@ -57,43 +76,6 @@
</div>
</div>
- <script>
- window.sh = {};
- window.sh.util = {};
- </script>
- <script src="js/shade/gl-matrix.js"></script>
- <script src="js/shade/util.js"></script>
- <script src="js/shade/object.js"></script>
- <script src="js/shade/program.js"></script>
- <script src="js/shade/resources.js"></script>
- <script src="js/shade/scene.js"></script>
- <script src="js/shade/scenenode.js"></script>
- <script src="js/shade/mesh.js"></script>
- <script src="js/shade/cube.js"></script>
- <script src="js/shade/line.js"></script>
- <script src="js/shade/square.js"></script>
- <script src="js/shade/camera.js"></script>
- <script src="js/shade/renderer.js"></script>
- <script src="js/shade/mesh-loader.js"></script>
- <script src="js/shade/collision.js"></script>
- <script src="js/shade/quadtree.js"></script>
- <script src="js/shade/aabb.js"></script>
- <script src="js/shade/sound.js"></script>
-
- <script src="js/zepto.min.js"></script>
- <script src="js/lib/binary.js"></script>
- <script src="js/packets.js"></script>
- <script src="js/server-conn.js"></script>
- <script src="js/server-events.js"></script>
- <script src="js/messages.js"></script>
-
- <script src="js/input.js"></script>
- <script src="js/simplex-noise.js"></script>
- <script src="js/terrain.js"></script>
- <script src="js/level.js"></script>
- <script src="js/entity.js"></script>
- <script src="js/player.js"></script>
- <script src="js/stats.min.js"></script>
- <script src="js/main.js"></script>
+ <script src="js/landing.js"></script>
</body>
</html>
@@ -0,0 +1,5 @@
+$(function() {
+ $('#intro button.play-start').click(function() {
+ showInGame();
+ });
+});
Oops, something went wrong.

0 comments on commit 1440df7

Please sign in to comment.