Καπνά Παιχνιδιού
- Προηγούμενη Σελίδα Βαρύτητα Παιχνιδιού
- Επόμενη Σελίδα Περιστροφή Παιχνιδιού
This red block will bounce up when it lands:
bounce
another feature we are going to add is bounce
property.
bounce
property indicates whether the component will bounce when it hits the ground due to gravity.
bounce
the property values must be numbers. 0 means no bounce at all, 1 will make the component bounce back to the starting position upon falling.
instance
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 = χρώμα; 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 πτάστης = this.gamearea.canvas.height - this.height; εάν (this.y > πτάστης) { this.y = πτάστης; this.gravitySpeed = -(this.gravitySpeed * this.bounce); } } }
- Προηγούμενη Σελίδα Βαρύτητα Παιχνιδιού
- Επόμενη Σελίδα Περιστροφή Παιχνιδιού