提示コードのコメント部のコードですがなぜ参考サイトを参考に一次変換を行っているのですが画面に表示されるブロックがおかしいのでしょうか?
p5ライブラリを使っています
参考サイト: http://www.geisya.or.jp/~mwm48961/kou2/linear_image3.html
const STAGE_WIDTH = 10; const STAGE_HEIGHT = 20; const STAGE_OFFSET_WIDTH = 200; const STAGE_OFFSET_HEIGHT = 150; const CELL = 30; const DONW_SPEED = 10; const PLAYER_START_POSITION_X = 3; const PLAYER_START_POSITION_Y = 0; const ColorCode = [ [0,0,0], //背景 [255,255,255], //壁 [0,255,255], //水色 [255,255,0], //黄色 [0,128,0], //緑 [255,0,0], //赤 [0,0,166], //ネイビー [255,166,0], //オレンジ [128,0,128], //紫 ]; //ブロック const Block = [ ]; class Stage { constructor() { //ステージ this.stage = [ ] } Update() { } Renderer() { for(let y = 0; y < this.stage.length; y++) { for(let x = 0; x < this.stage[y].length; x++) { fill(ColorCode[ this.stage[y][x] ][0],ColorCode[ this.stage[y][x] ][1],ColorCode[ this.stage[y][x] ][2]); rect( STAGE_OFFSET_WIDTH + x * CELL,STAGE_OFFSET_HEIGHT + y * CELL,CELL,CELL); } } } } let keyRight = false; let keyLeft = false; let keyShift = false; let holdLeft = false; let holdRight = false; let holdShift = false; function keyPressed() { if( (keyCode === LEFT_ARROW) && (holdLeft == false) ) { holdLeft = true; keyLeft = true; } else if( (keyCode === RIGHT_ARROW) && (holdRight == false) ) { holdRight = true; keyRight = true; } else if( (keyCode === SHIFT) && (holdShift == false) ) { holdShift = true; keyShift = true; } else{ keyShift = false; keyRight = false; keyLeft = false; } } function keyReleased() { keyRight = false; keyLeft = false; holdRight = false; holdLeft = false; holdShift = false; keyShift= false; } class Player { constructor() { this.position = new Vector(3,0); this.put = true; this.blockNumber = GetRandom(0,6); this.animation = 0; this.block = [4]; this.block[0] = [0,0,0,0]; this.block[1] = [0,0,0,0]; this.block[2] = [0,0,0,0]; this.block[3] = [0,0,0,0]; this.KeyPrevLeft = false; this.KeyPrevShift = false; this.KeyPrevRight = false; this.isPut = false; this.isDown = false; } KeyBoard() { if(!this.KeyPrevLeft && keyLeft) { this.position.x--; } else if(!this.KeyPrevRight && keyRight) { this.position.x++; } else if(!this.KeyPrevShift && keyShift) { console.log("ああああ"); this.Rotate(); } this.KeyPrevLeft = keyLeft; this.KeyPrevRight = keyRight; this.KeyPrefShift = keyShift; } Rotate() { for(let y = 0; y < 4; y++) { for(let x = 0; x < 4; x++) { this.block[y][x] = 0; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// for(let y = 0; y < 4; y++) { for(let x = 0; x < 4; x++) { if(Block[this.blockNumber][y][x] != 0) { let xx = (cos(PI /2) * x) + (-sin(PI /2) * x ); let yy = (sin(PI /2) * y) + (cos(PI /2) * y ); //console.log(y); console.log(x + parseInt(xx,10) + " , " + parseInt(yy,10)); this.block[ y + parseInt(yy,10)][ x + parseInt(xx,10)] = 1; }else { //this.block[y][x] = 0; } } } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// Update() { this.KeyBoard(); if((this.animation % DONW_SPEED) == 0) { this.position.y++; this.isDown = true; }else { this.isDown = false; } if(this.animation > 60) { this.animation = 0; } this.animation++; //console.log(this.position.x); } UpdateStage(stage) { for(let y = 0; y < STAGE_HEIGHT; y++) { for(let x = 0; x < STAGE_HEIGHT; x++) { //stage.stage[this.position.y + y][this.position.x + x] = Block[][][]; } } } //当たり判定 Collision(stage) { //壁判定 if( (keyLeft == true) || (keyRight == true) ) { for(let yy = 0; yy < 4; yy++) { for(let xx = 0; xx < 4; xx++) { if(Block[this.blockNumber][yy][xx] == 1) { if( (stage.stage[this.position.y + yy ][this.position.x + xx] == 1) ) { if(keyLeft == true) { this.position.x++; } else if(keyRight == true) { this.position.x--; } } } } } } if( this.isPut == false) { for(let yy = 0; yy < 4; yy++) { for(let xx = 0; xx < 4; xx++) { if((Block[this.blockNumber][yy][xx] == 1) ) { if( (stage.stage[this.position.y + yy ][this.position.x + xx] == 1) || (stage.stage[this.position.y + yy ][this.position.x + xx] > 1)) { this.position.y--; this.isPut = true; } } } } } if(this.isPut == true) { for(let yy = 0; yy < 4; yy++) { for(let xx = 0; xx < 4; xx++) { if((Block[this.blockNumber][yy][xx] == 1) ) { stage.stage[this.position.y + yy ][this.position.x + xx] = this.blockNumber + 2; } } } } if(this.isPut == true) { this.blockNumber = GetRandom(0,6); this.position.x = PLAYER_START_POSITION_X; this.position.y = PLAYER_START_POSITION_Y; this.isPut = false; } } Renderer() { for(let y = 0; y < 4; y++) { for(let x = 0; x < 4; x++) { if(this.block[y][x] != 0) { fill(ColorCode[ this.blockNumber ][0],ColorCode[ this.blockNumber ][1],ColorCode[ this.blockNumber ][2]); rect( (this.position.x * CELL) + STAGE_OFFSET_WIDTH + (x * CELL),(this.position.y * CELL) + STAGE_OFFSET_HEIGHT +(y * CELL),CELL,CELL); } } } } } class Game { constructor() { this.stage = new Stage(); this.player = new Player(); } Update() { this.player.Update(); this.player.Collision(this.stage); this.stage.Update(); } Renderer() { this.stage.Renderer(); this.player.Renderer(); } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。