Mbed project for a FRDM-K64F microcontroller. Game made out of five sub-games including flappy birds, snake, stack, trivia and space invaders.

Dependencies:   mbed

Fork of The_Children_of_Cronos_el15mggr by ELEC2645 (2016/17)

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Stymphalianlib.h Source File

Stymphalianlib.h

00001 #ifndef STYMPHALIANLIB_H
00002 #define STYMPHALIANLIB_H
00003 
00004 #include "mbed.h"
00005 #include "N5110.h"
00006 #include "Gamepad.h"
00007 
00008 #define widthB 82
00009 #define heightB 46
00010 #define sizeB 3
00011 #define NOTE_DS3 156
00012 #define NOTE_AS2 117
00013 
00014 /////////////////////////////////////STUCTURES/////////////////////////////////
00015 
00016     /** Aliens bullet position */
00017     struct alienbullet {
00018         int x;/**< x pos */
00019         int y;/**< y pos */
00020     } ;
00021 
00022 
00023     /** Spacecraft position */
00024     struct posplayer {
00025         int x;/**< x pos */
00026         int y;/**< y pos */
00027     } ;
00028 
00029     /** Bullet position */
00030     struct posbullet {
00031         int x;/**< x pos */
00032         int y;/**< y pos */
00033     } ;
00034 
00035 
00036 /////////////////////////////METHODS AND VARIABLES////////////////////////////////
00037 
00038 /** Stymphalianlib Class
00039  * @brief Library for the second game
00040 * @brief Revision 1.3
00041 * @author Mateo Randulfe
00042 * @date May 2017
00043  */
00044 
00045 class Stymphalianlib
00046 {
00047 public:
00048     /** Constructor */
00049     Stymphalianlib();
00050     /**
00051     * function that displays the game over screen and allows player to restart game
00052     *once restarted,all values set to original ones
00053     * @param lcd for drawing into the screen
00054     * @param start for restarting the game
00055     * @param pad for putting leds off
00056     */
00057     void gameover(N5110 &lcd,DigitalOut &start,Gamepad &pad);
00058     /**
00059     * updates the alien bullets and player bullets movement
00060     * also, it only allows to generate the bullet if the alein is on the screen
00061     * uses disp variables for knwing where to display the bullet(from an alive alien)
00062     * uses alienbullet variables for knowing if there is any bullet of that type already in
00063     *the screen(in that way no bullet will be generated untill there is no bullet in the screen
00064     */
00065     void updatescr();
00066     /**
00067     * allow player to move the spacecradt horizontally within the screen as well as to shoot only if there is no players bullet already in the screen
00068     * @param b/x/pad spacecraft horizontal movement
00069     * @param l/r shoot from left or right
00070     */
00071     void commands(Gamepad &pad,DigitalOut &l,DigitalOut &b,DigitalOut &x,DigitalOut &r);
00072     /**
00073     * function that initialises the values for the main positions
00074     * it initialises all the array alien x and y positions
00075     * sets no bullets bool on the screen and disp to true
00076     */
00077     void init();
00078     /**
00079     * main draw function that draws all the component of the game
00080     * it also clears some aliens and bullets pixels for improving appearance
00081     * @param lcd for drawing into the screen
00082     */
00083     void draw(N5110 &lcd);
00084     /**
00085     * checks if the palyers bullet hits any alien
00086     * checks if any alien bullet hits player
00087     */
00088     void touch();
00089     /**
00090     * function that switches only the same number of leds on as the same number of lifes
00091     * the player still have left
00092     * @param pad controls leds
00093     */
00094     void leds(Gamepad &pad);
00095     /**
00096     * function that moves 1 pixel the y alien position.Ready for being used by a ticker in the main file
00097     * in this way the aliens will move one pixel per second
00098     */
00099     void move();
00100     /**
00101     * checks if any alien alive arrived to the players height(in this way it will kill the player)
00102     * @returns true if any alien reached the players position
00103     * @returns false if not
00104     */
00105     bool destruction();
00106     /**
00107     * generates aliens bullet if no bullet in the screen (by checking alienbullet variables)
00108     * randomly generated bullets
00109     */
00110     void auxiliar();
00111     /**
00112     * @return die if dead variable is true
00113     */
00114     /** 
00115     * @returns score
00116     */
00117     int score ();
00118     /**
00119     * @returns true if dead
00120     * @returns false if not dead
00121     */
00122     bool die ();
00123 
00124     int _lifes, _score;
00125 
00126 // bools for knowing if there is any bullet of that type in the screen
00127     bool _bulletcheck,_alienbullet0,_alienbullet1,_alienbullet2;
00128 //bools for knowing if it died or for knowing if that alien whre the bullet was gona come out is alive or not
00129     bool _dead;
00130 
00131 
00132 
00133 //i recon here I could have used an structure bu i completely forgot about it
00134     int _alienXsmall[11];
00135     int _alienXmedium[9];
00136     int _alienXbig[7];
00137     int _alienYsmall[11];
00138     int _alienYmedium[9];
00139     int _alienYbig[7];
00140 //for printing score in the screen
00141     char _buffer[20];
00142     alienbullet _bullet0,_bullet1,_bullet2;
00143     posplayer _spacecraft;
00144     posbullet _bullet;
00145 
00146 };
00147 #endif