Skip to content

Commit

Permalink
The activation bar is now the paddle's center bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChickenProp committed Jul 31, 2012
1 parent f1b98e4 commit 0bb48cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
29 changes: 15 additions & 14 deletions src/Activator.hx
Expand Up @@ -5,6 +5,7 @@ import com.haxepunk.utils.Draw;

class Activator extends Entity {
var pitches:Array<Int>;
var remove:Bool;
public function new () {
super();

Expand All @@ -16,31 +17,31 @@ class Activator extends Entity {
pitches = [];
for (i in 0...15)
pitches.push(0);

remove = false;
}

override public function update () : Void {
if (remove) {
HXP.tween(G.paddle, {lineWidth:2}, 0.2);
world.remove(this);
return;
}
pitches.shift();
pitches.push(Pitch.getPitch());
G.paddle.lineWidth = 2 + (G.paddle.width - 6)*(15-samplesNeeded())/15;

// We tell it to remove next frame, because it looks weird if
// the bar never fills all the way up. I think actually this
// means we get two frames of being full because it doesn't
// actually get removed until the end of the frame that remove
// is called. At any rate, it looks nicer.
if (samplesNeeded() == 0) {
G.paddle.calibrate(Math.round(avg(pitches)));

// Remove next frame, because it looks weird if the bar
// doesn't completely fill up.
var self = this;
HXP.tween(this, {}, 0.01, { complete: function () { world.remove(self); } });
remove = true;
}
}

override public function render () : Void {
super.render();

var cx = Std.int(HXP.width/2);
Draw.rect(cx-32, 375, 64, 14, 0x000000);
Draw.rect(cx-30, 377, 60, 10, 0xFFFFFF);
Draw.rect(cx-30, 377, (15 - samplesNeeded())*4, 10, 0xFF0000);
}

function samplesNeeded () : Int {
var min = Math.POSITIVE_INFINITY;
var max = Math.NEGATIVE_INFINITY;
Expand Down
9 changes: 7 additions & 2 deletions src/Paddle.hx
Expand Up @@ -25,6 +25,7 @@ class Paddle extends Entity {
public var controls:InputType;
public var recentering:Bool;
public var needsCalibration:Bool;
public var lineWidth:Float;

public function new () {
super();
Expand All @@ -42,6 +43,7 @@ class Paddle extends Entity {
controls = PITCH_CONTROLS_POSITION;
recentering = false;
needsCalibration = true;
lineWidth = 2;
}

override public function update () : Void {
Expand Down Expand Up @@ -193,8 +195,11 @@ class Paddle extends Entity {

Draw.rect(Std.int(x - halfWidth), Std.int(y - halfHeight),
width, height, 0x0000CC);

Draw.rect(Std.int(x + pitch * (halfWidth-1) - 1), Std.int(y - halfHeight + 2), 2, height-4, 0xFFFFFF);

var lineleft = Std.int(x + pitch * (halfWidth-1) - lineWidth/2);
Draw.rect(lineleft, Std.int(y - halfHeight + 2),
Std.int(Math.min(lineWidth, right-lineleft-2)),
height-4, 0xFFFFFF);
}

public function calibrate (pitch:Int) {
Expand Down

0 comments on commit 0bb48cb

Please sign in to comment.