1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-11 15:28:44 +00:00

Add game_template (#1180)

Adds a template / sample for games built in Flutter, with all the bells and whistles, like ads, in-app purchases, audio, main menu, settings, and so on.

Co-authored-by: Parker Lougheed
Co-authored-by: Shams Zakhour
This commit is contained in:
Filip Hracek
2022-05-10 15:08:43 +02:00
committed by GitHub
parent 5143bcf302
commit daa024a829
208 changed files with 8993 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
// Copyright 2022, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import '../audio/audio_controller.dart';
import '../audio/sounds.dart';
import '../player_progress/player_progress.dart';
import '../style/palette.dart';
import '../style/responsive_screen.dart';
import 'levels.dart';
class LevelSelectionScreen extends StatelessWidget {
const LevelSelectionScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final palette = context.watch<Palette>();
final playerProgress = context.watch<PlayerProgress>();
return Scaffold(
backgroundColor: palette.backgroundLevelSelection,
body: ResponsiveScreen(
squarishMainArea: Column(
children: [
const Padding(
padding: EdgeInsets.all(16),
child: Center(
child: Text(
'Select level',
style:
TextStyle(fontFamily: 'Permanent Marker', fontSize: 30),
),
),
),
const SizedBox(height: 50),
Expanded(
child: ListView(
children: [
for (final level in gameLevels)
ListTile(
enabled: playerProgress.highestLevelReached >=
level.number - 1,
onTap: () {
final audioController = context.read<AudioController>();
audioController.playSfx(SfxType.buttonTap);
GoRouter.of(context)
.go('/play/session/${level.number}');
},
leading: Text(level.number.toString()),
title: Text('Level #${level.number}'),
)
],
),
),
],
),
rectangularMenuArea: ElevatedButton(
onPressed: () {
GoRouter.of(context).pop();
},
child: const Text('Back'),
),
),
);
}
}

View File

@@ -0,0 +1,49 @@
// Copyright 2022, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
const gameLevels = [
GameLevel(
number: 1,
difficulty: 5,
// TODO: When ready, change these achievement IDs.
// You configure this in App Store Connect.
achievementIdIOS: 'first_win',
// You get this string when you configure an achievement in Play Console.
achievementIdAndroid: 'NhkIwB69ejkMAOOLDb',
),
GameLevel(
number: 2,
difficulty: 42,
),
GameLevel(
number: 3,
difficulty: 100,
achievementIdIOS: 'finished',
achievementIdAndroid: 'CdfIhE96aspNWLGSQg',
),
];
class GameLevel {
final int number;
final int difficulty;
/// The achievement to unlock when the level is finished, if any.
final String? achievementIdIOS;
final String? achievementIdAndroid;
bool get awardsAchievement => achievementIdAndroid != null;
const GameLevel({
required this.number,
required this.difficulty,
this.achievementIdIOS,
this.achievementIdAndroid,
}) : assert(
(achievementIdAndroid != null && achievementIdIOS != null) ||
(achievementIdAndroid == null && achievementIdIOS == null),
'Either both iOS and Android achievement ID must be provided, '
'or none');
}