Skip to content

Commit

Permalink
feat: finish all features in ranking and minigame down, improve UI/UX
Browse files Browse the repository at this point in the history
  • Loading branch information
dnielopez committed Oct 14, 2023
1 parent 8fc05c6 commit f488582
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 44 deletions.
Binary file added assets/images/up/maps/01/left_btn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/up/maps/01/right_btn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/up/thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions lib/pages/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class _LoginScreenState extends State<LoginScreen> {

Future<dynamic> onDifferentAccountPressed(BuildContext context) async {
return showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return AlertDialog(
Expand Down
28 changes: 19 additions & 9 deletions lib/pages/mini-games/mini_games.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,35 @@ class _MiniGamesPageState extends State<MiniGamesScreen> {
body: Container(
height: MediaQuery.of(context).size.height,
decoration: const BoxDecoration(color: Colors.transparent),
child: const Center(
child: Center(
child: Padding(
padding: EdgeInsets.all(12),
padding: const EdgeInsets.all(12),
child: Wrap(
spacing: 12,
runSpacing: 12,
alignment: WrapAlignment.center,
children: [
GameCardWidget(
text: 'UP',
route: "/mini_games/comming_soon",
),
GameCardWidget(
text: 'DOWN',
route: "/mini_games/down",
localImage: Image.asset(
'assets/images/up/thumb.png',
width: 120,
),
),
GameCardWidget(
text: 'COMING SOON',
route: "/mini_games/comming_soon",
const Opacity(
opacity: 0.6,
child: GameCardWidget(
text: 'UP',
route: "/mini_games/comming_soon",
),
),
const Opacity(
opacity: 0.6,
child: GameCardWidget(
text: 'COMING SOON',
route: "/mini_games/comming_soon",
),
),
],
)),
Expand Down
14 changes: 6 additions & 8 deletions lib/pages/mini-games/up/buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,31 @@ class VirtualPadButtons extends PositionComponent {
List<PositionComponent> buttons = [];
List vpadbuttons() {
RectangleComponent btnLeftCircle;
final circlePaintLeft = BasicPalette.yellow.paint();
btnLeftCircle =
RectangleComponent.square(size: 0.95, paint: circlePaintLeft);
final circlePaintLeft = BasicPalette.transparent.paint();
btnLeftCircle = RectangleComponent.square(size: 1, paint: circlePaintLeft);
btnLeftCircle.position = Vector2(0, worldSize.y - 5.7);
btnLeftCircle.anchor = Anchor.topLeft;
buttons.add(btnLeftCircle);

RectangleComponent btnRightCircle;
final circlePaintRight = BasicPalette.yellow.paint();
final circlePaintRight = BasicPalette.transparent.paint();
btnRightCircle =
RectangleComponent.square(size: 0.95, paint: circlePaintRight);
RectangleComponent.square(size: 1, paint: circlePaintRight);
btnRightCircle.position = Vector2(3, worldSize.y - 5.7);
btnRightCircle.anchor = Anchor.topLeft;
buttons.add(btnRightCircle);

RectangleComponent btnJumpCircle;
final circlePaintJump = BasicPalette.gray.paint();
btnJumpCircle =
RectangleComponent.square(size: 0.95, paint: circlePaintJump);
btnJumpCircle = RectangleComponent.square(size: 1, paint: circlePaintJump);
btnJumpCircle.position = Vector2(1, worldSize.y - 5.7);
btnJumpCircle.anchor = Anchor.topLeft;
buttons.add(btnJumpCircle);

RectangleComponent btnAttackCircle;
final circlePaintAttack = BasicPalette.gray.paint();
btnAttackCircle =
RectangleComponent.square(size: 0.95, paint: circlePaintAttack);
RectangleComponent.square(size: 1, paint: circlePaintAttack);
btnAttackCircle.position = Vector2(2, worldSize.y - 5.7);
btnAttackCircle.anchor = Anchor.topLeft;
buttons.add(btnAttackCircle);
Expand Down
51 changes: 42 additions & 9 deletions lib/pages/mini-games/up/down.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class DownGame extends Forge2DGame with TapDetector {
if (isLeftPressed) {
btnLeft.paint.color = const Color.fromARGB(255, 91, 92, 91);
isRightPressed = false;
btnRight.paint.color = BasicPalette.yellow.color;
btnRight.paint.color = BasicPalette.transparent.color;

dino.walkLeft();

Expand All @@ -92,7 +92,7 @@ class DownGame extends Forge2DGame with TapDetector {
if (isRightPressed) {
btnRight.paint.color = const Color.fromARGB(255, 91, 92, 91);
isLeftPressed = false;
btnLeft.paint.color = BasicPalette.yellow.color;
btnLeft.paint.color = BasicPalette.transparent.color;

dino.walkRight();

Expand All @@ -117,11 +117,11 @@ class DownGame extends Forge2DGame with TapDetector {
bool onTapUp(TapUpInfo info) {
if (isLeftPressed) {
isLeftPressed = false;
btnLeft.paint.color = BasicPalette.yellow.color;
btnLeft.paint.color = BasicPalette.transparent.color;
}
if (isRightPressed) {
isRightPressed = false;
btnRight.paint.color = BasicPalette.yellow.color;
btnRight.paint.color = BasicPalette.transparent.color;
}
// if (isJumpPressed) {
// isJumpPressed = false;
Expand Down Expand Up @@ -168,13 +168,38 @@ class DownGame extends Forge2DGame with TapDetector {
}

newBoxAndScore() {
score += 1;
score += 10;
scoreText.text = 'Score: ${score.toString().padLeft(3, '0')}';
add(Box(newBoxAndScore, finishGame));
}

add(Box(newBoxAndScore, finishGame));

// Render floor
final boxFloor1 = BoxFloor()
..x = 1
..y = worldSize.y - 5.7;
await boxFloor1.loadImage();
add(boxFloor1);

final boxFloor2 = BoxFloor()
..x = 2
..y = worldSize.y - 5.7;
await boxFloor2.loadImage();
add(boxFloor2);

final leftFloor = LeftFloor()
..x = 0
..y = worldSize.y - 5.7;
await leftFloor.loadImage();
add(leftFloor);

final rightFloor = RightFloor()
..x = 3
..y = worldSize.y - 5.7;
await rightFloor.loadImage();
add(rightFloor);

// add the player to the game
add(dino);

Expand Down Expand Up @@ -283,6 +308,7 @@ class _GameWidgetDownState extends State<GameWidgetDown> {
loading = true;
});
showDialog<String>(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Welcome to Down'),
Expand All @@ -301,6 +327,7 @@ class _GameWidgetDownState extends State<GameWidgetDown> {
Navigator.pop(context);
setState(() {
loading = false;
game = DownGame(showEndMessage);
});
},
child: const Text("Let's go!"),
Expand All @@ -312,6 +339,7 @@ class _GameWidgetDownState extends State<GameWidgetDown> {

showEndMessage(String score) {
showDialog<String>(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Ups ... game ended :('),
Expand Down Expand Up @@ -339,15 +367,16 @@ class _GameWidgetDownState extends State<GameWidgetDown> {

showrResultMessage(String transaction) {
showDialog<String>(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Score saved'),
content: Text(
"Perfect! You score is now in Ranking, good luck! \n\nIf you want you can review information on blockchain with this transaction reference: \n\n $transaction"),
"Perfect! You score is now in Ranking, good luck! \n\nIf you want, you can review information on blockchain with this transaction reference: \n\n$transaction"),
actions: <Widget>[
TextButton(
onPressed: () {
_launchUrl();
_launchUrl(transaction);
},
child: const Text('View transaction'),
),
Expand Down Expand Up @@ -459,8 +488,12 @@ class _GameWidgetDownState extends State<GameWidgetDown> {
}
}

Future<void> _launchUrl() async {
Uri url = Uri(scheme: 'https', host: 'x.com', path: '/din0gr0w');
Future<void> _launchUrl(String transaction) async {
Uri url = Uri(
scheme: 'https',
host: 'explorer.solana.com',
path: '/tx/$transaction',
queryParameters: {'cluster': 'devnet'});
if (!await launchUrl(url)) {
throw Exception('Could not launch $url');
}
Expand Down
35 changes: 33 additions & 2 deletions lib/pages/mini-games/up/objects/box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class Box extends BodyComponent with ContactCallbacks {
final bodyDef = BodyDef(
userData: this,
//position: Vector2(worldSize.x / 2, worldSize.y - 3), change dino position later
position: Vector2(rnd.nextDouble() * 2.5, -1),
position: Vector2(rnd.nextDouble() * 2.8 + 0.2, -1),
type: BodyType.dynamic,
gravityOverride: Vector2(0, rnd.nextDouble() * 3 + 1),
gravityOverride: Vector2(0, rnd.nextDouble() * 3 + 2),
);

final shape = PolygonShape()..setAsBoxXY(.5, .5);
Expand All @@ -56,3 +56,34 @@ class Box extends BodyComponent with ContactCallbacks {
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}

class BoxFloor extends SpriteComponent {
BoxFloor() : super(priority: 1);

Future<void> loadImage() async {
// load the image to be used as the box
sprite = await Sprite.load('up/maps/01/box.png');
width = 1;
height = 1;
}
}

class LeftFloor extends SpriteComponent {
LeftFloor() : super(priority: 1);

Future<void> loadImage() async {
sprite = await Sprite.load('up/maps/01/left_btn.png');
width = 1;
height = 1;
}
}

class RightFloor extends SpriteComponent {
RightFloor() : super(priority: 1);

Future<void> loadImage() async {
sprite = await Sprite.load('up/maps/01/right_btn.png');
width = 1;
height = 1;
}
}
43 changes: 41 additions & 2 deletions lib/pages/my-dinogrow/my_dinogrow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:go_router/go_router.dart';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:solana/solana.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../ui/widgets/widgets.dart';

Expand Down Expand Up @@ -253,8 +254,7 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {

if (filteredData.length == 1 ||
(filteredData.length > 0 &&
dinoSelected != null &&
dinoSelected.isEmpty)) {
(dinoSelected == null || dinoSelected.isEmpty))) {
await storage.write(
key: 'dinoSelected', value: filteredData[0]['tokenAddress']);
setState(() {
Expand Down Expand Up @@ -290,6 +290,7 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {

beforeOtherNft() {
showDialog<String>(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Claim other Dino'),
Expand All @@ -312,6 +313,32 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {
);
}

showrResultMessage(String transaction) {
showDialog<String>(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('New Dino claimed'),
content: Text(
"Congrats, you already have new Dino NFT! \n\nIf you want, you can review information on blockchain with this transaction reference: \n\n$transaction"),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text("Back"),
),
TextButton(
onPressed: () {
_launchUrl(transaction);
},
child: const Text('View transaction'),
),
],
),
);
}

createNft() async {
try {
if (_loading) {
Expand Down Expand Up @@ -456,6 +483,7 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {
commitment: solana.Commitment.confirmed,
);
print('Tx successful with hash: $signature');
showrResultMessage(signature);
fetchNfts();
} catch (e) {
final snackBar = SnackBar(
Expand All @@ -473,3 +501,14 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {
}
}
}

Future<void> _launchUrl(String transaction) async {
Uri url = Uri(
scheme: 'https',
host: 'explorer.solana.com',
path: '/tx/$transaction',
queryParameters: {'cluster': 'devnet'});
if (!await launchUrl(url)) {
throw Exception('Could not launch $url');
}
}
Loading

0 comments on commit f488582

Please sign in to comment.