A puzzle game made on live-stream, demonstrating various animation techniques in Flutter

Overview

Slide Puzzle: Escape of Cao Cao

This is a puzzle game made on live-stream, demonstrating various animation techniques in Flutter with just Dart code - no dependencies or asset files. It can target mobile, desktop, and the web from a single code base.

The goal of the game is to move "the biggest puzzle piece (Cao Cao)" to "the exit" at the bottom, in as few steps as possible.

A playable web version is available. For the best experience, you can also try out native desktop or mobile apps.

Releases

v1.2.1 (2022-03-14)

  • Added an animation when the game launches.

an intro animation when the game starts

v1.2.0 (2022-03-12)

  • Added a hint button.
  • Minor changes to the reset button.

The new hint feature spawns an isolate to find an optimal solution for the current state using Breadth-First Search. Once the result comes back, an OverlayEntry is created precisely on top of the hinted piece, with the help of a CompositedTransformFollower widget and LayerLinks embedded in the pieces.

the new hint button in action

v1.1.0 (2022-03-06)

  • Added more levels.
  • Added a new 3D animation during level transitions.
  • Added an option to hide decorative texts on puzzle pieces.
  • Various minor UI enhancements and performance improvements.

This is my first time trying to simulate 3D objects without 3rd party tools or plugins in Flutter. It's made using Transform widgets to translate and rotate 6 rectangles to correct places to form a cuboid.

a 3d cube made with transform widget

Further optimizations were made so only up to 3 faces (visible to the viewers) are rendered at a time, and a glare effect was added by changing stops on a LinearGradient. This formed the basis for a new transition animation when a level is completed.

a 3d puzzle piece with glare effect

I've published a video tutorial on this topic, watch it in English | Chinese.

v1.0.1 (2022-02-26)

  • Added a simple tutorial screen.
  • Fixed a bug where the web version was not rendering correctly on mobile browsers.

The tutorial screen is a responsive dialog made with LayoutBuilder and ConstrainedBox, and decorated by CupertinoPopupSurface. It also includes a WillPopScope to allow Android users to dismiss it with the back button.

new tutorial dialog with an option to hide decorative texts

It provides an option to hide decorative texts (v1.1.0) in case they don't render properly, e.g. when there are no international fonts installed.

When building for web, make sure to use canvaskit renderer for better experience across devices. You can do so with flutter build web --web-renderer canvaskit command. Otherwise, the puzzle might not render correctly on mobile browsers. I've created an issue for this and looks like the Flutter team is already on it.

v1.0.0 (2022-02-22)

  • Initial release for all platforms.

The initial version of the app was created as "live coding" stream sessions. With discussions and voting polls on design choices such as the color palette, together we built the game in 12 live-stream sessions.

the project was created on live stream

The support for more platforms were added after the live stream ended.

multi-platform: a photo of the app running on multiple devices

The video overview (see below) was released at the same time as the initial version, so new features mentioned above are not included in the video.

Video Overview

A short video (less than 3 min) is available, providing a brief overview of version 1.0.0.

video

You can choose to watch the video in English | Chinese.

At a high level, the app can be divided into 3 parts: the background layer, the game board, and the puzzle pieces. Each puzzle piece also comes with a pair of interlocking attachments and a shadow for some added depth. These components are stacked as 3 different layers, to make sure they always appear in the correct order when being moved.

each puzzle piece is layered 3 times

The color palette is configured as an InheritedWidget so its values can be modified in one place, and easily accessed elsewhere in the widget tree.

The puzzle pieces are made from AnimatedPositioned. For the duration, I pass in zero if the window size is different from before. This is to skip the unwanted animation when the app is being resized. And for the curve, I use EaseOut to slow them down naturally.

To handle user input, I added GestureDetector. I used the onPanUpdate event instead of the onPanEnd event, to reduce input lag.

use onPanUpdate for a faster response

From the picture above you can see that the user has not finished the action (finger is still touching the screen), but with onPanUpdate event, the game has already responded.

For the reset button, I added a MouseRegion widget to make it glow when being hovered.

use MouseRegion to make the reset button glow

The step counter on the side is another example of utilizing implicit animations in Flutter. It’s also wrapped in a ValueListenableBuilder, so it can always keep up with the steps.

an animated flip counter used to track steps

I’ve published the counter as a package on pub and made a video explaining how it was made. If you like this animation, you can import it to your own project.

The game board is mostly a Container with some decorations and clipping. I also used a BackdropFilter here to blur everything behind it, and a ShaderMask to create a beam effect.

BackdropFilter and ShaderMask

The beam created by ShaderMask is an explicit animation with its controller set to repeat, so it can keep dancing around in the game.

glare effect on texts

Similarly, the decorative texts puzzle pieces are also animated to have a subtle glare effect.

Lastly, I used a CustomPaint for the app background. It efficiently draws colorful rectangles every frame and runs well even on low-end devices.

What's Next

  • Resolve web rendering issue for mobile browsers
  • Add a tutorial screen to explain the game
  • Add more levels to the game
  • Add an automatic solver or a hint system
  • Allow users to select levels
  • Add keyboard support
  • Further improve swiping gestures

Extra Resources

I've been making lots of video tutorials (mostly in Chinese) on Flutter, covering a wide range of topics and popular questions from viewers. If you are interested, please follow me on "bilibili" so you won't miss the next live stream or video from me.

Animations

I've made a total of 19 video tutorials on Flutter Animations, divided into 3 sections: implicit, explicit and others.

Implicit Animations

Explicit Animations

Other types of Animations

Keys

I've made 7 video tutorials on keys, covering basic concepts such as widgets and elements, 3 types of local keys, 2 different uses of global keys, and more.

Scrollable

Asynchronous

Layout

Slivers

Coding challenge and follow-ups

(Sometimes I post questions for my viewers and then do follow-up videos to discuss all the creative solutions I receive, so we can learn from each other.)

Other popular topics

You might also like...

Flutter Switch Game: Get Fun With Play This Game

Flutter Switch Game: Get Fun With Play This Game

switch_game A new Flutter project. Getting Started Try Swap red circle to green

Jun 17, 2022

A simple dice game built using Flutter, that allows users to engage in a dice game

A simple dice game built using Flutter, that allows users to engage in a dice game. Each player rolls the dice and the highest value number that you can make WINS!

Sep 1, 2022

Game Flutter Using Flame.It was for the Game Jam 2022

binarymemory Memory Binary Flame Flutter Game Jam Getting Started This project is a starting point for a Flutter application. A few resources to get y

Sep 7, 2022

A starter game in Flutter with all the bells and whistles of a mobile (iOS & Android) game

A starter game in Flutter with all the bells and whistles of a mobile (iOS & Android) game including the following features: sound music main menu scr

Dec 22, 2022

Wordle-flutter - A Wordle Game Made With Flutter

Wordle-flutter - A Wordle Game Made With Flutter

wordle with flutter A small wordle made with flutter Getting Started Just a 4 ho

Dec 11, 2022

Tic-tac-toe-flutter - Multi player TIC-TAC-TOE game made using flutter

Tic-tac-toe-flutter - Multi player TIC-TAC-TOE game made using flutter

tic_tac_toe Multi player TIC-TAC-TOE game made using flutter State Management li

Feb 22, 2022

This is The Tic Tac Toe Game Made Using Flutter

hello A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this is

Dec 19, 2022

🎮🔥 Game streaming app UI kit made with Flutter

🎮🔥 Game streaming app UI kit made with Flutter

🍔 😋 Flutter Gaming UI - A Flutter Game Streaming App Template A Flutter UI template of a Game Streaming App I found on Dribble. Design screens are o

Oct 10, 2022

Hangman style game with words from the askOuija subreddit. Made in Flutter.

Hangman style game with words from the askOuija subreddit. Made in Flutter.

Ouija Quizz Hangman style game with questions and answers from the askOuija subreddit. The user is given a question and he has to guess the answer giv

Dec 26, 2022
Owner
null
Cyberpunk-inspired puzzle game prototype created with Flutter and Flame #Hack20 #FlutterHackathon

Ghost Rigger Prototype of a cyberpunk-inspired puzzle game set in a dystopian future: In the year 2078, the megacorporation Native Development Initiat

Float like a dash Sting like a dart 184 Dec 26, 2022
A simple slide puzzle flutter game

Flutter Puzzle Hack This game is for the "Flutter Puzzle Hack" contest, 2022. It is a simple slide puzzle game, where the player has to arrange the sq

Md. Siam 46 Jan 4, 2023
A slide puzzle game you can play with your friend on cross-platform.

slideparty Inspiration I want to make a puzzle game that runs on all platforms: Web, Android, iOS, Linux, Windows and MacOS. You can play with your fr

Duong Bui Dai 29 Nov 23, 2022
Box2D Flutter Slide Puzzle

It uses Box2D physics to create an interesting gameplay mechanic where you need to manage a bit more than a simple slider. The code is all pure Flutter with widgets, animations, and CustomPaint. It doesn't use any Flutter game engine.

Gordon Hayes 25 Nov 11, 2022
Warrior Runner - Game made with Flutter and Flame game engine

Warrior Runner - Game made with Flutter Demo and Screenshot Flutter Version Used : 1.22.4 flame: 0.29.3 hive: 1.5.0-pre Learing Resources: Create a Mo

Mohammed Hashim 20 Oct 10, 2022
Chess-game - Some simple lines of coding and made this awesome looking full functional chess board game

flutter simple chess game It's a flutter chess game application with fast code.

Munem Sarker 5 Jun 17, 2022
An application cum Game-based App built using Flutter that compose a mind-tricked word game, Just for fun.

destini_challenge A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you st

dev_allauddin 3 Feb 3, 2022
M.U.D. Role-playing text-based game. A multiple-choice multiplayer interactive game developed on Flutter (Android, iOS, Windows, Web)

Teia M.U.D. Role-playing text-based game. A multiple-choice multiplayer interactive game developed on Flutter (Android, iOS, Windows, Web). The main f

Pedro Gonçalves 3 Feb 17, 2022
Snake-Game - A flutter based classic snake game with nothing just and just a feel to have play

snake_game This is a simple snake Game under development made with the help of y

Shubham Kumar 2 Mar 22, 2022
Game characters ui - A redesign of a game characters app using flutter

Game characters ui - A redesign of a game characters app using flutter

null 20 Oct 23, 2022