గేమ్ బోంబ్
- 上一页 గేమ్ గ్రావిటీ
- 下一页 గేమ్ రోటేషన్
这个红色方块落地时会弹起:
弹跳
我们要添加的另一个功能是 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); } } }
- 上一页 గేమ్ గ్రావిటీ
- 下一页 గేమ్ రోటేషన్