Skip to content

Commit

Permalink
Merge pull request #1 from naarcini/master
Browse files Browse the repository at this point in the history
Comments and aminations fix
  • Loading branch information
mayfer committed May 12, 2013
2 parents b10d59d + 35ca1d1 commit e9254ab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
9 changes: 8 additions & 1 deletion game.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ def assign_hat(self, session_id):

def dictify(self):
players = {}
hat = {'owner': self.hat.owner, 'x': self.hat.position.x, 'y': self.hat.position.y}
hat = self.hat.dictify()
for key, val in self.players.items():
players[key] = val.dictify()
return {'players': players, 'hat': hat}

class Player(object):
# Guy types should be updated if new character models added
guy_types = [1, 2, 3]

def __init__(self, session_id):
self.id = session_id
# Player initial spawn position
self.position = Position(0, 0)
self.movement = Movement(0, 0)
self.character = choice(self.guy_types)
Expand All @@ -48,9 +51,13 @@ def dictify(self):

class Hat(object):
def __init__(self):
# Initial starting position of hat defined here.
self.position = Position(700, 700)
self.owner = None

def dictify(self):
return {'owner': self.owner, 'x': self.position.x, 'y': self.position.y}

class Position(object):
def __init__(self, x, y):
self.x = x
Expand Down
35 changes: 27 additions & 8 deletions static/scripts/animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function gameCanvas(jq_elem, xpos, ypos, move_speed, max_x, max_y) {

var that = this;
this.network = null
this.hat = new Hat(null, 700, 700);
this.hat = new Hat(null, this.max_x, this.max_y);

// Methods
this.init = function() {
Expand All @@ -225,11 +225,13 @@ function gameCanvas(jq_elem, xpos, ypos, move_speed, max_x, max_y) {
this.xpos_img = this.background_width/2;
this.ypos_img = this.background_height/2;

// dude(player_id, xpos, ypos, dx, dy, move_speed, has_hat)
// dude(player_id, xpos, ypos, dx, dy, move_speed, has_hat, guy)
this.your_dude = new dude("you", this.xpos, this.ypos, this.dx, this.dy, this.move_speed, 0, 1);
//this.other_dudes["not_you"] = new dude("not_you", this.test_dude_x, 0, 10, 0, this.move_speed, 1);
//this.hat = new Hat(null, 700, 700);

// A tile refers to the picture of a guy at a given position (ie idle, right foot forward)
// Switching tiles causes animation
this.tile_num = 1;
this.total_tiles = 2;
this.frame_counter = 1;
Expand Down Expand Up @@ -314,6 +316,7 @@ function gameCanvas(jq_elem, xpos, ypos, move_speed, max_x, max_y) {
if( !this.hat.get_owner() ) {
this.draw_object(this.hat);
}

}

this.update_dude = function(dude, xpos, ypos, dx, dy, has_hat, guy) {
Expand Down Expand Up @@ -354,15 +357,31 @@ function gameCanvas(jq_elem, xpos, ypos, move_speed, max_x, max_y) {
draw_locations.push([draw_x, draw_y])
}
else {
if( Math.abs(x_off) < this.context.width/2 && Math.abs(y_off) < this.context.height/2) {
if( Math.abs(x_off) < this.context.width/2 ) {
draw_x = this.context.width/2 - img_width/2 + x_off;
draw_y = this.context.height/2 - img_height/2 - y_off;
draw_locations.push([draw_x, draw_y]);

if( Math.abs(y_off) < this.context.height/2 ) {
draw_y = this.context.height/2 - img_height/2 - y_off;
draw_locations.push([draw_x, draw_y]);
}

if( Math.abs(y_off_other) < this.context.height/2 ) {
draw_y = this.context.height/2 - img_height/2 - y_off_other;
draw_locations.push([draw_x, draw_y]);
}
}
if( Math.abs(x_off_other) < this.context.width/2 && Math.abs(y_off_other) < this.context.height/2) {
if( Math.abs(x_off_other) < this.context.width/2 ) {
draw_x = this.context.width/2 - img_width/2 + x_off_other;
draw_y = this.context.height/2 - img_height/2 - y_off_other;
draw_locations.push([draw_x, draw_y]);

if( Math.abs(y_off) < this.context.height/2 ) {
draw_y = this.context.height/2 - img_height/2 - y_off;
draw_locations.push([draw_x, draw_y]);
}

if( Math.abs(y_off_other) < this.context.height/2 ) {
draw_y = this.context.height/2 - img_height/2 - y_off_other;
draw_locations.push([draw_x, draw_y]);
}
}
}

Expand Down

0 comments on commit e9254ab

Please sign in to comment.