Browse Source

SpaceGame modified for client/server.

Keith Johnston 10 years ago
parent
commit
b5bc0dbfb0
2 changed files with 22 additions and 5 deletions
  1. 9 0
      SpaceGame/Resources/Components/SpaceGame.js
  2. 13 5
      SpaceGame/Resources/UI/mainMenu.js

+ 9 - 0
SpaceGame/Resources/Components/SpaceGame.js

@@ -6,6 +6,7 @@ var options = require("UI/options")
 exports.component = function(self) {
 
   var game = Atomic.game;
+  var network;
 
   // expose ourselves as a global, this is invalid in "use strict"; which perhaps we should be using
   // to enforce better form
@@ -246,9 +247,17 @@ exports.component = function(self) {
       Atomic.input.bindButton(self.fireButton, Atomic.KEY_SPACE);
     }
 
+    var spaceNode =self.myscene.createChild("SpaceBackground");
+    spaceNode.createJSComponent("Components/SpaceBackground.js");
+
     spawnPlayer();
     spawnEnemies();
 
+    // Start server
+    network = new Atomic.Network();
+
+    network.startServerSimple(27000, self.myscene);
+
   }
 
 

+ 13 - 5
SpaceGame/Resources/UI/mainMenu.js

@@ -6,6 +6,7 @@ var UI = Atomic.UI;
 var UIWindow = Atomic.UIWindow;
 
 var window;
+var network;
 
 function closeWindow() {
 
@@ -37,19 +38,26 @@ exports.init = function() {
 
     closeWindow();
 
-  	var node = game.scene.createChild("SpaceGame");
-  	node.createJSComponent("Components/SpaceGame.js");
+    game.createScene2D();
 
+    var node = game.scene.createChild("SpaceGame");
+    node.createJSComponent("Components/SpaceGame.js");
   }
 
   window.getWidget("about").onClick = function () {
 
+    closeWindow();
+
     // disable ourselves until ok is clicked on about
-    window.setState(UI.WIDGET_STATE_DISABLED, true);
+    //window.setState(UI.WIDGET_STATE_DISABLED, true);
 
-    var ui = require("./ui");
-    ui.showAbout(function() {window.setState(UI.WIDGET_STATE_DISABLED, false);});
+    //var ui = require("./ui");
+    //ui.showAbout(function() {window.setState(UI.WIDGET_STATE_DISABLED, false);});
+
+    game.createScene2D();
 
+    network = new Atomic.Network();
+    network.connectSimple('127.0.0.1', 27000, game.scene); 
   }
 
   window.getWidget("options").onClick = function () {