ã¯ããã«
åå¼·ãã¦ã Canvas ã使ã£ã¦ãªã«ãä½ããããªã¼ã¨æãã¾ãã¦ãæä½ã£ã¦ãã STG ã®ãããç´ æãå©ç¨ãã¦ãç°¡åãªãã«ãã¿ããå¯¾å¿ STG ãä½ã£ã¦ã¿ã¾ããã
触ã£ãæã®æ°ã ããã£ãããåºã¦ãã¾ãããã¦ã¹ã§ããã¬ã¤åºæ¥ã¾ããæ»ãã ãã¯ãªãã¯ã§å¾©æ´»ãã¾ãã
ä½æã®éç¨ã§å¦ãã ãã¨ãªã©ãå
±æã§ããã°ã¨æããç°¡åã«ã¾ã¨ãã¦ã¿ã¾ããã
解説ã¯ä½åãã«åãã¦è¡ããã¨æãã¾ããä»åã¯ãN-Way å¼¾ãç»åã§åºããã¨ããã¾ã§æ¸ãã¦ã¿ã¾ããã
ããã¡ãªã¿ã«ã¿ã¤ãã«ã§ã¯ãããªãã¨è¨ã£ã¦ã¾ãããã¶ã£ã¡ããéãã®ã§å¼¾ã¨ãã¨ãã§ã¯ãã1000åã¨ãçµæ§è¾ãã§ã(´ã»Ï:;.:...ã
åå¼·ã«ä½¿ã£ãå ´æ
- Canvas - HTML5.JP
- 今更聞けないcanvasの基礎の基礎 | tech.kayac.com - KAYAC engineers' blog
- canvasでキラキラした背景を作る方法 | tech.kayac.com - KAYAC engineers' blog
ãã®è¾ºããèªãã§ã¾ãé°å²æ°ãã¤ãã¿ã¾ããã
Canvas ã®ç¨æ
ãåèã«ãã㨠Canvas ã§åºæ¥ããã¨ãè²ã
ã¨ãããã¾ãã
ã¾ã㯠Canvas ãç¨æããããã«ä¸è¨ã®ãã㪠HTML 㨠CSS ãæ¸ãã¾ãã
index.html
<!DOCTYPE HTML> <html lang="ja"> <head> <meta charset="UTF-8"> <title>ã ãã¾ãã¦ãã¨</title> <link rel="stylesheet" href="style.css" /> </head> <body> <canvas id="canvas" width="640" height="480"></canvas> </body> </html>
style.css
* { margin: 0px; padding: 0px; } html, body { height: 100%; overflow: hidden; background-color: #000; text-align: center; } canvas { border: 3px #333 dotted; }
Canvas ã®æ¨ªå¹
/縦å¹
ã¯ãç´æ¥ width / height å±æ§ã§æå®ãã CSS ã§æå®ãã¦ãã¾ãããCSS ã§æå®ããã¨å±æ§ã§æå®ããå¤ãåç´ã«ç¸®å°/æ¡å¤§ãããµãã¾ãã«ãªãã¾ããimg ã¿ã°ã¨åããããªæãã§ãã
ããããã©ã¦ã¶ã§è¡¨ç¤ºãã¦ã¿ã¾ãã
ç¹ç·ã§å²ã¾ããå ´æã Canvas ã§ãã
ãã ããã ã¨ããã©ã¦ã¶ç»é¢ã大ããæã¯å°ããã¦è¿«åããªãã§ãããéã«å°ããã¨ãã¯ã¯ã¿åºãã¦ãã¾ãã¾ããããã§ãã©ã¦ã¶ã®å¤§å°ã«åãã㦠Canvas ã®æ¡å¤§ç¸®å°ãããããã«ãã¦ã¿ã¾ãã
HTML ã« JavaScript ãèªã¿è¾¼ãè¨è¿°ã追å ãã¾ãã
... <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript" src="shooting.js"></script> ...
jQuery ããã¼ããã¦ããã¾ããjQuery ãèªã¿è¾¼ã script ã¿ã°ã¯ãä¸è¨ã®ãã¼ã¸ããã³ãããã¦ãã¦ä¸ããã
JavaScript å´ã§ã¯ããã¥ã¡ã³ãèªã¿è¾¼ã¿æ㨠resize ã¤ãã³ããã³ãã©ãå¼ã°ããã¨ãã«ç»é¢ã®ãµã¤ãºã®å¤æ´ãè¡ãã¾ãããã®ã¾ã¾ width ã height ã 100% ã«ãã¦ãã¾ãã¨ãç»é¢ã横é·ã®æ㯠Canvas ã横é·ã«å¼ã伸ã°ãããå½¢ã«ãªã£ã¦ãã¾ãã®ã§ãç辺ãæ大ã«ãªãããã«æ¡å¤§ããã¾ãã
shooting.js
$(function(){ /* ------------------------------------------------------------------------- */ // Global Parameters /* ------------------------------------------------------------------------- */ const WIDTH = 640; const HEIGHT = 480; /* ------------------------------------------------------------------------- */ // Canvas /* ------------------------------------------------------------------------- */ var Canvas = { resize : function() { var wRate = $(window).width() / WIDTH; var hRate = $(window).height() / HEIGHT; var rate = Math.min(wRate, hRate); $('#canvas').css({ width : WIDTH * rate, height : HEIGHT * rate, }); }, }; /* ------------------------------------------------------------------------- */ // OnLoad /* ------------------------------------------------------------------------- */ $(window).bind({ resize : Canvas.resize }); Canvas.resize(); main(); /* ------------------------------------------------------------------------- */ // Main /* ------------------------------------------------------------------------- */ function main() { }
ããã§ãç»é¢ã«åããã¦å¼ã伸ã°ãããããã«ãªãã¾ãã
ä½ãæãã¦åããã¦ã¿ã
Canvas ãåºæ¥ããåããããä½ãæãã¦ã¿ããã§ãããã¼ãCanvas ã¸ã©ããã£ã¦å³å½¢ãæç»ãããã«ã¤ãã¦ã¯ãさまざまな図形を描く - Canvas - HTML5.JP ããåç
§ä¸ããã
ããã§ã¯ jQuery 風㫠Canvas ãæä½ãããå³å½¢ãæããããããã¨ã®åºæ¥ã jCanvas ãå©ç¨ãã¦ã¿ããã¨æãã¾ãã
jCanvas ã«ã¤ãã¦ã¯ä¸è¨ãã¼ã¸ Docs ãããµã³ãã«ã解説ãè¦ããã¨ãåºæ¥ã¾ããSandbox ãç¨æããã¦ããã®ã§ããµã³ãã«ã³ã¼ããã¡ãã£ã¨è©¦ãã¦ã¿ããã¨ãã£ããã¨ãç°¡åãªã®ã§ã¨ã¦ããªã¹ã¹ã¡ã§ãã
ã§ã¯ãããããåãããã¨ãèæ
®ãã¦ç§»åç©ä½ã¯ã©ã¹ Mover ãä½ã£ã¦ã¿ã¾ãããã
/* ------------------------------------------------------------------------- */ // Mover /* ------------------------------------------------------------------------- */ var Mover = function(mover) { this.x = ('x' in mover) ? mover.x : 0; this.y = ('y' in mover) ? mover.y : 0; this.vx = ('vx' in mover) ? mover.vx : 0; this.vy = ('vy' in mover) ? mover.vy : 3; this.w = ('w' in mover) ? mover.w : 10; this.h = ('h' in mover) ? mover.h : 10; this.cnt = 0; this.flag = true; }; Mover.prototype = { move : function() { this.x += this.vx; this.y += this.vy; ++this.cnt; }, draw : function() { $("#canvas").drawEllipse({ x : this.x, y : this.y, width : this.w, height : this.h, fillStyle : '#fff', }); }, };
ããã main é¢æ°ã§çæãã¾ãã
function main() { var mover = new Mover({ x : WIDTH/2, y : HEIGHT/2, w : 10, h : 10, vx : 1, vy : 3, }); setInterval(function(){ mover.move(); mover.draw(); }, 1000/30); }
30 FPS 㧠â ãåããã¨æããããç·ã«ãªã£ã¦ãã¾ãã¾ãããããã¯åæãã â ãæ¶å»ããã¦ããªãããã§ãããã㧠Canvas ãªãã¸ã§ã¯ãã«æ¬¡ã®ãã㪠reset ã¡ã½ããã追å ãã¦ããããæç»åã«å¿
ãå¼ã°ããããã«ãã¦ã¿ã¾ãããã
var Canvas = { // ...(ç¥) clear : function() { $('#canvas').clearCanvas(); }, }; function main() { // ...(ç¥) setInterval(function(){ mover.move(); Canvas.clear(); mover.draw(); }, 1000/30); }
ç¡äºåãã¾ããï¼
ã¡ãªã¿ã«ãã¯ã©ã¹ã®ååã Bullet ã¨ããã« Mover ã¨ããã®ã¯ãå¾ã
ãå¼¾ã«éããæµããã¬ã¤ã¤ã¼ããã®ã¯ã©ã¹ãç¶æ¿ãã¦ä½ããã¨æã£ã¦ããããã§ãã
ããã¾ã§ã®ã³ã¼ã
ããããã®å¼¾ãåããã¦ã¿ã
ã§ã¯æ¬¡ã«å¼¾ã®æ°ãå¢ããã¦ã¿ã¾ããããå¼¾ã管çãã¦ããã Container ã¯ã©ã¹ãä½ã£ã¦ã¿ã¾ãã
var Container = function() { this.array = []; } Container.prototype = { add : function(instance) { this.array.push(instance); }, move : function() { var n = 0; for (var i in this.array) { this.array[i].move(); if (!this.array[i].flag) { this.array.splice(n, 1); } ++n; } }, draw : function() { for (var i in this.array) { this.array[i].draw(); } }, };
Container ã¯ã©ã¹ã¯å
é¨ã« array é
åããããã£ãæã£ã¦ãã¦ãadd 㧠array ã«è¦ç´ ã追å ãããã¨ãå¯è½ã§ãããã㦠move / draw ãå¼ã¶ã¨ãarray ã«æ ¼ç´ããã¦ããè¦ç´ ãå
¨ã¦èµ°æ»ã㦠move / draw ãå¼ã³åºããã¨ããç°¡åãªä½ãã«ãªã£ã¦ãã¾ãããã®ã¨ããflag ããããã£ã false ã«ãªã£ã¦ããè¦ç´ ã«ã¤ãã¦ã¯ array ããåé¤ããããã«ãã¦ãã¾ãããããå©ç¨ããã°ãå¼¾ãèªæ©ã¨è¡çªããæããç»é¢å¤ã«åºãæãªã©ã« flag ã false ã«ããã°ãèªåçã«åé¤ããã寸æ³ã§ãã
ã§ã¯ãã¤ãã§ã«ç»é¢å¤ã«åºãã flag ã false ã«ããå¦çã Mover ã¯ã©ã¹ã«è¿½å ãã¦ãã¾ãã¾ãããã
const MARGIN = 50; Mover.prototype = { move : function() { this.x += this.vx; this.y += this.vy; this.chkBoundary(); ++this.cnt; }, // ...(ç¥) chkBoundary : function() { if (this.x < -this.w - MARGIN || this.x > WIDTH + this.w + MARGIN || this.y < -this.h - MARGIN || this.y > HEIGHT + this.h + MARGIN) { this.flag = false; } }, };
ç»é¢å¤ã« MARGIN ã ãã¯ã¿åºããæ¶ãããã«ãã¦ãã¾ãã
ã§ã¯æ¬¡ã«å¼¾ãé©å½ã«å¤§éã«çæãã¦ã¿ã¾ããããmain é¢æ°ã以ä¸ã®ããã«æ¸ãæãã¾ãã
function main() { var frame = 0; var Movers = new Container(); setInterval(function(){ if (frame%5 === 0) { var angle = 2 * Math.PI * Math.random(); Movers.add( new Mover({ x : WIDTH/2, y : HEIGHT/2, w : 10, h : 10, vx : Math.sin(angle), vy : Math.cos(angle), }) ); console.log(Movers.array.length); } Movers.move(); Canvas.clear(); Movers.draw(); ++frame; }, 1000/FPS); }
5ãã¬ã«ï¼åãå¼¾ãä¸å¿ããã©ã³ãã ãªæ¹åã«çºå°ãã¾ãã
Chrome ã®ãããã°ã³ã³ã½ã¼ã«ã使ã£ã¦ Movers.array ãç£è¦ãã¦ããã°ãç»é¢å¤ã«åºãå¼¾ãæ¶å»ããã¦ããæ§åãè¦ããã¨ãåºæ¥ã¾ãã
ããã¾ã§ã®ã³ã¼ã
å¼¾ãç»åã«ãã¦ã¿ã
ã§ã¯ã次ã«å¼¾ãç»åã«ãã¦ã¿ã¾ãã画像を組み込む - Canvas - HTML5.JP ã« Canvas ã¸ã®
ç»åæç»ã«ã¤ãã¦è©³ãã説æãæ¸ããã¦ãã¾ãããCanvas ã«æç»ããã¨ãã«ã¯ãç»åããã¼ããã¦ããå¿
è¦ãããã¾ããããjCanvas ã§ã¯ãã®ããããé è½ãã¦ãããæ´ã«ç»åããã¼ããããéã«å¼ã°ãã callback ãæå®ãããã¨ãåºæ¥ã¾ãã
ããããªãããæç»ãããã³ã«æ¯åèªã¿ã«è¡ãããããã²ã¼ã ã®æåã¨ãã¦ã¯ãäºãç»åããã¼ããã¦ãããæ¹ãè¯ãã§ããããç»åãèªã¿è¾¼ãã®ãé
ãã¦ãã¼ããçµãã£ããçªç¶å¼¾ãåºç¾ããï¼ãªãã¦ãã㪠Lunatic ãªé£æ度ã¯ç¡çã§ããã¨ãããã¨ã§ãç»åããã¼ãããã¯ã©ã¹ãæ¸ãã¦ã¿ã¾ãã
/* ------------------------------------------------------------------------- */ // Image Loader /* ------------------------------------------------------------------------- */ var ImageLoader = function(imgPath) { this.loaded = false; this.img = new Image(); this.path = imgPath + "?" + new Date().getTime(); }; ImageLoader.prototype = { load : function() { this.img.src = this.path; this.img.onload = function(_this) { return function() { this.loaded = true; } }(this); }, }; /* ------------------------------------------------------------------------- */ // Materials Container /* ------------------------------------------------------------------------- */ var Materials = { map : {}, add : function(material) { var key = material.key; this.map[key] = { instance : new ImageLoader(material.path), path : material.path, width : material.width, height : material.height, cd : material.cd, }; this.map[key].instance.load(); }, loaded : function() { for (var key in map) { if (!this.map[key].instance.loaded) return false; } return true; }, img : function(key) { return this.map[key].instance.img; }, path : function(key) { console.log(this.map[key]); return this.map[key].path; }, width : function(key) { return this.map[key].width; }, height : function(key) { return this.map[key].height; }, cd : function(key) { return this.map[key].cd; }, }
ImageLoader ã§ç»åã«ç»åãã¹ã渡ã㦠load ãå®è¡ããã¨ãã¼ããã¾ãããã¼ããå®äºãã㨠loaded ã false ãã true ã«å¤ããã¾ãã
ããã Materials ãªãã¸ã§ã¯ãã® map ããããã£ã« add ã§çªã£è¾¼ãã§ç®¡çãããã¼ã§ãªã½ã¼ã¹æ
å ±ãåå¾ã§ããããã«ãã¾ããcd 㯠collisiion detection = å½ããå¤å®ã§ãã
èªã¿è¾¼ã¾ããç»åã§ããã以ä¸ã®ãããªãã®ãç¨æãã¾ãã
ãããããªãã³ã°ãã¦è¡¨ç¤ºããããã«ãã¾ãã試ãã« main é¢æ°ãæ¸ãæãã¦ç»åã表示ãã¦ã¿ã¾ãããã
// color const COLOR = { RED : 0, GREEN : 1, BLUE : 2, YELLOW : 3, PURPLE : 4, PINK : 5, ORANGE : 6, SKYBLUE : 7, BLACK : 8, WHITE : 9, }; function main() { Materials.add({ key : 'bullet.normal', path : 'img/bullet/normal.png', width : 20, height : 20, cd : 5, }); var key = 'bullet.normal'; var loadTimer = setInterval(function(){ console.log(Materials.loaded()); if (Materials.loaded()) { clearInterval(loadTimer); $('#canvas').drawImage({ source : Materials.path(key), x : WIDTH/2, y : HEIGHT/2, width : Materials.width(key), height : Materials.height(key), sWidth : Materials.width(key), sHeight : Materials.height(key), sx : Materials.width(key) * COLOR.GREEN, sy : 0, cropFromCenter: false, }); } }, 100); }
100 ms æ¯ã«ãã¼ãã®å®äºããã§ãã¯ãã¦ããã¼ããå®äºãããã¡ã¤ã³ã®å¦çã«å
¥ãããã«ãã¦ãã¾ãã
ã¾ããå
ç»åã 20 px ééã«è²ãåºåãããå¼¾ãæããã¦ããã®ã§ããããå©ç¨ãã¦ããªãã³ã°ãããã¨ã§å¼¾ã®è²ãå¤ãã¦ãã¾ãã
ã§ã¯ãå ã»ã©ã® Ellipse ã§æãã¦ãããã®ããç»åã«å¤ãã¦ã¿ã¾ããããã¾ããMover ã¯ã©ã¹ããããã¾ãã
var Mover = function(mover) { this.x = ('x' in mover) ? mover.x : 0; this.y = ('y' in mover) ? mover.y : 0; this.vx = ('vx' in mover) ? mover.vx : 0; this.vy = ('vy' in mover) ? mover.vy : 3; this.color = ('color' in mover) ? mover.color : 0; this.key = ('key' in mover) ? mover.key : null, this.w = ('key' in mover) ? Materials.width(mover.key) : 0; this.h = ('key' in mover) ? Materials.height(mover.key) : 0; this.cd = ('key' in mover) ? Materials.cd(mover.key) : 0; this.sx = this.w * this.color; this.sy = 0; this.cnt = 0; this.flag = true; }; Mover.prototype = { move : function() { this.x += this.vx; this.y += this.vy; this.chkBoundary(); ++this.cnt; }, draw : function() { $('#canvas').drawImage({ source : Materials.path(this.key), x : this.x, y : this.y, width : this.w, height : this.h, sWidth : this.w, sHeight : this.h, sx : this.sx, sy : this.sy, cropFromCenter: false, }); }, chkBoundary : function() { if (this.x < -this.w - MARGIN || this.x > WIDTH + this.w + MARGIN || this.y < -this.h - MARGIN || this.y > HEIGHT + this.h + MARGIN) { this.flag = false; } }, };
ãªã½ã¼ã¹ã®èªã¿è¾¼ã¿é¨å㨠main é¢æ°ã¯ä»¥ä¸ã®ããã«ãã¾ãã
/* ------------------------------------------------------------------------- */ // Resource /* ------------------------------------------------------------------------- */ Materials.add({ key : 'bullet.normal', path : 'img/bullet/normal.png', width : 20, height : 20, cd : 5, }); var loadTimer = setInterval(function(){ if (Materials.loaded()) { clearInterval(loadTimer); main(); } }, 100); /* ------------------------------------------------------------------------- */ // Main /* ------------------------------------------------------------------------- */ function main() { var frame = 0; var Movers = new Container(); setInterval(function(){ if (frame%5 === 0) { var angle = 2 * Math.PI * Math.random(); Movers.add( new Mover({ x : WIDTH/2, y : HEIGHT/2, w : 10, h : 10, vx : 3 * Math.sin(angle), vy : 3 * Math.cos(angle), key : 'bullet.normal', color : COLOR.BLUE, }) ); } Movers.move(); Canvas.clear(); Movers.draw(); ++frame; }, 1000/FPS); }
ããã¾ã§ã®ã³ã¼ã
å¼¾å¹ãä½ã£ã¦ã¿ã
ãã¦ãã¦ãã·ã¥ã¼ãã£ã³ã°ãä½ãééå³ã¯ãã¯ãå¼¾å¹ãä½ãã¨ããã§ãããï¼
å¼¾ãæç»ããã¨ããã¾ã§ã¯åºæ¥ãã®ã§ãããããå¼¾ã秩åºç«ã¦ã¦åããã¨ãããå®è£
ãã¦ã¿ã¾ããããæ±ç¨çã«ä½¿ããå¼¾å¹ã®ä¾ã¨ã㦠N-way å¼¾ãä½ã£ã¦ã¿ããã¨ã«ãã¾ãã
ã¨ããã®åã«å¼¾ã Mover ã¨ãã¦çæãã¦ããã®ã¯ã¡ãã£ã¨æ°æã¡æªãã®ã§ Mover ãç¶æ¿ãã Bullet ã¨ããã¯ã©ã¹ãä½ã£ã¦ã¿ã¾ãããã
ç¶æ¿ã«ã¤ãã¦
ã§ãç¶æ¿ã®ä»æ¹ãªã®ã§ãããJavaScript ã¯ãããã¿ã¤ããã¼ã¹ã®ãªãã¸ã§ã¯ãæåè¨èªã§ãä¸è¨ã®ãµã¤ãã§ã¾ã¨ãã¦ä¸ãã£ã¦ããããã«ãããæ¹ã¯ããããæãã¾ãã
ä»å㯠jQuery ãç¨ãã¦ãããã¨ã§ããã $.extend ã使ã£ãç¶æ¿ã§å®è£ ãã¦ã¿ã¾ãã
ä¸è¨ã¨ã³ããªãåèã«ããã¦é ãã¾ããã
var Bullet = function(bullet) { Mover.call(this, bullet); }; Bullet.prototype = $.extend({}, Mover.prototype);
ã³ã³ã¹ãã©ã¯ã¿ã§ Mover ã®ã³ã³ã¹ãã©ã¯ã¿ã call ã§å¼ãã§ãprototype 㯠Mover ã®ããã空ãªãã¸ã§ã¯ã {} ã«ä¸æ¸ããã¾ãã
N-way å¼¾ã¯è§åº¦æå®ã§å¼¾ãé£ã°ãããã®ã§ãé度ã¨è§åº¦ãæå®ããã°ãã®æ¹åã«å¼¾ãçºå°ãã¦ããã RadianBullet ã¯ã©ã¹ãç·´ç¿ãã¦ãä½ã£ã¦ã¿ã¾ãããã
var RadianBullet = function(bullet) { this.v = ('v' in bullet) ? bullet.v : 0; this.ang = ('ang' in bullet) ? bullet.ang : 0; Mover.call(this, bullet); }; RadianBullet.prototype = $.extend({}, Bullet.prototype, { move : function() { this.x += this.v * Math.cos(this.ang); this.y += this.v * Math.sin(this.ang); this.chkBoundary(); ++this.cnt; }, });
ããã§è§åº¦ãã¼ã¹ã®å¼¾ãçºå°ã§ããããã«ãªãã¾ããï¼ã³ã³ã¹ãã©ã¯ã¿ã§ this.vx 㨠this.vy ã«ä»£å ¥ãã¦ããã©ã«ãã® move 使ã£ãã»ããå®è¡é度çã«ã¯éãã®ã§ããâ¦ãã¾ãç·´ç¿ã®ããã¨ãããã¨ã§ããï¼
ã§ã¯ããã® RadianBullet ãå©ç¨ã㦠BulletCurtain ã¯ã©ã¹ãä½ãã¾ãããã
/* ------------------------------------------------------------------------- */ // Bullet Curtain /* ------------------------------------------------------------------------- */ var BulletCurtain = function() { this.cnt = 0; this.flag = true; }; /* ------------------------------------------------------------------------- */ // Bullet Curtain Variations /* ------------------------------------------------------------------------- */ // N-Way Pattern var BC_NWay = function(bc) { BulletCurtain.call(this); for (var x in bc) { this[x] = bc[x]; } }; BC_NWay.prototype = { move : function() { for (var i = 0; i < this.num; ++i) { if (this.cnt === this.period*i) { for (var n = 0; n < this.nway; ++n) { Bullets.add(new RadianBullet({ x : this.x, y : this.y, v : this.v, ang : this.ang0 - this.dang*(this.nway-1)/2 + this.dang*n, key : this.key, color : 'color' in this ? this.color : COLOR.RED, })); } } } ++this.cnt; if (this.cnt > this.period*this.num) { this.flag = false; } }, draw : function() {}, };
ãã¹ãæ·±ãâ¦ãMover ã§ã¯ç¡ãã®ã§ãããContainer ã«çªã£è¾¼ãã æã«åé¡ãªãåãã¦ãããããã« move 㨠draw ã¡ã½ãããæ¸ãã¦ããã¾ãã
ãªãã§ãã®å®è£
㧠N-Way å¼¾ãé£ãã§ãããã¯é¢ç½ãã®ã§ãã²èãã¦ã¿ã¦ä¸ããã
ã§ã¯ main é¢æ°å
ã§ãã® BC_NWay ãå¼ãã§ã¿ã¾ããããã¡ãªã¿ã« BC_NWay.move() å
é¨ã§ Container ã§ãã Bullets ã® add ã¡ã½ãããå¼ãã§ããå½¢ã«ãªã£ã¦ãã¾ãã®ã§ãContainer ã®å®£è¨ç®æ㯠main() é¢æ°ã®å¤ã«åºãã¦ãmain é¢æ°ãæ¸ãã¾ãã
/* ------------------------------------------------------------------------- */ // Containers /* ------------------------------------------------------------------------- */ var Bullets = new Container(); var BulletCurtains = new Container(); /* ------------------------------------------------------------------------- */ // Main /* ------------------------------------------------------------------------- */ function main() { var frame = 0; setInterval(function(){ if (frame%60 === 0) { BulletCurtains.add( new BC_NWay({ nway : 5, x : WIDTH/2, y : HEIGHT/4, v : 5, ang0 : Math.PI/2, dang : Math.PI/10, num : 8, period : 5, color : COLOR.RED, key : 'bullet.normal', }, Bullets) ); } BulletCurtains.move(); Bullets.move(); Canvas.clear(); Bullets.draw(); ++frame; }, 1000/FPS); }
90度ï¼çä¸ï¼ã®æ¹åã¸ï¼ãã¬ã¼ã ç½®ãã«18度ééã§8é£çºèµ¤ãå¼¾ãï¼æ¹åã«é£ãã§è¡ãã¾ãï¼
ããã¾ã§ã®ã³ã¼ã
次åäºå
次åã¯ãæµãåºãããèªæ©ãæ縦ãããããã«ãã¿ãã対å¿ããããâ¦ããªã¨ãããæ¸ããã¨æãã¾ãã
ä½è«
ããªãã³ã°å¦çã¯éãï¼
å¼¾æ°ãå¤ããªã£ã¦ããã¨ãFPS ãè½ã¡ã¦ãã¾ãã詳ããã¯èª¿ã¹ã¦ããªãã§ãããããããæç»ã«ä¸çªæéãããã£ã¦ãã¾ããå人çã«ã¯ããªãã³ã°ã³ã¹ããçµæ§ããã£ã¦ããã®ã§ã¯â¦ãã¨çã£ã¦ããã®ã§ãããæä½ã£ã¦ãããããçµµãåå²ããã®ãé¢åã§è©¦ãã¦è¦ã¦ãã¾ãããèå³ãããæ¹ã¯ãã£ã¦ã¿ã¦ãã ããï¼ããã¦æãã¦ä¸ããããï¼ã