add start of client rendering

This commit is contained in:
Asraelite 2016-03-21 16:15:49 +00:00
parent 9787a9d468
commit ebcee954bf
13 changed files with 127 additions and 7 deletions

View file

View file

View file

@ -2,8 +2,28 @@
window.addEventListener('load', init);
var socket;
var game;
function init() {
socket = io.connect('http://localhost:8080');
game = new Game();
game.tick();
game.net.connect();
}
function Game() {
var self = this;
this.connected = false;
this.state = 'connecting';
this.net = new Net();
this.renderer = new Renderer();
this.tick = function() {
self.renderer.render(self.state);
requestAnimationFrame(self.tick);
}
}

17
public/js/starbugs/net.js Normal file
View file

@ -0,0 +1,17 @@
function Net() {
this.socket;
this.connect = function() {
this.socket = io.connect('http://localhost:8080');
this.socket.on('connect', function() {
game.connected = true;
game.state = 'connected';
});
this.socket.on('disconnect', function() {
game.connected = false;
game.state = 'disconnected';
});
};
}

View file

@ -0,0 +1,24 @@
function Renderer() {
var self = this;
var canvas = document.getElementsByTagName('canvas')[0];
var context = canvas.getContext('2d');
var pallet = new Pallet();
this.render = function(state) {
if (state == 'connecting' || state == 'disconnected') {
pallet.clear();
pallet.fill('#111');
var str = state == 'connecting' ? 'Connecting' : 'Shit\'s ' +
'diconnected, yo!';
pallet.text(str, canvas.width / 2, canvas.height / 2, '#fff', 'FreePixel', 16, 'center', 'middle');
return;
}
pallet.clear();
pallet.fill('#000');
}
pallet.fillScreen();
window.addEventListener('resize', pallet.fillScreen);
}

View file

View file

@ -0,0 +1,5 @@
function Player(own, name, ship) {
this.name = name;
this.ship = ship;
this.own = own;
}

View file