Skip to content

Commit

Permalink
Fix escape-to-clear
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaefferer committed Dec 8, 2011
1 parent c39c45a commit 494dc68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bouncing.html
Expand Up @@ -10,6 +10,6 @@
<title>Bouncing Ball</title>
</head>
<body>
Click to create a new ball; down, drag and up to create a new one with initial velocity. Resize the window.
Click to create a new ball; down, drag and up to create a new one with initial velocity. Resize the window. Escape key to clear.
</body>
</html>
8 changes: 7 additions & 1 deletion bouncing.js
Expand Up @@ -16,6 +16,9 @@ $(function() {
this.velocity = new Vector(-5, 0);
}
Ball.prototype = {
remove: function() {
this.output.remove();
},
move: function() {

this.velocity = this.velocity.add(GRAVITY.scale(0.1));
Expand Down Expand Up @@ -65,7 +68,10 @@ $(function() {
$(document).keyup(function(event) {
// clear on escape
if (event.keyCode === 27) {
balls.splice(0, birds.length);
balls.forEach(function(ball) {
ball.remove();
});
balls.splice(0, balls.length);
}
})
});

0 comments on commit 494dc68

Please sign in to comment.