From 3a25659629273d5a155151885d87924eee07eaba Mon Sep 17 00:00:00 2001 From: naarcini Date: Tue, 14 May 2013 00:19:28 -0400 Subject: [PATCH 1/4] Walk speed fix and start to speech --- static/scripts/animations.js | 22 ++++++++++---- static/scripts/speech.js | 56 ++++++++++++++++++++++++++++++++++++ templates/index.html | 10 ++++++- 3 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 static/scripts/speech.js diff --git a/static/scripts/animations.js b/static/scripts/animations.js index f4eeb7b..c6c9de9 100644 --- a/static/scripts/animations.js +++ b/static/scripts/animations.js @@ -407,25 +407,37 @@ function gameCanvas(jq_elem, xpos, ypos, move_speed, max_x, max_y) { // Down this.dy = this.move_speed; } + + if( this.dx != 0 && this.dy != 0 ) { + this.dx = this.dx > 0 ? this.move_speed / 2 : -this.move_speed / 2; + this.dy = this.dy > 0 ? this.move_speed / 2 : -this.move_speed / 2; + } } this.move_stop = function( keyCode ) { - if( keyCode == 37 && this.dx == -this.move_speed ) { + if( keyCode == 37 && this.dx < 0 ) { // Left this.dx = 0; } - else if( keyCode == 38 && this.dy == -this.move_speed ) { + else if( keyCode == 38 && this.dy < 0 ) { // Up this.dy = 0; } - else if( keyCode == 39 && this.dx == this.move_speed ) { + else if( keyCode == 39 && this.dx > 0 ) { // Right this.dx = 0; } - else if( keyCode == 40 && this.dy == this.move_speed ) { + else if( keyCode == 40 && this.dy > 0 ) { // Down this.dy = 0; } + + if( this.dx != 0 ) { + this.dx = this.dx > 0 ? this.move_speed : -this.move_speed ; + } + if( this.dy != 0 ) { + this.dy = this.dy > 0 ? this.move_speed : -this.move_speed ; + } } this.change_speed = function( speed ) { @@ -763,4 +775,4 @@ function gameCanvas(jq_elem, xpos, ypos, move_speed, max_x, max_y) { this.state = 'stopped'; cancelAnimFrame(this.anim_frame); } -} +} \ No newline at end of file diff --git a/static/scripts/speech.js b/static/scripts/speech.js new file mode 100644 index 0000000..3ffd9c1 --- /dev/null +++ b/static/scripts/speech.js @@ -0,0 +1,56 @@ +(function( $ ) { + // Constants + var PROMPT_NAME = "speechJS_prompt"; + + // Private variables + var message = ""; + var listening = false; + var character_limit = 140; + + // plugin definition + $.fn.speech = function( action, arg ) { + if( action == "probe" ) { + return [message, listening]; + } + else if( action == "set_limit" ) { + character_limit = arg; + return true; + } + else if( action == "get_limit" ) { + return character_limit; + } + else if( action == "trigger" ) { + console.log(this); + return trigger(); + } + else if ( action == "add_char" ) { + } + }; + + // Private methods + function trigger() { + // Toggle listening + listening = !listening; + + // Start listening to keyboard input + if( listening ) { + message = ""; + display_prompt(); + } + else { + remove_prompt(); + } + + return message; + }; + + function display_prompt() { + var prompt = '' + + '' + + ''; + }; + + function remove_prompt() { + }; + +})( jQuery ); \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 8fddaf3..e22efe1 100644 --- a/templates/index.html +++ b/templates/index.html @@ -14,6 +14,7 @@ + - From 9b46e39551a127d8a4039fe650331e1595c646a0 Mon Sep 17 00:00:00 2001 From: naarcini Date: Fri, 30 Aug 2013 00:29:24 -0700 Subject: [PATCH 3/4] Boot players when idle --- messenger.py | 8 +++- static/scripts/animations.js | 71 ++++++++---------------------------- static/scripts/network.js | 1 + 3 files changed, 24 insertions(+), 56 deletions(-) diff --git a/messenger.py b/messenger.py index 15f73d5..c642ed1 100644 --- a/messenger.py +++ b/messenger.py @@ -25,7 +25,13 @@ def on_open(self, info): def on_message(self, text): message = json.loads(text) if message['action'] == 'move': - player = message['body']['session'] + try: + player = message['body']['session'] + except KeyError: + self.debug() + self.send_obj('ack', {}) + return + x = message['body']['x'] y = message['body']['y'] dx = message['body']['dx'] diff --git a/static/scripts/animations.js b/static/scripts/animations.js index 53fc237..c621bd5 100644 --- a/static/scripts/animations.js +++ b/static/scripts/animations.js @@ -169,41 +169,6 @@ function dude(player_id, xpos, ypos, dx, dy, move_speed, has_hat, guy) { this.set_message = function(message) { this.message = message; } - -/* - talk = function( ctx, width, height, text ) { - var x = xpos + dude_size + 5; - var y = ypos - 5; - - var curvy_width = 20; - var curvy_height = 20; - var curviness = 10; - - // Draw curvy part - ctx.beginPath(); - ctx.moveTo(x, y); - ctx.quadraticCurveTo(x+curvy_width/2+curviness, y-curvy_height/2, x, y-curvy_height); - ctx.moveTo(x, y); - ctx.quadraticCurveTo(x+curvy_width/2+curviness, y-curvy_height/2, x+curvy_height, y-curvy_height); - - //Draw Rectangular part - var rect_x = x + curvy_width/2 - width/2; - var rect_y = y - curvy_height - height; - - ctx.moveTo(rect_x, rect_y+radius); - ctx.lineTo(rect_x, rect_y+height-radius); - ctx.quadraticCurveTo(rect_x, rect_y+height, rect_x+radius, rect_y+height); - ctx.lineTo(rect_x+width/2-curvy_width/2, rect_y+height); - ctx.moveTo(rect_x+width/2+curvy_width/2, rect_y+height); - ctx.lineTo(rect_x+width-radius, rect_y+height); - ctx.quadraticCurveTo(rect_x+width, rect_y+height, rect_x+width, rect_y+height-radius); - ctx.lineTo(rect_x+width, rect_y+radius); - ctx.quadraticCurveTo(rect_x+width, rect_y, rect_x+width-radius, rect_y); - ctx.lineTo(rect_x+radius, rect_y); - ctx.quadraticCurveTo(rect_x, rect_y, rect_x, rect_y+radius); - ctx.stroke(); - } - */ } @@ -223,6 +188,8 @@ function gameCanvas(jq_elem, xpos, ypos, move_speed, max_x, max_y) { this.other_dudes = {}; this.messageTimeout = 500; this.messageCounter = 0; + this.idleTimeout = 1000; + this.idleTimer = 0; var that = this; this.network = null @@ -296,6 +263,11 @@ function gameCanvas(jq_elem, xpos, ypos, move_speed, max_x, max_y) { this.messageCounter = 0; this.your_dude.set_message(null); } + + this.idleTimer++; + if ( this.idleTimer >= this.idleTimeout ) { + location.reload(true); + } // Draw player this.draw_object(this.your_dude); @@ -329,18 +301,10 @@ function gameCanvas(jq_elem, xpos, ypos, move_speed, max_x, max_y) { this.hat.set_owner(window.session_id); this.your_dude.set_hat_status(1); } + else { + this.draw_object(this.hat); + } } - else if ( this.hat.get_owner() != window.session_id ){ - this.your_dude.set_hat_status(0); - } - else { - this.hat.set_position(this.your_dude.get_position()[0], this.your_dude.get_position()[1]); - } - - if( !this.hat.get_owner() ) { - this.draw_object(this.hat); - } - } this.update_dude = function(dude, xpos, ypos, dx, dy, has_hat, guy) { @@ -495,6 +459,9 @@ function gameCanvas(jq_elem, xpos, ypos, move_speed, max_x, max_y) { this.dx = this.dx > 0 ? this.move_speed / 2 : -this.move_speed / 2; this.dy = this.dy > 0 ? this.move_speed / 2 : -this.move_speed / 2; } + + this.idleTimer = 0; + } this.move_stop = function( keyCode ) { @@ -521,6 +488,9 @@ function gameCanvas(jq_elem, xpos, ypos, move_speed, max_x, max_y) { if( this.dy != 0 && this.dx == 0 ) { this.dy = this.dy > 0 ? this.move_speed : -this.move_speed ; } + + this.idleTimer = 0; + } this.change_speed = function( speed ) { @@ -870,20 +840,11 @@ function speech(character_limit) { return true; } - // Some character - if( code == 32 || (code >= 32 ) ) { - //console.log(code, String.fromCharCode(code)); - } - // Backspace - else if ( code == 8 ) { - //console.log("Backspace"); - } } this.trigger = function() { // Toggle listening this.listening = !this.listening; - //console.log(this.listening); // Start listening to keyboard input if( this.listening ) { diff --git a/static/scripts/network.js b/static/scripts/network.js index 152a875..e80be9c 100644 --- a/static/scripts/network.js +++ b/static/scripts/network.js @@ -46,6 +46,7 @@ function Networking(game) { $.each(that.game.other_dudes, function(session, player) { if(!(session in state.players)) { if( hat_owner == session ) { + that.game.hat.set_position(that.game.other_dudes[session].get_position()[0], that.game.other_dudes[session].get_position()[1]); that.game.hat.set_owner(0); } delete that.game.other_dudes[session]; From eadaecc7f36fe232837c92efd075c40e5134f451 Mon Sep 17 00:00:00 2001 From: naarcini Date: Fri, 30 Aug 2013 00:48:26 -0700 Subject: [PATCH 4/4] Create README.md --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..e64ebba --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +hat +=== + +"Wear a Hat". Browser-based multiplayer game. Currently only tested and functioning on Google Chrome. + + +Why +== + +This is just for fun. The point of the game is to find and hold on to the one hat that exists in the world. The only way to lose the hat is to close the window or stay idle for some time. Press enter to open the chat prompt. + +Instructions +== + +1. Get the files +2. "python ./loop.py" +3. Play with people on your local network (your_ip_address:8000)