Merge branch 'master' into gh-pages
This commit is contained in:
@@ -5,10 +5,10 @@ Made just for fun. [Play it here!](http://gabrielecirulli.github.io/2048/)
|
||||
|
||||
[](http://pictures.gabrielecirulli.com/2048-20140309-234100.png)
|
||||
|
||||
That screenshot is fake by, the way. I never reached 2048 :smile:
|
||||
That screenshot is fake, by the way. I never reached 2048 :smile:
|
||||
|
||||
## Contributing
|
||||
Changes and improvements are more than welcome! Feel free to fork and open a pull request. Please make your changes in a specifically made branch and request to pull on `master`! If you can, please make sure the game fully works before sending the PR, as that will help speed up the process.
|
||||
Changes and improvements are more than welcome! Feel free to fork and open a pull request. Please make your changes in a specific branch and request to pull into `master`! If you can, please make sure the game fully works before sending the PR, as that will help speed up the process.
|
||||
|
||||
You can find the same information in the [contributing guide.](https://github.com/gabrielecirulli/2048/blob/master/CONTRIBUTING.md)
|
||||
|
||||
@@ -16,4 +16,4 @@ You can find the same information in the [contributing guide.](https://github.co
|
||||
2048 is licensed under the [MIT license.](https://github.com/gabrielecirulli/2048/blob/master/LICENSE.txt)
|
||||
|
||||
## Donations
|
||||
I made this in my spare time, and it's hosted on GitHub (which means I don't have any hosting costs), but if you enjoyed the game and feel like you'd like to buy me a coffee, you can me donate at the `1Ec6onfsQmoP9kkL3zkpB6c5sA4PVcXU2i` BTC address. Thank you very much!
|
||||
I made this in my spare time, and it's hosted on GitHub (which means I don't have any hosting costs), but if you enjoyed the game and feel like buying me coffee, you can donate at my BTC address: `1Ec6onfsQmoP9kkL3zkpB6c5sA4PVcXU2i`. Thank you very much!
|
||||
|
||||
@@ -85,7 +85,6 @@
|
||||
</div>
|
||||
|
||||
<script src="js/animframe_polyfill.js"></script>
|
||||
<script src="js/hammer.min.js"></script>
|
||||
<script src="js/keyboard_input_manager.js"></script>
|
||||
<script src="js/html_actuator.js"></script>
|
||||
<script src="js/grid.js"></script>
|
||||
|
||||
Vendored
-9
File diff suppressed because one or more lines are too long
@@ -57,20 +57,32 @@ KeyboardInputManager.prototype.listen = function () {
|
||||
retry.addEventListener("click", this.restart.bind(this));
|
||||
|
||||
// Listen to swipe events
|
||||
var gestures = [Hammer.DIRECTION_UP, Hammer.DIRECTION_RIGHT,
|
||||
Hammer.DIRECTION_DOWN, Hammer.DIRECTION_LEFT];
|
||||
|
||||
var touchStartClientX, touchStartClientY;
|
||||
var gameContainer = document.getElementsByClassName("game-container")[0];
|
||||
var handler = Hammer(gameContainer, {
|
||||
drag_block_horizontal: true,
|
||||
drag_block_vertical: true
|
||||
});
|
||||
|
||||
handler.on("swipe", function (event) {
|
||||
event.gesture.preventDefault();
|
||||
mapped = gestures.indexOf(event.gesture.direction);
|
||||
gameContainer.addEventListener("touchstart", function(event) {
|
||||
if (event.touches.length > 1) return;
|
||||
|
||||
if (mapped !== -1) self.emit("move", mapped);
|
||||
touchStartClientX = event.touches[0].clientX;
|
||||
touchStartClientY = event.touches[0].clientY;
|
||||
event.preventDefault();
|
||||
});
|
||||
gameContainer.addEventListener("touchmove", function(event) {
|
||||
event.preventDefault();
|
||||
});
|
||||
gameContainer.addEventListener("touchend", function(event) {
|
||||
if (event.touches.length > 0) {
|
||||
return;
|
||||
}
|
||||
var dx = event.changedTouches[0].clientX - touchStartClientX;
|
||||
var absDx = Math.abs(dx);
|
||||
|
||||
var dy = event.changedTouches[0].clientY - touchStartClientY;
|
||||
var absDy = Math.abs(dy);
|
||||
|
||||
if (Math.max(absDx, absDy) > 10) {
|
||||
// (right : left) : (down : up)
|
||||
self.emit("move", absDx > absDy ? (dx > 0 ? 1 : 3) : (dy > 0 ? 2 : 0));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user