Skip to content

Commit

Permalink
Fixed some stuff. I think this actually fixes #11, believe it or not.
Browse files Browse the repository at this point in the history
  • Loading branch information
Continuities committed Aug 22, 2014
1 parent 7b05eef commit 450c5ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
32 changes: 17 additions & 15 deletions www/js/app/action/moveto.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define(['app/action/action'], function(Action) {
var _action = this;
this._entity = entity;
var func = this.useMove ? "move" : "moveTo";
this._dir = whichSide(entity, this.target);
entity[func](this.useMove ? _action.target.p() : _action.target, (function(entity) {
entity.makeIdle();
if(entity.action == this) {
Expand All @@ -21,23 +22,24 @@ define(['app/action/action'], function(Action) {

MoveTo.prototype.doFrameAction = function(frame) {
var _this = this;
require(['app/world'], function(W) {
if(frame == 3 && _this._entity == W.getDude()) {
// Reset the dude's move action every step to make sure he's
// still doing the right thing.
var closest = W.findClosestMonster();
if(closest == null) {
closest = W.findClosestLoot();
}
if(closest == null) {
_this.terminateAction(_this._entity);
} else if(closest != _this.target) {
_this.target = closest;
_this.doAction(_this._entity);
}
var W = require('app/world');
if(frame == 3 && this._entity == W.getDude()) {
// Reset the dude's move action every step to make sure he's
// still doing the right thing.
var closest = W.findClosestMonster() || w.findClosestLoot();
if(closest == null) {
this.terminateAction(this._entity);
} else if(closest != this.target ||
whichSide(this._entity, this.target) != this._dir) {
this.target = closest;
this.doAction(this._entity);
}
});
}
};

function whichSide(entity, target) {
return entity.p() < target.p() ? 'right' : 'left';
}

return MoveTo;
});
6 changes: 3 additions & 3 deletions www/js/app/graphics/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ define(['jquery', 'app/eventmanager', 'app/textStore', 'app/gameoptions',
}

function setEntityPosition(entity, pos) {
var el = entity.el ? entity.el() : entity;
var val = 'translateX(' + (pos - (entity.width() / 2)) + 'px)';
entity.el().css({
el.css({
'transform': val,
'-webkit-transform': val,
'-moz-transform': val,
Expand Down Expand Up @@ -678,8 +679,7 @@ define(['jquery', 'app/eventmanager', 'app/textStore', 'app/gameoptions',
pos = this.worldWidth() - 20;
entity.p(pos);
}
var el = entity.el ? entity.el() : entity;
el.css('transform', 'translateX(' + (pos - (el.width() / 2)) + 'px)');
setEntityPosition(entity, pos);
},

selectTile: function(tile) {
Expand Down

0 comments on commit 450c5ca

Please sign in to comment.