-
-
Save z3t0/47aca1e581e59ccffdb1dcb88575201b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var pixi = require('pixi.js'); | |
| var player = require('./player.js') | |
| module.exports = function(host) { | |
| return new Game(host); | |
| } | |
| function Game (host) { | |
| this.host = host; | |
| console.log("Creating game") | |
| if (host == "") { | |
| console.log("No host provided"); | |
| return; | |
| } | |
| this.players = [] | |
| this.init(); | |
| // this.connect() | |
| } | |
| Game.prototype.init = function() { | |
| self = this; | |
| console.log("Initializing Pixi") | |
| // Setup Pixi.JS | |
| self.renderer = pixi.autoDetectRenderer(256, 256); | |
| document.body.appendChild(self.renderer.view); | |
| self.stage = new pixi.Container(); | |
| self.renderer.view.style.position = "absolute"; | |
| self.renderer.view.style.display = "block"; | |
| self.renderer.autoRescale = true; | |
| self.renderer.resize(window.innerWidth, window.innerHeight); | |
| // Load Resources | |
| pixi.loader.add("res/img/circle.png").load(this.connect.bind(this)); | |
| // Start rendering | |
| gameLoop(); | |
| } | |
| function gameLoop() { | |
| // Loop at 60 | |
| requestAnimationFrame(gameLoop); | |
| // console.log(this); | |
| console.log("Rendered"); | |
| } | |
| Game.prototype.connect = function() { | |
| console.log("Trying to connect..."); | |
| this.ws = new WebSocket(this.host); | |
| this.ws.onopen = this.OnConnectHandler.bind(this); | |
| this.ws.onmessage = this.MessageHandler.bind(this); | |
| this.ws.onclose = this.CloseHandler.bind(this); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment