In this video, we look at the provided code for the base bullet and the player’s spell.
These two classes provide the base behavior for the bullet and the player’s spells, respectively.
We provided these scripts so that you will have to read the code and use the provided functions to create new kinds of bullets. This is as it would be if you worked professionally on this kind of game, in a team.
By default, the bullet moves forward from its spawn position and gets destroyed when it reaches its maximum range or hits something.
We created multiple small functions in the Bullet.gd
script to allow replacing them in scripts that extend
Bullet.
That way, you can keep some behavior as default and replace other parts.
For example, if you want a bullet to move in a wave-like motion, you
could override the _move()
function. If you want the bullet
to explode before being freed from memory, you can override the
_destroy()
function.
The project comes with a sample fireball bullet you can use as a
reference to create more bullets: Fireball.tscn
.
While the bullet only has a script, the spell comes with both a script and a scene that you have to inherit.
That way, you will practice working with inherited scenes (spell) and extending a script in multiple scenes (bullet).
The spell in this project is a bit like a gun or a cannon that shoots projectiles. We named it “spell” because the game’s theme is that the player uses magic.
A spell can shoot one or more bullets at a time and at different rates.
The default behavior of a spell is to shoot one bullet when you call
the shoot()
function. But you could override the
shoot()
function to fire multiple bullets at a time.
It’s up to you to write the input code for each spell. We don’t put default inputs in the base script because you may want different spells to work differently.
Some may shoot automatically on a cooldown, while you might want others to charge when the player keeps the shoot key down.
The project comes with a sample spell you can study to create more
spells: SpellBasicFire.tscn
. This spell shoots fireballs
and is loaded by default into the player’s character.