├── todo.txt ├── index.html ├── Vector2.js ├── DrawText.js └── OneKeyUpDown.js /todo.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/misohena/js_1keyupdown/master/todo.txt -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/misohena/js_1keyupdown/master/index.html -------------------------------------------------------------------------------- /Vector2.js: -------------------------------------------------------------------------------- 1 | 2 | function Vector2() 3 | { 4 | this.initialize.apply(this, arguments); 5 | } 6 | 7 | Vector2.prototype = { 8 | initialize: function(x, y) 9 | { 10 | this.x = x; 11 | this.y = y; 12 | }, 13 | 14 | clone: function() 15 | { 16 | return new Vector2(this.x, this.y); 17 | }, 18 | 19 | lengthSq: function() 20 | { 21 | return this.x*this.x + this.y*this.y; 22 | }, 23 | 24 | length: function() 25 | { 26 | return Math.sqrt(this.lengthSq()); 27 | }, 28 | 29 | add: function(rhs) 30 | { 31 | return new Vector2(this.x + rhs.x, this.y + rhs.y); 32 | }, 33 | 34 | subtract: function(rhs) 35 | { 36 | return new Vector2(this.x - rhs.x, this.y - rhs.y); 37 | }, 38 | 39 | multiply: function(k) 40 | { 41 | return new Vector2(this.x * k, this.y * k); 42 | }, 43 | 44 | dot: function(rhs) 45 | { 46 | return this.x * rhs.x + this.y * rhs.y; 47 | }, 48 | 49 | perpdot: function(rhs) 50 | { 51 | return this.x * rhs.y - this.y * rhs.x; 52 | }, 53 | 54 | distanceFrom: function(v) 55 | { 56 | return this.subtract(v).length(); 57 | }, 58 | 59 | distanceSqFrom: function(v) 60 | { 61 | return this.subtract(v).lengthSq(); 62 | } 63 | }; 64 | -------------------------------------------------------------------------------- /DrawText.js: -------------------------------------------------------------------------------- 1 | var font = { 2 | 'A':[[26,232,45,195,114,39,119,30,131,45,172,116,178,126,188,154,206,194,232,234],[69,146,189,149]], 3 | 'B':[[31,22,31,249],[36,25,158,28,179,40,204,61,206,72,205,82,197,103,184,120,174,127,164,130,131,132,35,130],[35,130,162,133,193,144,202,152,212,172,212,183,206,203,193,220,183,224,96,245,46,243,43,241]], 4 | 'C':[[205,72,196,52,187,46,165,37,132,29,101,38,68,67,49,108,49,118,52,174,65,196,74,204,104,219,160,232,181,229,189,223,200,218,208,208,212,196,215,176,215,175]], 5 | 'D':[[32,23,33,225],[35,24,98,31,204,79,209,88,220,118,212,160,194,190,173,214,151,222,107,229,39,229]], 6 | 'E':[[36,16,37,215],[38,20,163,20],[40,120,157,120],[40,225,217,225]], 7 | 'F':[[21,21,23,241],[26,22,203,22],[26,129,127,130,143,130]], 8 | 'G':[[201,69,196,49,180,36,149,27,95,35,77,50,67,70,47,144,53,186,67,213,92,234,102,237,124,238,175,231,194,222,201,213,206,202,208,192,213,157],[180,148,200,151,236,155],[223,153,221,241]], 9 | 'H':[[29,19,35,56,34,236],[35,113,63,116,219,117],[210,18,222,71,220,227]], 10 | 'I':[[96,10,138,11],[119,13,119,248],[90,245,161,247]], 11 | 'J':[[152,11,205,9],[185,14,188,37,180,174,160,214,145,227,135,227,94,221,53,202,28,181,24,170,17,139,17,138]], 12 | 'K':[[32,10,35,209,39,233],[36,163,56,136,63,128,81,99,94,89,194,28,198,24],[113,91,200,225]], 13 | 'L':[[36,16,39,220,44,229,56,227,227,223]], 14 | 'M':[[25,18,33,54,32,218],[24,23,62,73,106,130,115,124,142,98,156,71,164,60,173,52,211,25,217,35,217,45,217,219]], 15 | 'N':[[32,233,50,44,57,55,186,236,192,228,195,216,203,152,209,117,213,83,213,21]], 16 | 'O':[[195,65,172,42,150,33,107,25,87,31,79,37,63,51,51,70,35,111,37,165,54,205,80,228,100,236,111,236,142,231,181,214,196,197,210,169,221,117,217,97,206,80,200,69]], 17 | 'P':[[38,22,44,55,41,234],[43,24,147,26,177,38,209,64,227,94,230,118,226,140,208,163,196,163,49,164]], 18 | 'Q':[[136,231,105,226,45,196,38,176,38,92,56,50,71,36,92,27,126,20,158,24,178,34,213,61,218,70,227,88,229,110,225,173,211,204,188,226,157,230,114,224,78,204,82,194,92,190,115,186,147,190,217,210,247,212]], 19 | 'R':[[35,18,35,229],[40,22,59,16,155,19,197,32,205,42,210,61,203,79,189,93,169,101,136,113,105,122,40,124],[128,122,202,227]], 20 | 'S':[[204,45,180,24,137,14,96,19,74,28,56,42,52,54,54,65,64,87,80,102,99,110,191,147,205,163,209,174,209,184,204,204,197,212,188,217,177,219,74,225,45,212,31,198,28,192]], 21 | 'T':[[27,20,215,22],[114,25,115,233]], 22 | 'U':[[39,23,46,160,67,224,76,230,96,238,128,242,192,239,211,227,216,217,216,207,230,23]], 23 | 'V':[[23,23,124,234,130,225,142,201,164,164,181,133,191,111,222,57,228,47,243,32,246,28]], 24 | 'W':[[11,21,13,45,70,224,69,213,73,192,96,135,104,113,124,55,128,35,133,46,184,209,191,229,191,218,204,109,229,45,237,32]], 25 | 'X':[[31,16,111,93,211,234],[219,18,167,61,153,73,145,87,135,97,93,142,44,222]], 26 | 'Y':[[19,21,121,94,136,108,141,99,176,58,224,14],[132,109,130,233]], 27 | 'Z':[[37,24,212,32,196,55,141,123,126,142,118,150,63,226,73,226,225,224]], 28 | '0':[[119,232,85,228,65,219,50,204,47,194,35,139,39,84,60,30,73,15,83,11,115,4,148,7,197,28,199,38,210,156,181,227,164,239,154,240,114,238,104,233,96,229],[218,6,55,250]], 29 | '1':[[79,51,108,37,130,14,134,24,134,34,133,234],[83,242,103,243,155,242,169,242]], 30 | '2':[[65,96,55,77,53,55,56,43,69,26,89,16,110,14,142,21,166,41,169,52,170,72,165,114,159,123,150,131,102,172,85,187,78,196,61,240,210,240]], 31 | '3':[[57,54,58,34,66,26,84,17,117,8,163,14,183,24,190,33,198,52,198,73,193,82,184,90,165,102,125,113,167,117,184,128,194,148,201,181,199,204,194,214,184,219,174,221,143,224,63,210,46,189,42,180]], 32 | '4':[[169,19,140,46,125,62,87,91,78,97,52,121,21,166,33,166,224,164],[164,22,162,114,161,128,157,138,156,151,159,224,157,231]], 33 | '5':[[66,18,62,56,53,118,61,170,70,165,78,158,90,155,115,141,127,136,158,131,170,135,200,150,224,171,226,181,225,192,221,202,209,222,193,237,183,237,55,232,49,226],[69,38,221,36]], 34 | '6':[[192,54,178,40,159,31,138,27,107,29,96,34,69,49,55,64,48,84,48,179,52,189,62,209,78,223,97,230,171,230,180,225,187,217,190,207,200,155,196,124,188,115,178,111,138,103,117,107,88,119,63,141,56,150]], 35 | '7':[[44,15,44,55],[45,16,198,25,169,69,150,134,140,241]], 36 | '8':[[183,30,166,15,145,10,77,15,59,27,54,37,53,48,58,59,71,78,79,84,134,112,143,117,170,137,176,146,189,173,189,203,180,221,161,232,149,233,68,225,61,217,56,208,51,189,55,176,71,135,80,125,97,110,169,57,184,22]], 37 | '9':[[192,41,182,23,173,18,162,15,132,9,97,12,65,27,59,35,57,46,61,67,67,76,76,84,105,98,136,97,145,92,184,61,150,238]], 38 | '!':[[120,224,116,206,126,201,137,203,145,209,145,219,135,231,119,228],[125,159,133,21,156,31,156,43,153,53,138,166,128,169,127,169]], 39 | ':':[[119,75,108,61,116,55,126,56,137,66,127,79,118,78],[117,189,107,173,112,164,122,164,132,170,136,180,130,188,120,187,112,185]], 40 | '.':[[120,232,109,216,118,211,128,210,135,218,135,228,125,230,122,230]] 41 | }; 42 | 43 | function drawText(ctx, text, x, y, w, h) 44 | { 45 | var ti; 46 | for(ti = 0; ti < text.length; ti++){ 47 | var strokes = font[text[ti]]; 48 | if(strokes){ 49 | 50 | for(si = 0; si < strokes.length; si++){ 51 | var points = strokes[si]; 52 | if(points.length < 4){ 53 | continue; 54 | } 55 | 56 | ctx.beginPath(); 57 | ctx.moveTo( 58 | points[0] * w / 256 + x, 59 | points[1] * h / 256 + y); 60 | 61 | for(pi = 2; pi < points.length - 1; pi += 2){ 62 | ctx.lineTo( 63 | points[pi+0] * w / 256 + x, 64 | points[pi+1] * h / 256 + y); 65 | } 66 | 67 | ctx.stroke(); 68 | } 69 | 70 | } 71 | x += w; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /OneKeyUpDown.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function main() 4 | { 5 | var canvas = document.getElementById("canvas"); 6 | if(!canvas.getContext){ 7 | return; 8 | } 9 | 10 | var game = new Game(canvas); 11 | game.start(); 12 | } 13 | 14 | 15 | // --------------------------------------------------------------------------- 16 | // class ButtonState 17 | // --------------------------------------------------------------------------- 18 | function ButtonState() 19 | { 20 | this.initialize.apply(this, arguments); 21 | } 22 | ButtonState.prototype = { 23 | initialize: function() 24 | { 25 | this.pressed = false; 26 | }, 27 | 28 | isPressed: function() 29 | { 30 | return this.pressed; 31 | }, 32 | 33 | setPressed: function(down) 34 | { 35 | this.pressed = down; 36 | } 37 | }; 38 | 39 | 40 | 41 | 42 | // --------------------------------------------------------------------------- 43 | // class Obstacle 44 | // --------------------------------------------------------------------------- 45 | function Obstacle() 46 | { 47 | this.initialize.apply(this, arguments); 48 | } 49 | Obstacle.prototype = { 50 | initialize: function(model, x, y, radius, speed) 51 | { 52 | this.model = model; 53 | this.position = new Vector2(x, y); 54 | this.radius = radius; 55 | this.color = "#ff0000"; 56 | this.speed = speed; 57 | }, 58 | 59 | 60 | advanceTime: function(dt) 61 | { 62 | this.position.x += -this.speed * dt; 63 | }, 64 | 65 | 66 | isDead: function() 67 | { 68 | return this.position.x < this.model.FIELDAREA_LEFT - this.radius; 69 | } 70 | }; 71 | 72 | 73 | // --------------------------------------------------------------------------- 74 | // class LifeUpBall 75 | // --------------------------------------------------------------------------- 76 | function LifeUpBall() 77 | { 78 | this.initialize.apply(this, arguments); 79 | } 80 | LifeUpBall.prototype = { 81 | initialize: function(model, x, y, radius, speed) 82 | { 83 | this.model = model; 84 | this.position = new Vector2(x, y); 85 | this.radius = radius; 86 | this.color = "#00ff33"; 87 | this.speed = speed; 88 | }, 89 | 90 | 91 | advanceTime: function(dt) 92 | { 93 | this.position.x += -this.speed * dt; 94 | }, 95 | 96 | 97 | isDead: function() 98 | { 99 | return this.position.x < this.model.FIELDAREA_LEFT - this.radius; 100 | } 101 | }; 102 | 103 | 104 | // --------------------------------------------------------------------------- 105 | // class GameModel 106 | // --------------------------------------------------------------------------- 107 | 108 | function GameModel() 109 | { 110 | this.initialize.apply(this, arguments); 111 | } 112 | 113 | GameModel.prototype = { 114 | initialize: function(canvasSizeX, canvasSizeY) 115 | { 116 | this.canvasSizeX = canvasSizeX; 117 | this.canvasSizeY = canvasSizeY; 118 | 119 | this.gameTime = 0.0; 120 | this.gameStarted = false; 121 | this.gameFinished = false; 122 | 123 | this.gameProgressDistance = 0.0; 124 | 125 | this.buttonA = new ButtonState(); 126 | 127 | this.objects = new Array(); 128 | 129 | this.initPlayer(canvasSizeX, canvasSizeY); 130 | 131 | this.obstacleTime = 0.0; 132 | this.lifeupballTime = 10.0; 133 | 134 | this.FIELDAREA_LEFT = 0.0; 135 | this.FIELDAREA_TOP = 0.0; 136 | this.FIELDAREA_RIGHT = canvasSizeX; 137 | this.FIELDAREA_BOTTOM = canvasSizeY; 138 | 139 | this.SCROLLSPEED = 100.0; 140 | 141 | this.GUTTER_HEIGHT = 20.0; 142 | this.gutterTop = this.GUTTER_HEIGHT; 143 | this.gutterBottom = canvasSizeY - this.GUTTER_HEIGHT; 144 | }, 145 | 146 | 147 | isPlaying: function() 148 | { 149 | return this.gameStarted && !this.gameFinished; 150 | }, 151 | 152 | isStarted: function() 153 | { 154 | return this.gameStarted; 155 | }, 156 | 157 | isFinished: function() 158 | { 159 | return this.gameFinished; 160 | }, 161 | 162 | startGame: function() 163 | { 164 | this.gameStarted = true; 165 | }, 166 | 167 | finishGame: function() 168 | { 169 | this.gameFinished = true; 170 | }, 171 | 172 | 173 | advanceTime: function(dt) 174 | { 175 | if(!this.isPlaying()){ 176 | return; 177 | } 178 | 179 | 180 | this.gameTime += dt; 181 | this.gameProgressDistance += dt * this.SCROLLSPEED; 182 | 183 | // move player 184 | this.advancePlayerTime(dt); 185 | 186 | // create new obstacles 187 | this.obstacleTime += dt; 188 | while(this.obstacleTime >= 0.75){ 189 | this.obstacleTime -= 0.75; 190 | 191 | var r = 30.0 + Math.random() * this.gameProgressDistance / 100.0; 192 | var speed = this.SCROLLSPEED; 193 | this.objects.push(new Obstacle(this, this.FIELDAREA_RIGHT + r, (this.FIELDAREA_BOTTOM - this.FIELDAREA_TOP) * Math.random() + this.FIELDAREA_TOP, r, speed)); 194 | } 195 | 196 | // create new life up ball 197 | if(this.playerLife < 0.8){ 198 | this.lifeupballTime -= dt; 199 | if(this.lifeupballTime <= 0){ 200 | var r = 30.0 + Math.random() * this.gameProgressDistance / 100.0; 201 | //var r = Math.max(5.0, 40.0 - this.gameProgressDistance / 1000.0); 202 | this.objects.push(new LifeUpBall(this, this.FIELDAREA_RIGHT + r, (this.FIELDAREA_BOTTOM - this.FIELDAREA_TOP) * Math.random() + this.FIELDAREA_TOP, r, this.SCROLLSPEED * 1.2)); 203 | this.lifeupballTime = 2.0 + Math.random() * 5.0; 204 | } 205 | } 206 | 207 | // move objects 208 | for(var i = 0; i < this.objects.length; i++){ 209 | this.objects[i].advanceTime(dt); 210 | 211 | if(this.objects[i].isDead()){ 212 | this.objects.splice(i, 1); 213 | --i; 214 | } 215 | 216 | } 217 | 218 | }, 219 | 220 | 221 | 222 | initPlayer: function(canvasSizeX, canvasSizeY) 223 | { 224 | this.playerVelocity = new Vector2(0, 0); 225 | this.playerPosition = new Vector2(canvasSizeX/3, canvasSizeY/2); 226 | this.playerRadius = 10; 227 | this.playerLife = 1.0; 228 | this.playerLastDamageTime = -9999; 229 | }, 230 | 231 | 232 | advancePlayerTime: function(dt) 233 | { 234 | var accY = 0; 235 | 236 | if(this.buttonA.isPressed()){ 237 | accY -= 30.0; 238 | } 239 | accY += 15.0; 240 | 241 | this.playerVelocity.y += dt * accY; 242 | this.playerPosition.y += this.playerVelocity.y; 243 | 244 | // foreach intersection objects 245 | for(var i = 0; i < this.objects.length; i++){ 246 | var o = this.objects[i]; 247 | var radius = o.radius + this.playerRadius; 248 | var distSq = o.position.distanceSqFrom(this.playerPosition); 249 | if(distSq < radius * radius){ 250 | if((typeof o == "object") && (o instanceof Obstacle)){ 251 | this.decreasePlayerLife(dt); 252 | } 253 | if((typeof o == "object") && (o instanceof LifeUpBall)){ 254 | this.increasePlayerLife(dt); 255 | } 256 | } 257 | } 258 | 259 | // gutter 260 | if(this.playerPosition.y - this.playerRadius < this.gutterTop){ 261 | this.decreasePlayerLife(dt); 262 | } 263 | if(this.playerPosition.y + this.playerRadius > this.gutterBottom){ 264 | this.decreasePlayerLife(dt); 265 | } 266 | 267 | // out of field 268 | if(this.playerPosition.y < this.gutterTop){ 269 | this.playerPosition.y = this.gutterTop; 270 | this.playerVelocity.y = 0; 271 | } 272 | if(this.playerPosition.y > this.gutterBottom){ 273 | this.playerPosition.y = this.gutterBottom; 274 | this.playerVelocity.y = 0; 275 | } 276 | 277 | }, 278 | 279 | 280 | decreasePlayerLife: function(dt) 281 | { 282 | this.playerLastDamageTime = this.gameTime; 283 | this.playerLife -= 0.5 * dt; 284 | if(this.playerLife <= 0){ 285 | this.playerLife = 0; 286 | this.finishGame(); 287 | } 288 | 289 | }, 290 | 291 | increasePlayerLife: function(dt) 292 | { 293 | this.playerLife += 0.8 * dt; 294 | if(this.playerLife >= 1.0){ 295 | this.playerLife = 1.0; 296 | } 297 | 298 | }, 299 | 300 | getElapsedFromLastDamage: function() 301 | { 302 | return this.gameTime - this.playerLastDamageTime; 303 | } 304 | 305 | 306 | }; 307 | 308 | 309 | 310 | // --------------------------------------------------------------------------- 311 | // class Game 312 | // --------------------------------------------------------------------------- 313 | 314 | function Game() 315 | { 316 | this.initialize.apply(this, arguments); 317 | } 318 | 319 | Game.prototype = { 320 | initialize: function(canvas) 321 | { 322 | this.intervalId = null; 323 | this.canvas = canvas; 324 | this.ctx = canvas.getContext("2d"); 325 | 326 | this.TIMER_PERIOD = 50; 327 | 328 | this.model = new GameModel(canvas.width, canvas.height); 329 | 330 | this.initKeyHandler(); 331 | this.initMouseHandler(); 332 | }, 333 | 334 | start: function() 335 | { 336 | var self = this; 337 | this.intervalId = window.setInterval(function(){self.advanceTime(self.TIMER_PERIOD/1000.0);}, this.TIMER_PERIOD); 338 | }, 339 | 340 | stop: function() 341 | { 342 | if(this.intervalId){ 343 | window.clearInterval(this.intervalId); 344 | this.intervalId = null; 345 | } 346 | }, 347 | 348 | advanceTime: function(dt) 349 | { 350 | this.model.advanceTime(dt); 351 | this.paint(); 352 | }, 353 | 354 | // View 355 | 356 | paint: function() 357 | { 358 | this.paintField(); 359 | 360 | 361 | // draw overlapped text. 362 | var ctx = this.ctx; 363 | ctx.save(); 364 | ctx.strokeStyle = "#ffffff"; 365 | 366 | if(!this.model.isStarted()){ 367 | drawText(ctx, "CLICK TO START", this.canvas.width/2 - 14*16/2, this.canvas.height/2, 16, 16); 368 | } 369 | 370 | if(this.model.isFinished()){ 371 | drawText(ctx, "GAME OVER", this.canvas.width/2 - 9*16/2, this.canvas.height/2, 16, 16); 372 | 373 | } 374 | 375 | // draw score. 376 | var distStr = Math.floor(this.model.gameProgressDistance).toString(10) + " PIXELS"; 377 | drawText(ctx, distStr, this.canvas.width - 4 - distStr.length * 16, 4, 16, 16); 378 | 379 | // paint player life. 380 | var lifeBarWidth = canvas.width/2 - 2; 381 | lifeBarWidth *= this.model.playerLife; 382 | ctx.fillStyle = "#0088ff"; 383 | ctx.fillRect(this.canvas.width/2, this.canvas.height - 10, lifeBarWidth, 8); 384 | 385 | ctx.restore(); 386 | }, 387 | 388 | 389 | paintField: function() 390 | { 391 | var ctx = this.ctx; 392 | ctx.save(); 393 | 394 | 395 | ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); 396 | ctx.fillStyle = this.model.getElapsedFromLastDamage() < 0.1 ? (Math.floor(this.model.gameTime * 16) % 2 ? "#440000" : "#000000") : "#000000"; 397 | ctx.fillRect(0, 0, this.canvas.width, this.canvas.height); 398 | 399 | var t = this.model.gameTime; 400 | 401 | 402 | // draw objects 403 | for(var i = 0; i < this.model.objects.length; i++){ 404 | var position = this.model.objects[i].position; 405 | var radius = this.model.objects[i].radius; 406 | var color = this.model.objects[i].color; 407 | ctx.fillStyle = color; 408 | ctx.beginPath(); 409 | ctx.moveTo(position.x, position.y); 410 | ctx.arc(position.x, position.y, radius, 0, Math.PI*2, true); 411 | ctx.fill(); 412 | } 413 | 414 | // draw player token 415 | var px = this.model.playerPosition.x; 416 | var py = this.model.playerPosition.y; 417 | ctx.lineWidth = 5; 418 | ctx.strokeStyle = "#325fa2"; 419 | ctx.fillStyle = "#bbd400"; 420 | ctx.beginPath(); 421 | ctx.moveTo(px, py); 422 | ctx.arc(px, py, this.model.playerRadius, 0, Math.PI*2, true); 423 | ctx.fill(); 424 | 425 | // draw gutters 426 | ctx.fillStyle = "#ff0000"; 427 | ctx.fillRect(0, 0, this.canvas.width, this.model.gutterTop); 428 | ctx.fillRect(0, this.model.gutterBottom, this.canvas.width, this.canvas.height - this.model.gutterBottom); 429 | 430 | 431 | ctx.restore(); 432 | }, 433 | 434 | // Key Event Handler 435 | 436 | initKeyHandler: function() 437 | { 438 | var self = this; 439 | window.document.onkeydown = function(e){ self.onKeyDown(e);}; 440 | window.document.onkeyup = function(e){ self.onKeyUp(e);}; 441 | }, 442 | 443 | onKeyDown: function(e) 444 | { 445 | this.onKey(e, true); 446 | }, 447 | 448 | onKeyUp: function(e) 449 | { 450 | this.onKey(e, false); 451 | }, 452 | 453 | onKey: function(e, down) 454 | { 455 | var keycode = e ? e.which : window.event.keyCode; 456 | var ctrl = e ? (typeof e.modifiers == 'undefined' ? e.ctrlKey : e.modifiers & Event.CONTROL_MASK) : event.ctrlKey; 457 | var shift = e ? (typeof e.modifiers == 'undefined' ? e.shiftKey : e.modifiers & Event.SHIFT_MASK) : event.shiftKey; 458 | 459 | /* 460 | if(e){ 461 | e.preventDefault(); 462 | e.stopPropagation(); 463 | } 464 | else{ 465 | event.returnValue = false; 466 | event.cancelBubble = true; 467 | } 468 | */ 469 | 470 | if(keycode == 0x20){ 471 | this.model.buttonA.setPressed(down); 472 | } 473 | }, 474 | 475 | 476 | 477 | initMouseHandler: function() 478 | { 479 | var self = this; 480 | canvas.addEventListener("mousedown", function(e){self.onMouseDown(e);}, false); 481 | canvas.addEventListener("mouseup", function(e){self.onMouseUp(e);}, false); 482 | }, 483 | 484 | 485 | onMouseDown: function(e) 486 | { 487 | if(!this.model.isStarted()){ 488 | this.model.startGame(); 489 | } 490 | 491 | this.model.buttonA.setPressed(true); 492 | }, 493 | 494 | onMouseUp: function(e) 495 | { 496 | this.model.buttonA.setPressed(false); 497 | } 498 | 499 | 500 | }; 501 | 502 | 503 | 504 | --------------------------------------------------------------------------------