Timer countdown doesn't work properly
mlemaudit opened this issue · 2 comments
mlemaudit commented
The world timer doesn't stop when it reaches 0.
And Mario doesn't die when world time equals 0.
mlemaudit commented
The following patch should fix the issue :
Index: core/src/com/brentaureli/mariobros/Scenes/Hud.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/com/brentaureli/mariobros/Scenes/Hud.java (date 1445566359000)
+++ core/src/com/brentaureli/mariobros/Scenes/Hud.java (revision )
@@ -24,6 +24,7 @@
//Mario score/time Tracking Variables
private Integer worldTimer;
+ private boolean timeUp; // true when the world timer reaches 0 // @SuperMario#2
private float timeCount;
private static Integer score;
@@ -80,7 +81,11 @@
public void update(float dt){
timeCount += dt;
if(timeCount >= 1){
+ if (worldTimer > 0) { // @SuperMario#2
- worldTimer--;
+ worldTimer--;
+ } else { // @SuperMario#2
+ timeUp = true; // @SuperMario#2
+ } // @SuperMario#2
countdownLabel.setText(String.format("%03d", worldTimer));
timeCount = 0;
}
@@ -95,4 +100,6 @@
public void dispose() {
stage.dispose();
}
+
+ public boolean isTimeUp() { return timeUp; } // @SuperMario#2
}
Index: core/src/com/brentaureli/mariobros/Sprites/Mario.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/com/brentaureli/mariobros/Sprites/Mario.java (date 1445566359000)
+++ core/src/com/brentaureli/mariobros/Sprites/Mario.java (revision )
@@ -107,6 +107,15 @@
}
public void update(float dt){
+
+ // time is up : too late mario dies T_T // @SuperMario#2
+ // the !isDead() method is used to prevent multiple invocation // @SuperMario#2
+ // of "die music" and jumping // @SuperMario#2
+ // there is probably better ways to do that but it works for now. // @SuperMario#2
+ if (screen.getHud().isTimeUp() && !isDead()) { // @SuperMario#2
+ die(); // @SuperMario#2
+ } // @SuperMario#2
+
//update our sprite to correspond with the position of our Box2D body
if(marioIsBig)
setPosition(b2body.getPosition().x - getWidth() / 2, b2body.getPosition().y - getHeight() / 2 - 6 / MarioBros.PPM);
@@ -207,6 +216,24 @@
MarioBros.manager.get("audio/sounds/powerup.wav", Sound.class).play();
}
+ public void die() { // @SuperMario#2
+
+ if (!isDead()) { // @SuperMario#2
+
+ MarioBros.manager.get("audio/music/mario_music.ogg", Music.class).stop(); // @SuperMario#2
+ MarioBros.manager.get("audio/sounds/mariodie.wav", Sound.class).play(); // @SuperMario#2
+ marioIsDead = true; // @SuperMario#2
+ Filter filter = new Filter(); // @SuperMario#2
+ filter.maskBits = MarioBros.NOTHING_BIT; // @SuperMario#2
+
+ for (Fixture fixture : b2body.getFixtureList()) { // @SuperMario#2
+ fixture.setFilterData(filter); // @SuperMario#2
+ } // @SuperMario#2
+
+ b2body.applyLinearImpulse(new Vector2(0, 4f), b2body.getWorldCenter(), true); // @SuperMario#2
+ } // @SuperMario#2
+ } // @SuperMario#2
+
public boolean isDead(){
return marioIsDead;
}
@@ -234,14 +261,7 @@
setBounds(getX(), getY(), getWidth(), getHeight() / 2);
MarioBros.manager.get("audio/sounds/powerdown.wav", Sound.class).play();
} else {
- MarioBros.manager.get("audio/music/mario_music.ogg", Music.class).stop();
- MarioBros.manager.get("audio/sounds/mariodie.wav", Sound.class).play();
- marioIsDead = true;
- Filter filter = new Filter();
- filter.maskBits = MarioBros.NOTHING_BIT;
- for (Fixture fixture : b2body.getFixtureList())
- fixture.setFilterData(filter);
- b2body.applyLinearImpulse(new Vector2(0, 4f), b2body.getWorldCenter(), true);
+ die(); // @SuperMario#2
}
}
}
Index: core/src/com/brentaureli/mariobros/Screens/PlayScreen.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/com/brentaureli/mariobros/Screens/PlayScreen.java (date 1445566359000)
+++ core/src/com/brentaureli/mariobros/Screens/PlayScreen.java (revision )
@@ -259,4 +259,5 @@
hud.dispose();
}
+ public Hud getHud(){ return hud; } // @SuperMario#2
}
BrentAureli commented
fixed