調整点。
・中央値と描画の左上座標の調整。
・マウスとキー入力のチェンジ。
・タイムウェイトの調整。
調整点。
・中央値と描画の左上座標の調整。
・マウスとキー入力のチェンジ。
・タイムウェイトの調整。
ブロック崩しのコーディング(1)
コーディングの途中経過(Java Script)です。
ーーーーーーー
function sgn(a) {
if(a > 0) return(1); else return(-1);
WIDTH = 640;
HEIGHT = 480;
// white, red, yellow, green, blue
var colortable = ["red","yellow","green"];
var username = ["ipad","iphone","android"]; //端末の名前
var br = 10; // ボールの半径
var paddlew = 96; // パドルの幅
var paddleh = 16; // パドルの高さ
var blockw = 48; // ブロックの幅
var blockh = 24; // ブロックの高さ
var blocks = [];
var blocksu = 50;
var endflag = 0; // 処理の終わりを判定する
var paddlex = 0; // パドルのx座標
var paddley = 0; // パドルのy座標
// ブロックスに配列要素にプロパティを付与する。
function bkock() {
this.id = -1;
this.x = 0;
this.y = 0;
this.color = 0;
}
// 初期処理
function init(){
canvas = document.getElementById('world');
canvas.width = WIDTH;
canvas.height = HEIGHT;
ctx = canvas.getContext('2d');
ctx.font = "64px 'MS Pゴシック'";
user = window.navigator.userAgent.toLowerCase();
for(i=0; i
if(user.indexOf(username[i]) > 0)break;
}
if(i
document.addEventListener("touchmove", touchmove);
}else{
document.addEventListener("mousemove", mousemove);
}
// ブロックスを定義する。
blocks = new Array(blocksu);
for(i=0; i
blocks[i] = new block();
}
}
for(i=0; i
blocks[i].id = 1;
blocks[i].x = (i % 10) * (blockw + 4) + 64;
blocks[i].y = Math.floor(i / 10) * (blockh + 4) + 64;
blocks[i].color = Math.floor(blocks[i].y / 28) % 3;
}
}
//スマホ/タブレットのタッチイベントで起動する関数
function touchmove(e){
if (e.targetTouches.length == 1){
touch = e.targetTouches[0];
touchpice(touch.pageX ,touch.pageY);
}
}
//pcのマウスクリックイベントで起動する関数
function mousemove(e){
touchpice(e.clientX ,e.clientY);
}
//引数で指定した位置にある駒の移動処理(※変更前です)
function touchpice(tx,ty){
element = document.getElementById("idselect");
if(element.value != turn) return; //相手の番の場合は無効
cx = Math.floor((tx-8)/psize);
cy = Math.floor((ty-8)/psize);
if(isinside(cx,cy,0,0,bw,bh)==false)return; //将棋盤バッファ外なら処理を終了
if(startx == -1){
movestart(cx,cy); //移動開始
}else{
moveend(cx,cy); //指定したマスに駒を移動させる
startx = -1;
redraw(); //将棋盤バッファのデータに基づいて画面を再描画
}
}
function main() {
while(endflag == 0) {
ballx = WIDTH / 2; // ボールのx座標
bally = HEIGHT - 170; // ボールのy座標
bx1 = 2; // ボールの速度(x成分)
by1 = -2.5; // ボールの速度(y成分)
x = WIDTH / 2; // パドルの位置(x座標)
y = HEIGHT - 64; // パドルの位置(y座標)
paddlex = x - (paddlew / 2);
paddley = y - (paddleh / 2);
for(i=0; i
blocks[i].id = 1;
blocks[i].x = (i % 10) * (blockw + 4) + 64;
blocks[i].y = Math.floor(i / 10) * (blockh + 4) + 64;
blocks[i].color = Math.floor(blocks[i].y / 28) % 3;
}
gameover = 0;
while(endflag == 0){
//キーコード取得しパドルの位置を移動させる。← →
x = paddlex;
k = event.keyCode;
if(k==100) x -= 8; if(k==102) x += 8;
//パドルがゲーム画面内ならパドルの位置を変更する
if( (x >= (paddlew / 2)) && (x <= (WIDTH - (paddlew / 2))){
paddlex = x;
}
//ボールの速度と位置の変更
x = ballx + bx1;
y = bally + by1;
//ボールが左右の壁に当たるとxの速度を反転する
if( (x < br) || (x > (WIDTH - br ) bx1 = -bx1;
//ボールが天井にあたるとyの速度を反転する
if( y
//ボールが底にあたるとゲームオーバー
if( y > HEIGHT ) gameover += 1;
//パドルとボールとの距離の差を計算する
dx = paddlex -x;
dy = paddley -y;
//つづく(2)
//ゼロ割を回避するための処理
if(dy == 0) dy = 1;
//パドルとボールが当たっているかの判断
if((Math.abs(dx) < (paddlew / 2 + br)) && (Math.abs(dy) < (paddleh / 2 + br)
{
//角度により反射を判定
if(Math.abs(dx / dy) > (paddlew / paddleh)){
bx1 = -bx1;
ballx = paddlex - sgn(dx) * (paddlew / 2 + br);
} else {
bx1 = -dx / 10;
by1 = -by1;
bally = paddley - sgn(dy) * (paddleh / 2 + br);
}
}
//ブロックとボールが当たった時の処理
for(i=0; i
dx = blocks[i].x - x;
dy = blocks[i].y - y;
//ゼロ割を回避するための処理
if(dy == 0) dy = 1;
//ブロックとボールが当たっているかの判断
if((Math.abs(dx) < (blockw / 2 + br)) && (Math.abs(dy) < (blockh / 2 + br)
{
//角度により反射を判定
if(Math.abs(dx / dy) > (blockw / blockh)){
bx1 = -bx1;
ballx = blocks[i].x - sgn(dx) * (blockw / 2 + br);
} else {
by1 = -by1;
bally = blocks[i].y - sgn(dy) * (blockh / 2 + br);
}
blocks[i].id = 0;
break;
}
ballx += bx1;
bally += by1;
//つづく(描画処理)
blockdraw();
paddledraw();
balldraw();
if(gameover > 0){
gemeoverdraw();
if(gameover > 200) break;
}
//クロックの処理
}
}
}
//描画ファンクションのコーディング
//つづく
// ブロックの描画
function blockdraw() {
for (i=0; i
if(blocks[i].id == 1) {
wkcolor = blocks[i].color;
wkx = blocks[i].x;
wky = blocks[i].y;
ctx.fillStyle = colortable[wkcolor];
ctx.fillRect(wkx, wky, blockw, blockh);
}
}
}
// パドルの描画
function paddledraw() {
ctx.fillRect(paddlex, paddley, paddlew, paddleh);
}
// ボールの描画
function balldraw() {
wkx = Math.floor(ballx);
wky = Math.floor(bally);
ctx.fillStyle = "white";
ctx.arc(wkx,wky,br,0*Math.PI,2*Math.PI);
ctx.fill();
}
// ゲームオーバーの表示
function gameoverdraw(){
ctx.font = "64px 'MS Pゴシック'";
ctx.fillStyle = "white";
ctx.fillText("GAME OVER",180,300);
}
先手:渡辺明棋王 対 後手:本田奎五段
第3局
第45期 棋王戦 五番勝負
<開始> .
001◆歩7,6-0021.
002◇歩8,4-0021.
003◆銀6,8-0011.
004◇歩3,4-0021.
005◆銀7,7-0031.
006◇銀6,2-0031.
007◆歩2,6-0021.
008◇銀4,2-0011.
009◆歩2,5-0021.
010◇銀3,3-0031.
011◆銀4,8-0031.
012◇金3,2-0031.
013◆金5,8-0031.
014◇金5,2-0031.
015◆歩5,6-0021.
016◇歩7,4-0021.
017◆金7,8-0031.
018◇歩6,4-0021.
019◆玉6,9-0032.
020◇銀6,3-0021.
021◆歩3,6-0021.
022◇桂7,3-0031.
023◆銀3,7-0011.
024◇玉4,1-0032.
025◆銀4,6-0031.
026◇銀4,4-0011.
027◆桂3,7-0031.
028◇歩5,4-0021.
029◆歩2,4-0021.
030◇歩2,4-0021.
031◆飛2,4-0021.
032◇歩2,3-0100.
033◆飛2,9-0023.
034◇歩6,5-0021.
035◆銀6,8-0013.
036◇飛8,1-0023.
037◆玉7,9-0032.
038◇玉5,1-0012.
039◆銀4,5-0021.
040◇銀3,3-0033.
041◆歩3,5-0021.
042◇歩3,5-0021.
043◆桂2,5-0011.
044◇銀4,4-0011.
045◆銀4,4-0021.
046◇歩4,4-0021.
047◆歩3,4-0100.
048◇銀2,4-0100.
049◆歩5,5-0021.
050◇銀2,5-0021.
051◆飛2,5-0021.
052◇歩5,5-0021.
053◆歩7,5-0021.
054◇玉6,2-0011.
055◆歩7,4-0021.
056◇銀7,4-0011.
057◆歩5,4-0100.
058◇銀6,3-0033.
059◆飛3,5-0032.
060◇桂4,3-0100.
061◆飛3,6-0023.
062◇歩3,5-0100.
063◆飛2,6-0012.
064◇角3,1-0013.
065◆歩9,6-0021.
066◇角6,4-0011.
067◆角9,7-0031.
068◇歩7,5-0100.
069◆歩7,6-0100.
070◇銀5,4-0031.
071◆角7,5-0011.
072◇銀6,3-0013.
073◆歩5,4-0100.
074◇歩7,4-0100.
075◆銀5,3-0100.
076◇金5,3-0021.
077◆と5,3-1021.
078◇角5,3-0033.
079◆馬5,3-1011.
080◇玉5,3-0031.
081◆銀8,2-0100.
(先手の勝利)
後手:渡辺明棋王 対 先手:本田奎五段
第45期 棋王戦 五番勝負 第四局
貼り付けて再生してみてください。
リンク 一人将棋
<開始> .
001◆歩2,6-0021.
002◇歩3,4-0021.
003◆歩7,6-0021.
004◇歩4,4-0021.
005◆歩2,5-0021.
006◇角3,3-0011.
007◆銀4,8-0031.
008◇歩8,4-0021.
009◆銀7,8-0021.
010◇歩8,5-0021.
011◆銀7,7-0021.
012◇銀3,2-0021.
013◆歩5,6-0021.
014◇銀4,3-0011.
015◆角7,9-0013.
016◇金3,2-0031.
017◆歩3,6-0021.
018◇金5,2-0031.
019◆角4,6-0011.
020◇銀6,2-0031.
021◆玉6,8-0031.
022◇飛8,4-0021.
023◆玉7,8-0032.
024◇歩6,4-0021.
025◆銀3,7-0011.
026◇歩7,4-0021.
027◆金5,8-0031.
028◇桂7,3-0031.
029◆角6,4-0031.
030◇金6,3-0011.
031◆角4,6-0013.
032◇歩7,5-0021.
033◆歩7,5-0021.
034◇歩4,5-0021.
035◆角5,5-0031.
036◇角5,5-0011.
037◆歩5,5-0021.
038◇角3,9-0100.
039◆角6,6-0100.
040◇馬2,8-1033.
041◆銀2,8-0013.
042◇玉4,2-0031.
043◆角5,6-0100.
044◇飛4,4-0032.
045◆馬8,3-1031.
046◇桂3,3-0011.
047◆銀3,7-0031.
048◇飛6,4-0012.
049◆馬5,6-0013.
050◇歩9,4-0021.
051◆歩4,6-0021.
052◇歩4,6-0021.
053◆歩3,5-0021.
054◇と4,7-1021.
055◆馬4,7-0013.
056◇歩9,5-0021.
057◆馬5,6-0031.
058◇歩9,6-0021.
059◆歩9,6-0021.
060◇香9,6-0021.
061◆歩9,8-0100.
062◇歩6,5-0100.
063◆角4,8-0013.
064◇飛9,4-0012.
065◆歩7,4-0021.
066◇杏9,8-1021.
067◆と7,3-1021.
068◇金7,3-0012.
069◆歩9,5-0100.
070◇飛9,5-0021.
071◆歩3,4-0021.
072◇杏9,9-0021.
073◆と3,3-1021.
074◇金3,3-0021.
075◆玉6,8-0012.
076◇竜9,8-1021.
077◆玉5,9-0013.
078◇杏8,9-0032.
079◆玉4,9-0012.
080◇歩4,5-0100.
081◆歩4,4-0100.
082◇銀4,4-0021.
083◆桂3,6-0100.
084◇香3,4-0100.
085◆歩4,6-0100.
086◇銀3,5-0031.
087◆桂2,6-0100.
088◇銀2,6-0031.
089◆銀2,6-0011.
090◇香3,6-0021.
091◆馬4,7-0013.
092◇桂4,4-0100.
093◆銀3,5-0031.
094◇歩4,6-0021.
095◆馬4,6-0021.
096◇桂5,6-0100.
(後手の勝利)