Hey, everyone. Welcome back to Learning to Fly.
In this episode, we'll go over some changes
and improvements that we've made to Doodle Dash since Episode 2.
Then we'll talk about new challenges we faced
and how we solved those challenges.
And at the end, we'll show you the completed first version of our game.
Let's get into it.
♪ [music] ♪
So as of the last episode, our game works
and has the bare minimum features we wanted to include.
This means things like menus, pausing the game,
and a couple gameplay features that make it more interesting,
like Dash's first power-up, the springboard.
And for this sprint, it's all about the polish.
We wanted to do that last 20% of the work
that was needed to make the game seem less like a weekend project
and a little more like a quality game.
We've updated our assets and styling to make it look more cohesive,
added more power-ups and interesting platforms
to make the game more fun,
and some overall code refactoring and cleanup
to make the game feel smoother and more maintainable.
So the first thing you'll notice when you launch the game
is the updated start menu.
We styled it, of course, but more importantly,
it has two new options to customize your experience.
First, you can choose your character.
We've added Sparky,
the mascot for Firebase,
as another character option in addition to Dash.
You can choose either one,
but you obviously got to choose the cutest mascot.
There's a right answer here.
And there's also a difficulty slider on the start screen
which lets you choose how difficult you want the game to be.
There are five difficulties.
Each difficulty affects the speed of the game
and how the platforms are populated in the game,
both distance-wise and the types of platforms that are populated.
You'll also see updated styling on the other overlays,
just to make the game a bit more professional looking.
For the styling itself,
we had talked to a few of the creative folks on our team
to help us come up with some fun assets
and a theme for our Doodle Dash game,
and we landed on a multi-platform theme.
Get it?
Multi-platform?
Flutter?
The things that Dash is jumping on our platforms.
Anyway, they gave us some awesome assets
and we swap them out one for one
to replace the temporary assets that we pulled from the web.
Once we had an idea of what it would look like,
along with some rough colors that would be used,
we plugged those colors into the material theme builder,
and exported the color scheme that we're using in the game.
We also added new features to the gameplay.
Let's start with the platforms.
In addition to the standard platform that we already had,
there's now a moving platform and a breakable platform
that Dash can only jump on once.
Both of these new platforms help to make the game a bit trickier.
We've also added an enemy,
a trash can that moves side to side.
The player has to dodge it, or it's an instant game over.
Finally, last but not least,
we also added two new power-ups for Dash.
One is a rocket ship.
When Dash collides to the rocket, she launches upwards.
And the second new power-up is a Noogler hat.
If you haven't seen a Noogler hat,
it's a goofy hat that Google employees get when they start at the company,
and yep, it has a propeller on it!
Naturally, when Dash is equipped with the Noogler hat,
it will propel Dash upwards much faster than jumping on the platforms.
And I know what you're thinking.
It sounds like these are the same,
but there is a difference between these two power-ups.
First, the speed.
The rocket really boosts Dash's speed for a while.
While the Noogler hat is more like a pleasant ride into the sky,
and less like a launch.
And because the rocket is so fast, Dash is invincible while wearing it
and will bust right through the trash can and maze without getting hurt.
But with the Noogler hat, you have to dodge the enemies.
And lastly, we introduced LayoutBuilder into the app
to set a max width on the game widget as well.
This prevents the game width from being so wide
that sometimes platforms are further apart than Dash can jump.
And outside of those headline changes,
we also went through the code and cleaned it up.
There was quite a bit of refactoring
to make the game more modular and readable.
As far as challenges go, we talked a little about this offline
and agreed that we didn't run into any major challenges
with implementing the new features and improvements.
Because, well,
most of the sprint was adding objects and features that were similar to
and building on top of code and functionality that we already had.
However, there was a challenge,
and it came after we'd already implemented all the requirements for the sprint.
Right. Because the series is about learning new programming skills,
the code itself is just as important as the game it produces,
and this code was a mess.
We don't have any state management system
or a centralized place to hold the business logic.
Rather, we are just calling functions that change game state willy-nilly
from wherever we wanted.
For example, some of the business logic
that took effect when Dash collided with a platform
was handled on the platform object,
while some was handled on the Dash object.
Also, setting the difficulty started with a slider widget on the main menu,
which called a method on the game object,
which then called to the platform manager object
where the difficulty is actually set.
When the difficulty was changed,
it changed values in the platform manager and on the Dash object.
This is bad because the platform manager didn't need to know
about the concept of difficulties at all.
And the Dash object certainly didn't need to know
about the platform manager object.
All the platform manager really needs to know
is the values that change due to the difficulty changing.
So we just needed to pass those in the manager,
but the manager didn't need to be responsible
for changing those values itself.
And there was also some funkiness
with the platform's power-ups and enemies,
all the objects that Dash interacts with,
because some of them were sharing superclasses
and some of them weren't,
including some that had pretty similar behavior.
So, the big challenge was thinking retroactively
about how to architect this better,
and then refactoring all the code
to be easier to understand and extend later.
And this is especially important because the code is part of a code lab,
and we certainly don't want to teach bad code.
Yes, though I will say that I think we did the right thing
by starting with spaghetti code.
We haven't had any experience building games before,
so we didn't know what we didn't know.
So even if we did try to start with some kind of big brain architecture,
we would have missed a lot.
We'd probably have ended up over-architecting our way
into a corner, anyways,
and just wasting our time.
Absolutely, I agree.
I'm a big fan of not trying to anticipate making code dry,
which means don't repeat yourself,
and I think this experience highlighted that.
On top of that, Learning to Fly is about learning,
and I think it's much more valuable to struggle through a problem
than it is to read about a problem in a hypothetical way.
The correct way or solution makes more sense
when you can compare it to first-hand experience
with the bad way.
I wholeheartedly agree with you on that one,
and it was a challenge at times,
but personally, I think that with our method,
writing code that worked and then refactoring it to be better
was a really fun learning process and challenge.
Wait, actually, speaking of challenges, we have one for you.
What's the most fun, creative power-up or enemy
that you can come up with for Doodle Dash?
Your mission, should you choose to accept it,
is to take our Doodle Dash code or, if you want,
build Doodle Dash from scratch by following the code lab,
and add on your own power-up or enemy.
If you share with us by Sunday, January 22nd, 2023,
we might just feature it as part of the 17 Days of Flutter.
For more information on the challenge and submission details,
head on over to the 17 Days of Flutter calendar page linked below.
Well, Eric, I think that's going to do it for this episode.
We're taking a bit of a break after this one,
so we'd love to have your suggestions
on what we might add to the game in the future.
Maybe something like multiplayer support or leaderboard with Firebase?
Let us know what you think.
If you have any other ideas for future episodes,
please drop them in the comments right down below.
And again, if you want to learn how to build Doodle Dash
step by step with Flutter and Flame, check out the code lab.
Of course, you'll be getting a fully polished and code-reviewed sample
with the code lab.
We've already cleaned up our spaghetti,
and you can find a link to the code lab in the show notes down below.
Thanks for joining us, and we'll catch you later.
See ya.
♪ [music] ♪