Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed player restarts

  • Loading branch information...
commit 9aaa2bde4e87a01966261fe5cd2bad4469b40eb1 1 parent 5c7814d
@MrJaba MrJaba authored
View
6 controllers/game_controller.rb
@@ -31,7 +31,7 @@ def push_bombs
def receive_register(message, uuid=nil)
player_uuid = UUID.new.generate
- GameController.player_states[player_uuid] = {:x => 0, :y => 0, :state => 'restart', :score => 0}
+ GameController.player_states[player_uuid] = {:x => 0, :y => 0, :score => 0}
render ({:type => 'uuid', :uuid => player_uuid, :class_id => self.object_id}).to_json
end
@@ -53,6 +53,10 @@ def receive_send_kill_player(message, uuid)
restart_player(message['data']['killed'])
end
+ def receive_send_reset_state(message, uuid)
+ GameController.player_states[uuid].delete(:state)
+ end
+
def restart_player(uuid)
GameController.player_states[uuid][:x] = 0
GameController.player_states[uuid][:y] = 0
View
16 public/javascripts/game.js
@@ -89,6 +89,19 @@ MrJaba.Bomberman = function(){
MrJaba.Bomberman.GameClient.trigger('send_kill_player', uuid);
}
+ function isOpponent(uuid){
+ return uuid !== MrJaba.Bomberman.uuid;
+ }
+
+ function iAmRestarting(uuid, position){
+ return (uuid === MrJaba.Bomberman.uuid && position.state === "restart");
+ }
+
+ function restartMe(position){
+ MrJaba.Bomberman.me.setX(parseInt(position.x)); MrJaba.Bomberman.me.setY(parseInt(position.y))
+ MrJaba.Bomberman.GameClient.trigger('send_reset_state', "restart");
+ }
+
function initCharacter(id){
var me = new Sprite();
me.initialize(id, MrJaba.Bomberman.Images.getImage('CharacterBoy'), canvasNode());
@@ -149,7 +162,8 @@ MrJaba.Bomberman = function(){
updateOpponentPositions: function(positions){
$("#scores").html("");
$.each(positions, function(uuid, position){
- if( uuid !== MrJaba.Bomberman.uuid ){ MrJaba.Bomberman.opponents[uuid] = {x: parseInt(position.x), y:parseInt(position.y)} }
+ if( isOpponent(uuid) ){ MrJaba.Bomberman.opponents[uuid] = {x:parseInt(position.x), y:parseInt(position.y)} }
+ if( iAmRestarting(uuid, position) ){ restartMe(position); }
var style = ( uuid === MrJaba.Bomberman.uuid ) ? "background-color:red;" : ""
$("#scores").prepend("<ul style='"+style+"'>"+uuid+':'+position.score+"</ul>");
})
View
5 public/javascripts/game_client.js
@@ -42,6 +42,10 @@ var GameClient = function(){
return {killed:uuid};
}
+ var sendResetState = function(state){
+ return state;
+ }
+
var handleEvent = function(eventName, message){
var handler = callbacks[eventName];
if(typeof handler === undefined) return;
@@ -67,6 +71,7 @@ var GameClient = function(){
this.bind('send_bomb_drop', notifyBombDrop);
this.bind('send_bomb_detonate', notifyBombDetonate);
this.bind('send_kill_player', notifyPlayerKill);
+ this.bind('send_reset_state', sendResetState);
}
$(document).bind( 'initDone', function(){ MrJaba.Bomberman.GameClient = new GameClient() } );
Please sign in to comment.
Something went wrong with that request. Please try again.