![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A complex 2D-dungeon game on LPC1768 in SWJTU-Leeds Joint School XJEL2645 project. Referenced from the framework contributed by https://os.mbed.com/users/Siriagus/code/SimplePlatformGame/
Dependencies: mbed N5110 ShiftReg PinDetect
Music.h
- Committer:
- hugohu
- Date:
- 2021-03-25
- Revision:
- 19:89c3eeb3761b
File content as of revision 19:89c3eeb3761b:
#ifndef MUSIC_H #define MUSIC_H /// @file Music.h #include "mbed.h" #include "Sprites.h" // #include "Tone.h" /// A note is given by its frequency and beat. struct Note { Note(float f, float b = 1.0) : frequency(f), beat(b) {} float frequency; /// Frequency of note float beat; /// Normal beat last for 1 cycle }; /// Sound uses a piezo buzzer connect to a PWMOut to output sound class Sound { public: /* Creates a new sound object. * @param pin The pin of the pwm output the piezo buzzer is connected to. */ Sound(PinName buzzerPin); /// Destructor ~Sound(); /// Plays the given note. @param note The note to be played. void playNote(Note ¬e); private: void start() {*buzzer = 0.5;} // Set duty cycle to 50% void stop() {*buzzer = 0.0;} // Turn off pwm out // Variables private: PwmOut *buzzer; // Piezo buzzer. Timeout ticker; // Used for stopping sound after the given beat. }; /// Sound effects. Commonly used notes. namespace SFX { extern Note PLAYER_DEAD; extern Note ENEMY_DEAD; extern Note BULLET_FIRED; extern Note PLAYER_JUMP; extern Note RESTART; } #endif