Skip to content

Commit

Permalink
fixing progress tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
aruhant committed Feb 8, 2024
1 parent b66c12c commit 64e3392
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 46 deletions.
6 changes: 2 additions & 4 deletions app/lib/game/flammable_decoration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ class FlammableDecoration extends GameDecoration with Sensor {
animation: PlatformSpritesheet.fire,
position: position..translate(0, -8),
size: Vector2(128 * 1.5, 128 * 1.5),
) {
controller.configure(maxLife: 100, maxProgress: controller.maxProgress + 1);
}
) {}

@override
void onContact(GameComponent component) {
if (component is Player && !_onFire) {
// change the animation to burning fire
controller.increaseProgress(1);
controller.goals--;
AudioController.playEffect('fire.wav');
PlatformSpritesheet.fireOn.then((fire) {
setAnimation(fire);
Expand Down
3 changes: 3 additions & 0 deletions app/lib/game/rakshasa.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'dart:math';
import 'package:bonfire/bonfire.dart';
import 'package:ramayana/game/ui/score_controller.dart';
import 'package:ramayana/user_prefs/audioController.dart';
import 'player_one.dart';
import 'platform_spritesheet.dart';

class Rakshasa extends PlatformEnemy with HandleForces {
int _timeToWaitBeforeJump = 4000;
ProgressBarController controller = ProgressBarController();
Rakshasa({required super.position})
: super(
size: Vector2(471 * .7, 480 * .7),
Expand Down Expand Up @@ -46,6 +48,7 @@ class Rakshasa extends PlatformEnemy with HandleForces {

@override
void die() {
controller.enemies--;
AudioController.playEffect('enemy_die.mp3');
super.die();
animation?.playOnce(
Expand Down
48 changes: 16 additions & 32 deletions app/lib/game/ui/score_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,34 @@ class ProgressBarController extends ChangeNotifier {

ProgressBarController._internal();

double _maxLife = 100;
double _maxProgress = 0;
get maxLife => _maxLife;
get maxProgress => _maxProgress;

double _life = 0;
double _progress = 0;
int _goals = 0;
int _enemies = 0;

double get score => _life;
double get progress => _progress;
double get life => _life;
int get goals => _goals;
int get enemies => _enemies;

set score(double newLife) {
set life(double newLife) {
_life = newLife;
notifyListeners();
}

set progress(double progress) {
_progress = progress;
set goals(int g) {
_goals = g;
notifyListeners();
}

void configure({required double maxLife, required double maxProgress}) {
_life = _maxLife = maxLife;
_maxProgress = maxProgress;
set enemies(int e) {
_enemies = e;
notifyListeners();
}

void increaseProgress(int value) {
progress += value;
if (progress > 100) {
progress = 100;
}
}

void decrementProgress(int value) {
progress -= value;
if (progress < 0) {
progress = 0;
}
}

void updateLife(double life) {
if (this.score != life) {
this.score = life;
}
void configure(
{required double life, required int goals, required int enemies}) {
_life = life;
_goals = goals;
_enemies = enemies;
notifyListeners();
}
}
12 changes: 2 additions & 10 deletions app/lib/game/ui/score_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,9 @@ class ProgressBarWidget extends StatelessWidget {
Row(
children: [
Text(
controller.progress.toInt().toString(),
'${(controller.goals).toInt()}🔥 ${(controller.enemies).toInt()} 👹',
style: const TextStyle(color: Colors.yellowAccent),
),
const Text(
' / ',
style: TextStyle(color: Colors.yellowAccent),
),
Text(
controller.maxProgress.toInt().toString(),
style: const TextStyle(color: Colors.yellowAccent),
),
)
],
),
],
Expand Down

0 comments on commit 64e3392

Please sign in to comment.