2016年5月25日 星期三

Gamedev Canvas Workshop - lesson 10: finishing up

2016年5月11日 星期三

紀錄

    function drawPaddle() {
        ctx.beginPath();
        ctx.rect(paddleX, canvas.height-paddleHeight, paddleWidth, paddleHeight);
        ctx.fillStyle = "#0095DD";
        ctx.fill();
        ctx.closePath();
    }
    function drawBricks() {
        for(c=0; c<brickColumnCount; c++) {
            for(r=0; r<brickRowCount; r++) {
                if(bricks[c][r].status == 1) {
                    var brickX = (r*(brickWidth+brickPadding))+brickOffsetLeft;
                    var brickY = (c*(brickHeight+brickPadding))+brickOffsetTop;
                    bricks[c][r].x = brickX;
                    bricks[c][r].y = brickY;
                    ctx.beginPath();
                    ctx.rect(brickX, brickY, brickWidth, brickHeight);
                    ctx.fillStyle = "#0000FF";
                    ctx.fill();
                    ctx.closePath();
                if(bricks[c][r].count == 1){
                   ctx.beginPath();
                    ctx.rect(brickX, brickY, brickWidth, brickHeight);
                    ctx.fillStyle = "#00FF99";
                    ctx.fill();
                    ctx.closePath();
                     }
                if(bricks[c][r].count == 2){
                   ctx.beginPath();
                    ctx.rect(brickX, brickY, brickWidth, brickHeight);
                    ctx.fillStyle = "#E93EFF";
                    ctx.fill();
                    ctx.closePath();
                     }
                }
            }
        }
    }
    function draw() {
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        drawBricks();
        drawBall();
        drawPaddle();
        collisionDetection();
        if(x + dx > canvas.width-ballRadius || x + dx < ballRadius) {
            dx = -dx;
        }
        if(y + dy < ballRadius) {
            dy = -dy;
        }
        else if(y + dy > canvas.height-ballRadius) {
            if(x > paddleX && x < paddleX + paddleWidth) {
                dy = -dy;
            }
            else {
                alert("GAME OVER");
                document.location.reload();
            }
        }
        if(rightPressed && paddleX < canvas.width-paddleWidth) {
            paddleX += 7;
        }
        else if(leftPressed && paddleX > 0) {
            paddleX -= 7;
        }
        x += dx;
        y += dy;
    }
    setInterval(draw, 10);

2016年4月27日 星期三

讓三角形反彈

Gamedev Canvas Workshop - lesson 2: move the ball

讓球移動

Gamedev Canvas Workshop - lesson 2: move the ball 向下 變慢 在DX DY 的正負改變 可改變方向 在毫秒數調大可變慢

2016年3月23日 星期三

地圖位置加座標

点击这个按钮,获得您的坐标:

点击这个按钮,获得您的位置:

影片緩衝托放+背景



轉興星星

 抱歉!瀏覽器不支援HTML5 canvas。
No canvas support in this browser