Skip to content

Commit

Permalink
new player info
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie committed Oct 13, 2017
1 parent ea3fb5d commit 8d2ff5f
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Naprawdę bardzo fajna gra!
22 changes: 20 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,38 @@
<html>
<head>
<title>Multiplayer</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
#messages { list-style-type: none; margin: 0; padding: 0; }
#messages li { padding: 5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
div#createButton { padding: 10px; background: pink}
</style>
</head>
<body ng-app="app">
<div class='content'>
<div ui-view></div>
</div>
<script type="text/javascript" src="bower_components/angular/angular.min.js"></script>
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
<script type="text/javascript" src="bower_components/phaser/build/phaser.min.js"></script>
<script type="text/javascript" src="scripts/ng-game.js"></script>
<script type="text/javascript" src="bower_components/angular-socket-io/socket.min.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>

<script type="text/javascript" src="scripts/menu/index.js"></script>
<script type="text/javascript" src="scripts/menu/menu_controller.js"></script>
<script type="text/javascript" src="scripts/game/index.js"></script>
<script type="text/javascript" src="scripts/game/game_controller.js"></script>
<script type="text/javascript" src="scripts/game/game.js"></script>
<script type="text/javascript" src="scripts/game/loader.js"></script>
<script type="text/javascript" src="scripts/game/network.js"></script>
<script type="text/javascript" src="scripts/ng-game.js"></script>

<script src="/socket.io/socket.io.js"></script>

</body>
</html>
4 changes: 4 additions & 0 deletions scripts/game/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,11 @@ playState.prototype = {
// The first two arguments are the width and the height of the canvas element. In this case 640 x 480 pixels. You can resize this in the gameProperties object above.
// The third argument is the renderer that will be used. Phaser.AUTO is used to automatically detect whether to use the WebGL or Canvas renderer.
// The fourth argument is 'gameDiv', which is the id of the DOM element we used above in the index.html file where the canvas element is inserted.
<<<<<<< ea3fb5d9eafe80441a500bb00cd16728b3a66b3a
window.createGame = function(scope, players, mapIdm, injector){
=======
window.createGame = function(scope, players, mapId, injector){
>>>>>>> new player info

game = new Phaser.Game(gameProperties.screenWidth, gameProperties.screenHeight, Phaser.AUTO, 'gameDiv');

Expand Down
17 changes: 14 additions & 3 deletions scripts/game/game_controller.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
angular.module('app.game')
.controller('GameController', function() {

.controller('GameController', function($scope, mySocket) {
mySocket.then(function(socket) {
console.log("?????????Socket??????????");
console.log(socket);
socket.on('gameUpdated:add', function(data){
console.log(">><><><><><><><><><");
})
});
})
.directive('gameCanvas', function($injector) {
var linkFn = function(scope, ele, attrs) {
// link Function
console.log("create game");
createGame(scope, scope.players, scope.mapId, $injector);
console.log("=============scope==============");
console.log(scope);
console.log("=============scope==============");

};

return {
Expand Down
2 changes: 1 addition & 1 deletion scripts/game/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ angular.module('app.game', [])
})
.state('game.play', {
url: '/id',
template: '<div><div id="gameCanvas"></div></div>',
template: '<div game-canvas></div>',
controller: 'GameController'
})
});
30 changes: 30 additions & 0 deletions scripts/game/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
angular.module('app.loader', [])
.provider('ioLoader', function() {
this.scriptUrl = window.location.origin+'/socket.io/socket.io.js';

this.$get = function($window, $document, $q) {
var defer = $q.defer(), scriptUrl = this.scriptUrl;

return {
done: function(){
var onScriptLoad=function(){return defer.resolve($window.io);};
console.log("loader --- done");
if($window.io) { onScriptLoad(); } else {
var scriptTag = $document[0].createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.async = true;
scriptTag.src = scriptUrl;
scriptTag.onreadystatechange = function () {
if (this.readyState === 'complete') {
onScriptLoad();
}
};
scriptTag.onload = onScriptLoad;
$document[0].getElementsByTagName('head')[0]
.appendChild(scriptTag);
}
return defer.promise;
}
};
};
});
12 changes: 12 additions & 0 deletions scripts/game/network.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
angular.module('app.network', [])
.factory('mySocket', function(ioLoader, $q, socketFactory) {
var mySocket = $q.defer();
ioLoader.done().then(function(io) {
var myIoSocket = io.connect(window.location.hostname);
var aSock = socketFactory({
ioSocket: myIoSocket
});
mySocket.resolve(aSock);
});
return mySocket.promise;
});
8 changes: 6 additions & 2 deletions scripts/menu/main.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<div>
<div class="panel play"
<div class="panel play"
ng-repeat="room in ctrl.rooms track by room.id"
ui-sref='game.play({id: room.id})'>
<span ng-bind="room.players.length"></span> Players
</div>
<div class="panel create"
<div id="createButton" class="panel create"
ui-sref='game.play({id: ctrl.createId()})'>
<a>Create a game</a>
</div>
<ul id="messages"></ul>
<form action="">
<input id="m" autocomplete="off" /><button>Send</button>
</form>
</div>
13 changes: 12 additions & 1 deletion scripts/menu/menu_controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
angular.module('app.menu')
.controller('MenuController', function() {
var ctrl = this;

var socket = io();
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
});
socket.on('gameUpdated:add', function(data){
$('#messages').append($('<li>').text("A NEW PLAYER JOINED THE GAME: " + data.player.id));
});
});
5 changes: 4 additions & 1 deletion scripts/ng-game.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
angular.module('app', [
'ui.router',
'btford.socket-io',
'app.menu',
'app.game'
'app.game',
'app.network',
'app.loader'
]);
2 changes: 1 addition & 1 deletion server/routes/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = (function(app, io) {
var player = new Player({ id: socket.id });
g.players.push(player);
console.log("Player: " + player.id);
this.emit('gameUpdated:add', {player: player.id});
this.emit('gameUpdated:add', {player: player});
socket.on('newPlayer', onNewPlayer);
});

Expand Down

0 comments on commit 8d2ff5f

Please sign in to comment.