Skip to content

Commit

Permalink
fix: improve world scene of down game and tabs layout
Browse files Browse the repository at this point in the history
  • Loading branch information
dnielopez committed Oct 18, 2023
1 parent ab918f4 commit ac86acf
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 76 deletions.
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:label="DinoGrow"
android:name="${applicationName}"
Expand Down
14 changes: 11 additions & 3 deletions lib/pages/generate_phrase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _GeneratePhraseScreenState extends State<GeneratePhraseScreen> {
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const SizedBox(height: 60),
const Expanded(child: SizedBox()),
Container(
color: Colors.orange[700],
padding: const EdgeInsets.all(8),
Expand All @@ -51,7 +51,9 @@ class _GeneratePhraseScreenState extends State<GeneratePhraseScreen> {
textAlign: TextAlign.center,
),
),
const Expanded(child: SizedBox()),
TextBoxWidget(text: _mnemonic),
const Expanded(child: SizedBox()),
IntroButtonWidget(
text: 'Copy phrase',
onPressed: () {
Expand All @@ -63,6 +65,7 @@ class _GeneratePhraseScreenState extends State<GeneratePhraseScreen> {
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
),
const Expanded(child: SizedBox()),
Container(
decoration: const BoxDecoration(color: Colors.black),
child: Row(
Expand All @@ -76,9 +79,15 @@ class _GeneratePhraseScreenState extends State<GeneratePhraseScreen> {
});
},
),
const Text("I have stored the recovery phrase securely"),
const Expanded(
child: Text(
"I have stored the recovery phrase securely",
textAlign: TextAlign.center,
),
),
],
)),
const Expanded(child: SizedBox()),
IntroButtonWidget(
text: 'Continue',
variant: _copied ? 'primary' : 'disabled',
Expand All @@ -95,7 +104,6 @@ class _GeneratePhraseScreenState extends State<GeneratePhraseScreen> {
}
: () {},
),
const SizedBox(height: 60),
],
),
),
Expand Down
10 changes: 7 additions & 3 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ class _HomeScreenState extends State<HomeScreen> {

@override
Widget build(BuildContext context) {
final statusBarHeight = MediaQuery.of(context).viewPadding.top;

return DefaultTabController(
length: 4,
child: Scaffold(
appBar: AppBar(
backgroundColor: const Color.fromRGBO(241, 189, 57, 1),
elevation: 6,
toolbarHeight: 120,
toolbarHeight: 122 + (statusBarHeight > 0 ? 41 : 0) - statusBarHeight,
flexibleSpace: Column(
children: [
const SizedBox(height: 38),
SizedBox(height: statusBarHeight),
Card(
color: Colors.white,
shadowColor: Colors.white,
Expand All @@ -58,6 +60,7 @@ class _HomeScreenState extends State<HomeScreen> {
_publicKey == null
? 'Loading...'
: '${_publicKey!.substring(0, 6)}...${_publicKey!.substring(_publicKey!.length - 6, _publicKey!.length)}',
maxLines: 1,
style: const TextStyle(color: Colors.black),
)),
const SizedBox(width: 12),
Expand All @@ -71,6 +74,7 @@ class _HomeScreenState extends State<HomeScreen> {
_balance != null
? double.parse(_balance ?? '0').toStringAsFixed(2)
: 'Loading...',
maxLines: 1,
style: const TextStyle(color: Colors.black)),
const SizedBox(width: 3),
const Text('SOL',
Expand Down Expand Up @@ -119,7 +123,7 @@ class _HomeScreenState extends State<HomeScreen> {
physics: const NeverScrollableScrollPhysics(),
children: [
const MiniGamesScreen(),
RankingScreen(),
const RankingScreen(),
MydinogrowScreen(
address: _publicKey ?? '', getBalance: () => _getBalance()),
WalletScreen(
Expand Down
65 changes: 33 additions & 32 deletions lib/pages/input_phrase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class InputPhraseScreen extends StatefulWidget {

class _InputPhraseScreenState extends State<InputPhraseScreen> {
final _formKey = GlobalKey<FormState>();
bool validationFailed = false;
var controllers =
List<TextEditingController>.generate(12, (i) => TextEditingController());

Expand Down Expand Up @@ -70,50 +69,46 @@ class _InputPhraseScreenState extends State<InputPhraseScreen> {
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const SizedBox(height: 60),
const Expanded(child: SizedBox()),
const TextBoxWidget(
text: 'Please enter your recovery phrase'),
const Expanded(child: SizedBox()),
Center(
child: Form(
key: _formKey,
child: SizedBox(
width: 300,
child: GridView.count(
padding: const EdgeInsets.all(3),
crossAxisSpacing: 10,
mainAxisSpacing: 3,
shrinkWrap: true,
crossAxisCount: 3,
children: List.generate(12, (index) {
return SizedBox(
height: 50,
child: TextFormField(
controller: controllers[index],
decoration: InputDecoration(
filled: true,
fillColor: Colors.black,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
hintText: '${index + 1}',
),
textInputAction: TextInputAction.next,
padding: const EdgeInsets.all(3),
crossAxisSpacing: 10,
mainAxisSpacing: 3,
shrinkWrap: true,
crossAxisCount: 3,
children: List.generate(12, (index) {
return SizedBox(
height: 50,
child: TextFormField(
controller: controllers[index],
decoration: InputDecoration(
filled: true,
fillColor: Colors.black,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
);
}),
)),
hintText: '${index + 1}',
),
textInputAction: TextInputAction.next,
),
);
}),
)),
),
),
validationFailed
? const TextBoxWidget(text: 'Invalid keyphrase')
: const SizedBox(),
IntroButtonWidget(
text: 'Continue',
onPressed: () {
_onSubmit(context);
},
),
const SizedBox(height: 32),
],
),
),
Expand Down Expand Up @@ -147,9 +142,15 @@ class _InputPhraseScreenState extends State<InputPhraseScreen> {
},
);
} else {
setState(() {
validationFailed = true;
});
const snackBar = SnackBar(
content: Text(
'Error: Invalid keyphrase',
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.red,
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions lib/pages/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class _LoginScreenState extends State<LoginScreen> {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 60),
const Expanded(child: SizedBox()),
const IntroLogoWidget(),
const SizedBox(height: 30),
const Expanded(child: SizedBox()),
const TextBoxWidget(
text:
'To continue, please enter your current password'),
const SizedBox(height: 16),
const Expanded(child: SizedBox()),
Form(
key: _formKey,
child: Column(
Expand All @@ -81,13 +81,12 @@ class _LoginScreenState extends State<LoginScreen> {
),
),
),
const SizedBox(height: 8),
const SizedBox(height: 8),
const SizedBox(height: 12),
IntroButtonWidget(
text: 'Login',
onPressed: _onSubmit,
),
const SizedBox(height: 32),
const SizedBox(height: 12),
IntroButtonWidget(
text: 'Use different Account',
onPressed: () {
Expand All @@ -97,7 +96,7 @@ class _LoginScreenState extends State<LoginScreen> {
],
),
),
const SizedBox(height: 60),
const Expanded(child: SizedBox()),
]),
),
),
Expand Down
34 changes: 20 additions & 14 deletions lib/pages/mini-games/up/down.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ class DownGame extends Forge2DGame with TapDetector {
@override
Future<void> onLoad() async {
final screenSize = Vector2(size.x, size.y);

// Scaled viewport size
final worldSize = Vector2(7.2, 12.8);
final worldSize = screenSize;

await super.onLoad();

Expand All @@ -157,9 +156,9 @@ class DownGame extends Forge2DGame with TapDetector {
// windowSize: 60,
// textRenderer: TextPaint(style: const TextStyle(color: Colors.white))));

add(Floor());
add(LeftWall());
add(RightWall());
add(Floor(worldSize));
add(LeftWall(worldSize));
add(RightWall(worldSize));

//Testing
// Add instance of Box
Expand All @@ -168,49 +167,56 @@ class DownGame extends Forge2DGame with TapDetector {
endGameCallback('$score');
}

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

await Future.delayed(const Duration(milliseconds: 1000), () {
add(Box(newBoxAndScore, finishGame, worldSize));
});
}

add(Box(newBoxAndScore, finishGame));
await Future.delayed(const Duration(milliseconds: 1000), () {
add(Box(newBoxAndScore, finishGame, worldSize));
});

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

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

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

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

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

// add the buttons to the game
btnLeft.position = Vector2(0, worldSize.y - 1);
btnRight.position = Vector2(3, worldSize.y - 1);
add(btnLeft);
add(btnRight);
// add(btnJump);
// add(btnAttack);
add(btnJumpText);
add(btnAttackText);
// add(btnJumpText);
// add(btnAttackText);

// Score text
final btnStyleLetters = TextPaint(
Expand Down
15 changes: 8 additions & 7 deletions lib/pages/mini-games/up/objects/box.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:math';

import 'package:dinogrow/pages/mini-games/up/objects/floor.dart';
import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';

Expand All @@ -9,8 +8,10 @@ import 'dino.dart';
class Box extends BodyComponent with ContactCallbacks {
final Function onCollisionBox;
final Function onCollisionDino;
final Vector2 worldSize;

Box(this.onCollisionBox, this.onCollisionDino) : super(priority: 1);
Box(this.onCollisionBox, this.onCollisionDino, this.worldSize)
: super(priority: 1);

@override
Future<void> onLoad() async {
Expand All @@ -28,21 +29,21 @@ class Box extends BodyComponent with ContactCallbacks {
@override
void beginContact(Object other, Contact contact) {
removeFromParent();
if (other is Floor) {
onCollisionBox();
} else if (other is Dino) {
if (other is Dino) {
onCollisionDino();
}
onCollisionBox();
}

@override
Body createBody() {
final rnd = Random();

final xpos = (rnd.nextDouble() * (worldSize.x - 1)).abs();
print('xpos: ${xpos}');
final bodyDef = BodyDef(
userData: this,
//position: Vector2(worldSize.x / 2, worldSize.y - 3), change dino position later
position: Vector2(rnd.nextDouble() * 2.8 + 0.2, -1),
position: Vector2(xpos, -1),
type: BodyType.dynamic,
gravityOverride: Vector2(0, rnd.nextDouble() * 3 + 2),
);
Expand Down
Loading

0 comments on commit ac86acf

Please sign in to comment.