Modular Upgrades Made Easy Using the Strategy Pattern

preview_player
Показать описание
In this video we'll look at an application of the Strategy Pattern to game dev in Godot 4.

The Strategy Pattern is a programming pattern useful for switching how an algorithm works at runtime. We use it a little differently here to apply a variable set of upgrades to a projectile fired by the player. A very closely related term is "polymorphism" if you're familiar with that.

Project Link:

Resources:

Timestamps:
00:00 Intro
00:12 The Strategy Pattern
00:17 Simple list example
00:50 Number filter class
02:17 But why use it?
02:34 Applying upgrades
02:55 GitHub and project info
03:34 Godot time
03:51 Base upgrade class
04:19 Player upgrade usage
04:38 Upgrades as resources
05:10 Custom upgrade
05:59 Possibilty for extension
06:11 Semi-important announcement (You are free to leave)
Рекомендации по теме
Комментарии
Автор

IMPORTANT:
The GDScript project seems to be broken upon first loading. It complains about some classes missing. Until I can figure out why and push up a fix, you can simply do Project -> Reload Current Project and that should fix the issue

Bitlytic
Автор

godot really needs more tutorials like this.

dovos
Автор

Your initial example of strategy pattern is the most simplify and fully complete example of what the strategy pattern is. Honestly, I plan to refer back to it when thinking about teaching design patterns from now on.

Sirlegna
Автор

this is insanely useful for games whose content is built on modular upgrades.
For example, for a card battler game (akin to Slay the Spire) you never know what kind of crazy effect you have to implement at a later date.
By making the points of applying the changes more modular (and by use of fitting signals) you can plug in modular effects at any given stage of the game (during draw phase, initiate combat, after combat, on damage taken, on turn end, etc) while the actual base code remain untouched.

LocherYT
Автор

Found your channel in the comments section of Brackies, and am blown away at how good your videos are... Keep it up! 💙

acecooldev
Автор

I'd love to see more videos like this as someone just getting into Godot. But even for people not using Godot, these are very helpful in just breaking down common ways of handling problems that we may not have heard of. I hadn't considered nor heard of this way of doing things before.

JackAllpikeMusic
Автор

You can even do with less Boilerplate in C# (also kinda in Godot, but less elegantly, cause the first class functions aren't as strictly typed)
In C# you have the Action<T> and Func<T> and with those you can make types that are functions that take in certain types of parameters and return certain types. And with that you don't need the Class + Polymorhpism Boilerplate.

MargudnRoboter
Автор

I understand barely anything, but i have faith that with practice this is gonna be so helpful

maxamillion
Автор

I watched this video a long time ago and it mostly went over my head. Watching it now, it makes a lot of sense to me, and it looks like a design pattern I'll be adding to my toolbelt.

harmoen
Автор

I was sad that you stopped posting videos for a while because I really like your content on Godot, now I saw this video explaining exactly what I needed for my game, thank you so much, keep uploading pls :)

LucasFerreira-ekpr
Автор

This is some top-tier genius level content right here and in less than 7 minutes. You explained this so well and succinctly

LandonDevelops
Автор

"Sorry cant make it new Bitlytic video just dropped!!"

brockcotterill
Автор

You are immensely good at teaching concepts like these, please continue to make these amazing tutorials :)

Based
Автор

Great video! Appreciate the fact that the samples are available to look at to dissect and learn!

kartopod
Автор

beginner here. i always had a vague understanding of what polymorphism and interfaces are, but thanks to this i finally have a more tangible example of why they're pretty useful

DrickRT
Автор

Also to note, callables are better than straight up changing the value in more complex games.

Also the example is using resources which means if you have multiple things that can take a powerup you will want to create a unique instance of these resources.

You could also have a wrapper class which handles storing data and have the resources that handle the strategy though.

So for example the apply_update would take 2 arguments (the wrapper and the subject... in this case the bullet)

So say the effect is to reduce the cool down time until you can fire the next bullet, but that you want that effect to stack 3 times.

this will increase the stack amount from in the resource and adjust the subject as needed with a callable.

This then incorporates a mediator pattern which will handle referencing the source of the modifier that way if these modifiers have a duration we can remove its specific effect.

The use case for this would be say you have a Ring of Vengeance and a Sword of Vengeance which give an effect Vengeance +3 to attack when you attack.

Lets say you want the effect to stack 3 times and refresh when reapplied.

You could have the wrapper handle the stacking and duration data, the strategy handle updating that when called and the mediator ensuring the same effect isn't duplicated or throws an exception if you are using a dictionary.

dibaterman
Автор

Hopefully will wrap my head around it with enough practice

cryptidpog
Автор

I love your Godot videos! I am actually implementing a similar weapon/projectile modifier to a game I'm working on so it's great to see how someone else approaches it.

sligoman
Автор

Wow this video just blew me away !
Really short, but also really clear and with actual code to implement eveything.
This is probably the best Godot video I've seen. Keep it up !

Avandale
Автор

You have the best videos on these coding topics that I have ever come across in my 6+ years of coding. Seriously, thank you.

ColinBeauregard
join shbcf.ru