Skip to content

Commit

Permalink
Merge pull request #21 from erosilk/gh-pages
Browse files Browse the repository at this point in the history
Add auto-shifting
  • Loading branch information
RobertoGonzalez authored Aug 6, 2017
2 parents 150d3af + 4314a91 commit a38129e
Show file tree
Hide file tree
Showing 7 changed files with 2,671 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Then you just include **jquery** and **blockrain** and setup the game with **$('

```html
<!-- The stylesheet should go in the <head>, or be included in your CSS -->
<link rel="stylesheet" src="blockrain.css">
<link rel="stylesheet" href="blockrain.css">

<!-- jQuery and Blockrain.js -->
<script src="jquery.js"></script>
Expand Down
46 changes: 43 additions & 3 deletions dist/blockrain.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,51 @@
orientation: 0, // 4 possible

rotate: function(direction) {
var orientation = (this.orientation + (direction === 'left' ? 1 : -1) + 4) % 4;
var orientation =
(this.orientation + (direction === "left" ? 1 : -1) + 4) % 4;

if (!game._checkCollisions(
this.x,
this.y,
this.getBlocks(orientation)
)) {
this.orientation = orientation;
game._board.renderChanged = true;
} else {
var ogOrientation = this.orientation;
var ogX = this.x;
var ogY = this.y;

//TODO - when past limit - auto shift and remember that too!
if (!game._checkCollisions(this.x, this.y, this.getBlocks(orientation))) {
this.orientation = orientation;

while (this.x >= game._BLOCK_WIDTH - 2) {
this.x--;
}
while (this.x < 0) {
this.x++;
}

if (this.blockType === "line" && this.x === 0) this.x++;

if ( game._checkCollisions(
this.x,
this.y,
this.getBlocks(orientation)
)
) {
this.y--;
if (
game._checkCollisions(
this.x,
this.y,
this.getBlocks(orientation)
)
) {
this.x = ogX;
this.y = ogY;
this.orientation = ogOrientation;
}
}
game._board.renderChanged = true;
}
},
Expand Down
2 changes: 1 addition & 1 deletion dist/blockrain.jquery.min.js

Large diffs are not rendered by default.

Binary file modified dist/blockrain.zip
Binary file not shown.
Loading

1 comment on commit a38129e

@mikirobles
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 😁

Please sign in to comment.