Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: databyss/shuttle
base: 1ece5990c4
...
head fork: databyss/shuttle
compare: 102bfa810e
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 44 additions and 7 deletions.
  1. +1 −1  index.html
  2. +5 −0 js/button.js
  3. +38 −6 js/shuttle.js
View
2  index.html
@@ -25,7 +25,7 @@
P to pause<br />
R to restart current map<br />
Z/X = last map/next map<br />
- THE ON SCREEN BUTTONS DO NOTHING RIGHT NOW<br />
+ <input type="checkbox" id="useTouch" /> Use Touch Input?<br />
<br />
View
5 js/button.js
@@ -63,6 +63,11 @@ Button.prototype.draw = function () {
if (this.image !== null) {
this.ctx.save();
this.ctx.globalAlpha = this.alpha;
+
+ // highlight depressed buttons
+ if(this.isDown) {
+ this.ctx.fillRect(this.pos.x, this.pos.y, this.drawWidth, this.drawHeight);
+ }
this.ctx.drawImage(this.image, this.pos.x, this.pos.y, this.drawWidth, this.drawHeight);
this.ctx.restore();
}
View
44 js/shuttle.js
@@ -55,6 +55,7 @@ define(['imageloader', 'player', 'level', 'gameengine', 'button'], function() {
if (evt.target.id === 'gameCanvas') {
for(var i = 0; i < buttons.length; i++) {
if (buttons[i].isInside({x: x, y: (c.height - y)})) {
+ buttons[i].untouch();
} else if(buttons[i].isDown) {
buttons[i].untouch();
}
@@ -214,15 +215,43 @@ define(['imageloader', 'player', 'level', 'gameengine', 'button'], function() {
timeChange = newUpdate - lastUpdate;
+ if($('#useTouch:checkbox').is(':checked')) {
+ for (i = 0; i < buttons.length; i++) {
+ if (buttons[i].isDown) {
+ if(buttons[i].id === 'up') {
+ input.up = true;
+ }
+ if(buttons[i].id === 'left') {
+ input.left = true;
+ }
+ if(buttons[i].id === 'right') {
+ input.right = true;
+ }
+ } else {
+ if(buttons[i].id === 'up') {
+ input.up = false;
+ }
+ if(buttons[i].id === 'left') {
+ input.left = false;
+ }
+ if(buttons[i].id === 'right') {
+ input.right = false;
+ }
+ }
+ }
+ }
+
// update engine
engine.update(timeChange);
// draw engine
engine.draw();
- // draw buttons
- for(i = 0; i < buttons.length; i++) {
- buttons[i].draw();
+ if($('#useTouch:checkbox').is(':checked')) {
+ // draw buttons
+ for(i = 0; i < buttons.length; i++) {
+ buttons[i].draw();
+ }
}
lastUpdate = newUpdate;
@@ -260,21 +289,21 @@ define(['imageloader', 'player', 'level', 'gameengine', 'button'], function() {
var tempButton = new Button(c, ctx, 'left');
tempButton.setImage(imageManager.getAsset('images/button_left.png'));
tempButton.setPosition({ x: 50, y: 50 });
- tempButton.setScale(2);
+ tempButton.setScale(1.5);
tempButton.alpha = 0.20;
buttons.push(tempButton);
tempButton = new Button(c, ctx, 'right');
tempButton.setImage(imageManager.getAsset('images/button_right.png'));
tempButton.setPosition({ x: 200, y: 50 });
- tempButton.setScale(2);
+ tempButton.setScale(1.5);
tempButton.alpha = 0.20;
buttons.push(tempButton);
tempButton = new Button(c, ctx, 'up');
tempButton.setImage(imageManager.getAsset('images/button_up.png'));
tempButton.setPosition({ x: 350, y: 50 });
- tempButton.setScale(2);
+ tempButton.setScale(1.5);
tempButton.alpha = 0.20;
buttons.push(tempButton);
});
@@ -312,6 +341,9 @@ define(['imageloader', 'player', 'level', 'gameengine', 'button'], function() {
window.addEventListener('mousedown', handleMouseDown, true);
window.addEventListener('mouseup', handleMouseUp, true);
window.addEventListener('mousemove', handleMouseMove, true);
+ window.addEventListener('touchstart', handleMouseDown, true);
+ window.addEventListener('touchend', handleMouseUp, true);
+ window.addEventListener('touchmove', handleMouseMove, true);
//BEGIN RAF SHIM
// reference: http://paulirish.com/2011/requestanimationframe-for-smart-animating/

No commit comments for this range

Something went wrong with that request. Please try again.