├── .gitignore ├── audio-game ├── css │ └── audiogame.css ├── images │ ├── dot.png │ ├── game_bg.jpg │ ├── hit_line.png │ ├── menu_bg.jpg │ └── play_button.png ├── index.htm ├── js │ ├── html5games.audio.js │ └── jquery-1.6.min.js ├── media │ ├── button_active.mp3 │ ├── button_active.ogg │ ├── button_over.ogg │ ├── button_over.wav │ ├── minuet_in_g.mp3 │ ├── minuet_in_g.ogg │ ├── minuet_in_g_melody.mp3 │ └── minuet_in_g_melody.ogg └── readme.md ├── ball-shooting ├── images │ ├── assets.fla │ ├── lv1.png │ ├── lv2.png │ ├── lv3.png │ ├── lv4.png │ ├── lv5.jpg │ └── lv6.jpg ├── index.html ├── scripts │ ├── assets.js │ ├── game.js │ ├── helpers.js │ ├── level.js │ ├── physics.js │ └── view.js ├── styles │ └── game.css └── vendors │ ├── Box2dWeb-2.1.a.3.min.js │ ├── easeljs-0.7.1.min.js │ ├── movieclip-0.7.1.min.js │ ├── preloadjs-0.4.1.min.js │ └── tweenjs-0.5.1.min.js ├── box2d-car-game ├── css │ └── cargame.css ├── images │ ├── bg.jpg │ ├── bg2.jpg │ ├── bg3.jpg │ ├── bg4.jpg │ ├── bg5.jpg │ ├── bus.png │ ├── flag.png │ ├── game_completed_screen.jpg │ ├── starting_screen.jpg │ ├── website_background.jpg │ └── wheel.png ├── index.htm ├── js │ ├── AUTHORS │ ├── COPYING │ ├── README │ ├── box2d │ │ ├── collision │ │ │ ├── ClipVertex.js │ │ │ ├── Features.js │ │ │ ├── b2AABB.js │ │ │ ├── b2Bound.js │ │ │ ├── b2BoundValues.js │ │ │ ├── b2BroadPhase.js │ │ │ ├── b2BufferedPair.js │ │ │ ├── b2Collision.js │ │ │ ├── b2ContactID.js │ │ │ ├── b2ContactPoint.js │ │ │ ├── b2Distance.js │ │ │ ├── b2Manifold.js │ │ │ ├── b2OBB.js │ │ │ ├── b2Pair.js │ │ │ ├── b2PairCallback.js │ │ │ ├── b2PairManager.js │ │ │ ├── b2Proxy.js │ │ │ └── shapes │ │ │ │ ├── b2BoxDef.js │ │ │ │ ├── b2CircleDef.js │ │ │ │ ├── b2CircleShape.js │ │ │ │ ├── b2MassData.js │ │ │ │ ├── b2PolyDef.js │ │ │ │ ├── b2PolyShape.js │ │ │ │ ├── b2Shape.js │ │ │ │ └── b2ShapeDef.js │ │ ├── common │ │ │ ├── b2Settings.js │ │ │ └── math │ │ │ │ ├── b2Mat22.js │ │ │ │ ├── b2Math.js │ │ │ │ └── b2Vec2.js │ │ └── dynamics │ │ │ ├── b2Body.js │ │ │ ├── b2BodyDef.js │ │ │ ├── b2CollisionFilter.js │ │ │ ├── b2ContactManager.js │ │ │ ├── b2Island.js │ │ │ ├── b2TimeStep.js │ │ │ ├── b2World.js │ │ │ ├── b2WorldListener.js │ │ │ ├── contacts │ │ │ ├── b2CircleContact.js │ │ │ ├── b2Conservative.js │ │ │ ├── b2Contact.js │ │ │ ├── b2ContactConstraint.js │ │ │ ├── b2ContactConstraintPoint.js │ │ │ ├── b2ContactNode.js │ │ │ ├── b2ContactRegister.js │ │ │ ├── b2ContactSolver.js │ │ │ ├── b2NullContact.js │ │ │ ├── b2PolyAndCircleContact.js │ │ │ └── b2PolyContact.js │ │ │ └── joints │ │ │ ├── b2DistanceJoint.js │ │ │ ├── b2DistanceJointDef.js │ │ │ ├── b2GearJoint.js │ │ │ ├── b2GearJointDef.js │ │ │ ├── b2Jacobian.js │ │ │ ├── b2Joint.js │ │ │ ├── b2JointDef.js │ │ │ ├── b2JointNode.js │ │ │ ├── b2MouseJoint.js │ │ │ ├── b2MouseJointDef.js │ │ │ ├── b2PrismaticJoint.js │ │ │ ├── b2PrismaticJointDef.js │ │ │ ├── b2PulleyJoint.js │ │ │ ├── b2PulleyJointDef.js │ │ │ ├── b2RevoluteJoint.js │ │ │ └── b2RevoluteJointDef.js │ ├── excanvas.js │ ├── html5games.box2dcargame.js │ ├── jquery-1.6.min.js │ └── protoclass.js └── readme.md ├── canvas-untangle-game ├── css │ └── untangle.css ├── images │ ├── bg_repeat.png │ ├── board.png │ ├── guide_sprite.png │ └── title_bg.png ├── index.html ├── js │ ├── jquery-2.1.3.min.js │ ├── untangle.data.js │ ├── untangle.drawing.js │ ├── untangle.game.js │ ├── untangle.input.js │ ├── untangle.js │ └── untangle.levels.js └── readme.md ├── count-99 ├── css │ ├── count99-game.css │ ├── pf_tempesta_seven_compressed_bold-webfont.css │ ├── pf_tempesta_seven_compressed_bold-webfont.eot │ ├── pf_tempesta_seven_compressed_bold-webfont.svg │ ├── pf_tempesta_seven_compressed_bold-webfont.ttf │ └── pf_tempesta_seven_compressed_bold-webfont.woff ├── images │ ├── bg.png │ ├── gameover.jpg │ ├── hud.png │ ├── restart-button.png │ └── tile.png ├── index.html ├── js │ └── count99-game.js ├── readme.md └── vendors │ └── easeljs-0.7.1.min.js ├── css3-matching-game ├── css │ └── matchgame.css ├── images │ ├── bg.jpg │ ├── deck.png │ ├── popup_bg.jpg │ └── table.jpg ├── index.html ├── js │ ├── html5games.matchgame.js │ └── jquery-1.6.min.js └── readme.md ├── multiply-defense ├── css │ ├── multiply-defense.css │ └── multiply-defense.css.less ├── index.html ├── js │ ├── multiply-defense.coffee │ └── multiply-defense.js ├── readme.md └── vendors │ ├── easeljs-0.4.min.js │ ├── jquery-1.7.1.min.js │ └── underscore-1.3.1.min.js ├── pingpoing ├── index.html ├── js │ ├── html5games.pingpong.js │ └── jquery-1.4.3.js └── readme.md ├── readme.md └── rush ├── css └── rush-game.css ├── images ├── coin.json ├── coin.png ├── coin1.png ├── hr.png ├── landscape.png ├── noise-bg.png ├── obstacle.json ├── obstacle.png ├── platform-left.png ├── platform-middle.png ├── platform-right.png ├── platform.png ├── running.json ├── running.png ├── rush-gameover-scene.png ├── rush-header.png ├── rush-menu-scene.png └── trees.png ├── index.html ├── js ├── game.js ├── rush-coin.js ├── rush-common-shapes.js ├── rush-game.js ├── rush-gameobject.js ├── rush-hero.js ├── rush-movable-gameobject.js ├── rush-obstacle.js ├── rush-platform.js ├── rush-preloader.js └── rush-topscores.js └── vendors └── easeljs-0.7.1.min.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Rakefile 3 | 4 | -------------------------------------------------------------------------------- /audio-game/css/audiogame.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #837400; 3 | color: #333; 4 | padding: 50px; 5 | } 6 | 7 | #game { 8 | position: relative; 9 | width: 768px; 10 | height: 440px; 11 | overflow: hidden; 12 | } 13 | 14 | #game, footer { 15 | width: 768px; 16 | margin: 0 auto; 17 | } 18 | 19 | .scene { 20 | position: absolute; 21 | width: 100%; 22 | height: 100%; 23 | } 24 | 25 | #menu-scene { 26 | background: #ccc url(../images/menu_bg.jpg); 27 | display: -webkit-box; 28 | -webkit-box-pack:center; 29 | -webkit-box-align: center; 30 | 31 | display: -moz-box; 32 | -moz-box-pack:center; 33 | -moz-box-align: center; 34 | 35 | display: box; 36 | box-pack:center; 37 | box-align: center; 38 | } 39 | 40 | #game-scene { 41 | background: #efefef url(../images/game_bg.jpg); 42 | top: -440px; 43 | } 44 | 45 | #game-scene.show-scene { 46 | top: 0; 47 | -webkit-transition: top .3s linear; 48 | -moz-transition: top .3s linear; 49 | transition: top .3s linear; 50 | } 51 | 52 | 53 | #game-canvas, #game-background-canvas { 54 | position: absolute; 55 | } 56 | 57 | 58 | /* Menu Scene Elements */ 59 | a[href='#game'] { 60 | width: 146px; 61 | height: 78px; 62 | background: url(../images/play_button.png); 63 | overflow: hidden; 64 | display: block; 65 | } 66 | 67 | a[href='#game']:hover { 68 | background-position: -146px; 69 | } 70 | 71 | a[href='#game']:active { 72 | background-position: -292px; 73 | } 74 | 75 | a[href='#game'] span { 76 | display: block; 77 | margin-top: -999px; 78 | } 79 | 80 | /* Game Scene Elements */ 81 | 82 | .hit-line { 83 | background: url(../images/hit_line.png); 84 | position: absolute; 85 | width: 50px; 86 | height: 50px; 87 | } 88 | 89 | 90 | .show { 91 | opacity: 1; 92 | } 93 | 94 | .hide{ 95 | opacity: 0; 96 | -webkit-transition: opacity .2s linear; 97 | -moz-transition: opacity .2s linear; 98 | transition: opacity .2s linear; 99 | } 100 | 101 | #hit-line-1 { 102 | left: 259px; 103 | top: 335px; 104 | } 105 | 106 | #hit-line-2 { 107 | left: 359px; 108 | top: 335px; 109 | } 110 | 111 | #hit-line-3 { 112 | left: 459px; 113 | top: 335px; 114 | } 115 | -------------------------------------------------------------------------------- /audio-game/images/dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/images/dot.png -------------------------------------------------------------------------------- /audio-game/images/game_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/images/game_bg.jpg -------------------------------------------------------------------------------- /audio-game/images/hit_line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/images/hit_line.png -------------------------------------------------------------------------------- /audio-game/images/menu_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/images/menu_bg.jpg -------------------------------------------------------------------------------- /audio-game/images/play_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/images/play_button.png -------------------------------------------------------------------------------- /audio-game/index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HTML5 Audio Game 6 | 7 | 8 | 9 |
10 | 13 | 14 |
15 | 16 | Sorry, your web browser does not support canvas content. 17 | 18 | 19 | Sorry, your web browser does not support canvas content. 20 | 21 |
22 |
23 |
24 |
25 |
26 | 27 | 31 | 35 | 36 | 40 | 41 | 45 | 46 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /audio-game/media/button_active.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/media/button_active.mp3 -------------------------------------------------------------------------------- /audio-game/media/button_active.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/media/button_active.ogg -------------------------------------------------------------------------------- /audio-game/media/button_over.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/media/button_over.ogg -------------------------------------------------------------------------------- /audio-game/media/button_over.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/media/button_over.wav -------------------------------------------------------------------------------- /audio-game/media/minuet_in_g.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/media/minuet_in_g.mp3 -------------------------------------------------------------------------------- /audio-game/media/minuet_in_g.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/media/minuet_in_g.ogg -------------------------------------------------------------------------------- /audio-game/media/minuet_in_g_melody.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/media/minuet_in_g_melody.mp3 -------------------------------------------------------------------------------- /audio-game/media/minuet_in_g_melody.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/audio-game/media/minuet_in_g_melody.ogg -------------------------------------------------------------------------------- /audio-game/readme.md: -------------------------------------------------------------------------------- 1 | # Audio Game 2 | 3 | This game makes use of audio tag and keyboard input to create a music notes dropping game. 4 | 5 | This is originally from the book [HTML5 Games Development by Examples][1]. 6 | 7 | Please note that this code was written in 2012 and I didn't followed some best practice in Javasscript programming. It is suggested to learn the concept and update the code to follow latest JavaScript practice. 8 | 9 | [1]: http://www.packtpub.com/html5-games-development-using-css-javascript-beginners-guide/book 10 | -------------------------------------------------------------------------------- /ball-shooting/images/assets.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/ball-shooting/images/assets.fla -------------------------------------------------------------------------------- /ball-shooting/images/lv1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/ball-shooting/images/lv1.png -------------------------------------------------------------------------------- /ball-shooting/images/lv2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/ball-shooting/images/lv2.png -------------------------------------------------------------------------------- /ball-shooting/images/lv3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/ball-shooting/images/lv3.png -------------------------------------------------------------------------------- /ball-shooting/images/lv4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/ball-shooting/images/lv4.png -------------------------------------------------------------------------------- /ball-shooting/images/lv5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/ball-shooting/images/lv5.jpg -------------------------------------------------------------------------------- /ball-shooting/images/lv6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/ball-shooting/images/lv6.jpg -------------------------------------------------------------------------------- /ball-shooting/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Shoot the ball 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 |
16 |
17 |
18 |

Shoot the ball

19 |
20 |
21 |
22 |

How to Play?

23 | 24 |
25 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 52 | 53 | -------------------------------------------------------------------------------- /ball-shooting/scripts/game.js: -------------------------------------------------------------------------------- 1 | var game = this.game || (this.game={}); 2 | var createjs = createjs || {}; 3 | var images = images||{}; 4 | 5 | ;(function(game, cjs, b2d){ 6 | game.load = function() { 7 | // load bitmap assets before starts the game 8 | var loader = new createjs.LoadQueue(false); 9 | loader.addEventListener("fileload", function(e){ 10 | if (e.item.type === "image") { images[e.item.id] = e.result; } // assgin to images object for assets.js to use 11 | }); 12 | loader.addEventListener("complete", game.start); 13 | loader.loadManifest(lib.properties.manifest); 14 | }; 15 | 16 | game.start = function() { 17 | console.log("Let's start."); 18 | 19 | cjs.EventDispatcher.initialize(game); // allow the game object to listen and dispatch custom events. 20 | 21 | game.canvas = document.getElementById('canvas'); 22 | 23 | game.stage = new cjs.Stage(game.canvas); 24 | cjs.Touch.enable(game.stage, /*single touch=*/ true, /*allow default=*/ true); 25 | 26 | cjs.Ticker.setFPS(60); 27 | cjs.Ticker.addEventListener('tick', game.stage); // add game.stage to ticker make the stage.update call automatically. 28 | cjs.Ticker.addEventListener('tick', game.tick); // gameloop 29 | 30 | game.physics.createWorld(); 31 | game.view.initPowerIndicator(); 32 | 33 | var levelSelection = new lib.LevelSelection(); 34 | game.stage.addChild(levelSelection); 35 | levelSelection.levels.stop(); 36 | 37 | levelSelection.rightButton.on('click', function(){ 38 | var next = levelSelection.levels.currentFrame + 1; 39 | levelSelection.levels.gotoAndStop(next); 40 | }); 41 | levelSelection.leftButton.on('click', function(){ 42 | var prev = levelSelection.levels.currentFrame - 1; 43 | levelSelection.levels.gotoAndStop(prev); 44 | }); 45 | 46 | var isPlaying = false; 47 | levelSelection.playButton.on('click', function() { 48 | levelSelection.parent.removeChild(levelSelection); 49 | 50 | // game.physics.showDebugDraw(); 51 | 52 | game.score = 0; 53 | 54 | game.currentLevel = game.levels[levelSelection.levels.currentFrame]; 55 | 56 | game.physics.createLevel(); 57 | 58 | game.view.showScoreBoard(); 59 | 60 | isPlaying = true; 61 | }); 62 | 63 | game.tickWhenDown = 0; 64 | game.tickWhenUp = 0; 65 | game.stage.on('stagemousedown', function(e){ 66 | if (!isPlaying) { return; } 67 | var position = game.physics.ballPosition(); 68 | game.view.showPowerIndicator(position.x, position.y); 69 | 70 | var rotation = game.physics.launchAngle(e.stageX, e.stageY); 71 | game.view.rotatePowerIndicator(rotation* 180 / Math.PI); 72 | 73 | game.tickWhenDown = cjs.Ticker.getTicks(); 74 | game.view.updatePowerBar(0); 75 | }); 76 | game.stage.on('stagemousemove', function(e){ 77 | if (!isPlaying) { return; } 78 | var rotation = game.physics.launchAngle(e.stageX, e.stageY); 79 | game.view.rotatePowerIndicator(rotation* 180 / Math.PI); 80 | }); 81 | game.stage.on('stagemouseup', function(e){ 82 | if (!isPlaying) { return; } 83 | game.view.hidePowerIndicator(); 84 | game.tickWhenUp = cjs.Ticker.getTicks(); 85 | ticksDiff = game.tickWhenUp - game.tickWhenDown; 86 | 87 | game.physics.shootBall(e.stageX, e.stageY, ticksDiff); 88 | 89 | setTimeout(game.spawnBall, 500); 90 | }); 91 | 92 | }; 93 | 94 | game.increaseScore = function() { 95 | game.score += 1; 96 | game.view.updateScore(); 97 | console.log(game.score); 98 | }; 99 | 100 | game.spawnBall = function() { 101 | game.physics.spawnBall(); 102 | }; 103 | 104 | game.tick = function(){ 105 | if (cjs.Ticker.getPaused()) { return; } // run when not paused 106 | 107 | game.physics.update(); 108 | 109 | // launch power preview 110 | var ticksDiff = cjs.Ticker.getTicks() - game.tickWhenDown; 111 | game.view.updatePowerBar(ticksDiff); 112 | }; 113 | 114 | game.load(); 115 | 116 | 117 | }).call(this, game, createjs, Box2D); 118 | 119 | 120 | -------------------------------------------------------------------------------- /ball-shooting/scripts/helpers.js: -------------------------------------------------------------------------------- 1 | var game = this.game || (this.game={}); 2 | var createjs = createjs || {}; 3 | 4 | ;(function(game, cjs){ 5 | game.helper = game.helper || {}; 6 | 7 | }).call(this, game, createjs); -------------------------------------------------------------------------------- /ball-shooting/scripts/level.js: -------------------------------------------------------------------------------- 1 | var game = this.game || (this.game={}); 2 | 3 | (function(game){ 4 | 5 | var degrees = Math.PI / 180 6 | 7 | game.balls = { 8 | 'slow ball': { 9 | className: 'SlowBall', 10 | radius: 13, 11 | density: 0.6, 12 | friction: 0.8, 13 | restitution: 0.1 14 | }, 15 | 'bouncy ball': { 16 | className: 'BouncyBall', 17 | radius: 10, 18 | density: 1.1, 19 | friction: 0.8, 20 | restitution: 0.4 21 | } 22 | }; 23 | game.levels = [ 24 | { 25 | hoopPosition: {x:50, y:150}, 26 | ballName: 'slow ball', 27 | ballPosition: {x:350, y:250}, 28 | ballRandomRange: {x:60, y:60}, 29 | obstacles: [] 30 | }, 31 | { 32 | hoopPosition: {x:50, y:200}, 33 | ballName: 'slow ball', 34 | ballPosition: {x:350, y:200}, 35 | ballRandomRange: {x:160, y:0}, 36 | obstacles: [] 37 | }, 38 | { 39 | hoopPosition: {x:50, y:160}, 40 | ballName: 'bouncy ball', 41 | ballPosition: {x:350, y:250}, 42 | ballRandomRange: {x:80, y:80}, 43 | obstacles: [] 44 | }, 45 | { 46 | hoopPosition: {x:50, y:160}, 47 | ballName: 'slow ball', 48 | ballPosition: {x:350, y:250}, 49 | ballRandomRange: {x:80, y:80}, 50 | obstacles: [ 51 | { 52 | type: 'rect', 53 | graphicName: 'BrownSquare', 54 | position: {x: 200, y: 160}, 55 | dimension: {width: 10, height:10}, 56 | angle: 0 57 | }, 58 | { 59 | type: 'rect', 60 | graphicName: 'BrownSquare', 61 | position: {x: 200, y: 120}, 62 | dimension: {width: 10, height:10}, 63 | angle: 0 64 | }, 65 | ] 66 | }, 67 | { 68 | hoopPosition: {x:50, y:160}, 69 | ballName: 'slow ball', 70 | ballPosition: {x:350, y:250}, 71 | ballRandomRange: {x:80, y:80}, 72 | obstacles: [ 73 | { 74 | type: 'cross', 75 | graphicName: 'Cross', 76 | position: {x: 165, y: 140}, 77 | length: 60, 78 | width: 10, 79 | enableMotor: true, 80 | maxTorque: 25, 81 | motorSpeed: 3.0 82 | }, 83 | ] 84 | }, 85 | { 86 | hoopPosition: {x:50, y:150}, 87 | ballName: 'slow ball', 88 | ballPosition: {x:350, y:250}, 89 | ballRandomRange: {x:60, y:60}, 90 | obstacles: [ 91 | { 92 | type: 'cross', 93 | graphicName: 'Cross', 94 | position: {x: 165, y: 140}, 95 | length: 60, 96 | width: 10, 97 | enableMotor: true, 98 | maxTorque: 25, 99 | motorSpeed: 3.0 100 | }, 101 | { 102 | type: 'rect', 103 | graphicName: 'BrownSquare', 104 | position: {x: 200, y: 55}, 105 | dimension: {width: 10, height:10}, 106 | angle: 0 107 | }, 108 | { 109 | type: 'rect', 110 | graphicName: 'BrownSquare', 111 | position: {x: 260, y: 100}, 112 | dimension: {width: 10, height:10}, 113 | angle: 0 114 | }, 115 | { 116 | type: 'rect', 117 | graphicName: 'BrownSquare', 118 | position: {x: 300, y: 100}, 119 | dimension: {width: 10, height:10}, 120 | angle: 0 121 | } 122 | ] 123 | } 124 | ]; 125 | game.currentLevel = game.levels[0]; // default the 1st level. 126 | }).call(this, game); -------------------------------------------------------------------------------- /ball-shooting/scripts/view.js: -------------------------------------------------------------------------------- 1 | var game = this.game || (this.game={}); 2 | var createjs = createjs || {}; 3 | 4 | ;(function(game, cjs){ 5 | game.view = game.view || {}; 6 | 7 | game.view.showScoreBoard = function(){ 8 | this.scoreBoard = new lib.ScoreBoard(); 9 | this.scoreBoard.x = 10; 10 | this.scoreBoard.y = 10; 11 | game.stage.addChild(this.scoreBoard); 12 | }; 13 | game.view.updateScore = function() { 14 | this.scoreBoard.textField.text = game.score + ''; 15 | }; 16 | 17 | game.view.addSpriteToBody = function(body, spriteName, index) { 18 | var sprite = new lib[spriteName](); 19 | sprite.x = -99; 20 | if (index !== undefined) { 21 | game.stage.addChildAt(sprite, index); 22 | } else { 23 | game.stage.addChild(sprite); 24 | } 25 | body.SetUserData(sprite); 26 | }; 27 | 28 | game.view.initPowerIndicator = function() { 29 | this.power = new lib.PowerArrow(); 30 | game.stage.addChild(this.power); 31 | this.power.visible = false; 32 | }; 33 | 34 | game.view.showPowerIndicator = function(x, y) { 35 | this.power.visible = true; 36 | this.power.x = x; 37 | this.power.y = y; 38 | }; 39 | game.view.hidePowerIndicator = function() { 40 | this.power.visible = false; 41 | }; 42 | game.view.rotatePowerIndicator = function(rotation) { 43 | this.power.rotation = rotation; 44 | }; 45 | game.view.updatePowerBar = function(value) { 46 | this.power.powerBar.scaleY = Math.min(30, value); 47 | }; 48 | 49 | 50 | }).call(this, game, createjs); -------------------------------------------------------------------------------- /ball-shooting/styles/game.css: -------------------------------------------------------------------------------- 1 | /* normalize */ 2 | body, h1, h2, p { 3 | margin: 0; 4 | padding: 0; 5 | } 6 | 7 | * { 8 | box-sizing: border-box; 9 | } 10 | 11 | /* page layout */ 12 | body { 13 | background: #333; 14 | color: ghostwhite; 15 | } 16 | .row { 17 | width: 480px; 18 | max-width: 100%; 19 | margin: 0 auto; 20 | } 21 | 22 | /* Scenes */ 23 | #game { 24 | width: 480px; 25 | height: 360px; 26 | max-width: 100%; 27 | margin: 0 auto; 28 | border-radius: 8px; 29 | text-align: center; 30 | position: relative; 31 | background-color: #DEF0E5; 32 | } 33 | 34 | 35 | canvas { 36 | position: absolute; 37 | top: 0; 38 | left: 0; 39 | } 40 | 41 | #hud { 42 | position: absolute; 43 | width: 100%; 44 | height: 60px; 45 | background: rgba(0, 0, 0, 0.5); 46 | color: white; 47 | } 48 | 49 | .add-buttons { 50 | position: absolute; 51 | width: 100%; 52 | height: 60px; 53 | bottom: 0; 54 | background: rgba(0, 0, 0, 0.5); 55 | } 56 | 57 | .add-button { 58 | display: inline-block; 59 | width: 50px; 60 | height: 50px; 61 | background-color: rgba(255, 255, 255, 0.3); 62 | color: white; 63 | text-decoration: none; 64 | text-align: center; 65 | line-height: 50px; 66 | cursor: pointer; 67 | } 68 | .add-button:hover { 69 | background-color: rgba(255, 255, 255, 0.6); 70 | } -------------------------------------------------------------------------------- /ball-shooting/vendors/movieclip-0.7.1.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * @license EaselJS 3 | * Visit http://createjs.com/ for documentation, updates and examples. 4 | * 5 | * Copyright (c) 2011-2013 gskinner.com, inc. 6 | * 7 | * Distributed under the terms of the MIT license. 8 | * http://www.opensource.org/licenses/mit-license.html 9 | * 10 | * This notice shall be included in all copies or substantial portions of the Software. 11 | */ 12 | this.createjs=this.createjs||{},function(){"use strict";var a=function(a,b,c,d){this.initialize(a,b,c,d)},b=a.prototype=new createjs.Container;a.INDEPENDENT="independent",a.SINGLE_FRAME="single",a.SYNCHED="synched",b.mode,b.startPosition=0,b.loop=!0,b.currentFrame=0,b.timeline=null,b.paused=!1,b.actionsEnabled=!0,b.autoReset=!0,b.frameBounds=null,b._synchOffset=0,b._prevPos=-1,b._prevPosition=0,b._managed,b.Container_initialize=b.initialize,b.initialize=function(b,c,d,e){this.mode=b||a.INDEPENDENT,this.startPosition=c||0,this.loop=d;var f={paused:!0,position:c,useTicks:!0};this.Container_initialize(),this.timeline=new createjs.Timeline(null,e,f),this._managed={}},b.isVisible=function(){return!!(this.visible&&this.alpha>0&&0!=this.scaleX&&0!=this.scaleY)},b.Container_draw=b.draw,b.draw=function(a,b){return this.DisplayObject_draw(a,b)?!0:(this._updateTimeline(),this.Container_draw(a,b),!0)},b.play=function(){this.paused=!1},b.stop=function(){this.paused=!0},b.gotoAndPlay=function(a){this.paused=!1,this._goto(a)},b.gotoAndStop=function(a){this.paused=!0,this._goto(a)},b.getLabels=function(){return this.timeline.getLabels()},b.getCurrentLabel=function(){return this._updateTimeline(),this.timeline.getCurrentLabel()},b.clone=function(){throw"MovieClip cannot be cloned."},b.toString=function(){return"[MovieClip (name="+this.name+")]"},b.Container__tick=b._tick,b._tick=function(b){this.paused||this.mode!=a.INDEPENDENT||(this._prevPosition=this._prevPos<0?0:this._prevPosition+1,this._updateTimeline()),this.Container__tick(b)},b._goto=function(a){var b=this.timeline.resolve(a);null!=b&&(-1==this._prevPos&&(this._prevPos=0/0),this._prevPosition=b,this._updateTimeline())},b._reset=function(){this._prevPos=-1,this.currentFrame=0},b._updateTimeline=function(){var b=this.timeline,c=this.mode!=a.INDEPENDENT;if(b.loop=null==this.loop?!0:this.loop,c?b.setPosition(this.startPosition+(this.mode==a.SINGLE_FRAME?0:this._synchOffset),createjs.Tween.NONE):b.setPosition(this._prevPos<0?0:this._prevPosition,this.actionsEnabled?null:createjs.Tween.NONE),this._prevPosition=b._prevPosition,this._prevPos!=b._prevPos){this.currentFrame=this._prevPos=b._prevPos;for(var d in this._managed)this._managed[d]=1;for(var e=b._tweens,f=0,g=e.length;g>f;f++){var h=e[f],i=h._target;if(i!=this&&!h.passive){var j=h._stepPosition;i instanceof createjs.DisplayObject?this._addManagedChild(i,j):this._setState(i.state,j)}}var k=this.children;for(f=k.length-1;f>=0;f--){var l=k[f].id;1==this._managed[l]&&(this.removeChildAt(f),delete this._managed[l])}}},b._setState=function(a,b){if(a)for(var c=a.length-1;c>=0;c--){var d=a[c],e=d.t,f=d.p;for(var g in f)e[g]=f[g];this._addManagedChild(e,b)}},b._addManagedChild=function(b,c){b._off||(this.addChildAt(b,0),b instanceof a&&(b._synchOffset=c,b.mode==a.INDEPENDENT&&b.autoReset&&!this._managed[b.id]&&b._reset()),this._managed[b.id]=2)},b.Container__getBounds=b._getBounds,b._getBounds=function(a,b){var c=this.DisplayObject_getBounds();return c||(this._updateTimeline(),this.frameBounds&&(c=this._rectangle.copy(this.frameBounds[this.currentFrame]))),c?this._transformBounds(c,a,b):this.Container__getBounds(a,b)},createjs.MovieClip=a;var c=function(){throw"MovieClipPlugin cannot be instantiated."};c.priority=100,c.install=function(){createjs.Tween.installPlugin(c,["startPosition"])},c.init=function(a,b,c){return c},c.step=function(){},c.tween=function(b,c,d,e,f,g){return b.target instanceof a?1==g?f[c]:e[c]:d},c.install()}(); -------------------------------------------------------------------------------- /box2d-car-game/css/cargame.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Box2D Car Game Example 3 | * http://42games.net/html5games/box2d-car-game/ 4 | * 5 | * This is an example game for the book HTML5 Games Development: A Beginning Guide. 6 | * 7 | * Copyright 2010, Thomas Seng Hin Mak 8 | * makzan@42games.net 9 | * 10 | * All Right Reserved. 11 | */ 12 | 13 | html, body{ 14 | background: url(../images/website_background.jpg); 15 | 16 | font-family: 'Play', arial, serif; 17 | } 18 | 19 | em { 20 | margin: 0 6px; 21 | color: #006600; 22 | } 23 | 24 | .startscreen { 25 | background: #eee url(../images/starting_screen.jpg); 26 | } 27 | 28 | .gamebg_level0 { 29 | background: #eee url(../images/bg.jpg); 30 | } 31 | 32 | .gamebg_level1 { 33 | background: #eee url(../images/bg2.jpg); 34 | } 35 | 36 | .gamebg_level2 { 37 | background: #eee url(../images/bg3.jpg); 38 | } 39 | 40 | .gamebg_level3 { 41 | background: #eee url(../images/bg4.jpg); 42 | } 43 | 44 | .gamebg_level4 { 45 | background: #eee url(../images/bg5.jpg); 46 | } 47 | 48 | .gamebg_won { 49 | background: #eee url(../images/game_completed_screen.jpg); 50 | } 51 | 52 | #game { 53 | width: 1300px; 54 | } 55 | 56 | #asset { 57 | position: absolute; 58 | top: -99999px; 59 | } 60 | 61 | #game-container { 62 | position: relative; 63 | width: 1300px; 64 | } 65 | 66 | #level { 67 | position: absolute; 68 | top: 10px; 69 | left: 10px; 70 | } 71 | 72 | .progressbar { 73 | position: absolute; 74 | top: 10px; 75 | right: 10px; 76 | 77 | width: 300px; 78 | height:20px; 79 | margin: 2px; 80 | border: 1px solid #000; 81 | 82 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#8C906F), color-stop(48%,#8C906F), color-stop(51%,#323721), color-stop(54%,#55624F), color-stop(100%,#55624F)); /* webkit */ 83 | background: gradient(linear, left top, left bottom, color-stop(0%,#8C906F), color-stop(48%,#8C906F), color-stop(51%,#323721), color-stop(54%,#55624F), color-stop(100%,#55624F)); 84 | } 85 | 86 | .progressbar .fuel-value { 87 | height:20px; 88 | 89 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#A8D751), color-stop(48%,#A8D751), color-stop(51%,#275606), color-stop(54%,#4A8A49), color-stop(100%,#4A8A49)); /* webkit */ 90 | background: gradient(linear, left top, left bottom, color-stop(0%,#A8D751), color-stop(48%,#A8D751), color-stop(51%,#275606), color-stop(54%,#4A8A49), color-stop(100%,#4A8A49)); 91 | } -------------------------------------------------------------------------------- /box2d-car-game/images/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/box2d-car-game/images/bg.jpg -------------------------------------------------------------------------------- /box2d-car-game/images/bg2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/box2d-car-game/images/bg2.jpg -------------------------------------------------------------------------------- /box2d-car-game/images/bg3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/box2d-car-game/images/bg3.jpg -------------------------------------------------------------------------------- /box2d-car-game/images/bg4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/box2d-car-game/images/bg4.jpg -------------------------------------------------------------------------------- /box2d-car-game/images/bg5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/box2d-car-game/images/bg5.jpg -------------------------------------------------------------------------------- /box2d-car-game/images/bus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/box2d-car-game/images/bus.png -------------------------------------------------------------------------------- /box2d-car-game/images/flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/box2d-car-game/images/flag.png -------------------------------------------------------------------------------- /box2d-car-game/images/game_completed_screen.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/box2d-car-game/images/game_completed_screen.jpg -------------------------------------------------------------------------------- /box2d-car-game/images/starting_screen.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/box2d-car-game/images/starting_screen.jpg -------------------------------------------------------------------------------- /box2d-car-game/images/website_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/box2d-car-game/images/website_background.jpg -------------------------------------------------------------------------------- /box2d-car-game/images/wheel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/box2d-car-game/images/wheel.png -------------------------------------------------------------------------------- /box2d-car-game/index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | Box2D Car Game 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 |

Box2DJS Car Game

28 |
29 | 30 | 31 | 32 |
33 | 34 | 35 | 36 |
37 |
38 |
39 | 40 |
41 |
42 | 43 |
44 | 45 | 46 | 47 |
48 | 49 |

Press X to move right. Z to move left. R to restart the game.

50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /box2d-car-game/js/AUTHORS: -------------------------------------------------------------------------------- 1 | ExplorerCanvas 2 | 3 | Google Open Source: 4 | 5 | 6 | 7 | Developers: 8 | Emil A Eklund 9 | Erik Arvidsson 10 | Glen Murphy -------------------------------------------------------------------------------- /box2d-car-game/js/README: -------------------------------------------------------------------------------- 1 | ExplorerCanvas 2 | Copyright 2006 Google Inc. 3 | 4 | ------------------------------------------------------------------------------- 5 | DESCRIPTION 6 | 7 | Firefox, Safari and Opera 9 support the canvas tag to allow 2D command-based 8 | drawing operations. ExplorerCanvas brings the same functionality to Internet 9 | Explorer; web developers only need to include a single script tag in their 10 | existing canvas webpages to enable this support. 11 | 12 | 13 | ------------------------------------------------------------------------------- 14 | INSTALLATION 15 | 16 | Include the ExplorerCanvas tag in the same directory as your HTML files, and 17 | add the following code to your page, preferably in the tag. 18 | 19 | 20 | 21 | If you run into trouble, please look at the included example code to see how 22 | to best implement this -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/ClipVertex.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var ClipVertex = Class.create(); 24 | ClipVertex.prototype = 25 | { 26 | v: new b2Vec2(), 27 | id: new b2ContactID(), 28 | initialize: function() { 29 | // initialize instance variables for references 30 | this.v = new b2Vec2(); 31 | this.id = new b2ContactID(); 32 | // 33 | }}; 34 | 35 | 36 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/Features.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | // We use contact ids to facilitate warm starting. 21 | var Features = Class.create(); 22 | Features.prototype = 23 | { 24 | // 25 | set_referenceFace: function(value){ 26 | this._referenceFace = value; 27 | this._m_id._key = (this._m_id._key & 0xffffff00) | (this._referenceFace & 0x000000ff) 28 | }, 29 | get_referenceFace: function(){ 30 | return this._referenceFace; 31 | }, 32 | _referenceFace: 0, 33 | // 34 | set_incidentEdge: function(value){ 35 | this._incidentEdge = value; 36 | this._m_id._key = (this._m_id._key & 0xffff00ff) | ((this._incidentEdge << 8) & 0x0000ff00) 37 | }, 38 | get_incidentEdge: function(){ 39 | return this._incidentEdge; 40 | }, 41 | _incidentEdge: 0, 42 | // 43 | set_incidentVertex: function(value){ 44 | this._incidentVertex = value; 45 | this._m_id._key = (this._m_id._key & 0xff00ffff) | ((this._incidentVertex << 16) & 0x00ff0000) 46 | }, 47 | get_incidentVertex: function(){ 48 | return this._incidentVertex; 49 | }, 50 | _incidentVertex: 0, 51 | // 52 | set_flip: function(value){ 53 | this._flip = value; 54 | this._m_id._key = (this._m_id._key & 0x00ffffff) | ((this._flip << 24) & 0xff000000) 55 | }, 56 | get_flip: function(){ 57 | return this._flip; 58 | }, 59 | _flip: 0, 60 | _m_id: null, 61 | initialize: function() {}}; 62 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/b2AABB.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | // A manifold for two touching convex shapes. 22 | var b2AABB = Class.create(); 23 | b2AABB.prototype = 24 | { 25 | IsValid: function(){ 26 | //var d = b2Math.SubtractVV(this.maxVertex, this.minVertex); 27 | var dX = this.maxVertex.x; 28 | var dY = this.maxVertex.y; 29 | dX = this.maxVertex.x; 30 | dY = this.maxVertex.y; 31 | dX -= this.minVertex.x; 32 | dY -= this.minVertex.y; 33 | var valid = dX >= 0.0 && dY >= 0.0; 34 | valid = valid && this.minVertex.IsValid() && this.maxVertex.IsValid(); 35 | return valid; 36 | }, 37 | 38 | minVertex: new b2Vec2(), 39 | maxVertex: new b2Vec2(), 40 | initialize: function() { 41 | // initialize instance variables for references 42 | this.minVertex = new b2Vec2(); 43 | this.maxVertex = new b2Vec2(); 44 | // 45 | }}; 46 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/b2Bound.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | var b2Bound = Class.create(); 22 | b2Bound.prototype = { 23 | IsLower: function(){ return (this.value & 1) == 0; }, 24 | IsUpper: function(){ return (this.value & 1) == 1; }, 25 | Swap: function(b){ 26 | var tempValue = this.value; 27 | var tempProxyId = this.proxyId; 28 | var tempStabbingCount = this.stabbingCount; 29 | 30 | this.value = b.value; 31 | this.proxyId = b.proxyId; 32 | this.stabbingCount = b.stabbingCount; 33 | 34 | b.value = tempValue; 35 | b.proxyId = tempProxyId; 36 | b.stabbingCount = tempStabbingCount; 37 | }, 38 | 39 | value: 0, 40 | proxyId: 0, 41 | stabbingCount: 0, 42 | 43 | initialize: function() {}} 44 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/b2BoundValues.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | var b2BoundValues = Class.create(); 22 | b2BoundValues.prototype = { 23 | lowerValues: [0,0], 24 | upperValues: [0,0], 25 | 26 | initialize: function() { 27 | // initialize instance variables for references 28 | this.lowerValues = [0,0]; 29 | this.upperValues = [0,0]; 30 | // 31 | }} 32 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/b2BufferedPair.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | var b2BufferedPair = Class.create(); 22 | b2BufferedPair.prototype = { 23 | proxyId1: 0, 24 | proxyId2: 0, 25 | 26 | initialize: function() {}} 27 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/b2ContactID.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | // We use contact ids to facilitate warm starting. 22 | var b2ContactID = Class.create(); 23 | b2ContactID.prototype = 24 | { 25 | initialize: function(){ 26 | // initialize instance variables for references 27 | this.features = new Features(); 28 | // 29 | 30 | this.features._m_id = this; 31 | 32 | }, 33 | Set: function(id){ 34 | this.set_key(id._key); 35 | }, 36 | Copy: function(){ 37 | var id = new b2ContactID(); 38 | id.set_key(this._key); 39 | return id; 40 | }, 41 | get_key: function(){ 42 | return this._key; 43 | }, 44 | set_key: function(value) { 45 | this._key = value; 46 | this.features._referenceFace = this._key & 0x000000ff; 47 | this.features._incidentEdge = ((this._key & 0x0000ff00) >> 8) & 0x000000ff; 48 | this.features._incidentVertex = ((this._key & 0x00ff0000) >> 16) & 0x000000ff; 49 | this.features._flip = ((this._key & 0xff000000) >> 24) & 0x000000ff; 50 | }, 51 | features: new Features(), 52 | _key: 0}; 53 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/b2ContactPoint.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | // We use contact ids to facilitate warm starting. 22 | var b2ContactPoint = Class.create(); 23 | b2ContactPoint.prototype = 24 | { 25 | position: new b2Vec2(), 26 | separation: null, 27 | normalImpulse: null, 28 | tangentImpulse: null, 29 | id: new b2ContactID(), 30 | initialize: function() { 31 | // initialize instance variables for references 32 | this.position = new b2Vec2(); 33 | this.id = new b2ContactID(); 34 | // 35 | }}; 36 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/b2Manifold.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | // A manifold for two touching convex shapes. 22 | var b2Manifold = Class.create(); 23 | b2Manifold.prototype = 24 | { 25 | initialize: function(){ 26 | this.points = new Array(b2Settings.b2_maxManifoldPoints); 27 | for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++){ 28 | this.points[i] = new b2ContactPoint(); 29 | } 30 | this.normal = new b2Vec2(); 31 | }, 32 | points: null, 33 | normal: null, 34 | pointCount: 0}; 35 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/b2OBB.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | // A manifold for two touching convex shapes. 22 | var b2OBB = Class.create(); 23 | b2OBB.prototype = 24 | { 25 | R: new b2Mat22(), 26 | center: new b2Vec2(), 27 | extents: new b2Vec2(), 28 | initialize: function() { 29 | // initialize instance variables for references 30 | this.R = new b2Mat22(); 31 | this.center = new b2Vec2(); 32 | this.extents = new b2Vec2(); 33 | // 34 | }}; 35 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/b2Pair.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | // The pair manager is used by the broad-phase to quickly add/remove/find pairs 20 | // of overlapping proxies. It is based closely on code provided by Pierre Terdiman. 21 | // http: 22 | 23 | 24 | 25 | 26 | 27 | var b2Pair = Class.create(); 28 | b2Pair.prototype = 29 | { 30 | 31 | 32 | SetBuffered: function() { this.status |= b2Pair.e_pairBuffered; }, 33 | ClearBuffered: function() { this.status &= ~b2Pair.e_pairBuffered; }, 34 | IsBuffered: function(){ return (this.status & b2Pair.e_pairBuffered) == b2Pair.e_pairBuffered; }, 35 | 36 | SetRemoved: function() { this.status |= b2Pair.e_pairRemoved; }, 37 | ClearRemoved: function() { this.status &= ~b2Pair.e_pairRemoved; }, 38 | IsRemoved: function(){ return (this.status & b2Pair.e_pairRemoved) == b2Pair.e_pairRemoved; }, 39 | 40 | SetFinal: function() { this.status |= b2Pair.e_pairFinal; }, 41 | IsFinal: function(){ return (this.status & b2Pair.e_pairFinal) == b2Pair.e_pairFinal; }, 42 | 43 | userData: null, 44 | proxyId1: 0, 45 | proxyId2: 0, 46 | next: 0, 47 | status: 0, 48 | 49 | // STATIC 50 | 51 | // enum 52 | 53 | initialize: function() {}}; 54 | b2Pair.b2_nullPair = b2Settings.USHRT_MAX; 55 | b2Pair.b2_nullProxy = b2Settings.USHRT_MAX; 56 | b2Pair.b2_tableCapacity = b2Settings.b2_maxPairs; 57 | b2Pair.b2_tableMask = b2Pair.b2_tableCapacity - 1; 58 | b2Pair.e_pairBuffered = 0x0001; 59 | b2Pair.e_pairRemoved = 0x0002; 60 | b2Pair.e_pairFinal = 0x0004; 61 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/b2PairCallback.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | var b2PairCallback = Class.create(); 22 | b2PairCallback.prototype = 23 | { 24 | //virtual ~b2PairCallback() {} 25 | 26 | // This returns the new pair user data. 27 | PairAdded: function(proxyUserData1, proxyUserData2){return null}, 28 | 29 | // This should free the pair's user data. In extreme circumstances, it is possible 30 | // this will be called with null pairUserData because the pair never existed. 31 | PairRemoved: function(proxyUserData1, proxyUserData2, pairUserData){}, 32 | initialize: function() {}}; 33 | 34 | 35 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/b2Proxy.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | var b2Proxy = Class.create(); 22 | b2Proxy.prototype = { 23 | GetNext: function(){ return this.lowerBounds[0]; }, 24 | SetNext: function(next) { this.lowerBounds[0] = next /*& 0x0000ffff*/; }, 25 | 26 | IsValid: function(){ return this.overlapCount != b2BroadPhase.b2_invalid; }, 27 | 28 | lowerBounds: [/*uint*/(0), /*uint*/(0)], 29 | upperBounds: [/*uint*/(0), /*uint*/(0)], 30 | overlapCount: 0, 31 | timeStamp: 0, 32 | 33 | userData: null, 34 | 35 | initialize: function() { 36 | // initialize instance variables for references 37 | this.lowerBounds = [/*uint*/(0), /*uint*/(0)]; 38 | this.upperBounds = [/*uint*/(0), /*uint*/(0)]; 39 | // 40 | }} 41 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/shapes/b2BoxDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | var b2BoxDef = Class.create(); 26 | Object.extend(b2BoxDef.prototype, b2ShapeDef.prototype); 27 | Object.extend(b2BoxDef.prototype, 28 | { 29 | initialize: function() 30 | { 31 | // The constructor for b2ShapeDef 32 | this.type = b2Shape.e_unknownShape; 33 | this.userData = null; 34 | this.localPosition = new b2Vec2(0.0, 0.0); 35 | this.localRotation = 0.0; 36 | this.friction = 0.2; 37 | this.restitution = 0.0; 38 | this.density = 0.0; 39 | this.categoryBits = 0x0001; 40 | this.maskBits = 0xFFFF; 41 | this.groupIndex = 0; 42 | // 43 | 44 | this.type = b2Shape.e_boxShape; 45 | this.extents = new b2Vec2(1.0, 1.0); 46 | }, 47 | 48 | extents: null}); 49 | 50 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/shapes/b2CircleDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | var b2CircleDef = Class.create(); 26 | Object.extend(b2CircleDef.prototype, b2ShapeDef.prototype); 27 | Object.extend(b2CircleDef.prototype, 28 | { 29 | initialize: function() 30 | { 31 | // The constructor for b2ShapeDef 32 | this.type = b2Shape.e_unknownShape; 33 | this.userData = null; 34 | this.localPosition = new b2Vec2(0.0, 0.0); 35 | this.localRotation = 0.0; 36 | this.friction = 0.2; 37 | this.restitution = 0.0; 38 | this.density = 0.0; 39 | this.categoryBits = 0x0001; 40 | this.maskBits = 0xFFFF; 41 | this.groupIndex = 0; 42 | // 43 | 44 | this.type = b2Shape.e_circleShape; 45 | this.radius = 1.0; 46 | }, 47 | 48 | radius: null}); 49 | 50 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/shapes/b2MassData.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | var b2MassData = Class.create(); 26 | b2MassData.prototype = 27 | { 28 | mass: 0.0, 29 | center: new b2Vec2(0,0), 30 | I: 0.0, 31 | 32 | initialize: function() { 33 | // initialize instance variables for references 34 | this.center = new b2Vec2(0,0); 35 | // 36 | }} 37 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/shapes/b2PolyDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | var b2PolyDef = Class.create(); 26 | Object.extend(b2PolyDef.prototype, b2ShapeDef.prototype); 27 | Object.extend(b2PolyDef.prototype, 28 | { 29 | initialize: function() 30 | { 31 | // The constructor for b2ShapeDef 32 | this.type = b2Shape.e_unknownShape; 33 | this.userData = null; 34 | this.localPosition = new b2Vec2(0.0, 0.0); 35 | this.localRotation = 0.0; 36 | this.friction = 0.2; 37 | this.restitution = 0.0; 38 | this.density = 0.0; 39 | this.categoryBits = 0x0001; 40 | this.maskBits = 0xFFFF; 41 | this.groupIndex = 0; 42 | // 43 | 44 | // initialize instance variables for references 45 | this.vertices = new Array(b2Settings.b2_maxPolyVertices); 46 | // 47 | 48 | this.type = b2Shape.e_polyShape; 49 | this.vertexCount = 0; 50 | 51 | for (var i = 0; i < b2Settings.b2_maxPolyVertices; i++){ 52 | this.vertices[i] = new b2Vec2(); 53 | } 54 | }, 55 | 56 | vertices: new Array(b2Settings.b2_maxPolyVertices), 57 | vertexCount: 0}); 58 | 59 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/collision/shapes/b2ShapeDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | var b2ShapeDef = Class.create(); 26 | b2ShapeDef.prototype = 27 | { 28 | initialize: function() 29 | { 30 | this.type = b2Shape.e_unknownShape; 31 | this.userData = null; 32 | this.localPosition = new b2Vec2(0.0, 0.0); 33 | this.localRotation = 0.0; 34 | this.friction = 0.2; 35 | this.restitution = 0.0; 36 | this.density = 0.0; 37 | this.categoryBits = 0x0001; 38 | this.maskBits = 0xFFFF; 39 | this.groupIndex = 0; 40 | }, 41 | 42 | //virtual ~b2ShapeDef() {} 43 | 44 | ComputeMass: function(massData) 45 | { 46 | 47 | massData.center = new b2Vec2(0.0, 0.0) 48 | 49 | if (this.density == 0.0) 50 | { 51 | massData.mass = 0.0; 52 | massData.center.Set(0.0, 0.0); 53 | massData.I = 0.0; 54 | }; 55 | 56 | switch (this.type) 57 | { 58 | case b2Shape.e_circleShape: 59 | { 60 | var circle = this; 61 | massData.mass = this.density * b2Settings.b2_pi * circle.radius * circle.radius; 62 | massData.center.Set(0.0, 0.0); 63 | massData.I = 0.5 * (massData.mass) * circle.radius * circle.radius; 64 | } 65 | break; 66 | 67 | case b2Shape.e_boxShape: 68 | { 69 | var box = this; 70 | massData.mass = 4.0 * this.density * box.extents.x * box.extents.y; 71 | massData.center.Set(0.0, 0.0); 72 | massData.I = massData.mass / 3.0 * b2Math.b2Dot(box.extents, box.extents); 73 | } 74 | break; 75 | 76 | case b2Shape.e_polyShape: 77 | { 78 | var poly = this; 79 | b2Shape.PolyMass(massData, poly.vertices, poly.vertexCount, this.density); 80 | } 81 | break; 82 | 83 | default: 84 | massData.mass = 0.0; 85 | massData.center.Set(0.0, 0.0); 86 | massData.I = 0.0; 87 | break; 88 | } 89 | }, 90 | 91 | type: 0, 92 | userData: null, 93 | localPosition: null, 94 | localRotation: null, 95 | friction: null, 96 | restitution: null, 97 | density: null, 98 | 99 | // The collision category bits. Normally you would just set one bit. 100 | categoryBits: 0, 101 | 102 | // The collision mask bits. This states the categories that this 103 | // shape would accept for collision. 104 | maskBits: 0, 105 | 106 | // Collision groups allow a certain group of objects to never collide (negative) 107 | // or always collide (positive). Zero means no collision group. Non-zero group 108 | // filtering always wins against the mask bits. 109 | groupIndex: 0}; 110 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/common/b2Settings.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2Settings = Class.create(); 24 | b2Settings.prototype = { 25 | 26 | 27 | 28 | // Define your unit system here. The default system is 29 | // meters-kilograms-seconds. For the tuning to work well, 30 | // your dynamic objects should be bigger than a pebble and smaller 31 | // than a house. 32 | //static public const b2Settings.b2_lengthUnitsPerMeter = 1.0; 33 | 34 | // Use this for pixels: 35 | 36 | // Global tuning constants based on MKS units. 37 | 38 | // Collision 39 | 40 | // Dynamics 41 | 42 | // Sleep 43 | 44 | // assert 45 | 46 | initialize: function() {}} 47 | b2Settings.USHRT_MAX = 0x0000ffff; 48 | b2Settings.b2_pi = Math.PI; 49 | b2Settings.b2_massUnitsPerKilogram = 1.0; 50 | b2Settings.b2_timeUnitsPerSecond = 1.0; 51 | b2Settings.b2_lengthUnitsPerMeter = 30.0; 52 | b2Settings.b2_maxManifoldPoints = 2; 53 | b2Settings.b2_maxShapesPerBody = 64; 54 | b2Settings.b2_maxPolyVertices = 8; 55 | b2Settings.b2_maxProxies = 1024; 56 | b2Settings.b2_maxPairs = 8 * b2Settings.b2_maxProxies; 57 | b2Settings.b2_linearSlop = 0.005 * b2Settings.b2_lengthUnitsPerMeter; 58 | b2Settings.b2_angularSlop = 2.0 / 180.0 * b2Settings.b2_pi; 59 | b2Settings.b2_velocityThreshold = 1.0 * b2Settings.b2_lengthUnitsPerMeter / b2Settings.b2_timeUnitsPerSecond; 60 | b2Settings.b2_maxLinearCorrection = 0.2 * b2Settings.b2_lengthUnitsPerMeter; 61 | b2Settings.b2_maxAngularCorrection = 8.0 / 180.0 * b2Settings.b2_pi; 62 | b2Settings.b2_contactBaumgarte = 0.2; 63 | b2Settings.b2_timeToSleep = 0.5 * b2Settings.b2_timeUnitsPerSecond; 64 | b2Settings.b2_linearSleepTolerance = 0.01 * b2Settings.b2_lengthUnitsPerMeter / b2Settings.b2_timeUnitsPerSecond; 65 | b2Settings.b2_angularSleepTolerance = 2.0 / 180.0 / b2Settings.b2_timeUnitsPerSecond; 66 | b2Settings.b2Assert = function(a) 67 | { 68 | if (!a){ 69 | var nullVec; 70 | nullVec.x++; 71 | } 72 | }; 73 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/common/math/b2Mat22.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2Mat22 = Class.create(); 24 | b2Mat22.prototype = 25 | { 26 | initialize: function(angle, c1, c2) 27 | { 28 | if (angle==null) angle = 0; 29 | // initialize instance variables for references 30 | this.col1 = new b2Vec2(); 31 | this.col2 = new b2Vec2(); 32 | // 33 | 34 | if (c1!=null && c2!=null){ 35 | this.col1.SetV(c1); 36 | this.col2.SetV(c2); 37 | } 38 | else{ 39 | var c = Math.cos(angle); 40 | var s = Math.sin(angle); 41 | this.col1.x = c; this.col2.x = -s; 42 | this.col1.y = s; this.col2.y = c; 43 | } 44 | }, 45 | 46 | Set: function(angle) 47 | { 48 | var c = Math.cos(angle); 49 | var s = Math.sin(angle); 50 | this.col1.x = c; this.col2.x = -s; 51 | this.col1.y = s; this.col2.y = c; 52 | }, 53 | 54 | SetVV: function(c1, c2) 55 | { 56 | this.col1.SetV(c1); 57 | this.col2.SetV(c2); 58 | }, 59 | 60 | Copy: function(){ 61 | return new b2Mat22(0, this.col1, this.col2); 62 | }, 63 | 64 | SetM: function(m) 65 | { 66 | this.col1.SetV(m.col1); 67 | this.col2.SetV(m.col2); 68 | }, 69 | 70 | AddM: function(m) 71 | { 72 | this.col1.x += m.col1.x; 73 | this.col1.y += m.col1.y; 74 | this.col2.x += m.col2.x; 75 | this.col2.y += m.col2.y; 76 | }, 77 | 78 | SetIdentity: function() 79 | { 80 | this.col1.x = 1.0; this.col2.x = 0.0; 81 | this.col1.y = 0.0; this.col2.y = 1.0; 82 | }, 83 | 84 | SetZero: function() 85 | { 86 | this.col1.x = 0.0; this.col2.x = 0.0; 87 | this.col1.y = 0.0; this.col2.y = 0.0; 88 | }, 89 | 90 | Invert: function(out) 91 | { 92 | var a = this.col1.x; 93 | var b = this.col2.x; 94 | var c = this.col1.y; 95 | var d = this.col2.y; 96 | //var B = new b2Mat22(); 97 | var det = a * d - b * c; 98 | //b2Settings.b2Assert(det != 0.0); 99 | det = 1.0 / det; 100 | out.col1.x = det * d; out.col2.x = -det * b; 101 | out.col1.y = -det * c; out.col2.y = det * a; 102 | return out; 103 | }, 104 | 105 | // this.Solve A * x = b 106 | Solve: function(out, bX, bY) 107 | { 108 | //float32 a11 = this.col1.x, a12 = this.col2.x, a21 = this.col1.y, a22 = this.col2.y; 109 | var a11 = this.col1.x; 110 | var a12 = this.col2.x; 111 | var a21 = this.col1.y; 112 | var a22 = this.col2.y; 113 | //float32 det = a11 * a22 - a12 * a21; 114 | var det = a11 * a22 - a12 * a21; 115 | //b2Settings.b2Assert(det != 0.0); 116 | det = 1.0 / det; 117 | out.x = det * (a22 * bX - a12 * bY); 118 | out.y = det * (a11 * bY - a21 * bX); 119 | 120 | return out; 121 | }, 122 | 123 | Abs: function() 124 | { 125 | this.col1.Abs(); 126 | this.col2.Abs(); 127 | }, 128 | 129 | col1: new b2Vec2(), 130 | col2: new b2Vec2()}; 131 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/common/math/b2Math.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | var b2Math = Class.create(); 22 | b2Math.prototype = { 23 | 24 | 25 | /*static public function b2InvSqrt(x) 26 | { 27 | float32 xhalf = 0.5f * x; 28 | int32 i = *(int32*)&x; 29 | i = 0x5f3759df - (i >> 1); 30 | x = *(float32*)&i; 31 | x = x * (1.5f - xhalf * x * x); 32 | return x; 33 | }*/ 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | // A * B 46 | 47 | // A^T * B 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | // b2Math.b2Random number in range [-1,1] 60 | 61 | /*inline float32 b2Math.b2Random(float32 lo, float32 hi) 62 | { 63 | float32 r = (float32)rand(); 64 | r /= RAND_MAX; 65 | r = (hi - lo) * r + lo; 66 | return r; 67 | }*/ 68 | 69 | // "Next Largest Power of 2 70 | // Given a binary integer value x, the next largest power of 2 can be computed by a SWAR algorithm 71 | // that recursively "folds" the upper bits into the lower bits. This process yields a bit vector with 72 | // the same most significant 1, but all 1's below it. Adding 1 to that value yields the next 73 | // largest power of 2. For a 32-bit value:" 74 | 75 | 76 | 77 | // Temp vector functions to reduce calls to 'new' 78 | /*static public var tempVec = new b2Vec2(); 79 | 80 | 81 | static public var tempAABB = new b2AABB(); */ 82 | 83 | 84 | 85 | initialize: function() {}} 86 | b2Math.b2IsValid = function(x) 87 | { 88 | return isFinite(x); 89 | }; 90 | b2Math.b2Dot = function(a, b) 91 | { 92 | return a.x * b.x + a.y * b.y; 93 | }; 94 | b2Math.b2CrossVV = function(a, b) 95 | { 96 | return a.x * b.y - a.y * b.x; 97 | }; 98 | b2Math.b2CrossVF = function(a, s) 99 | { 100 | var v = new b2Vec2(s * a.y, -s * a.x); 101 | return v; 102 | }; 103 | b2Math.b2CrossFV = function(s, a) 104 | { 105 | var v = new b2Vec2(-s * a.y, s * a.x); 106 | return v; 107 | }; 108 | b2Math.b2MulMV = function(A, v) 109 | { 110 | var u = new b2Vec2(A.col1.x * v.x + A.col2.x * v.y, A.col1.y * v.x + A.col2.y * v.y); 111 | return u; 112 | }; 113 | b2Math.b2MulTMV = function(A, v) 114 | { 115 | var u = new b2Vec2(b2Math.b2Dot(v, A.col1), b2Math.b2Dot(v, A.col2)); 116 | return u; 117 | }; 118 | b2Math.AddVV = function(a, b) 119 | { 120 | var v = new b2Vec2(a.x + b.x, a.y + b.y); 121 | return v; 122 | }; 123 | b2Math.SubtractVV = function(a, b) 124 | { 125 | var v = new b2Vec2(a.x - b.x, a.y - b.y); 126 | return v; 127 | }; 128 | b2Math.MulFV = function(s, a) 129 | { 130 | var v = new b2Vec2(s * a.x, s * a.y); 131 | return v; 132 | }; 133 | b2Math.AddMM = function(A, B) 134 | { 135 | var C = new b2Mat22(0, b2Math.AddVV(A.col1, B.col1), b2Math.AddVV(A.col2, B.col2)); 136 | return C; 137 | }; 138 | b2Math.b2MulMM = function(A, B) 139 | { 140 | var C = new b2Mat22(0, b2Math.b2MulMV(A, B.col1), b2Math.b2MulMV(A, B.col2)); 141 | return C; 142 | }; 143 | b2Math.b2MulTMM = function(A, B) 144 | { 145 | var c1 = new b2Vec2(b2Math.b2Dot(A.col1, B.col1), b2Math.b2Dot(A.col2, B.col1)); 146 | var c2 = new b2Vec2(b2Math.b2Dot(A.col1, B.col2), b2Math.b2Dot(A.col2, B.col2)); 147 | var C = new b2Mat22(0, c1, c2); 148 | return C; 149 | }; 150 | b2Math.b2Abs = function(a) 151 | { 152 | return a > 0.0 ? a : -a; 153 | }; 154 | b2Math.b2AbsV = function(a) 155 | { 156 | var b = new b2Vec2(b2Math.b2Abs(a.x), b2Math.b2Abs(a.y)); 157 | return b; 158 | }; 159 | b2Math.b2AbsM = function(A) 160 | { 161 | var B = new b2Mat22(0, b2Math.b2AbsV(A.col1), b2Math.b2AbsV(A.col2)); 162 | return B; 163 | }; 164 | b2Math.b2Min = function(a, b) 165 | { 166 | return a < b ? a : b; 167 | }; 168 | b2Math.b2MinV = function(a, b) 169 | { 170 | var c = new b2Vec2(b2Math.b2Min(a.x, b.x), b2Math.b2Min(a.y, b.y)); 171 | return c; 172 | }; 173 | b2Math.b2Max = function(a, b) 174 | { 175 | return a > b ? a : b; 176 | }; 177 | b2Math.b2MaxV = function(a, b) 178 | { 179 | var c = new b2Vec2(b2Math.b2Max(a.x, b.x), b2Math.b2Max(a.y, b.y)); 180 | return c; 181 | }; 182 | b2Math.b2Clamp = function(a, low, high) 183 | { 184 | return b2Math.b2Max(low, b2Math.b2Min(a, high)); 185 | }; 186 | b2Math.b2ClampV = function(a, low, high) 187 | { 188 | return b2Math.b2MaxV(low, b2Math.b2MinV(a, high)); 189 | }; 190 | b2Math.b2Swap = function(a, b) 191 | { 192 | var tmp = a[0]; 193 | a[0] = b[0]; 194 | b[0] = tmp; 195 | }; 196 | b2Math.b2Random = function() 197 | { 198 | return Math.random() * 2 - 1; 199 | }; 200 | b2Math.b2NextPowerOfTwo = function(x) 201 | { 202 | x |= (x >> 1) & 0x7FFFFFFF; 203 | x |= (x >> 2) & 0x3FFFFFFF; 204 | x |= (x >> 4) & 0x0FFFFFFF; 205 | x |= (x >> 8) & 0x00FFFFFF; 206 | x |= (x >> 16)& 0x0000FFFF; 207 | return x + 1; 208 | }; 209 | b2Math.b2IsPowerOfTwo = function(x) 210 | { 211 | var result = x > 0 && (x & (x - 1)) == 0; 212 | return result; 213 | }; 214 | b2Math.tempVec2 = new b2Vec2(); 215 | b2Math.tempVec3 = new b2Vec2(); 216 | b2Math.tempVec4 = new b2Vec2(); 217 | b2Math.tempVec5 = new b2Vec2(); 218 | b2Math.tempMat = new b2Mat22(); 219 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/common/math/b2Vec2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | // b2Vec2 has no constructor so that it 24 | // can be placed in a union. 25 | var b2Vec2 = Class.create(); 26 | b2Vec2.prototype = 27 | { 28 | initialize: function(x_, y_) {this.x=x_; this.y=y_;}, 29 | 30 | SetZero: function() { this.x = 0.0; this.y = 0.0; }, 31 | Set: function(x_, y_) {this.x=x_; this.y=y_;}, 32 | SetV: function(v) {this.x=v.x; this.y=v.y;}, 33 | 34 | Negative: function(){ return new b2Vec2(-this.x, -this.y); }, 35 | 36 | 37 | Copy: function(){ 38 | return new b2Vec2(this.x,this.y); 39 | }, 40 | 41 | Add: function(v) 42 | { 43 | this.x += v.x; this.y += v.y; 44 | }, 45 | 46 | Subtract: function(v) 47 | { 48 | this.x -= v.x; this.y -= v.y; 49 | }, 50 | 51 | Multiply: function(a) 52 | { 53 | this.x *= a; this.y *= a; 54 | }, 55 | 56 | MulM: function(A) 57 | { 58 | var tX = this.x; 59 | this.x = A.col1.x * tX + A.col2.x * this.y; 60 | this.y = A.col1.y * tX + A.col2.y * this.y; 61 | }, 62 | 63 | MulTM: function(A) 64 | { 65 | var tX = b2Math.b2Dot(this, A.col1); 66 | this.y = b2Math.b2Dot(this, A.col2); 67 | this.x = tX; 68 | }, 69 | 70 | CrossVF: function(s) 71 | { 72 | var tX = this.x; 73 | this.x = s * this.y; 74 | this.y = -s * tX; 75 | }, 76 | 77 | CrossFV: function(s) 78 | { 79 | var tX = this.x; 80 | this.x = -s * this.y; 81 | this.y = s * tX; 82 | }, 83 | 84 | MinV: function(b) 85 | { 86 | this.x = this.x < b.x ? this.x : b.x; 87 | this.y = this.y < b.y ? this.y : b.y; 88 | }, 89 | 90 | MaxV: function(b) 91 | { 92 | this.x = this.x > b.x ? this.x : b.x; 93 | this.y = this.y > b.y ? this.y : b.y; 94 | }, 95 | 96 | Abs: function() 97 | { 98 | this.x = Math.abs(this.x); 99 | this.y = Math.abs(this.y); 100 | }, 101 | 102 | Length: function() 103 | { 104 | return Math.sqrt(this.x * this.x + this.y * this.y); 105 | }, 106 | 107 | Normalize: function() 108 | { 109 | var length = this.Length(); 110 | if (length < Number.MIN_VALUE) 111 | { 112 | return 0.0; 113 | } 114 | var invLength = 1.0 / length; 115 | this.x *= invLength; 116 | this.y *= invLength; 117 | 118 | return length; 119 | }, 120 | 121 | IsValid: function() 122 | { 123 | return b2Math.b2IsValid(this.x) && b2Math.b2IsValid(this.y); 124 | }, 125 | 126 | x: null, 127 | y: null}; 128 | b2Vec2.Make = function(x_, y_) 129 | { 130 | return new b2Vec2(x_, y_); 131 | }; 132 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/b2BodyDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2BodyDef = Class.create(); 24 | b2BodyDef.prototype = 25 | { 26 | initialize: function() 27 | { 28 | // initialize instance variables for references 29 | this.shapes = new Array(); 30 | // 31 | 32 | this.userData = null; 33 | for (var i = 0; i < b2Settings.b2_maxShapesPerBody; i++){ 34 | this.shapes[i] = null; 35 | } 36 | this.position = new b2Vec2(0.0, 0.0); 37 | this.rotation = 0.0; 38 | this.linearVelocity = new b2Vec2(0.0, 0.0); 39 | this.angularVelocity = 0.0; 40 | this.linearDamping = 0.0; 41 | this.angularDamping = 0.0; 42 | this.allowSleep = true; 43 | this.isSleeping = false; 44 | this.preventRotation = false; 45 | }, 46 | 47 | userData: null, 48 | shapes: new Array(), 49 | position: null, 50 | rotation: null, 51 | linearVelocity: null, 52 | angularVelocity: null, 53 | linearDamping: null, 54 | angularDamping: null, 55 | allowSleep: null, 56 | isSleeping: null, 57 | preventRotation: null, 58 | 59 | AddShape: function(shape) 60 | { 61 | for (var i = 0; i < b2Settings.b2_maxShapesPerBody; ++i) 62 | { 63 | if (this.shapes[i] == null) 64 | { 65 | this.shapes[i] = shape; 66 | break; 67 | } 68 | } 69 | }}; 70 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/b2CollisionFilter.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | var b2CollisionFilter = Class.create(); 26 | b2CollisionFilter.prototype = 27 | { 28 | 29 | // Return true if contact calculations should be performed between these two shapes. 30 | ShouldCollide: function(shape1, shape2){ 31 | if (shape1.m_groupIndex == shape2.m_groupIndex && shape1.m_groupIndex != 0) 32 | { 33 | return shape1.m_groupIndex > 0; 34 | } 35 | 36 | var collide = (shape1.m_maskBits & shape2.m_categoryBits) != 0 && (shape1.m_categoryBits & shape2.m_maskBits) != 0; 37 | return collide; 38 | }, 39 | 40 | 41 | initialize: function() {}}; 42 | b2CollisionFilter.b2_defaultFilter = new b2CollisionFilter; 43 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/b2TimeStep.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | var b2TimeStep = Class.create(); 22 | b2TimeStep.prototype = 23 | { 24 | dt: null, 25 | inv_dt: null, 26 | iterations: 0, 27 | initialize: function() {}}; 28 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/b2WorldListener.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | var b2WorldListener = Class.create(); 26 | b2WorldListener.prototype = 27 | { 28 | 29 | // If a body is destroyed, then any joints attached to it are also destroyed. 30 | // This prevents memory leaks, but you may unexpectedly be left with an 31 | // orphaned joint pointer. 32 | // Box2D will notify you when a joint is implicitly destroyed. 33 | // It is NOT called if you directly destroy a joint. 34 | // Implement this abstract class and provide it to b2World via 35 | // b2World::SetListener(). 36 | // DO NOT modify the Box2D world inside this callback. 37 | NotifyJointDestroyed: function(joint){}, 38 | 39 | // This is called when a body's shape passes outside of the world boundary. If you 40 | // override this and pass back e_destroyBody, you must nullify your copies of the 41 | // body pointer. 42 | NotifyBoundaryViolated: function(body) 43 | { 44 | //NOT_USED(body); 45 | return b2WorldListener.b2_freezeBody; 46 | }, 47 | 48 | 49 | 50 | initialize: function() {}}; 51 | b2WorldListener.b2_freezeBody = 0; 52 | b2WorldListener.b2_destroyBody = 1; 53 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/contacts/b2CircleContact.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | var b2CircleContact = Class.create(); 23 | Object.extend(b2CircleContact.prototype, b2Contact.prototype); 24 | Object.extend(b2CircleContact.prototype, 25 | { 26 | 27 | initialize: function(s1, s2) { 28 | // The constructor for b2Contact 29 | // initialize instance variables for references 30 | this.m_node1 = new b2ContactNode(); 31 | this.m_node2 = new b2ContactNode(); 32 | // 33 | this.m_flags = 0; 34 | 35 | if (!s1 || !s2){ 36 | this.m_shape1 = null; 37 | this.m_shape2 = null; 38 | return; 39 | } 40 | 41 | this.m_shape1 = s1; 42 | this.m_shape2 = s2; 43 | 44 | this.m_manifoldCount = 0; 45 | 46 | this.m_friction = Math.sqrt(this.m_shape1.m_friction * this.m_shape2.m_friction); 47 | this.m_restitution = b2Math.b2Max(this.m_shape1.m_restitution, this.m_shape2.m_restitution); 48 | 49 | this.m_prev = null; 50 | this.m_next = null; 51 | 52 | this.m_node1.contact = null; 53 | this.m_node1.prev = null; 54 | this.m_node1.next = null; 55 | this.m_node1.other = null; 56 | 57 | this.m_node2.contact = null; 58 | this.m_node2.prev = null; 59 | this.m_node2.next = null; 60 | this.m_node2.other = null; 61 | // 62 | 63 | // initialize instance variables for references 64 | this.m_manifold = [new b2Manifold()]; 65 | // 66 | 67 | //super(shape1, shape2); 68 | 69 | //b2Settings.b2Assert(this.m_shape1.m_type == b2Shape.e_circleShape); 70 | //b2Settings.b2Assert(this.m_shape2.m_type == b2Shape.e_circleShape); 71 | this.m_manifold[0].pointCount = 0; 72 | this.m_manifold[0].points[0].normalImpulse = 0.0; 73 | this.m_manifold[0].points[0].tangentImpulse = 0.0; 74 | }, 75 | //~b2CircleContact() {} 76 | 77 | Evaluate: function(){ 78 | b2Collision.b2CollideCircle(this.m_manifold[0], this.m_shape1, this.m_shape2, false); 79 | 80 | if (this.m_manifold[0].pointCount > 0) 81 | { 82 | this.m_manifoldCount = 1; 83 | } 84 | else 85 | { 86 | this.m_manifoldCount = 0; 87 | } 88 | }, 89 | 90 | GetManifolds: function() 91 | { 92 | return this.m_manifold; 93 | }, 94 | 95 | m_manifold: [new b2Manifold()]}); 96 | 97 | b2CircleContact.Create = function(shape1, shape2, allocator){ 98 | return new b2CircleContact(shape1, shape2); 99 | }; 100 | b2CircleContact.Destroy = function(contact, allocator){ 101 | // 102 | }; 103 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/contacts/b2ContactConstraint.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2ContactConstraint = Class.create(); 24 | b2ContactConstraint.prototype = 25 | { 26 | initialize: function(){ 27 | // initialize instance variables for references 28 | this.normal = new b2Vec2(); 29 | // 30 | 31 | this.points = new Array(b2Settings.b2_maxManifoldPoints); 32 | for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++){ 33 | this.points[i] = new b2ContactConstraintPoint(); 34 | } 35 | 36 | 37 | }, 38 | points: null, 39 | normal: new b2Vec2(), 40 | manifold: null, 41 | body1: null, 42 | body2: null, 43 | friction: null, 44 | restitution: null, 45 | pointCount: 0}; 46 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/contacts/b2ContactConstraintPoint.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2ContactConstraintPoint = Class.create(); 24 | b2ContactConstraintPoint.prototype = 25 | { 26 | localAnchor1: new b2Vec2(), 27 | localAnchor2: new b2Vec2(), 28 | normalImpulse: null, 29 | tangentImpulse: null, 30 | positionImpulse: null, 31 | normalMass: null, 32 | tangentMass: null, 33 | separation: null, 34 | velocityBias: null, 35 | initialize: function() { 36 | // initialize instance variables for references 37 | this.localAnchor1 = new b2Vec2(); 38 | this.localAnchor2 = new b2Vec2(); 39 | // 40 | }}; 41 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/contacts/b2ContactNode.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2ContactNode = Class.create(); 24 | b2ContactNode.prototype = 25 | { 26 | other: null, 27 | contact: null, 28 | prev: null, 29 | next: null, 30 | initialize: function() {}}; 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/contacts/b2ContactRegister.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | var b2ContactRegister = Class.create(); 22 | b2ContactRegister.prototype = 23 | { 24 | createFcn: null, 25 | destroyFcn: null, 26 | primary: null, 27 | initialize: function() {}}; 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/contacts/b2NullContact.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2NullContact = Class.create(); 24 | Object.extend(b2NullContact.prototype, b2Contact.prototype); 25 | Object.extend(b2NullContact.prototype, 26 | { 27 | initialize: function(s1, s2) { 28 | // The constructor for b2Contact 29 | // initialize instance variables for references 30 | this.m_node1 = new b2ContactNode(); 31 | this.m_node2 = new b2ContactNode(); 32 | // 33 | this.m_flags = 0; 34 | 35 | if (!s1 || !s2){ 36 | this.m_shape1 = null; 37 | this.m_shape2 = null; 38 | return; 39 | } 40 | 41 | this.m_shape1 = s1; 42 | this.m_shape2 = s2; 43 | 44 | this.m_manifoldCount = 0; 45 | 46 | this.m_friction = Math.sqrt(this.m_shape1.m_friction * this.m_shape2.m_friction); 47 | this.m_restitution = b2Math.b2Max(this.m_shape1.m_restitution, this.m_shape2.m_restitution); 48 | 49 | this.m_prev = null; 50 | this.m_next = null; 51 | 52 | this.m_node1.contact = null; 53 | this.m_node1.prev = null; 54 | this.m_node1.next = null; 55 | this.m_node1.other = null; 56 | 57 | this.m_node2.contact = null; 58 | this.m_node2.prev = null; 59 | this.m_node2.next = null; 60 | this.m_node2.other = null; 61 | // 62 | }, 63 | Evaluate: function() {}, 64 | GetManifolds: function(){ return null; }}); 65 | 66 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/contacts/b2PolyAndCircleContact.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2PolyAndCircleContact = Class.create(); 24 | Object.extend(b2PolyAndCircleContact.prototype, b2Contact.prototype); 25 | Object.extend(b2PolyAndCircleContact.prototype, { 26 | 27 | 28 | initialize: function(s1, s2) { 29 | // The constructor for b2Contact 30 | // initialize instance variables for references 31 | this.m_node1 = new b2ContactNode(); 32 | this.m_node2 = new b2ContactNode(); 33 | // 34 | this.m_flags = 0; 35 | 36 | if (!s1 || !s2){ 37 | this.m_shape1 = null; 38 | this.m_shape2 = null; 39 | return; 40 | } 41 | 42 | this.m_shape1 = s1; 43 | this.m_shape2 = s2; 44 | 45 | this.m_manifoldCount = 0; 46 | 47 | this.m_friction = Math.sqrt(this.m_shape1.m_friction * this.m_shape2.m_friction); 48 | this.m_restitution = b2Math.b2Max(this.m_shape1.m_restitution, this.m_shape2.m_restitution); 49 | 50 | this.m_prev = null; 51 | this.m_next = null; 52 | 53 | this.m_node1.contact = null; 54 | this.m_node1.prev = null; 55 | this.m_node1.next = null; 56 | this.m_node1.other = null; 57 | 58 | this.m_node2.contact = null; 59 | this.m_node2.prev = null; 60 | this.m_node2.next = null; 61 | this.m_node2.other = null; 62 | // 63 | 64 | // initialize instance variables for references 65 | this.m_manifold = [new b2Manifold()]; 66 | // 67 | 68 | //super(shape1, shape2); 69 | 70 | b2Settings.b2Assert(this.m_shape1.m_type == b2Shape.e_polyShape); 71 | b2Settings.b2Assert(this.m_shape2.m_type == b2Shape.e_circleShape); 72 | this.m_manifold[0].pointCount = 0; 73 | this.m_manifold[0].points[0].normalImpulse = 0.0; 74 | this.m_manifold[0].points[0].tangentImpulse = 0.0; 75 | }, 76 | //~b2PolyAndCircleContact() {} 77 | 78 | Evaluate: function(){ 79 | b2Collision.b2CollidePolyAndCircle(this.m_manifold[0], this.m_shape1, this.m_shape2, false); 80 | 81 | if (this.m_manifold[0].pointCount > 0) 82 | { 83 | this.m_manifoldCount = 1; 84 | } 85 | else 86 | { 87 | this.m_manifoldCount = 0; 88 | } 89 | }, 90 | 91 | GetManifolds: function() 92 | { 93 | return this.m_manifold; 94 | }, 95 | 96 | m_manifold: [new b2Manifold()]}) 97 | 98 | b2PolyAndCircleContact.Create = function(shape1, shape2, allocator){ 99 | return new b2PolyAndCircleContact(shape1, shape2); 100 | }; 101 | b2PolyAndCircleContact.Destroy = function(contact, allocator){ 102 | // 103 | }; 104 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/contacts/b2PolyContact.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2PolyContact = Class.create(); 24 | Object.extend(b2PolyContact.prototype, b2Contact.prototype); 25 | Object.extend(b2PolyContact.prototype, 26 | { 27 | 28 | initialize: function(s1, s2) { 29 | // The constructor for b2Contact 30 | // initialize instance variables for references 31 | this.m_node1 = new b2ContactNode(); 32 | this.m_node2 = new b2ContactNode(); 33 | // 34 | this.m_flags = 0; 35 | 36 | if (!s1 || !s2){ 37 | this.m_shape1 = null; 38 | this.m_shape2 = null; 39 | return; 40 | } 41 | 42 | this.m_shape1 = s1; 43 | this.m_shape2 = s2; 44 | 45 | this.m_manifoldCount = 0; 46 | 47 | this.m_friction = Math.sqrt(this.m_shape1.m_friction * this.m_shape2.m_friction); 48 | this.m_restitution = b2Math.b2Max(this.m_shape1.m_restitution, this.m_shape2.m_restitution); 49 | 50 | this.m_prev = null; 51 | this.m_next = null; 52 | 53 | this.m_node1.contact = null; 54 | this.m_node1.prev = null; 55 | this.m_node1.next = null; 56 | this.m_node1.other = null; 57 | 58 | this.m_node2.contact = null; 59 | this.m_node2.prev = null; 60 | this.m_node2.next = null; 61 | this.m_node2.other = null; 62 | // 63 | 64 | // initialize instance variables for references 65 | this.m0 = new b2Manifold(); 66 | this.m_manifold = [new b2Manifold()]; 67 | // 68 | 69 | //super(shape1, shape2); 70 | //b2Settings.b2Assert(this.m_shape1.m_type == b2Shape.e_polyShape); 71 | //b2Settings.b2Assert(this.m_shape2.m_type == b2Shape.e_polyShape); 72 | this.m_manifold[0].pointCount = 0; 73 | }, 74 | //~b2PolyContact() {} 75 | 76 | // store temp manifold to reduce calls to new 77 | m0: new b2Manifold(), 78 | 79 | Evaluate: function(){ 80 | var tMani = this.m_manifold[0]; 81 | // replace memcpy 82 | // memcpy(&this.m0, &this.m_manifold, sizeof(b2Manifold)); 83 | //this.m0.points = new Array(tMani.pointCount); 84 | var tPoints = this.m0.points; 85 | 86 | for (var k = 0; k < tMani.pointCount; k++){ 87 | var tPoint = tPoints[k]; 88 | var tPoint0 = tMani.points[k]; 89 | //tPoint.separation = tPoint0.separation; 90 | tPoint.normalImpulse = tPoint0.normalImpulse; 91 | tPoint.tangentImpulse = tPoint0.tangentImpulse; 92 | //tPoint.position.SetV( tPoint0.position ); 93 | 94 | tPoint.id = tPoint0.id.Copy(); 95 | 96 | /*this.m0.points[k].id.features = new Features(); 97 | this.m0.points[k].id.features.referenceFace = this.m_manifold[0].points[k].id.features.referenceFace; 98 | this.m0.points[k].id.features.incidentEdge = this.m_manifold[0].points[k].id.features.incidentEdge; 99 | this.m0.points[k].id.features.incidentVertex = this.m_manifold[0].points[k].id.features.incidentVertex; 100 | this.m0.points[k].id.features.flip = this.m_manifold[0].points[k].id.features.flip;*/ 101 | } 102 | //this.m0.normal.SetV( tMani.normal ); 103 | this.m0.pointCount = tMani.pointCount; 104 | 105 | b2Collision.b2CollidePoly(tMani, this.m_shape1, this.m_shape2, false); 106 | 107 | // Match contact ids to facilitate warm starting. 108 | if (tMani.pointCount > 0) 109 | { 110 | var match = [false, false]; 111 | 112 | // Match old contact ids to new contact ids and copy the 113 | // stored impulses to warm start the solver. 114 | for (var i = 0; i < tMani.pointCount; ++i) 115 | { 116 | var cp = tMani.points[ i ]; 117 | 118 | cp.normalImpulse = 0.0; 119 | cp.tangentImpulse = 0.0; 120 | var idKey = cp.id.key; 121 | 122 | for (var j = 0; j < this.m0.pointCount; ++j) 123 | { 124 | 125 | if (match[j] == true) 126 | continue; 127 | 128 | var cp0 = this.m0.points[j]; 129 | var id0 = cp0.id; 130 | 131 | if (id0.key == idKey) 132 | { 133 | match[j] = true; 134 | cp.normalImpulse = cp0.normalImpulse; 135 | cp.tangentImpulse = cp0.tangentImpulse; 136 | break; 137 | } 138 | } 139 | } 140 | 141 | this.m_manifoldCount = 1; 142 | } 143 | else 144 | { 145 | this.m_manifoldCount = 0; 146 | } 147 | }, 148 | 149 | GetManifolds: function() 150 | { 151 | return this.m_manifold; 152 | }, 153 | 154 | m_manifold: [new b2Manifold()]}); 155 | 156 | b2PolyContact.Create = function(shape1, shape2, allocator){ 157 | //void* mem = allocator->Allocate(sizeof(b2PolyContact)); 158 | return new b2PolyContact(shape1, shape2); 159 | }; 160 | b2PolyContact.Destroy = function(contact, allocator){ 161 | //((b2PolyContact*)contact)->~b2PolyContact(); 162 | //allocator->Free(contact, sizeof(b2PolyContact)); 163 | }; 164 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/joints/b2DistanceJointDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2DistanceJointDef = Class.create(); 24 | Object.extend(b2DistanceJointDef.prototype, b2JointDef.prototype); 25 | Object.extend(b2DistanceJointDef.prototype, 26 | { 27 | initialize: function() 28 | { 29 | // The constructor for b2JointDef 30 | this.type = b2Joint.e_unknownJoint; 31 | this.userData = null; 32 | this.body1 = null; 33 | this.body2 = null; 34 | this.collideConnected = false; 35 | // 36 | 37 | // initialize instance variables for references 38 | this.anchorPoint1 = new b2Vec2(); 39 | this.anchorPoint2 = new b2Vec2(); 40 | // 41 | 42 | this.type = b2Joint.e_distanceJoint; 43 | //this.anchorPoint1.Set(0.0, 0.0); 44 | //this.anchorPoint2.Set(0.0, 0.0); 45 | }, 46 | 47 | anchorPoint1: new b2Vec2(), 48 | anchorPoint2: new b2Vec2()}); 49 | 50 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/joints/b2GearJointDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | 24 | // A gear joint is used to connect two joints together. Either joint 25 | // can be a revolute or prismatic joint. You specify a gear ratio 26 | // to bind the motions together: 27 | // coordinate1 + ratio * coordinate2 = constant 28 | // The ratio can be negative or positive. If one joint is a revolute joint 29 | // and the other joint is a prismatic joint, then the ratio will have units 30 | // of length or units of 1/length. 31 | // 32 | // RESTRICITON: The revolute and prismatic joints must be attached to 33 | // a fixed body (which must be body1 on those joints). 34 | 35 | var b2GearJointDef = Class.create(); 36 | Object.extend(b2GearJointDef.prototype, b2JointDef.prototype); 37 | Object.extend(b2GearJointDef.prototype, 38 | { 39 | initialize: function() 40 | { 41 | this.type = b2Joint.e_gearJoint; 42 | this.joint1 = null; 43 | this.joint2 = null; 44 | this.ratio = 1.0; 45 | }, 46 | 47 | joint1: null, 48 | joint2: null, 49 | ratio: null}); 50 | 51 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/joints/b2Jacobian.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2Jacobian = Class.create(); 24 | b2Jacobian.prototype = 25 | { 26 | linear1: new b2Vec2(), 27 | angular1: null, 28 | linear2: new b2Vec2(), 29 | angular2: null, 30 | 31 | SetZero: function(){ 32 | this.linear1.SetZero(); this.angular1 = 0.0; 33 | this.linear2.SetZero(); this.angular2 = 0.0; 34 | }, 35 | Set: function(x1, a1, x2, a2){ 36 | this.linear1.SetV(x1); this.angular1 = a1; 37 | this.linear2.SetV(x2); this.angular2 = a2; 38 | }, 39 | Compute: function(x1, a1, x2, a2){ 40 | 41 | //return b2Math.b2Dot(this.linear1, x1) + this.angular1 * a1 + b2Math.b2Dot(this.linear2, x2) + this.angular2 * a2; 42 | return (this.linear1.x*x1.x + this.linear1.y*x1.y) + this.angular1 * a1 + (this.linear2.x*x2.x + this.linear2.y*x2.y) + this.angular2 * a2; 43 | }, 44 | initialize: function() { 45 | // initialize instance variables for references 46 | this.linear1 = new b2Vec2(); 47 | this.linear2 = new b2Vec2(); 48 | // 49 | }}; 50 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/joints/b2Joint.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2Joint = Class.create(); 24 | b2Joint.prototype = 25 | { 26 | GetType: function(){ 27 | return this.m_type; 28 | }, 29 | 30 | GetAnchor1: function(){return null}, 31 | GetAnchor2: function(){return null}, 32 | 33 | GetReactionForce: function(invTimeStep){return null}, 34 | GetReactionTorque: function(invTimeStep){return 0.0}, 35 | 36 | GetBody1: function() 37 | { 38 | return this.m_body1; 39 | }, 40 | 41 | GetBody2: function() 42 | { 43 | return this.m_body2; 44 | }, 45 | 46 | GetNext: function(){ 47 | return this.m_next; 48 | }, 49 | 50 | GetUserData: function(){ 51 | return this.m_userData; 52 | }, 53 | 54 | //--------------- Internals Below ------------------- 55 | 56 | 57 | 58 | initialize: function(def){ 59 | // initialize instance variables for references 60 | this.m_node1 = new b2JointNode(); 61 | this.m_node2 = new b2JointNode(); 62 | // 63 | 64 | this.m_type = def.type; 65 | this.m_prev = null; 66 | this.m_next = null; 67 | this.m_body1 = def.body1; 68 | this.m_body2 = def.body2; 69 | this.m_collideConnected = def.collideConnected; 70 | this.m_islandFlag = false; 71 | this.m_userData = def.userData; 72 | }, 73 | //virtual ~b2Joint() {} 74 | 75 | PrepareVelocitySolver: function(){}, 76 | SolveVelocityConstraints: function(step){}, 77 | 78 | // This returns true if the position errors are within tolerance. 79 | PreparePositionSolver: function(){}, 80 | SolvePositionConstraints: function(){return false}, 81 | 82 | m_type: 0, 83 | m_prev: null, 84 | m_next: null, 85 | m_node1: new b2JointNode(), 86 | m_node2: new b2JointNode(), 87 | m_body1: null, 88 | m_body2: null, 89 | 90 | m_islandFlag: null, 91 | m_collideConnected: null, 92 | 93 | m_userData: null 94 | 95 | 96 | // ENUMS 97 | 98 | // enum b2JointType 99 | 100 | // enum b2LimitState 101 | 102 | }; 103 | b2Joint.Create = function(def, allocator){ 104 | var joint = null; 105 | 106 | switch (def.type) 107 | { 108 | case b2Joint.e_distanceJoint: 109 | { 110 | //void* mem = allocator->Allocate(sizeof(b2DistanceJoint)); 111 | joint = new b2DistanceJoint(def); 112 | } 113 | break; 114 | 115 | case b2Joint.e_mouseJoint: 116 | { 117 | //void* mem = allocator->Allocate(sizeof(b2MouseJoint)); 118 | joint = new b2MouseJoint(def); 119 | } 120 | break; 121 | 122 | case b2Joint.e_prismaticJoint: 123 | { 124 | //void* mem = allocator->Allocate(sizeof(b2PrismaticJoint)); 125 | joint = new b2PrismaticJoint(def); 126 | } 127 | break; 128 | 129 | case b2Joint.e_revoluteJoint: 130 | { 131 | //void* mem = allocator->Allocate(sizeof(b2RevoluteJoint)); 132 | joint = new b2RevoluteJoint(def); 133 | } 134 | break; 135 | 136 | case b2Joint.e_pulleyJoint: 137 | { 138 | //void* mem = allocator->Allocate(sizeof(b2PulleyJoint)); 139 | joint = new b2PulleyJoint(def); 140 | } 141 | break; 142 | 143 | case b2Joint.e_gearJoint: 144 | { 145 | //void* mem = allocator->Allocate(sizeof(b2GearJoint)); 146 | joint = new b2GearJoint(def); 147 | } 148 | break; 149 | 150 | default: 151 | //b2Settings.b2Assert(false); 152 | break; 153 | } 154 | 155 | return joint; 156 | }; 157 | b2Joint.Destroy = function(joint, allocator){ 158 | /*joint->~b2Joint(); 159 | switch (joint.m_type) 160 | { 161 | case b2Joint.e_distanceJoint: 162 | allocator->Free(joint, sizeof(b2DistanceJoint)); 163 | break; 164 | 165 | case b2Joint.e_mouseJoint: 166 | allocator->Free(joint, sizeof(b2MouseJoint)); 167 | break; 168 | 169 | case b2Joint.e_prismaticJoint: 170 | allocator->Free(joint, sizeof(b2PrismaticJoint)); 171 | break; 172 | 173 | case b2Joint.e_revoluteJoint: 174 | allocator->Free(joint, sizeof(b2RevoluteJoint)); 175 | break; 176 | 177 | case b2Joint.e_pulleyJoint: 178 | allocator->Free(joint, sizeof(b2PulleyJoint)); 179 | break; 180 | 181 | case b2Joint.e_gearJoint: 182 | allocator->Free(joint, sizeof(b2GearJoint)); 183 | break; 184 | 185 | default: 186 | b2Assert(false); 187 | break; 188 | }*/ 189 | }; 190 | b2Joint.e_unknownJoint = 0; 191 | b2Joint.e_revoluteJoint = 1; 192 | b2Joint.e_prismaticJoint = 2; 193 | b2Joint.e_distanceJoint = 3; 194 | b2Joint.e_pulleyJoint = 4; 195 | b2Joint.e_mouseJoint = 5; 196 | b2Joint.e_gearJoint = 6; 197 | b2Joint.e_inactiveLimit = 0; 198 | b2Joint.e_atLowerLimit = 1; 199 | b2Joint.e_atUpperLimit = 2; 200 | b2Joint.e_equalLimits = 3; 201 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/joints/b2JointDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2JointDef = Class.create(); 24 | b2JointDef.prototype = 25 | { 26 | 27 | initialize: function() 28 | { 29 | this.type = b2Joint.e_unknownJoint; 30 | this.userData = null; 31 | this.body1 = null; 32 | this.body2 = null; 33 | this.collideConnected = false; 34 | }, 35 | 36 | type: 0, 37 | userData: null, 38 | body1: null, 39 | body2: null, 40 | collideConnected: null} 41 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/joints/b2JointNode.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2JointNode = Class.create(); 24 | b2JointNode.prototype = 25 | { 26 | 27 | other: null, 28 | joint: null, 29 | prev: null, 30 | next: null, 31 | 32 | 33 | initialize: function() {}} 34 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/joints/b2MouseJointDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2MouseJointDef = Class.create(); 24 | Object.extend(b2MouseJointDef.prototype, b2JointDef.prototype); 25 | Object.extend(b2MouseJointDef.prototype, 26 | { 27 | initialize: function() 28 | { 29 | // The constructor for b2JointDef 30 | this.type = b2Joint.e_unknownJoint; 31 | this.userData = null; 32 | this.body1 = null; 33 | this.body2 = null; 34 | this.collideConnected = false; 35 | // 36 | 37 | // initialize instance variables for references 38 | this.target = new b2Vec2(); 39 | // 40 | 41 | this.type = b2Joint.e_mouseJoint; 42 | this.maxForce = 0.0; 43 | this.frequencyHz = 5.0; 44 | this.dampingRatio = 0.7; 45 | this.timeStep = 1.0 / 60.0; 46 | }, 47 | 48 | target: new b2Vec2(), 49 | maxForce: null, 50 | frequencyHz: null, 51 | dampingRatio: null, 52 | timeStep: null}); 53 | 54 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/joints/b2PrismaticJointDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | var b2PrismaticJointDef = Class.create(); 24 | Object.extend(b2PrismaticJointDef.prototype, b2JointDef.prototype); 25 | Object.extend(b2PrismaticJointDef.prototype, 26 | { 27 | initialize: function() 28 | { 29 | // The constructor for b2JointDef 30 | this.type = b2Joint.e_unknownJoint; 31 | this.userData = null; 32 | this.body1 = null; 33 | this.body2 = null; 34 | this.collideConnected = false; 35 | // 36 | 37 | this.type = b2Joint.e_prismaticJoint; 38 | this.anchorPoint = new b2Vec2(0.0, 0.0); 39 | this.axis = new b2Vec2(0.0, 0.0); 40 | this.lowerTranslation = 0.0; 41 | this.upperTranslation = 0.0; 42 | this.motorForce = 0.0; 43 | this.motorSpeed = 0.0; 44 | this.enableLimit = false; 45 | this.enableMotor = false; 46 | }, 47 | 48 | anchorPoint: null, 49 | axis: null, 50 | lowerTranslation: null, 51 | upperTranslation: null, 52 | motorForce: null, 53 | motorSpeed: null, 54 | enableLimit: null, 55 | enableMotor: null}); 56 | 57 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/joints/b2PulleyJointDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | 24 | // The pulley joint is connected to two bodies and two fixed ground points. 25 | // The pulley supports a ratio such that: 26 | // length1 + ratio * length2 = constant 27 | // Yes, the force transmitted is scaled by the ratio. 28 | // The pulley also enforces a maximum length limit on both sides. This is 29 | // useful to prevent one side of the pulley hitting the top. 30 | 31 | var b2PulleyJointDef = Class.create(); 32 | Object.extend(b2PulleyJointDef.prototype, b2JointDef.prototype); 33 | Object.extend(b2PulleyJointDef.prototype, 34 | { 35 | initialize: function() 36 | { 37 | // The constructor for b2JointDef 38 | this.type = b2Joint.e_unknownJoint; 39 | this.userData = null; 40 | this.body1 = null; 41 | this.body2 = null; 42 | this.collideConnected = false; 43 | // 44 | 45 | // initialize instance variables for references 46 | this.groundPoint1 = new b2Vec2(); 47 | this.groundPoint2 = new b2Vec2(); 48 | this.anchorPoint1 = new b2Vec2(); 49 | this.anchorPoint2 = new b2Vec2(); 50 | // 51 | 52 | this.type = b2Joint.e_pulleyJoint; 53 | this.groundPoint1.Set(-1.0, 1.0); 54 | this.groundPoint2.Set(1.0, 1.0); 55 | this.anchorPoint1.Set(-1.0, 0.0); 56 | this.anchorPoint2.Set(1.0, 0.0); 57 | this.maxLength1 = 0.5 * b2PulleyJoint.b2_minPulleyLength; 58 | this.maxLength2 = 0.5 * b2PulleyJoint.b2_minPulleyLength; 59 | this.ratio = 1.0; 60 | this.collideConnected = true; 61 | }, 62 | 63 | groundPoint1: new b2Vec2(), 64 | groundPoint2: new b2Vec2(), 65 | anchorPoint1: new b2Vec2(), 66 | anchorPoint2: new b2Vec2(), 67 | maxLength1: null, 68 | maxLength2: null, 69 | ratio: null}); 70 | 71 | -------------------------------------------------------------------------------- /box2d-car-game/js/box2d/dynamics/joints/b2RevoluteJointDef.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http: 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked, and must not be 15 | * misrepresented the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | 20 | 21 | 22 | 23 | 24 | var b2RevoluteJointDef = Class.create(); 25 | Object.extend(b2RevoluteJointDef.prototype, b2JointDef.prototype); 26 | Object.extend(b2RevoluteJointDef.prototype, 27 | { 28 | initialize: function() 29 | { 30 | // The constructor for b2JointDef 31 | this.type = b2Joint.e_unknownJoint; 32 | this.userData = null; 33 | this.body1 = null; 34 | this.body2 = null; 35 | this.collideConnected = false; 36 | // 37 | 38 | this.type = b2Joint.e_revoluteJoint; 39 | this.anchorPoint = new b2Vec2(0.0, 0.0); 40 | this.lowerAngle = 0.0; 41 | this.upperAngle = 0.0; 42 | this.motorTorque = 0.0; 43 | this.motorSpeed = 0.0; 44 | this.enableLimit = false; 45 | this.enableMotor = false; 46 | }, 47 | 48 | anchorPoint: null, 49 | lowerAngle: null, 50 | upperAngle: null, 51 | motorTorque: null, 52 | motorSpeed: null, 53 | enableLimit: null, 54 | enableMotor: null}); 55 | 56 | -------------------------------------------------------------------------------- /box2d-car-game/js/protoclass.js: -------------------------------------------------------------------------------- 1 | 2 | /* Based on Alex Arnell's inheritance implementation. */ 3 | var Class = { 4 | create: function() { 5 | var parent = null, properties = $A(arguments); 6 | if (Object.isFunction(properties[0])) 7 | parent = properties.shift(); 8 | 9 | function klass() { 10 | this.initialize.apply(this, arguments); 11 | } 12 | 13 | Object.extend(klass, Class.Methods); 14 | klass.superclass = parent; 15 | klass.subclasses = []; 16 | 17 | if (parent) { 18 | var subclass = function() { }; 19 | subclass.prototype = parent.prototype; 20 | klass.prototype = new subclass; 21 | parent.subclasses.push(klass); 22 | } 23 | 24 | for (var i = 0; i < properties.length; i++) 25 | klass.addMethods(properties[i]); 26 | 27 | if (!klass.prototype.initialize) 28 | klass.prototype.initialize = this.emptyFunction; 29 | 30 | klass.prototype.constructor = klass; 31 | 32 | return klass; 33 | }, 34 | emptyFunction:function () {} 35 | 36 | }; 37 | 38 | Class.Methods = { 39 | addMethods: function(source) { 40 | var ancestor = this.superclass && this.superclass.prototype; 41 | var properties = Object.keys(source); 42 | 43 | if (!Object.keys({ toString: true }).length) 44 | properties.push("toString", "valueOf"); 45 | 46 | for (var i = 0, length = properties.length; i < length; i++) { 47 | var property = properties[i], value = source[property]; 48 | if (ancestor && Object.isFunction(value) && 49 | value.argumentNames().first() == "$super") { 50 | var method = value, value = Object.extend((function(m) { 51 | return function() { return ancestor[m].apply(this, arguments) }; 52 | })(property).wrap(method), { 53 | valueOf: function() { return method }, 54 | toString: function() { return method.toString() } 55 | }); 56 | } 57 | this.prototype[property] = value; 58 | } 59 | 60 | return this; 61 | } 62 | }; 63 | 64 | Object.extend = function(destination, source) { 65 | for (var property in source) 66 | destination[property] = source[property]; 67 | return destination; 68 | }; 69 | 70 | Object.extend(Object, { 71 | inspect: function(object) { 72 | try { 73 | if (Object.isUndefined(object)) return 'undefined'; 74 | if (object === null) return 'null'; 75 | return object.inspect ? object.inspect() : String(object); 76 | } catch (e) { 77 | if (e instanceof RangeError) return '...'; 78 | throw e; 79 | } 80 | }, 81 | 82 | toJSON: function(object) { 83 | var type = typeof object; 84 | switch (type) { 85 | case 'undefined': 86 | case 'function': 87 | case 'unknown': return; 88 | case 'boolean': return object.toString(); 89 | } 90 | 91 | if (object === null) return 'null'; 92 | if (object.toJSON) return object.toJSON(); 93 | if (Object.isElement(object)) return; 94 | 95 | var results = []; 96 | for (var property in object) { 97 | var value = Object.toJSON(object[property]); 98 | if (!Object.isUndefined(value)) 99 | results.push(property.toJSON() + ': ' + value); 100 | } 101 | 102 | return '{' + results.join(', ') + '}'; 103 | }, 104 | 105 | toQueryString: function(object) { 106 | return $H(object).toQueryString(); 107 | }, 108 | 109 | toHTML: function(object) { 110 | return object && object.toHTML ? object.toHTML() : String.interpret(object); 111 | }, 112 | 113 | keys: function(object) { 114 | var keys = []; 115 | for (var property in object) 116 | keys.push(property); 117 | return keys; 118 | }, 119 | 120 | values: function(object) { 121 | var values = []; 122 | for (var property in object) 123 | values.push(object[property]); 124 | return values; 125 | }, 126 | 127 | clone: function(object) { 128 | return Object.extend({ }, object); 129 | }, 130 | 131 | isElement: function(object) { 132 | return object && object.nodeType == 1; 133 | }, 134 | 135 | isArray: function(object) { 136 | return object != null && typeof object == "object" && 137 | 'splice' in object && 'join' in object; 138 | }, 139 | 140 | isHash: function(object) { 141 | return object instanceof Hash; 142 | }, 143 | 144 | isFunction: function(object) { 145 | return typeof object == "function"; 146 | }, 147 | 148 | isString: function(object) { 149 | return typeof object == "string"; 150 | }, 151 | 152 | isNumber: function(object) { 153 | return typeof object == "number"; 154 | }, 155 | 156 | isUndefined: function(object) { 157 | return typeof object == "undefined"; 158 | } 159 | }); 160 | 161 | function $A(iterable) { 162 | if (!iterable) return []; 163 | if (iterable.toArray) return iterable.toArray(); 164 | var length = iterable.length || 0, results = new Array(length); 165 | while (length--) results[length] = iterable[length]; 166 | return results; 167 | } 168 | 169 | if (WebKit = navigator.userAgent.indexOf('AppleWebKit/') > -1) { 170 | $A = function(iterable) { 171 | if (!iterable) return []; 172 | if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') && 173 | iterable.toArray) return iterable.toArray(); 174 | var length = iterable.length || 0, results = new Array(length); 175 | while (length--) results[length] = iterable[length]; 176 | return results; 177 | }; 178 | } 179 | -------------------------------------------------------------------------------- /box2d-car-game/readme.md: -------------------------------------------------------------------------------- 1 | # Box2D Car Game 2 | 3 | This game integrates Box2D 1.2 into canvas. 4 | 5 | This example is originally from the book [HTML5 Games Development by Examples][1]. 6 | 7 | [1]: http://www.packtpub.com/html5-games-development-using-css-javascript-beginners-guide/book 8 | -------------------------------------------------------------------------------- /canvas-untangle-game/css/untangle.css: -------------------------------------------------------------------------------- 1 | canvas { 2 | 3 | /* for iOS devices */ 4 | -webkit-tap-highlight-color: transparent; 5 | } 6 | 7 | html, body { 8 | background: url(../images/title_bg.png) 50% 0 no-repeat, 9 | url(../images/bg_repeat.png) 50% 0 repeat-y #889ba7; 10 | margin: 0; 11 | color: #111; 12 | } 13 | 14 | #game{ 15 | position:relative; 16 | } 17 | 18 | #page { 19 | width: 820px; 20 | min-height: 800px; 21 | margin: 0 auto; 22 | padding: 0; 23 | text-align: center; 24 | text-shadow: 0 1px 5px rgba(60,60,60,.6); 25 | } 26 | 27 | header { 28 | height: 88px; 29 | padding-top: 36px; 30 | margin-bottom: 50px; 31 | font-family: "Rock Salt", Arial, sans-serif; 32 | font-size: 14px; 33 | text-shadow: 0 1px 0 rgba(200,200,200,.5); 34 | color: #121; 35 | } 36 | 37 | /* Layers */ 38 | #layers { 39 | position: relative; 40 | margin: 0 auto; 41 | width:768px; 42 | height: 400px; 43 | } 44 | #layers canvas{ 45 | top: 0; 46 | left: 0; 47 | position: absolute; 48 | } 49 | #guide { 50 | opacity: 0.7; 51 | transition: opacity 0.5s ease-out; 52 | } 53 | #guide.fadeout { 54 | opacity: 0; 55 | } 56 | #ui { 57 | transition: opacity 0.3s ease-out; 58 | } 59 | #ui.dim { 60 | opacity: 0.3; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /canvas-untangle-game/images/bg_repeat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/canvas-untangle-game/images/bg_repeat.png -------------------------------------------------------------------------------- /canvas-untangle-game/images/board.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/canvas-untangle-game/images/board.png -------------------------------------------------------------------------------- /canvas-untangle-game/images/guide_sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/canvas-untangle-game/images/guide_sprite.png -------------------------------------------------------------------------------- /canvas-untangle-game/images/title_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/canvas-untangle-game/images/title_bg.png -------------------------------------------------------------------------------- /canvas-untangle-game/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Untangle Puzzle Game in Canvas 6 | 7 | 8 | 9 | 10 |
11 |
12 |

Untangle Puzzle Game in Canvas

13 |
14 | 15 |
16 | 17 | This is an interactive game with circles and lines connecting them. 18 | 19 | 20 | 21 | 22 |
23 | 24 |

Puzzle 0, Completeness: 0%

25 | 26 |
27 |

This is an example of Untangle Puzzle Game in Canvas.

28 |
29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /canvas-untangle-game/js/untangle.data.js: -------------------------------------------------------------------------------- 1 | if (untangleGame === undefined) { 2 | var untangleGame = {}; 3 | } 4 | 5 | untangleGame.circles = []; 6 | 7 | untangleGame.Circle = function(x,y,radius){ 8 | this.x = x; 9 | this.y = y; 10 | this.radius = radius; 11 | }; 12 | 13 | untangleGame.Line = function(startPoint, endPoint, thickness) { 14 | this.startPoint = startPoint; 15 | this.endPoint = endPoint; 16 | this.thickness = thickness; 17 | }; 18 | 19 | untangleGame.createRandomCircles = function(width, height) { 20 | // randomly draw 5 circles 21 | var circlesCount = 5; 22 | var circleRadius = 10; 23 | for (var i=0;i 5) { 109 | untangleGame.guideFrame = 0; 110 | } 111 | 112 | untangleGame.clear(1); 113 | untangleGame.drawGuide(); 114 | }; 115 | 116 | untangleGame.drawGuide = function() { 117 | var ctx = untangleGame.layers[1]; 118 | // draw the guide animation 119 | if (untangleGame.currentLevel < 2) { 120 | // the dimension of each frame is 80x130. 121 | var nextFrameX = untangleGame.guideFrame * 80; 122 | ctx.drawImage(untangleGame.guide, nextFrameX, 0, 80, 130, 325, 123 | 130, 80, 130); 124 | } 125 | 126 | // fade out the guideline after level 0 127 | if (untangleGame.currentLevel === 1) { 128 | $("#guide").addClass('fadeout'); 129 | } 130 | }; 131 | 132 | untangleGame.dimUILayerIfNeeded = function() { 133 | // get all circles, 134 | // check if the ui overlap with the game objects 135 | var isOverlappedWithCircle = false; 136 | for(var i in untangleGame.circles) { 137 | var point = untangleGame.circles[i]; 138 | if (point.y > 280) { 139 | isOverlappedWithCircle = true; 140 | } 141 | } 142 | if (isOverlappedWithCircle) { 143 | $("#ui").addClass('dim'); 144 | } else { 145 | $("#ui").removeClass('dim'); 146 | } 147 | }; 148 | 149 | -------------------------------------------------------------------------------- /canvas-untangle-game/js/untangle.game.js: -------------------------------------------------------------------------------- 1 | if (untangleGame === undefined) { 2 | var untangleGame = {}; 3 | } 4 | 5 | untangleGame.currentLevel = 0; 6 | untangleGame.levelProgress = 0; 7 | 8 | untangleGame.setupCurrentLevel = function() { 9 | untangleGame.circles = []; 10 | var level = untangleGame.levels[untangleGame.currentLevel]; 11 | for (var i=0; i 2 | 3 | 4 | 5 | 6 | Count 99 Game 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 |
15 | loading 16 |
17 |
18 |

19 |
20 |
21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /count-99/js/count99-game.js: -------------------------------------------------------------------------------- 1 | // window/global scope 2 | var c99 = {}; 3 | 4 | c99.Tile = (function(){ 5 | function Tile(number){ 6 | this.initialize(); 7 | 8 | this.number = number; 9 | 10 | this.width = this.height = 80; 11 | 12 | var image = new createjs.Bitmap(c99.graphics.tile.path); 13 | this.addChild(image); 14 | 15 | var numberText = new createjs.Text(number, "24px pf_tempesta_seven_compresseBd, sans-serif", "#ac1000"); 16 | // place it at the center of the tile box. 17 | numberText.x = this.width/2 + 1; 18 | numberText.y = this.height/2 - 2; 19 | 20 | // align cetner, vertically and horizontally. 21 | numberText.textAlign = "center"; 22 | numberText.textBaseline = "middle"; 23 | this.addChild(numberText); 24 | } 25 | var p = Tile.prototype = new createjs.Container(); 26 | 27 | return Tile; 28 | })(); 29 | 30 | c99.Preloader = (function(){ 31 | // constructor 32 | function Preloader(game) { 33 | this.game = game; 34 | }; 35 | 36 | Preloader.prototype.loadGraphics = function(){ 37 | var imagesList = [ 38 | {name:"tile", path:"images/tile.png"}, 39 | {name:"hud", path:"images/hud.png"}, 40 | {name:"bg", path:"images/bg.png"}, 41 | {name:"gameover", path:"images/gameover.jpg"}, 42 | {name:"restartButton", path:"images/restart-button.png"}, 43 | ] 44 | 45 | c99.graphics = {}; 46 | 47 | var totalFiles = imagesList.length; 48 | var loadedFiles = 0; 49 | for (var i=0, len=totalFiles; i= totalFiles) { 58 | this.game.initGame(); 59 | } 60 | }).bind(this); 61 | 62 | console.log ("loading: ", imageToLoad.path); 63 | img.src = imageToLoad.path; 64 | 65 | c99.graphics[imageToLoad.name] = imageToLoad; 66 | }; 67 | } 68 | return Preloader; 69 | })(); 70 | 71 | c99.Game = (function() { 72 | // constructor 73 | function Count99Game() { 74 | console.log("Count99 game starts."); 75 | 76 | this.canvas = document.getElementById('game-canvas'); 77 | 78 | // EaselJS Stage 79 | this.stage = new createjs.Stage(this.canvas); 80 | createjs.Touch.enable(this.stage); 81 | 82 | // this.initGame(); 83 | var preloader = new c99.Preloader(this); 84 | preloader.loadGraphics(); 85 | 86 | var restartButton = document.getElementById('restart-button'); 87 | restartButton.onclick = (function(event) { 88 | var gameoverScene = document.getElementById('gameover'); 89 | gameoverScene.classList.remove('gameover-appear'); 90 | this.initGame(); 91 | }).bind(this); 92 | } 93 | 94 | var p = Count99Game.prototype; 95 | 96 | p.initGame = function() { 97 | this.totalTiles = 3; 98 | 99 | // store which number player should click on next tile. 100 | this.nextCount = 1; 101 | 102 | // we have a in the HTML that display the nextCount variable. 103 | // We can store the reference of that element 104 | // so we can access later without finding it again. 105 | this.nextCountLabel = document.getElementById('next-count'); 106 | this.nextCountLabel.innerText = this.nextCount; 107 | 108 | // the onPress event handler for tile 109 | var tileOnPress = function(event) { 110 | if (event.currentTarget.number === this.nextCount) { 111 | this.stage.removeChild(event.currentTarget); 112 | 113 | // count the next tile. 114 | this.nextCount++; 115 | 116 | // game over, player wins. 117 | if (this.nextCount > this.totalTiles) { 118 | this.gameOver(); 119 | } 120 | 121 | // update the canvas to reflect the new display list. 122 | this.stage.update(); 123 | // update the element 124 | this.nextCountLabel.innerText = this.nextCount; 125 | 126 | } 127 | } 128 | 129 | for (var i=this.totalTiles; i>0; i--) { 130 | var tile = new c99.Tile(i); 131 | tile.x = Math.random()*(this.canvas.width-tile.width); 132 | tile.y = Math.random()*(this.canvas.height-tile.height); 133 | tile.on('mousedown', (tileOnPress).bind(this)); // bind the outer 'this' scope into the event handler function. 134 | this.stage.addChild(tile); 135 | } 136 | 137 | this.stage.update(); 138 | } 139 | 140 | p.gameOver = function() { 141 | // force the next count to be the total tiles maximum. 142 | this.nextCount = this.totalTiles; 143 | 144 | // display the game over scene. 145 | var gameoverScene = document.getElementById('gameover'); 146 | gameoverScene.classList.add('gameover-appear'); 147 | } 148 | 149 | return Count99Game; 150 | })(); 151 | 152 | window.onload = function() { 153 | // entry point 154 | var game = new c99.Game(); 155 | }; -------------------------------------------------------------------------------- /count-99/readme.md: -------------------------------------------------------------------------------- 1 | # Count 99 2 | 3 | A simple counting game with EaselJS. 4 | 5 | ![image](http://makzan.github.com/HTML5-Games-Examples/images/count99-screen.png) -------------------------------------------------------------------------------- /css3-matching-game/css/matchgame.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * CSS3 Card Games Example 3 | * http://gamedesign.cc/html5games/CSS3-matching-game/ 4 | * 5 | * This is an example game for the book HTML5 Games Development: A Beginning Guide. 6 | * 7 | * Copyright 2010, Thomas Seng Hin Mak 8 | * makzan@gmail.com 9 | * 10 | * All Right Reserved. 11 | */ 12 | 13 | body { 14 | text-align: center; 15 | font-family: 'Droid Serif', arial, serif; 16 | background: #a46740 url(../images/bg.jpg); 17 | color: #ccc; 18 | text-shadow: 0 1px 0 #222; 19 | } 20 | 21 | h1 { 22 | font-weight: bold; 23 | text-shadow: 0 2px 0 #222; 24 | } 25 | 26 | a, a:visited { 27 | color: #aea; 28 | text-decoration: none; 29 | -webkit-transition: all .3s; 30 | padding: 5px; 31 | } 32 | 33 | a:hover { 34 | color: #000; 35 | background: #aea; 36 | text-shadow: none; 37 | } 38 | 39 | #game { 40 | border-radius: 10px; 41 | border: 1px solid #666; 42 | -webkit-box-shadow: 0 -1px 0 #999, 0 1px 0 #999, inset 0 1px 6px #000; 43 | 44 | position: relative; 45 | background: #232 url(../images/table.jpg); 46 | width: 500px; 47 | height: 460px; 48 | margin: 0 auto; 49 | 50 | display: -webkit-box; 51 | -webkit-box-pack: center; 52 | -webkit-box-align: center; 53 | 54 | display: -moz-box; 55 | -moz-box-pack: center; 56 | -moz-box-align: center; 57 | } 58 | 59 | #cards { 60 | position: relative; 61 | width: 380px; 62 | height: 400px; 63 | } 64 | 65 | .card { 66 | -webkit-perspective: 600; 67 | width: 80px; 68 | height: 120px; 69 | 70 | /* changed */ 71 | position: absolute; 72 | 73 | -moz-transition: all .3s; 74 | -webkit-transition: all .3s; 75 | transition: all .3s; 76 | } 77 | 78 | .face { 79 | border-radius: 10px; 80 | width: 100%; 81 | height: 100%; 82 | position: absolute; 83 | 84 | -moz-transition-property: opacity, -moz-transform, -moz-box-shadow; 85 | -moz-transition-duration: .3s; 86 | -webkit-transition-property: opacity, -webkit-transform, -webkit-box-shadow; 87 | -webkit-transition-duration: .3s; 88 | transition-property: opacity, transform, box-shadow; 89 | transition-duration: .3s; 90 | 91 | -moz-backface-visibility: hidden; 92 | -webkit-backface-visibility: hidden; 93 | backface-visibility: hidden; 94 | 95 | } 96 | 97 | .front { 98 | background: #999 url(../images/deck.png) 0 -480px; 99 | z-index: 10; 100 | } 101 | 102 | .back { 103 | background: #efefef url(../images/deck.png); 104 | 105 | -moz-transform: rotate3d(0,1,0,-180deg); 106 | -webkit-transform: rotate3d(0,1,0,-180deg); 107 | transform: rotate3d(0,1,0,-180deg); 108 | 109 | z-index: 8; 110 | } 111 | 112 | .card:hover .face{ 113 | -webkit-box-shadow: 0 0 20px #aaa; 114 | box-shadow: 0 0 10px #aaa; 115 | } 116 | 117 | .card-flipped .face{ 118 | -webkit-box-shadow: 0 0 20px #aaa; 119 | box-shadow: 0 0 10px #aaa; 120 | } 121 | .card-flipped .front { 122 | -moz-transform: rotate3d(0,1,0,180deg); 123 | -webkit-transform: rotate3d(0,1,0,180deg); 124 | transform: rotate3d(0,1,0,180deg); 125 | 126 | /* ensure the front face is below the back face */ 127 | z-index: 8; 128 | } 129 | 130 | .card-flipped .back { 131 | -moz-transform: rotate3d(0,1,0,0deg); 132 | -webkit-transform: rotate3d(0,1,0,0deg); 133 | transform: rotate3d(0,1,0,0deg); 134 | 135 | /* ensure the back face is on top of the front face */ 136 | z-index: 10; 137 | } 138 | 139 | .card-removed { 140 | opacity: 0; 141 | } 142 | 143 | 144 | /* define the face graphics of the card deck*/ 145 | /* cardAA stands for Spade A */ 146 | /* cardA10 stands for Spade 10 */ 147 | /* cardAK stands for Spade K */ 148 | /* cardB_ stands for Heart _ */ 149 | /* cardC_ stands for Club _ */ 150 | /* cardD_ stands for Diamond _ */ 151 | 152 | .cardAJ {background-position: -800px 0;} 153 | .cardAQ {background-position: -880px 0;} 154 | .cardAK {background-position: -960px 0;} 155 | .cardBJ {background-position: -800px -120px;} 156 | .cardBQ {background-position: -880px -120px;} 157 | .cardBK {background-position: -960px -120px;} 158 | .cardCJ {background-position: -800px -240px;} 159 | .cardCQ {background-position: -880px -240px;} 160 | .cardCK {background-position: -960px -240px;} 161 | .cardDJ {background-position: -800px -360px;} 162 | .cardDQ {background-position: -880px -360px;} 163 | .cardDK {background-position: -960px -360px;} 164 | 165 | 166 | 167 | 168 | /* Styles for game over popup */ 169 | #popup { 170 | font-family: 'Orbitron', serif; 171 | font-size: 28px; 172 | font-weight: 700; 173 | text-shadow: 0px 1px 2px #fff; 174 | 175 | color: #222; 176 | 177 | position: absolute; 178 | width: 100%; 179 | height: 100%; 180 | top: 0; 181 | left: 0; 182 | 183 | background: rgba(0,0,0,.5); 184 | 185 | display: -webkit-box; 186 | -webkit-box-pack: center; 187 | -webkit-box-align: center; 188 | 189 | -webkit-transition: all .5s ease-in; 190 | } 191 | 192 | #popup h1 { 193 | font-weight: 400; 194 | } 195 | 196 | #popup-box { 197 | width: 400px; 198 | height: 300px; 199 | background: #ccc url(../images/popup_bg.jpg); 200 | 201 | border-radius: 10px; 202 | 203 | position: relative; 204 | 205 | -webkit-box-shadow: 0 5px 5px #333; 206 | 207 | display: -webkit-box; 208 | -webkit-box-pack: center; 209 | -webkit-box-align: center; 210 | 211 | -webkit-transition: all .5s ease-in; 212 | } 213 | 214 | #popup-box small { 215 | font-size: .6em; 216 | } 217 | 218 | /** 219 | * Styles to hide the popup box 220 | */ 221 | #popup.hide { 222 | background: rgba(0,0,0,0); 223 | visibility: hidden; 224 | } 225 | #popup.hide #popup-box{ 226 | margin-top: -800px; 227 | } 228 | 229 | 230 | /** 231 | * Styles for the ribbon 232 | */ 233 | .ribbon.hide { 234 | display: none; 235 | } 236 | 237 | .ribbon { 238 | float: left; 239 | position: absolute; 240 | 241 | left: -7px; 242 | top: 165px; 243 | 244 | z-index: 0; 245 | 246 | font-size: .5em; 247 | text-transform: uppercase; 248 | text-align: right; 249 | } 250 | 251 | .ribbon-body { 252 | height: 14px; 253 | background: #ca3d33; 254 | padding: 6px; 255 | z-index: 100; 256 | -webkit-box-shadow: 2px 2px 0 rgba(150,120,70,.4); 257 | border-radius: 0 5px 5px 0; 258 | 259 | color: #fff; 260 | text-shadow: 0px 1px 1px rgba(0,0,0,.3); 261 | } 262 | 263 | .triangle{ 264 | position: relative; 265 | height: 0px; 266 | width: 0; 267 | left: -5px; 268 | top: -32px; 269 | border-style: solid; 270 | border-width: 6px; 271 | border-color: transparent #882011 transparent transparent; 272 | z-index: -1; 273 | } 274 | -------------------------------------------------------------------------------- /css3-matching-game/images/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/css3-matching-game/images/bg.jpg -------------------------------------------------------------------------------- /css3-matching-game/images/deck.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/css3-matching-game/images/deck.png -------------------------------------------------------------------------------- /css3-matching-game/images/popup_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/css3-matching-game/images/popup_bg.jpg -------------------------------------------------------------------------------- /css3-matching-game/images/table.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/css3-matching-game/images/table.jpg -------------------------------------------------------------------------------- /css3-matching-game/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | CSS3 Matching Game 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 |

CSS3 Matching Game

28 |
29 | 30 |
31 | Elapsed time: 00:00 32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | 42 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /css3-matching-game/readme.md: -------------------------------------------------------------------------------- 1 | # Matching Game 2 | 3 | This matching game makes use of CSS3 for the flipping animation. 4 | It is originally from the book [HTML5 Games Development by Examples][1]. 5 | 6 | ![image](http://makzan.github.com/HTML5-Games-Examples/images/css-matching-screen.png) 7 | 8 | Please note that this code was written in 2012 and I didn't followed some best practice in Javasscript programming. It is suggested to learn the concept and update the code to follow latest JavaScript practice. 9 | 10 | [1]: http://www.packtpub.com/html5-games-development-using-css-javascript-beginners-guide/book 11 | -------------------------------------------------------------------------------- /multiply-defense/css/multiply-defense.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | margin: 0; 3 | } 4 | #game-canvas { 5 | background: #333; 6 | width: 320px; 7 | margin-top: 20px; 8 | } 9 | #ui { 10 | position: absolute; 11 | bottom: 0; 12 | left: 0; 13 | background: #efefef; 14 | } 15 | #ui a { 16 | display: block; 17 | padding: 20px; 18 | text-decoration: none; 19 | color: #000; 20 | } 21 | #fps { 22 | position: fixed; 23 | left: 0; 24 | top: 20px; 25 | background: rgba(0, 0, 0, 0.8); 26 | color: #ffffff; 27 | padding: 5px; 28 | border-bottom-right-radius: 3px; 29 | } 30 | -------------------------------------------------------------------------------- /multiply-defense/css/multiply-defense.css.less: -------------------------------------------------------------------------------- 1 | .debug (@color: red) { 2 | border: 1px solid @color; 3 | } 4 | 5 | html, body { 6 | margin: 0; 7 | } 8 | 9 | 10 | #game-canvas { 11 | background: #333; 12 | width: 320px; 13 | margin-top: 20px; 14 | } 15 | 16 | #ui { 17 | position: absolute; 18 | bottom: 0; 19 | left: 0; 20 | background: #efefef; 21 | 22 | a { 23 | display: block; 24 | padding: 20px; 25 | text-decoration: none; 26 | color: #000; 27 | } 28 | } 29 | 30 | #fps { 31 | position: fixed; 32 | left: 0; 33 | top: 20px; 34 | background: rgba(0,0,0,0.8); 35 | color: #ffffff; 36 | padding: 5px; 37 | border-bottom-right-radius: 3px; 38 | } -------------------------------------------------------------------------------- /multiply-defense/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Multiply Defense 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Please make sure you have the latest modern browser for the game. Chrome is a good choice :) 18 | 19 | 20 |
0.00
21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /multiply-defense/readme.md: -------------------------------------------------------------------------------- 1 | # Multiply Defense 2 | 3 | This example uses EaselJS, from the CreateJS suite. 4 | 5 | 6 | -------------------------------------------------------------------------------- /pingpoing/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Ping Pong 6 | 35 | 36 | 37 |
38 |

Ping Pong

39 |
40 |
41 |
42 |
Player A : 0
43 |
Player B : 0
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | This is an example to show basic control of Ping Pong. 54 |
55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /pingpoing/js/html5games.pingpong.js: -------------------------------------------------------------------------------- 1 | var KEY = { 2 | UP: 38, 3 | DOWN: 40, 4 | W: 87, 5 | S: 83 6 | } 7 | 8 | // a global object to store all global variable we use for the game 9 | var pingpong = { 10 | scoreA : 0, // score for player A 11 | scoreB : 0 // score for player B 12 | } 13 | 14 | // an array to remember which key is pressed and which is not. 15 | pingpong.pressedKeys = []; 16 | 17 | pingpong.ball = { 18 | speed: 5, 19 | directionX: 1, 20 | directionY: 1 21 | } 22 | 23 | $(function(){ 24 | // set interval to call gameloop every 30 milliseconds 25 | pingpong.timer = setInterval(gameloop,30); 26 | 27 | // mark down what key is down and up into an array called "pressedKeys" 28 | $(document).keydown(function(e){ 29 | pingpong.pressedKeys[e.keyCode] = true; 30 | }); 31 | $(document).keyup(function(e){ 32 | pingpong.pressedKeys[e.keyCode] = false; 33 | }); 34 | }); 35 | 36 | // this function is called every 30 milliseconds 37 | function gameloop() 38 | { 39 | moveBall(); 40 | movePaddless(); 41 | } 42 | 43 | function moveBall() 44 | { 45 | // move the ball in every 30 milliseconds 46 | // reference useful varaibles 47 | var ballTop = parseInt($("#ball").css("top")); 48 | var ballLeft = parseInt($("#ball").css("left")); 49 | var playgroundHeight = parseInt($("#playground").height()); 50 | var playgroundWidth = parseInt($("#playground").width()); 51 | var ball = pingpong.ball; 52 | 53 | // check playground boundary 54 | // check bottom 55 | if (ballTop+ball.speed*ball.directionY > playgroundHeight) 56 | { 57 | ball.directionY = -1; 58 | } 59 | // check top 60 | if (ballTop+ball.speed*ball.directionY < 0) 61 | { 62 | ball.directionY = 1; 63 | } 64 | // check right 65 | if (ballLeft+ball.speed*ball.directionX > playgroundWidth) 66 | { 67 | // player B lost. 68 | pingpong.scoreA++; 69 | $("#scoreA").html(pingpong.scoreA); 70 | 71 | // reset the ball; 72 | $("#ball").css({ 73 | "left":"250px", 74 | "top" :"100px" 75 | }); 76 | 77 | // update the ball location variables; 78 | ballTop = parseInt($("#ball").css("top")); 79 | ballLeft = parseInt($("#ball").css("left")); 80 | ball.directionX = -1; 81 | } 82 | // check left 83 | if (ballLeft + ball.speed*ball.directionX < 0) 84 | { 85 | // player A lost. 86 | pingpong.scoreB++; 87 | $("#scoreB").html(pingpong.scoreB); 88 | 89 | // reset the ball; 90 | $("#ball").css({ 91 | "left":"150px", 92 | "top" :"100px" 93 | }); 94 | 95 | // update the ball location variables; 96 | ballTop = parseInt($("#ball").css("top")); 97 | ballLeft = parseInt($("#ball").css("left")); 98 | ball.directionX = 1; 99 | } 100 | 101 | // check moving paddle here, later. 102 | // check left paddle 103 | var paddleAX = parseInt($("#paddleA").css("left"))+parseInt($("#paddleA").css("width")); 104 | var paddleAYBottom = parseInt($("#paddleA").css("top"))+parseInt($("#paddleA").css("height")); 105 | var paddleAYTop = parseInt($("#paddleA").css("top")); 106 | if (ballLeft + ball.speed*ball.directionX < paddleAX) 107 | { 108 | if (ballTop + ball.speed*ball.directionY <= paddleAYBottom && 109 | ballTop + ball.speed*ball.directionY >= paddleAYTop) 110 | { 111 | ball.directionX = 1; 112 | } 113 | } 114 | 115 | // check right paddle 116 | var paddleBX = parseInt($("#paddleB").css("left")); 117 | var paddleBYBottom = parseInt($("#paddleB").css("top"))+parseInt($("#paddleB").css("height")); 118 | var paddleBYTop = parseInt($("#paddleB").css("top")); 119 | if (ballLeft + ball.speed*ball.directionX >= paddleBX) 120 | { 121 | if (ballTop + ball.speed*ball.directionY <= paddleBYBottom && 122 | ballTop + ball.speed*ball.directionY >= paddleBYTop) 123 | { 124 | ball.directionX = -1; 125 | } 126 | } 127 | 128 | 129 | // actually move the ball with speed and direction 130 | $("#ball").css({ 131 | "left" : ballLeft + ball.speed * ball.directionX, 132 | "top" : ballTop + ball.speed * ball.directionY 133 | }); 134 | } 135 | 136 | function movePaddless() 137 | { 138 | // use our custom timer to continuously check if a key is pressed. 139 | if (pingpong.pressedKeys[KEY.UP]) // arrow up 140 | { 141 | // move the paddle B up 5 pixels 142 | var top = parseInt($("#paddleB").css("top")); 143 | $("#paddleB").css("top",top-5); 144 | } 145 | if (pingpong.pressedKeys[KEY.DOWN]) // arrow down 146 | { 147 | // move the paddle B down 5 pixels 148 | var top = parseInt($("#paddleB").css("top")); 149 | $("#paddleB").css("top",top+5); 150 | } 151 | if (pingpong.pressedKeys[KEY.W]) // w 152 | { 153 | // move the paddle A up 5 pixels 154 | var top = parseInt($("#paddleA").css("top")); 155 | $("#paddleA").css("top",top-5); 156 | } 157 | if (pingpong.pressedKeys[KEY.S]) // s 158 | { 159 | // move the paddle A down 5 pixels 160 | var top = parseInt($("#paddleA").css("top")); 161 | $("#paddleA").css("top",top+5); 162 | } 163 | } -------------------------------------------------------------------------------- /pingpoing/readme.md: -------------------------------------------------------------------------------- 1 | # Ping Pong 2 | 3 | This is a example on making Ping Pong game with jQuery. It supports two players playing on the same computer. This is from the [HTML5 Games Development][1] book. 4 | 5 | Please note that this code was written in 2012 and I didn't followed some best practice in Javasscript programming. It is suggested to learn the concept and update the code to follow latest JavaScript practice. 6 | 7 | [1]: http://www.packtpub.com/html5-games-development-using-css-javascript-beginners-guide/book 8 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # HTML5 Games Collection 2 | 3 | During my tutorials and book writings, I created different HTML5 games examples. And I would like to put all my games examples here. 4 | 5 | [Thomas Mak (Makzan)](http://makzan.net/) 6 | 7 | ## Games 8 | 9 | The games in this repo so far 10 | 11 | ### Audio game with Audio tag 12 | 13 | Originally designed from my book [HTML5 Games Development by Examples: Beginner's guide](http://makzan.net/works/book-html5-games-dev-by-examples/) and you can [play this game here](http://42games.net/html5/audio-game/). 14 | 15 | ### Car game with Box2D 16 | 17 | Originally designed from my book [HTML5 Games Development by Examples: Beginner's guide](http://makzan.net/works/book-html5-games-dev-by-examples/) and you can [play this game here](http://42games.net/html5/box2d-car-game/). 18 | 19 | ### Count99 20 | 21 | ![Count 99 screen](http://makzan.github.com/HTML5-Games-Examples/images/count99-screen.png) 22 | 23 | ### Memory matching game with CSS3 24 | 25 | ![Memory matching game screen](http://makzan.github.com/HTML5-Games-Examples/images/css-matching-screen.png) 26 | 27 | Originally designed from my book [HTML5 Games Development by Examples: Beginner's guide](http://makzan.net/works/book-html5-games-dev-by-examples/) and you can [play this game here](http://42games.net/css3memory/). 28 | 29 | ### Multiply Defense game with EaselJS 30 | 31 | ![Multiple-Defense game screen](http://makzan.github.io/HTML5-Games-Examples/images/multiple-deferse.png) 32 | 33 | ### Ping Pong game with jQuery 34 | 35 | ### Untagle game with Canvas 36 | 37 | Originally designed from my book [HTML5 Games Development by Examples: Beginner's guide](http://makzan.net/works/book-html5-games-dev-by-examples/) and you can [play this game here](http://42games.net/html5/untangle/). 38 | 39 | ![Untangle game screen](http://makzan.github.io/HTML5-Games-Examples/images/untangle-screen.png) 40 | 41 | ## License 42 | 43 | All game code here is under MIT license. 44 | -------------------------------------------------------------------------------- /rush/css/rush-game.css: -------------------------------------------------------------------------------- 1 | html { 2 | background: #fcf8fc url(../images/noise-bg.png); 3 | } 4 | body { 5 | padding: 0; 6 | margin: 0; 7 | background: url(../images/landscape.png) top center repeat-x; 8 | border-top: 5px solid #008894; 9 | } 10 | 11 | header { 12 | width: 480px; 13 | height: 100px; 14 | margin: 2em auto; 15 | background: url(../images/rush-header.png) center center no-repeat; 16 | overflow: hidden; 17 | } 18 | 19 | header h1 { 20 | white-space: nowrap; 21 | text-indent: 100%; 22 | } 23 | 24 | #game { 25 | position: relative; 26 | width: 480px; 27 | height: 320px; 28 | margin: auto; 29 | box-shadow: 0 6px 3px -5px #000; 30 | border-style: solid; 31 | border-width: 8px; 32 | border-top-color: #c5a578; 33 | border-left-color: #977e5a; 34 | border-right-color: #977e5a; 35 | border-bottom-color: #7c6749; 36 | } 37 | 38 | #game-canvas { 39 | background: #efefef; 40 | } 41 | 42 | .scene { 43 | width: 480px; 44 | height: 320px; 45 | background: #efefef; 46 | position: absolute; 47 | top: 0; 48 | left: 0; 49 | } 50 | 51 | .hidden { 52 | display: none; 53 | } 54 | 55 | #menu { 56 | background: url(../images/rush-menu-scene.png); 57 | } 58 | 59 | #gameover { 60 | background: url(../images/rush-gameover-scene.png); 61 | } 62 | 63 | #start-btn, #restart-btn { 64 | display: block; 65 | width: 480px; 66 | height: 320px; 67 | } 68 | 69 | #score { 70 | position: absolute; 71 | top: 10px; 72 | left: 10px; 73 | } 74 | 75 | #your-game-score { 76 | width: 480px; 77 | text-align: center; 78 | position: absolute; 79 | top: 90px; 80 | } 81 | 82 | #top-scores ul{ 83 | list-style: none; 84 | padding: 0; 85 | width: 100%; 86 | text-align: center; 87 | position: absolute; 88 | top: 120px; 89 | } 90 | 91 | .row { 92 | width: 480px; 93 | margin: auto; 94 | overflow: auto; 95 | } 96 | 97 | .half { 98 | width: 50%; 99 | float:left; 100 | } 101 | 102 | ul.how-to-play, #top-scores-board ul { 103 | list-style-image: url(../images/coin1.png); 104 | list-style-position: inside; 105 | padding: 0; 106 | } 107 | 108 | .hr { 109 | background: url(../images/hr.png) center center no-repeat; 110 | height: 50px; 111 | } 112 | 113 | .hr hr { 114 | display: none; 115 | } 116 | 117 | footer { 118 | text-align: center; 119 | color: #999; 120 | font-size: 0.8em; 121 | margin-bottom: 3em; 122 | } 123 | 124 | footer a { 125 | text-decoration: none; 126 | color: #999; 127 | -webkit-transition: all 0.3s ease-out; 128 | -moz-transition: all 0.3s ease-out; 129 | -ms-transition: all 0.3s ease-out; 130 | transition: all 0.3s ease-out; 131 | } 132 | 133 | footer a:hover { 134 | color: #000; 135 | } -------------------------------------------------------------------------------- /rush/images/coin.json: -------------------------------------------------------------------------------- 1 | {"frames": [[2, 2, 12, 12, 0, 0, 0], [18, 2, 12, 12, 0, 0, 0], [34, 2, 12, 12, 0, 0, 0]], "animations": {"all": {"frames": [0, 1, 2, 1, 0]}}, "images": ["coin.png"]} -------------------------------------------------------------------------------- /rush/images/coin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/coin.png -------------------------------------------------------------------------------- /rush/images/coin1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/coin1.png -------------------------------------------------------------------------------- /rush/images/hr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/hr.png -------------------------------------------------------------------------------- /rush/images/landscape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/landscape.png -------------------------------------------------------------------------------- /rush/images/noise-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/noise-bg.png -------------------------------------------------------------------------------- /rush/images/obstacle.json: -------------------------------------------------------------------------------- 1 | {"frames": [[2, 2, 28, 12, 0, 0, 0], [34, 2, 28, 12, 0, 0, 0]], "animations": {"all": {"frames": [0, 1]}}, "images": ["obstacle.png"]} -------------------------------------------------------------------------------- /rush/images/obstacle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/obstacle.png -------------------------------------------------------------------------------- /rush/images/platform-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/platform-left.png -------------------------------------------------------------------------------- /rush/images/platform-middle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/platform-middle.png -------------------------------------------------------------------------------- /rush/images/platform-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/platform-right.png -------------------------------------------------------------------------------- /rush/images/platform.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/platform.png -------------------------------------------------------------------------------- /rush/images/running.json: -------------------------------------------------------------------------------- 1 | {"frames": [[2, 2, 12, 12, 0, 0, 0], [18, 2, 12, 12, 0, 0, 0], [34, 2, 12, 12, 0, 0, 0], [50, 2, 12, 12, 0, 0, 0]], "animations": {"all": {"frames": [0, 1, 2, 3]}}, "images": ["running.png"]} -------------------------------------------------------------------------------- /rush/images/running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/running.png -------------------------------------------------------------------------------- /rush/images/rush-gameover-scene.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/rush-gameover-scene.png -------------------------------------------------------------------------------- /rush/images/rush-header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/rush-header.png -------------------------------------------------------------------------------- /rush/images/rush-menu-scene.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/rush-menu-scene.png -------------------------------------------------------------------------------- /rush/images/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makzan/HTML5-Games-Examples/646cc1dbfdb5238b36798eec3791a868ede9de2b/rush/images/trees.png -------------------------------------------------------------------------------- /rush/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Rush Game 6 | 7 | 8 | 9 |
10 |

Rush

11 |
12 |
13 | 14 |
0
15 | 18 | 23 |
24 | 25 |
26 |
27 |

How to Play?

28 |
    29 |
  • Press the screen to jump.
  • 30 |
  • Avoid the obstacles.
  • 31 |
  • Collect the game coins.
  • 32 |
33 |
34 |
35 |

Top Scores

36 |
37 |
38 |
39 | 40 |
41 |
42 |
43 | 44 |
45 |

@makzan

46 |

handmade in Macao.

47 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /rush/js/game.js: -------------------------------------------------------------------------------- 1 | // window/global scope 2 | var rush = rush || {}; 3 | 4 | 5 | window.onload = function() { 6 | // entry point 7 | rush.game = new rush.Game(); 8 | 9 | // listen to the a-href buttons 10 | var startButton = document.getElementById('start-btn'); 11 | startButton.onclick = function() { 12 | var menuScene = document.getElementById('menu'); 13 | menuScene.classList.add('hidden'); 14 | rush.game.initGame(); 15 | } 16 | 17 | var restartButton = document.getElementById('restart-btn'); 18 | restartButton.onclick = function() { 19 | var gameoverScene = document.getElementById('gameover'); 20 | gameoverScene.classList.add('hidden'); 21 | rush.game.initGame(); 22 | createjs.Ticker.setPaused(false); 23 | } 24 | 25 | // non-game top scores leader board 26 | var topScoresBoard = document.getElementById('top-scores-board'); 27 | topScoresBoard.innerHTML = (new rush.TopScores()).toHTML(); 28 | }; -------------------------------------------------------------------------------- /rush/js/rush-coin.js: -------------------------------------------------------------------------------- 1 | var rush = rush || {}; 2 | 3 | rush.Coin = (function(){ 4 | function Coin() { 5 | this.initialize(); 6 | } 7 | var p = Coin.prototype = new rush.GameObject(); 8 | 9 | // instance variables 10 | p.category = 'coin'; 11 | 12 | p.width = 10; 13 | p.height = 10; 14 | 15 | // put registration point to the bottom center. 16 | p.regX = p.width/2; 17 | p.regY = p.height; 18 | 19 | p.GameObject_initialize = p.initialize; 20 | p.initialize = function() { 21 | this.GameObject_initialize(); 22 | 23 | 24 | // copy from zoe exported coin.json file. 25 | // frame: [x, y, width, height, imageIndex, regX, regY] 26 | var spritesheetData = {"images": ["images/coin.png"], "frames": [[0, 0, 16, 16, 0, 0, 0], [16, 0, 16, 16, 0, 0, 0], [32, 0, 16, 16, 0, 0, 0]], "animations": {"all": {"frames": [0, 1, 2, 1, 0], frequency:10}}} 27 | var spritesheet = new createjs.SpriteSheet(spritesheetData); 28 | this.animation = new createjs.Sprite(spritesheet); 29 | this.animation.gotoAndPlay("all"); 30 | 31 | this.addChild(this.animation); 32 | } 33 | 34 | return Coin; 35 | })(); -------------------------------------------------------------------------------- /rush/js/rush-common-shapes.js: -------------------------------------------------------------------------------- 1 | var rush = rush || {}; 2 | 3 | rush.CommonShapes = (function() { 4 | function CommonShapes(){} 5 | 6 | // draw a rectangle with given styling. 7 | CommonShapes.rectangle = function(rect) { 8 | // defualt value for non-defined parameters. 9 | rect.strokeThickness = rect.strokeThickness || 0; 10 | rect.strokeColor = rect.strokeColor || "#000"; 11 | rect.fillColor = rect.fillColor || "#000"; 12 | rect.x = rect.x || 0; 13 | rect.y = rect.y || 0; 14 | rect.width = rect.width || 0; 15 | rect.height = rect.height || 0; 16 | 17 | // drawing the shape 18 | var shape = new createjs.Shape(); 19 | if (rect.strokeThickness > 0) 20 | { 21 | shape.graphics.setStrokeStyle(rect.strokeThickness); 22 | shape.graphics.beginStroke(rect.strokeColor); 23 | } 24 | shape.graphics.beginFill(rect.fillColor); 25 | shape.graphics.rect(rect.x, rect.y, rect.width, rect.height); 26 | return shape; 27 | }; 28 | 29 | return CommonShapes; 30 | })(); -------------------------------------------------------------------------------- /rush/js/rush-gameobject.js: -------------------------------------------------------------------------------- 1 | var rush = rush || {}; 2 | rush.GameObject = (function(){ 3 | function GameObject() { 4 | this.initialize(); 5 | }; 6 | 7 | var p = GameObject.prototype = new createjs.Container(); 8 | 9 | // instance variables 10 | // what kind of this game object? 11 | p.category = 'object'; 12 | 13 | // dimension 14 | p.width = 0; 15 | p.height = 0; 16 | 17 | // mark the game object to be outside of screen 18 | // useful for collision checking within screen only. 19 | p.isOutsideOfScreen = false; 20 | 21 | // reference the super initialize 22 | // before overriding the initialize method. 23 | p.Container_initialize = p.initialize; 24 | p.initialize = function(){ 25 | this.Container_initialize(); 26 | } 27 | 28 | p.hitPoint = function(point) { 29 | if (point.x >= 0 && point.x <= this.width && point.y >= 0 && point.y <= this.height) { 30 | return true; 31 | } 32 | return false; 33 | } 34 | 35 | return GameObject; 36 | })(); -------------------------------------------------------------------------------- /rush/js/rush-hero.js: -------------------------------------------------------------------------------- 1 | var rush = rush || {}; 2 | rush.Hero = (function(){ 3 | function Hero() { 4 | this.initialize(); 5 | }; 6 | var p = Hero.prototype = new rush.MovableGameObject(); 7 | 8 | // super initialize 9 | p.MovableGameObject_initialize = p.initialize; 10 | p.initialize = function() { 11 | this.MovableGameObject_initialize(); 12 | 13 | this.category = 'hero'; 14 | 15 | this.width = 10; 16 | this.height = 16; 17 | 18 | // put registration point to the middle of botth feet. 19 | this.regX = this.width/2; 20 | this.regY = this.height; 21 | 22 | // copy from zoe exported running.json file. 23 | var spritesheetData = {"images": ["images/running.png"], "frames": [[0, 0, 16, 16, 0, 0, 0], [16, 0, 16, 16, 0, 0, 0], [32, 0, 16, 16, 0, 0, 0], [48, 0, 16, 16, 0, 0, 0]], "animations": {"all": {"frames": [0, 1, 2, 3], frequency:4}}} 24 | var spritesheet = new createjs.SpriteSheet(spritesheetData); 25 | this.animation = new createjs.Sprite(spritesheet); 26 | this.animation.gotoAndPlay('all'); 27 | this.animation.y = 2; // there is some white space between hero graphics and the bottom of the graphics file. 28 | this.addChild(this.animation); 29 | 30 | // collision point 31 | this.collisionPoints = [ 32 | new createjs.Point(this.width/2, this.height), // bottom center 33 | new createjs.Point(this.width, this.height/2), // right middle 34 | ]; 35 | }; 36 | 37 | p.jump = function () { 38 | if (this.onGround) 39 | this.velocity.y = -10; 40 | } 41 | 42 | p.MovableGameObject_tick = p.tick; 43 | p.tick = function () { 44 | this.MovableGameObject_tick(); 45 | this.velocity.x = 3; 46 | } 47 | 48 | return Hero; 49 | })(); -------------------------------------------------------------------------------- /rush/js/rush-movable-gameobject.js: -------------------------------------------------------------------------------- 1 | var rush = rush || {}; 2 | 3 | rush.MovableGameObject = (function(){ 4 | function MovableGameObject() { 5 | this.initialize(); 6 | }; 7 | 8 | var p = MovableGameObject.prototype = new rush.GameObject(); 9 | 10 | p.GameObject_initialize = p.initialize; 11 | p.initialize = function() { 12 | this.GameObject_initialize(); 13 | 14 | this.velocity = new createjs.Point(0, 0); 15 | 16 | // how fast it goes downward? 17 | this.dropSpeed = 1; 18 | 19 | // is this game object stands on any ground (platform)? 20 | this.onGround = false; 21 | 22 | // Give heartbeat to MovableGameObject 23 | this.addEventListener('tick', this.tick.bind(this)); 24 | } 25 | 26 | p.tick = function(timeElapsed) { 27 | if (createjs.Ticker.getPaused()) return; // tick when not paused. 28 | 29 | // apply gravity 30 | this.velocity.y += this.dropSpeed; 31 | this.velocity.y = Math.min(this.velocity.y, 5); // bound to max velocity 32 | }; 33 | 34 | return MovableGameObject; 35 | })(); -------------------------------------------------------------------------------- /rush/js/rush-obstacle.js: -------------------------------------------------------------------------------- 1 | var rush = rush || {}; 2 | rush.Obstacle = (function(){ 3 | function Obstacle() { 4 | this.initialize(); 5 | } 6 | var p = Obstacle.prototype = new rush.GameObject(); 7 | 8 | p.category = 'obstacle'; 9 | 10 | p.width = 20; 11 | p.height = 10; 12 | 13 | // put registration point to the bottom center. 14 | p.regX = p.width/2; 15 | p.regY = p.height; 16 | 17 | p.GameObject_initialize = p.initialize; 18 | p.initialize = function() { 19 | this.GameObject_initialize(); 20 | 21 | // copy from zoe exported obstacle.json file. 22 | // frame: [x, y, width, height, imageIndex, regX, regY] 23 | var spritesheetData = {"images": ["images/obstacle.png"], "frames": [[0, 0, 32, 16, 0, 0, 0], [32, 0, 32, 16, 0, 0, 0]], "animations": {"all": {"frames": [0, 1], frequency:5}}} 24 | var spritesheet = new createjs.SpriteSheet(spritesheetData); 25 | this.animation = new createjs.Sprite(spritesheet); 26 | this.animation.gotoAndPlay("all"); 27 | 28 | this.addChild(this.animation); 29 | } 30 | 31 | return Obstacle; 32 | })(); -------------------------------------------------------------------------------- /rush/js/rush-platform.js: -------------------------------------------------------------------------------- 1 | var rush = rush || {}; 2 | 3 | rush.Platform = (function(){ 4 | function Platform(width){ 5 | this.initialize(width); 6 | } 7 | 8 | var p = Platform.prototype = new rush.GameObject(); 9 | 10 | p.category = 'platform'; 11 | 12 | p.GameObject_initialize = p.initialize; 13 | p.initialize = function(width) { 14 | this.GameObject_initialize(); 15 | 16 | this.width = width || 120; 17 | this.height = 12; 18 | 19 | // variable width with graphics 20 | if (width === 120) { 21 | var image = new createjs.Bitmap("images/platform.png"); 22 | this.addChild(image); 23 | } else if (width > 120) { 24 | var imageLeft = new createjs.Bitmap("images/platform-left.png"); 25 | this.addChild(imageLeft); // width 57 26 | var imageRight = new createjs.Bitmap("images/platform-right.png"); 27 | this.addChild(imageRight); // width 62 28 | var imageMiddle = new createjs.Bitmap("images/platform-middle.png"); 29 | this.addChild(imageMiddle); 30 | 31 | // place them in correct place. 32 | imageMiddle.x = 57; 33 | imageMiddle.scaleX = width - 57 - 62; 34 | imageRight.x = imageMiddle.x + imageMiddle.scaleX; 35 | } 36 | } 37 | 38 | return Platform; 39 | })(); -------------------------------------------------------------------------------- /rush/js/rush-preloader.js: -------------------------------------------------------------------------------- 1 | var rush = rush || {}; 2 | rush.Preloader = (function(){ 3 | // constructor 4 | function Preloader(game) { 5 | this.game = game; 6 | 7 | var bg = new createjs.Shape(); 8 | bg.graphics.beginFill("#000"); 9 | bg.graphics.rect(0, 0, game.stage.canvas.width, game.stage.canvas.height); 10 | this.addChild(bg); 11 | 12 | var progressBar = new createjs.Shape(); 13 | progressBar.graphics.beginFill("#333"); 14 | this.addChild(progressBar); 15 | this.progressBar = progressBar; 16 | 17 | var percentageText = new createjs.Text("loading...0", "32px sans-serif", "#999"); 18 | percentageText.x = game.stage.canvas.width/2; 19 | percentageText.y = game.stage.canvas.height/2; 20 | percentageText.textAlign = "center"; 21 | percentageText.textBaseline = "middle"; 22 | this.addChild(percentageText); 23 | this.percentageText = percentageText; 24 | }; 25 | 26 | Preloader.prototype = new createjs.Container(); 27 | 28 | Preloader.prototype.loadGraphics = function(){ 29 | var imagesList = [ 30 | {name:"coin", path:"images/coin.png"}, 31 | {name:"obstacle", path:"images/obstacle.png"}, 32 | {name:"platform", path:"images/platform.png"}, 33 | {name:"platformLeft", path:"images/platform-left.png"}, 34 | {name:"platformRight", path:"images/platform-right.png"}, 35 | {name:"platformMiddle", path:"images/platform-middle.png"}, 36 | {name:"hero", path:"images/running.png"}, 37 | {name:"trees", path:"images/trees.png"}, 38 | ]; 39 | 40 | rush.graphics = {}; 41 | 42 | var totalFiles = imagesList.length; 43 | var loadedFiles = 0; 44 | for (var i=0, len=totalFiles; i= totalFiles) { 55 | this.game.stage.removeChild(this); 56 | var menuScene = document.getElementById('menu'); 57 | menuScene.classList.remove('hidden'); 58 | } 59 | }).bind(this); 60 | 61 | console.log ("loading: ", imageToLoad.path); 62 | img.src = imageToLoad.path; 63 | 64 | rush.graphics[imageToLoad.name] = imageToLoad; 65 | }; 66 | } 67 | 68 | Preloader.prototype.updateProgress = function(percentage) { 69 | var width = percentage * this.game.stage.canvas.width; 70 | this.progressBar.graphics.rect(0, 0, width, this.game.stage.canvas.height); 71 | this.percentageText.text = "loading..." + Math.round(percentage*100); 72 | this.game.stage.update(); 73 | } 74 | 75 | 76 | return Preloader; 77 | })(); -------------------------------------------------------------------------------- /rush/js/rush-topscores.js: -------------------------------------------------------------------------------- 1 | var rush = rush || {}; 2 | 3 | rush.TopScores = (function(){ 4 | function TopScores() { 5 | if (localStorage['scores'] !== undefined) { 6 | this.data = JSON.parse(localStorage['scores']); 7 | } else { 8 | this.data = { 9 | scores: [] 10 | } 11 | } 12 | } 13 | 14 | var p = TopScores.prototype; 15 | 16 | p.saveScore = function(score) { 17 | // add to scores array 18 | this.data.scores.push(score); 19 | 20 | // sort the scores in descending order 21 | this.data.scores.sort(function(a, b){ 22 | return b-a; // descending numberic sort 23 | }); 24 | 25 | // slice the array to maximum 8 elements 26 | this.data.scores = this.data.scores.slice(0, 8); 27 | 28 | // save to local storage 29 | localStorage['scores'] = JSON.stringify(this.data); 30 | } 31 | 32 | p.toHTML = function() { 33 | var html = "
    "; 34 | 35 | for (var i=0, len=this.data.scores.length; i"; 37 | } 38 | 39 | html += "
"; 40 | return html; 41 | } 42 | 43 | return TopScores; 44 | })(); 45 | --------------------------------------------------------------------------------