Skip to content

Commit

Permalink
fix: improve function to show boxes. Add pause button
Browse files Browse the repository at this point in the history
  • Loading branch information
dnielopez committed Oct 19, 2023
1 parent ac86acf commit 4bc0494
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.
58 changes: 39 additions & 19 deletions lib/pages/mini-games/up/down.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ class DownGame extends Forge2DGame with TapDetector {

scoreText = TextComponent(
text: 'Score: 000',
anchor: Anchor.topRight,
position: Vector2(3.7, 0.65),
anchor: Anchor.center,
position: Vector2(worldSize.x / 2, 1),
textRenderer: btnStyleLetters,
);

Expand Down Expand Up @@ -265,6 +265,7 @@ class GameWidgetDown extends StatefulWidget {
class _GameWidgetDownState extends State<GameWidgetDown> {
DownGame game = DownGame((String data) {});
bool loading = true;
bool paused = false;

@override
void initState() {
Expand All @@ -290,24 +291,35 @@ class _GameWidgetDownState extends State<GameWidgetDown> {
GoRouter.of(context).pop();
},
),
actions: [
IconButton(
iconSize: 42,
icon: Icon(paused ? Icons.play_circle : Icons.pause_circle),
onPressed: () {
setState(() {
game.paused = !game.paused;
paused = !paused;
});
},
)
],
),
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/up/maps/01/up_map_1.jpeg"),
fit: BoxFit.cover,
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/up/maps/01/up_map_1.jpeg"),
fit: BoxFit.cover,
),
),
),
child: loading
? const Center(
child: CircularProgressIndicator(
color: Colors.black,
),
)
: GameWidget(game: game),
),
child: loading
? const Center(
child: CircularProgressIndicator(
color: Colors.black,
),
)
: GameWidget(game: game)),
);
}

Expand Down Expand Up @@ -336,6 +348,12 @@ class _GameWidgetDownState extends State<GameWidgetDown> {
setState(() {
loading = false;
game = DownGame(showEndMessage);
game.paused = true;

Future.delayed(const Duration(seconds: 1), () {
game.paused = false;
paused = false;
});
});
},
child: const Text("Let's go!"),
Expand All @@ -346,6 +364,8 @@ class _GameWidgetDownState extends State<GameWidgetDown> {
}

showEndMessage(String score) {
game.paused = true;

showDialog<String>(
barrierDismissible: false,
context: context,
Expand Down Expand Up @@ -419,9 +439,9 @@ class _GameWidgetDownState extends State<GameWidgetDown> {
TextButton(
onPressed: () {
Navigator.pop(context);
Navigator.pop(context);
showWelcome();
},
child: const Text("Go to minigames"),
child: const Text("Play again"),
),
],
),
Expand Down
10 changes: 6 additions & 4 deletions lib/pages/mini-games/up/objects/box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ class Box extends BodyComponent with ContactCallbacks {
@override
Body createBody() {
final rnd = Random();
final xpos = (rnd.nextDouble() * (worldSize.x - 1)).abs();
print('xpos: ${xpos}');
final xpos = (rnd.nextDouble() * (worldSize.x - 0.5)).abs();
final bodyDef = BodyDef(
userData: this,
//position: Vector2(worldSize.x / 2, worldSize.y - 3), change dino position later
position: Vector2(xpos, -1),
position: Vector2(
xpos > 0.6
? (xpos < (worldSize.x - 0.5) ? (xpos) : worldSize.x - 0.5)
: 0.6,
-1),
type: BodyType.dynamic,
gravityOverride: Vector2(0, rnd.nextDouble() * 3 + 2),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/mini-games/up/objects/dino.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class Dino extends BodyComponent with KeyboardHandler {
final bodyDef = BodyDef(
userData: this,
//position: Vector2(worldSize.x / 2, worldSize.y - 3), change dino position later
position: Vector2(2, 3),
position: Vector2(2, 3.5),
type: BodyType.dynamic,
);

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dinogrow
description: 2D blockchain game about growing dinosaurs.
version: 1.0.1+4
version: 1.0.2+5

environment:
sdk: ">=3.0.2 <4.0.0"
Expand Down

0 comments on commit 4bc0494

Please sign in to comment.