게임 반발
이 빨간 장애물이地面에 닿으면 뛰어 올릴 것입니다:
빠지기
추가할 추가 기능은 bounce
속성.
bounce
속성은 중력이 그를地面에 내리게 만들 때 성분이 반동할지 여부를 나타냅니다.
bounce
속성 값은 수여야 합니다. 0은 반동이 전혀 없음을 의미하며, 1은 시작하던 위치로 다시 올라가는 반동을 의미합니다.
实例
function component(width, height, color, x, y, type) { this.type = type; this.width = width; this.height = height; this.x = x; this.y = y; this.speedX = 0; this.speedY = 0; this.gravity = 0.1; this.gravitySpeed = 0; this.bounce = 0.6; this.update = function() { ctx = myGameArea.context; ctx.fillStyle = color; ctx.fillRect(this.x, this.y, this.width, this.height); } this.newPos = function() { this.gravitySpeed += this.gravity; this.x += this.speedX; this.y += this.speedY + this.gravitySpeed; this.hitBottom(); } this.hitBottom = function() { var rockbottom = this.gamearea.canvas.height - this.height; if (this.y > rockbottom) { this.y = rockbottom; this.gravitySpeed = -(this.gravitySpeed * this.bounce); } } }