Powerup Name
Choose a clever name for your powerup, such as 'clevername'.
Powerup Image
-
Select a PNG image to represent your powerup. Try to keep it small (in order to reduce the size of the executable).
Resize the image to 32x32; if it doesn't look good, try 64x64.
-
Name the file 'powerup_clevername.png' and put the file in the following directory:
/ext/libwiigui/images
-
Now you must add a declaration for your powerup image. Open the following file:
/ext/libwiigui/filelist.h
Look for the comment 'powerup image declarations go here' and add the following lines:
(note: please keep powerups in alphabetical order)
-
extern const u8 powerup_clevername_png[];
-
extern const u32 powerup_clevername_png_size;
Powerup Sound (optional)
Selecting a sound to represent your powerup is optional; if you don't provide one, a default sound will be played.
-
Select a sound to represent your powerup. The sample should be no more than a couple seconds long.
-
Convert your sound sample to the following format:
PCM signed 16 bit, big endian, stereo (raw) at 44100 Hz
-
GoldWave is a good program for converting to .pcm format.
-
If converting from .wav to .pcm, you may have to resample at 44100 Hz.
-
I found that if I convert from .wav to .ogg or .mp3, then convert to .pcm, it's automatically sampled at the correct frequency.
-
Name the file 'powerup_clevername.pcm' and put the file in the following directory:
/ext/libwiigui/sounds
-
Now you must add a declaration for your powerup sound. Open the following file:
/ext/libwiigui/filelist.h
Look for the comment 'powerup sound declarations go here' and add the following lines:
(note: please keep powerups in alphabetical order)
-
extern const u8 powerup_clevername_pcm[];
-
extern const u32 powerup_clevername_pcm_size;
Powerup Code Files
Now you're ready to write the header file and source file. There are templates located in:
/templates/Powerup
You could copy these templates and modify them by hand, but I wrote a script that does it for you; simply run Powerup.exe and follow the on-screen instructions (if you're paranoid, you can compile the program from the source).
- Move the generated header file to:
/code/include/powerups
- Move the generated source file to:
/code/source/powerups
- If you added a sound for your powerup, uncomment the optional sound code in the header file and source file.
- The only functions you need to implement are StartEffect and StopEffect (located in the source file).
- Your powerup is automagically added to the game menu.
Optional Overrides
By default powerups last for 10000 milliseconds and only affect one player. You can override this default behavior by providing definitions for the GetDuration and GetTargetType functions in the powerup header file.
There are 3 target types:
- POWERUP_TARGET_ONE - Affects the target player.
- POWERUP_TARGET_ALL - Affects all players.
- POWERUP_TARGET_ALL_BUT_ONE - Affects all but the target player.
Powerup Behavior
Now comes the hardest part: implementing the actual powerup behavior. As mentioned previously, you only need to implement the StartEffect and StopEffect functions in the powerup source file. Look at the other powerup classes for examples. In general, you will have to add a state flag to Player::PlayerPowerupData. StartEffect will turn the flag on, and StopEffect will turn the flag off; some piece of game logic will operate differently while the flag is turned on. Good luck, you can do it!