Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hand = (function() {
- function hand() {
- this.held_item = null;
- }
- hand.prototype.interact_at = function(x, y) {
- if (this.held_item !== null) {
- return this.drop_tile_if_over_it(x, y);
- } else {
- return this.pick_up_tile_if_over_it(x, y);
- }
- };
- hand.prototype.move_to = function(x, y) {
- if (this.held_item !== null) {
- return this.held_item.drag_to(x, y);
- }
- };
- hand.prototype.can_interact_with = function(touchable_game_pieces) {
- return this.game_pieces = touchable_game_pieces;
- };
- hand.prototype.drop_tile_if_over_it = function(x, y) {
- var game_piece, _i, _len, _ref, _results;
- _ref = this.game_pieces;
- _results = [];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- game_piece = _ref[_i];
- if (game_piece.is_at(x, y)) {
- this.held_item = null;
- break;
- }
- }
- return _results;
- };
- hand.prototype.pick_up_tile_if_over_it = function(x, y) {
- var game_piece, _i, _len, _ref, _results;
- _ref = this.game_pieces;
- _results = [];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- game_piece = _ref[_i];
- if (game_piece.is_at(x, y)) {
- this.held_item = game_piece;
- this.held_item.start_dragging(x, y);
- break;
- }
- }
- return _results;
- };
- return hand;
- })();
Add Comment
Please, Sign In to add comment