How to create a new powerup
We need to follow the below steps to create a new powerup :
A. Go to powerup.xml (or whatever the name will be for the XMl containing data of powerups). Then add another powerup like below :
<powerup type="SPACIAL_OCEAN" description ="Push back obstacles">
<recipe>
<material type="MAGMA" quantity="25"/>
<material type="ICE" quantity="25"/>
</recipe>
<wordToType values="spac,ciao,more,rode"/>
</powerup>
We need to change type, description, material required to craft it and also a 4 letter word needed to activate the powerup according to the powerup.
B. Then create a new class following below template :
extends PowerUp
class_name Fortification
var ship: Ship
func activate_powerup():
print("Fortification activated")
ship.show_area2d_blocking(10.0)
ship.fortification_animation(10)
Description of above code:
extends PowerUp This line just extends PowerUp , so it will be mandatory for all new powerups to be created.
class_name Fortification Here just write the powerup name with first alphabet of each word in uppercase.
var ship: Ship Here we are just taking ship from DI so that we can access the functions in ship.gd
func activate_powerup(): Here we need to name this function exactly like this as we are accessing it from activation script. Then we write the functionality of the powerup which will happen after the activation of it.
C. Then we need to bind it against a variable in the DI as below :
DI.bind(Fortification, DI.As.SINGLETON).to_var("fortification")
Description of above code:
DI.bind(Fortification, DI.As.SINGLETON).to_var("fortification"): Here we bind the class against a variable. So we need to put the class name DI.bind(class_name,DI.As.SINGLETON) and then variable name in to_var("variable_name")
D. Then finally we need to add the powerup name in the match case as below and put the activate powerup function in the statement below it after referencing it in the same file :
func activate_powerup(x):
match x:
"heat_wave":
heat_wave.activate_powerup()
"fortification":
fortification.activate_powerup()
"spacial_ocean":
spacial_ocean.activate_powerup()
"frost_field":
frost_field.activate_powerup()
"cryo_shield":
cryo_shield.activate_powerup()
No Comments