20241106 授業

20241106 授業

<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″ />
<title>Gamedev Canvas Workshop – lesson 10: finishing up</title>
<style>* { padding: 0; margin: 0; } canvas { background: #eee; display: block; margin: 0 auto; }</style>
</head>
<body>

<canvas id=”myCanvas” width=”480″ height=”320″></canvas>

<script>
var canvas = document.getElementById(“mycanvas”);
var ctx = canvas.getContext(“2d”);
var ballRadius = 10;
var x = canvas.width/2;
var y = canvas.height-30;
var dx = 2;
var dy = -2;
var paddleHeight = 10;
var paddleWidth = 75;
var paddle = (canvas.width-paddleWidth)/2;
var rightPressed = false;
var leftPressed = false;
var brickRowCount = 5;
var brickColumnCount = 3;
var brickWidth = 75;
var brickHeight = 20;
var brickPadding = 10;
var brick0ffseTop = 30;
var brick0ffsetLeft = 30;
var score = 0;
var lives = 3;

var bricks = [];
for(var c=0; c<brickColumnCount; c++) {
bricks[c] = [];
for(var r=0; r<brickRowCount; r++) {
bricks[c][r] = { x: 0, y: 0, status: 1 };
}
}

document.addEventListener(“keydown”, keyDownHandler, false);
document.addEventListener(“keyup”, keyUpHandler, false);
document.addEventListener(“mousemove”,mouseMoveHandler, false);

function keyDownHandler(e) {
if(e.code == “ArrowRight”) {
rightPressed = true;
}
else if(e.code == ‘ArrowLeft’) {
leftPressed = true;
}

}
function keyUpHandler(e) {
if(e.code == ‘ArrowRight’) {
rightPressed = false;
}
else if(e.code == ‘ArrowLeft’) {
leftPressed = false;
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です