Skip to content

Commit

Permalink
Tweak the bounce code to compare to the shuttlecocks position in the …
Browse files Browse the repository at this point in the history
…previous frame, which yields much better results.
  • Loading branch information
djcsdy committed Feb 12, 2012
1 parent def40d0 commit 7477715
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Expand Up @@ -91,7 +91,7 @@ package net.noiseinstitute.battledore_and_shuttlecock {

updateScore(score+1);

if (shuttlecock.x > battledore.prevX) {
if (shuttlecock.prevX > battledore.prevX) {
if (shuttlecock.x < battledore.x + (shuttlecock.width + battledore.battledoreWidth) * 0.5 + 1) {
shuttlecock.x = battledore.x + (shuttlecock.width + battledore.battledoreWidth) * 0.5 + 1;
}
Expand Down
Expand Up @@ -7,6 +7,9 @@ package net.noiseinstitute.battledore_and_shuttlecock {
public class Shuttlecock extends Entity {
private static const GRAVITY:Number = 0.1;

public var prevX:Number = 0;
public var prevY:Number = 0;

public var velocity:Point = new Point;

public function Shuttlecock() {
Expand All @@ -18,6 +21,9 @@ package net.noiseinstitute.battledore_and_shuttlecock {
}

override public function update():void {
prevX = x;
prevY = y;

velocity.y += GRAVITY;

x += velocity.x;
Expand Down

0 comments on commit 7477715

Please sign in to comment.