Permalink
Browse files

mostly finished ipad version

  • Loading branch information...
1 parent 83aee83 commit cca0bc8792907cd2cb21bf1b30c0c9464082399f @dmcinnes committed May 23, 2010
Showing with 49 additions and 96 deletions.
  1. +6 −86 game.js
  2. +8 −10 index.html
  3. +35 −0 ipad.js
View
@@ -3,87 +3,6 @@
// Copyright (c) 2010 Doug McInnes
//
-var ipad = navigator.userAgent.match(/iPad/i) != null;
-
-if (ipad) {
- $(function () {
-
- function handleTouch(e) {
- var touches = (e.type == 'touchend') ? e.changedTouches : e.touches;
-
- var ids = "";
- for (var i = 0; i < touches.length; i++) {
- var ele = document.elementFromPoint(touches[i].pageX, touches[i].pageY);
- ids += ele.id + " ";
- KEY_STATUS[ele.id] = (e.type != 'touchend');
- if (e.type != 'touchmove') {
- console.log(e.timeStamp + " :: " + e.type + " :: " + touches[i].target.id + " :: " + touches[i].identifier);
- }
- }
-
- if (e.type != 'touchmove') {
-// console.log(e.type + " :: " + e.target.id + " :: " + e.timeStamp);
-// var out = "";
-// for (f in e) {
-// out += f + " ";
-// }
-// console.log(out);
- }
-
- }
-
- var last = null;
- function handleTouchEnd(e) {
- var ele = document.elementFromPoint(e.changedTouches[0].pageX, e.changedTouches[0].pageY);
- KEY_STATUS[ele.id] = false;
- if (last) {
-// for (f in last) {
-// if (e[f].length) {
-// console.log(f + ":: " + last[f].length + ", " + e[f].length);
-// }
-// }
- var last = "";
- var current = "";
- for (var i = 0; i < e.type.length; i++) {
- last += last.type[i] + " ";
- current += e.type[i] + " ";
- }
- console.log("last type:: " + last);
- console.log("current type:: " + current);
- }
- last = e;
-// $('#console').prepend(ele.id + "<br/>");
-// var out = ""
-// for (f in e.changedTouches[0]) {
-// out += " ";
-// out += f;
-// }
-// console.log(ele.id + ' :: ' + e.changedTouches[0].target);
- }
-
-// document.addEventListener('touchstart', handleTouch, false);
-// document.addEventListener('touchmove', handleTouch, false);
-// document.addEventListener('touchend', handleTouch, false);
- $('#up, #left, #right, #space').bind('touchstart touchmove touchend', function (e) {
- handleTouch(e.originalEvent);
- e.preventDefault();
- }).bind('touchcancel', function (e) {
- console.log(e.type + ' target: ' + e.target.id);
- e.preventDefault();
- });
- $(document).bind('gesturestart gesturechange gestureend', function (e) {
-// console.log(e.type + ' target: ' + e.target.id);
- e.stopImmediatePropagation();
- e.preventDefault();
- });
-
-// $('.button').bind('mouseover mousedown mouseup', function (e) {
-// console.log(e.type + " :: " + e.target.id);
-// e.preventDefault();
-// });
- });
-}
-
KEY_CODES = {
32: 'space',
37: 'left',
@@ -998,9 +917,10 @@ Game = {
this.state = 'waiting';
},
waiting: function () {
- Text.renderText('Press Space to Start', 36, Game.canvasWidth/2 - 270, Game.canvasHeight/2);
- if (KEY_STATUS.space) {
+ Text.renderText(ipad ? 'Touch Sreen to Start' : 'Press Space to Start', 36, Game.canvasWidth/2 - 270, Game.canvasHeight/2);
+ if (KEY_STATUS.space || window.gameStart) {
KEY_STATUS.space = false; // hack so we don't shoot right away
+ window.gameStart = false;
this.state = 'start';
}
},
@@ -1086,6 +1006,8 @@ Game = {
this.timer = null;
this.state = 'waiting';
}
+
+ window.gameStart = false;
},
execute: function () {
@@ -1098,8 +1020,6 @@ Game = {
$(function () {
- if (ipad) setTimeout(function () {window.scrollTo(0,1);}, 10);
-
var canvas = $("#canvas");
Game.canvasWidth = canvas.width();
Game.canvasHeight = canvas.height();
@@ -1176,7 +1096,7 @@ $(function () {
extraDude.children = [];
var i, j = 0;
- var showFramerate = true;
+ var showFramerate = false;
var avgFramerate = 0;
var frameCount = 0;
var elapsedCounter = 0;
View
@@ -1,25 +1,24 @@
<html>
<head>
- <meta name="viewport" content="width=960; height=600; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<script src="jquery-1.4.1.min.js"></script>
<script src="vector_battle_regular.typeface.js"></script>
+ <script src="ipad.js"></script>
<script src="game.js"></script>
<style>
- #canvas { border:1px solid black; top:20px; left:20px; }
- #container { position:relative; top:20px; width:962px; }
- .button { position:absolute; border:1px solid green; display:block; }
- .selected { background: green; }
+ #canvas { border:1px solid black; top:0px; left:0px; }
+ #game-container { position:relative; top:0px; left:0px; }
+ .button { position:absolute; border:1px solid black; }
+ #left-controls { position:absolute; left:1px; bottom:0px; display:none; }
+ #right-controls { position:absolute; right:1px; bottom:0px; display:none; }
#up { width:200px; height:100px; bottom:100px;}
#left { width:100px; height:100px; bottom:0px;}
#right { width:100px; height:100px; bottom:0px; left:100px; }
#space { width:200px; height:200px; bottom:0px; right:0px; }
- #console { position:absolute; border: 1px solid green; top:0px; right:0px; width: 400px; height: 200px; overflow:auto;}
- * {-webkit-user-select: none;}
</style>
</head>
<body>
- <div id="container">
- <canvas id="canvas" height="600" width="960"></canvas>
+ <div id="game-container">
+ <canvas id="canvas" width="780" height="540"></canvas>
<div id="left-controls">
<div id="up" class='button'>THRUST</div>
<div id="left" class='button'>LEFT</div>
@@ -28,7 +27,6 @@
<div id="right-controls">
<div id="space" class='button'>FIRE</div>
</div>
- <div id="console"></div>
</div>
</body>
</html>
View
@@ -0,0 +1,35 @@
+var ipad = navigator.userAgent.match(/iPad/i) != null;
+
+if (ipad) {
+ $(function () {
+ $('#left-controls, #right-controls').show();
+ $('body > *').hide();
+ $('body').css('margin', '0px').css('background', 'black');
+ $('#game-container').width(1024).css('top', 26).show();
+ $('#canvas').attr('width', 1020).attr('height', 660).css('background', 'white').css('margin', '0 1');
+
+ $('head').prepend($('<meta/>').attr('name', 'viewport').attr('content', 'width=device-width; height=device-height; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;'));
+
+ $('#left-controls, #right-controls').bind('touchstart touchmove touchend', function (e) {
+ if (e.type != 'touchend') {
+ for (k in KEY_STATUS) {
+ KEY_STATUS[k] = false;
+ }
+ }
+ var touches = e.type == 'touchend' ? e.originalEvent.changedTouches : e.originalEvent.touches
+ for (var i = 0; i < touches.length; i++) {
+ var ele = document.elementFromPoint(touches[i].pageX, touches[i].pageY);
+ KEY_STATUS[ele.id] = (e.type != 'touchend');
+ }
+ });
+
+ $(document).bind('touchstart', function (e) {
+ window.gameStart = true;
+ });
+
+ $(document).bind('gesturestart gesturechange gestureend touchstart touchmove touchend', function (e) {
+ e.preventDefault();
+ });
+ });
+}
+

0 comments on commit cca0bc8

Please sign in to comment.