Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Self has different shirt colour

  • Loading branch information...
commit 6e08ff1e50699dd3d6d5ed40867f8446e34dad76 1 parent 51888f0
@MrJaba authored
View
8 controllers/game_controller.rb
@@ -8,6 +8,7 @@ class << self
attr_accessor :bomb_positions
end
TIMEOUT = 20
+ COLOURS = %w{ blue brown red yellow }
@player_states = {}
@bomb_positions = {}
@@ -31,10 +32,11 @@ def push_bombs
private
- def receive_register(message, uuid=nil)
+ def receive_register(message, null_uuid=nil)
player_uuid = UUID.new.generate
- GameController.player_states[player_uuid] = {:x => 0, :y => 0, :score => 0, :last_message_time => Time.now}
- render ({:type => 'uuid', :uuid => player_uuid, :class_id => self.object_id}).to_json
+ player_colour = COLOURS[GameController.player_states.size] rescue COLOURS.first
+ GameController.player_states[player_uuid] = {:x => 0, :y => 0, :score => 0, :last_message_time => Time.now, :player_colour => player_colour}
+ render ({:type => 'register', :uuid => player_uuid, :colour => player_colour}).to_json
end
def receive_player_move(message, uuid)
View
15 public/javascripts/game.js
@@ -69,10 +69,10 @@ MrJaba.Bomberman = function(){
function drawOpponents(row){
$.each(MrJaba.Bomberman.opponents, function(uuid, position){
- var boardY = position.y - 40 + (MrJaba.Bomberman.Images.getImage('CharacterBoy').height/2);
+ var boardY = position.y - 40 + (MrJaba.Bomberman.Images.getImage('CharacterBoy-brown').height/2);
var opRow = parseInt( boardY / MrJaba.Bomberman.Images.visibleTileHeight() );
if( opRow == row ){
- canvas().drawImage(MrJaba.Bomberman.Images.getImage('CharacterBoy'),position.x, position.y, 101,171);
+ canvas().drawImage(MrJaba.Bomberman.Images.getImage('CharacterBoy-brown'),position.x, position.y, 101,171);
}
});
}
@@ -118,7 +118,7 @@ MrJaba.Bomberman = function(){
function initCharacter(id){
var me = new Sprite();
- me.initialize(id, MrJaba.Bomberman.Images.getImage('CharacterBoy'), canvasNode());
+ me.initialize(id, MrJaba.Bomberman.Images.getImage('CharacterBoy-brown'), canvasNode());
return me;
}
@@ -155,8 +155,8 @@ MrJaba.Bomberman = function(){
killPlayersAt:function( tileX, tileY, alreadyKilled ){
var opponents = MrJaba.Bomberman.opponents;
$.each(opponents, function(uuid, position){
- var opponentTileY = parseInt((position.y - 40 + (MrJaba.Bomberman.Images.getImage('CharacterBoy').height/2)) / MrJaba.Bomberman.Images.visibleTileHeight());
- var opponentTileX = parseInt((position.x + (MrJaba.Bomberman.Images.getImage('CharacterBoy').width/2)) / MrJaba.Bomberman.Images.tileWidth());
+ var opponentTileY = parseInt((position.y - 40 + (MrJaba.Bomberman.Images.getImage('CharacterBoy-brown').height/2)) / MrJaba.Bomberman.Images.visibleTileHeight());
+ var opponentTileX = parseInt((position.x + (MrJaba.Bomberman.Images.getImage('CharacterBoy-brown').width/2)) / MrJaba.Bomberman.Images.tileWidth());
if(tileX === opponentTileX && tileY === opponentTileY && $.inArray( uuid, alreadyKilled ) == -1){
console.log(uuid);
alreadyKilled.push(uuid);
@@ -215,6 +215,11 @@ MrJaba.Bomberman = function(){
})
},
+ registerPlayer:function(registration){
+ MrJaba.Bomberman.uuid = registration['uuid'];
+ MrJaba.Bomberman.me.setImage(MrJaba.Bomberman.Images.getImage('CharacterBoy-'+registration['colour']));
+ },
+
initialize: function(){
MrJaba.Bomberman.map = readMap();
MrJaba.Bomberman.canvas = initCanvas();
View
6 public/javascripts/game_client.js
@@ -17,8 +17,8 @@ var GameClient = function(){
return MrJaba.Bomberman.me.position();
}
- var receiveUuid = function(data){
- MrJaba.Bomberman.uuid = data['uuid'];
+ var receiveRegister = function(data){
+ MrJaba.Bomberman.registerPlayer(data)
}
var updateOpponentPositions = function(data){
@@ -64,7 +64,7 @@ var GameClient = function(){
initWebSocket();
this.bind('player_move', notifyPlayerMove);
- this.bind('uuid', receiveUuid);
+ this.bind('register', receiveRegister);
this.bind('update_positions', updateOpponentPositions);
this.bind('update_bombs', updateBombPositions);
this.bind('send_bomb_drop', notifyBombDrop);
View
5 public/javascripts/images.js
@@ -51,6 +51,7 @@ GameImages.prototype = {
};
$(document).ready( function(){
- var images = ['images/tiles/StoneBlock.png', 'images/tiles/WallBlockTall.png','images/CharacterBoy.png', 'images/Bomb.png', 'images/FireBall.png']
- MrJaba.Bomberman.Images = new GameImages(images).initialize();
+ var playerImages = ['images/CharacterBoy-blue.png','images/CharacterBoy-brown.png','images/CharacterBoy-red.png','images/CharacterBoy-yellow.png'];
+ var images = ['images/tiles/StoneBlock.png', 'images/tiles/WallBlockTall.png', 'images/Bomb.png', 'images/FireBall.png'];
+ MrJaba.Bomberman.Images = new GameImages(images.concat(playerImages)).initialize();
});
View
6 public/javascripts/player.js
@@ -6,6 +6,12 @@ Player.prototype = {
protoSprite.initialize(MrJaba.Bomberman.uuid, MrJaba.Bomberman.Images.getImage('Bomb'), this.canvas );
var bomb = $.extend(protoSprite, new Bomb(this.x, this.y));
MrJaba.Bomberman.addBomb(MrJaba.Bomberman.uuid, bomb);
+ },
+
+ setImage:function(newImage){
+ this.imgHeight = newImage.height;
+ this.imgWidth = newImage.width;
+ this.img = newImage;
}
};
View
6 public/javascripts/sprite.js
@@ -3,6 +3,8 @@ Sprite.prototype = {
initialize:function(id, image, canvas) {
this.id = id;
this.img = image;
+ this.imgWidth = image.width;
+ this.imgHeight = image.height;
this.canvas = canvas;
this.x = 0;
this.y = -40;
@@ -35,7 +37,7 @@ Sprite.prototype = {
},
getFrameWidth:function(){
- return (this.frameWidth || this.img.width);
+ return (this.frameWidth || this.imgWidth);
},
getY:function() {
@@ -53,7 +55,7 @@ Sprite.prototype = {
},
getFrameHeight:function(){
- return (this.frameHeight || this.img.height);
+ return (this.frameHeight || this.imgHeight);
},
moveLeft:function(offset){
Please sign in to comment.
Something went wrong with that request. Please try again.