Skip to content

Commit

Permalink
simplified socket handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Jul 29, 2011
1 parent afaa415 commit bda9f7b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 96 deletions.
29 changes: 0 additions & 29 deletions index.html

This file was deleted.

18 changes: 15 additions & 3 deletions public/js/RacingGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var RacingGame = (function() {
function RacingGame(container, b2debugCanvas) {
this.model = {};

this.socket = this.setupSocket('http://localhost/');

this.shouldDebug = false;
this.b2DebugDraw = this.setupDebugDraw(b2debugCanvas);

Expand All @@ -11,8 +13,6 @@ var RacingGame = (function() {

this.keyHandler = new KeyHandler();

this.socketHandler = new SocketHandler(this.model);

this.model.camera = new Camera(50, window.innerWidth * .5 / window.innerHeight, 0.001, 1000);
this.model.scene = new Scene();
this.model.renderer = new Renderer(container, this.model.scene, this.model.camera);
Expand All @@ -22,13 +22,25 @@ var RacingGame = (function() {
this.model.userCar = new UserCar(this.model.scene, this.model.b2World, this.keyHandler);
this.model.cars.push(this.model.userCar);

for(var i = 0; i < 5; i++) {
for(var i = 0; i < 10; i++) {
this.model.cars.push(new Car(this.model.scene, this.model.b2World, Math.random() * 10, Math.random() * 10, Math.random() * Math.PI));
}

this.model.wall = new Wall(this.model.scene, this.model.b2World, 3, 3, 10, 1.2, 1, Math.random()*Math.PI);
}

RacingGame.prototype.setupSocket = function(url) {
var socket = io.connect(url);

socket.on('connecting', function(message) { console.log('Connecting to ', url) });
socket.on('connect_failed', function(message) { console.log('Connection failed') });
socket.on('connect', function(message) { console.log('Connected to socket!') });
socket.on('disconnect', function(message) { console.log('Disconnected from socket!') });
socket.on('message', function(message) { console.log('Socket message:', message) });

return socket;
}

RacingGame.prototype.setupDebugDraw = function(debugCanvas) {
var game = this;
debugCanvas.addEventListener('click', function() {
Expand Down
55 changes: 0 additions & 55 deletions public/js/SocketHandler.js

This file was deleted.

10 changes: 2 additions & 8 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ app.configure(function(){

app.get('/', function(req, res){
res.render('index', {
layout: false,
title: 'Express'
layout: false
});
});

Expand All @@ -25,12 +24,7 @@ app.listen(3000);
io = io.listen(app);

io.sockets.on('connection', function (client) {

console.log('User connected on socket');

client.json.send({
'type': 'welcome'
});
client.send('Welcome to the server!');
});

console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
1 change: 0 additions & 1 deletion views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<script src="js/Car/Car.js"></script>
<script src="js/Car/UserCar.js"></script>
<script src="js/Wall.js"></script>
<script src="js/SocketHandler.js"></script>

<script src="js/main.js"></script>
</body>
Expand Down

0 comments on commit bda9f7b

Please sign in to comment.