enchant.js ブロック崩しもどき _shimizu Follow 2012-08-16 07:56:44 License: Refer to code comments Fork2 Fav0 View4290 Play Stop Reload Fullscreen Smart Phone Fork tree Readme JavaScript 74 lines HTML 1 lines CSS 2 lines 当たり判定の学習用。 chromeでしか動作確認していません。 パッドの移動は、ドラッグ or タッチで。 クリアもゲームオーバーもありません。 ボールの挙動が変です orz 当たり判定って、「Spriteの下辺に接触したかどうか」といった判定ってどうやるものなんでしょうか? 素材はこちらからいただきました。 http://hp.vector.co.jp/authors/VA006860/block/gazou/index.html enchant.js ブロック崩しもどき enchant.js v0.4.5 enchant(); window.onload = function(){ var w = 460; var h = 460; var game = new Game(w, h); game.fps = 60; game.preload('http://jsrun.it/assets/k/1/7/X/k17X3.gif','http://jsrun.it/assets/l/P/W/m/lPWmO.gif', "http://jsrun.it/assets/c/Y/M/y/cYMy7.png"); game.onload = function(){ var ball = new Sprite(11, 11); ball.image = game.assets['http://jsrun.it/assets/k/1/7/X/k17X3.gif']; ball.x = 20; ball.y = 200; ball.dx = 4; ball.dy = 4; ball.wait = 0; ball.addEventListener('enterframe', function(){ this.x += this.dx; this.y += this.dy; if(0 > this.x || w-20 < this.x) this.dx = - this.dx; if(0 > this.y || h-20 < this.y) this.dy = - this.dy; if(ball.intersect(pad)){ this.dy = - this.dy; } }); game.rootScene.addChild(ball); var pad = new Sprite(60,8); pad.image = game.assets['http://jsrun.it/assets/l/P/W/m/lPWmO.gif']; pad.x = 210; pad.y = 420; pad.nx = 210; pad.addEventListener('enterframe', function(){ pad.moveTo(this.nx, this.y); }); game.rootScene.addChild(pad); var blocks = new Group(); for(var i=0; i< 8;i++){ var bw = 0; for(var j=0;j<26;j++){ var block = new Sprite(16, 16); block.image = game.assets['http://jsrun.it/assets/c/Y/M/y/cYMy7.png']; block.x = 16 + bw; block.y = 16 * i; block.addEventListener('enterframe', function(){ if(this.intersect(ball)){ ball.dy = - ball.dy; this.remove(); } }); blocks.addChild(block); bw = bw + 16; } } game.rootScene.addChild(blocks); game.rootScene.addEventListener("touchmove", function(e) { pad.nx = e.x - (pad.width/2); }); } game.start(); } <canvas id='world'></canvas> enchant.js ブロック崩しもどき body { margin:0px; } 当たり判定の学習用。 chromeでしか動作確認していません。 パッドの移動は、ドラッグ or タッチで。 クリアもゲームオーバーもありません。 ボールの挙動が変です orz 当たり判定って、「Spriteの下辺に接触したかどうか」といった判定ってどうやるものなんでしょうか? 素材はこちらからいただきました。 http://hp.vector.co.jp/authors/VA006860/block/gazou/index.html enchant(); window.onload = function(){ var w = 460; var h = 460; var game = new Game(w, h); game.fps = 60; game.preload('http://jsrun.it/assets/k/1/7/X/k17X3.gif','http://jsrun.it/assets/l/P/W/m/lPWmO.gif', "http://jsrun.it/assets/c/Y/M/y/cYMy7.png"); game.onload = function(){ var ball = new Sprite(11, 11); ball.image = game.assets['http://jsrun.it/assets/k/1/7/X/k17X3.gif']; ball.x = 20; ball.y = 200; ball.dx = 4; ball.dy = 4; ball.wait = 0; ball.addEventListener('enterframe', function(){ this.x += this.dx; this.y += this.dy; if(0 > this.x || w-20 < this.x) this.dx = - this.dx; if(0 > this.y || h-20 < this.y) this.dy = - this.dy; if(ball.intersect(pad)){ this.dy = - this.dy; } }); game.rootScene.addChild(ball); var pad = new Sprite(60,8); pad.image = game.assets['http://jsrun.it/assets/l/P/W/m/lPWmO.gif']; pad.x = 210; pad.y = 420; pad.nx = 210; pad.addEventListener('enterframe', function(){ pad.moveTo(this.nx, this.y); }); game.rootScene.addChild(pad); var blocks = new Group(); for(var i=0; i< 8;i++){ var bw = 0; for(var j=0;j<26;j++){ var block = new Sprite(16, 16); block.image = game.assets['http://jsrun.it/assets/c/Y/M/y/cYMy7.png']; block.x = 16 + bw; block.y = 16 * i; block.addEventListener('enterframe', function(){ if(this.intersect(ball)){ ball.dy = - ball.dy; this.remove(); } }); blocks.addChild(block); bw = bw + 16; } } game.rootScene.addChild(blocks); game.rootScene.addEventListener("touchmove", function(e) { pad.nx = e.x - (pad.width/2); }); } game.start(); } <canvas id='world'></canvas> body { margin:0px; } use an iframe compat browser, deer Play on jsdo.it games Author Share ブログに埋め込む QR Tag Download Complete! Description What kind of game? 当たり判定の学習用。 chromeでしか動作確認していません。 パッドの移動は、ドラッグ or タッチで。 クリアもゲームオーバーもありません。 ボールの挙動が変です orz 当たり判定って、「Spriteの下辺に接触したかどうか」といった判定ってどうやるものなんでしょうか? 素材はこちらからいただきました。 http://hp.vector.co.jp/authors/VA006860/block/gazou/index.html Control Device Smartphone Controllerjsdo.it WebSocket Controller» Mouse Keyboard Touch Device Fullscreen Activated Inactivated jsdo.it games から削除する Submit Author _shimizu URLhttp://shimz.me/blog/ 群馬県高崎市在住のエンジニア 。サーバ管理したり、自動組版のスクリプト組んだり、サイト作ったりして生きてます。データビジュアライゼーションとオープンデータにハマってます。Webデザイン & JS勉強中。 I luv javascript! Tweet Default Panel Auto play Screenshot Readme JavaScript HTML CSS Size Width: px Height: px code <script type="text/javascript" src="http://jsdo.it/blogparts/pKkt/js"></script> enchant.js game Discussion Questions on this code? Tags enchant.js game Forked sort by latest page views favorite forked forked: enchant.js ブロック崩しもどき syunnketu 00 379 75/1/2 enchant.js game forked: enchant.js ブロック崩しもどき syunnketu 00 605 74/1/2 enchant.js game