Game for Leeds University Gamepad for the FRDM-K64F: Game is a RPG Horror Title.

Dependencies:   mbed FATFileSystem

Committer:
rottenegg
Date:
Fri May 10 21:25:27 2019 +0000
Revision:
26:716bcd47f3ca
Parent:
21:f3b0ce18b44f
FINAL_SUBMISSION; ; Changes:; WDplayer: Major Memory Leek fixed related to fclose(); Game_Manager: Tuned Scene Order and Improved Random number generator.; SceneFuctions: Added a Randomly changing Object to Scene 4.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rottenegg 17:7d4d8905b608 1 #ifndef BITMAP_H
rottenegg 17:7d4d8905b608 2 #define BITMAP_H
rottenegg 17:7d4d8905b608 3
rottenegg 17:7d4d8905b608 4 /** Bitmap Class
rottenegg 17:7d4d8905b608 5 @breif A library to load .bmp images to the N5110 LCD
rottenegg 17:7d4d8905b608 6 @breif It works on 1-Bit MONO-Chrome Images only
rottenegg 17:7d4d8905b608 7 @breif Recommended online converter: https://online-converting.com/image/convert2bmp/
rottenegg 17:7d4d8905b608 8 @breif Recommended Size 84x48 pixels 1:1 aspect ratio
rottenegg 17:7d4d8905b608 9
rottenegg 17:7d4d8905b608 10 @author Saad Tayyab
rottenegg 17:7d4d8905b608 11 @date 18th April 2019
rottenegg 17:7d4d8905b608 12
rottenegg 17:7d4d8905b608 13 @code
rottenegg 17:7d4d8905b608 14 //Required Libraries to Work
rottenegg 17:7d4d8905b608 15 #include "Bitmap.h"
rottenegg 17:7d4d8905b608 16 #include "mbed.h"
rottenegg 17:7d4d8905b608 17 #include "SDFileSystem.h"
rottenegg 17:7d4d8905b608 18
rottenegg 17:7d4d8905b608 19 //Define SD card
rottenegg 17:7d4d8905b608 20 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
rottenegg 17:7d4d8905b608 21
rottenegg 21:f3b0ce18b44f 22 //Define LCD Pins
rottenegg 17:7d4d8905b608 23 Bitmap lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
rottenegg 17:7d4d8905b608 24
rottenegg 17:7d4d8905b608 25 int main() {
rottenegg 17:7d4d8905b608 26 //Create Path to Image File
rottenegg 17:7d4d8905b608 27 const char *path;
rottenegg 17:7d4d8905b608 28 path = "/sd/img.bmp";
rottenegg 17:7d4d8905b608 29
rottenegg 17:7d4d8905b608 30 //Intialize the LCD
rottenegg 17:7d4d8905b608 31 lcd.init();
rottenegg 17:7d4d8905b608 32 lcd.clear();
rottenegg 17:7d4d8905b608 33
rottenegg 17:7d4d8905b608 34 //Render the Image using Bitmap
rottenegg 17:7d4d8905b608 35 lcd.renderBMP(path,0,0);
rottenegg 17:7d4d8905b608 36 lcd.refresh();
rottenegg 17:7d4d8905b608 37 }
rottenegg 17:7d4d8905b608 38
rottenegg 17:7d4d8905b608 39 @endcode
rottenegg 17:7d4d8905b608 40 */
rottenegg 17:7d4d8905b608 41
rottenegg 17:7d4d8905b608 42 #include "N5110.h"
rottenegg 17:7d4d8905b608 43 #include <bitset>
rottenegg 17:7d4d8905b608 44 #include <iostream>
rottenegg 17:7d4d8905b608 45
rottenegg 17:7d4d8905b608 46 class Bitmap : public N5110 {
rottenegg 17:7d4d8905b608 47
rottenegg 17:7d4d8905b608 48 public:
rottenegg 17:7d4d8905b608 49 /** Constructor
rottenegg 17:7d4d8905b608 50 * @param sce Pin connected to chip enable for N5110 Constructor
rottenegg 17:7d4d8905b608 51 * @param rst Pin connected to reset for N5110 Constructor
rottenegg 17:7d4d8905b608 52 * @param dc Pin connected to data/command select for N5110 Constructor
rottenegg 17:7d4d8905b608 53 * @param mosi Pin connected to data input for N5110 Constructor
rottenegg 17:7d4d8905b608 54 * @param sclk Pin connected to serial clock for N5110 Constructor
rottenegg 17:7d4d8905b608 55 * @param led Pin connected to LED backlight for N5110 Constructor
rottenegg 17:7d4d8905b608 56 */
rottenegg 17:7d4d8905b608 57 Bitmap(PinName const scePin,
rottenegg 17:7d4d8905b608 58 PinName const rstPin,
rottenegg 17:7d4d8905b608 59 PinName const dcPin,
rottenegg 17:7d4d8905b608 60 PinName const mosiPin,
rottenegg 17:7d4d8905b608 61 PinName const sclkPin,
rottenegg 17:7d4d8905b608 62 PinName const ledPin);
rottenegg 17:7d4d8905b608 63 /** Loads the image into LCD Buffer at desired location on LCD.
rottenegg 17:7d4d8905b608 64 *
rottenegg 17:7d4d8905b608 65 * @param path Pointer to image file location.
rottenegg 21:f3b0ce18b44f 66 * @param x X-location of top left corner of image on LCD.
rottenegg 21:f3b0ce18b44f 67 * @param y Y-location of top left corner of image on LCD.
rottenegg 17:7d4d8905b608 68 *
rottenegg 17:7d4d8905b608 69 */
rottenegg 17:7d4d8905b608 70 void renderBMP(const char *path ,unsigned int const x, unsigned int const y);
rottenegg 17:7d4d8905b608 71 private:
rottenegg 21:f3b0ce18b44f 72 //Private Variables
rottenegg 17:7d4d8905b608 73 unsigned long offbits;
rottenegg 17:7d4d8905b608 74 unsigned long height;
rottenegg 17:7d4d8905b608 75 unsigned long width;
rottenegg 21:f3b0ce18b44f 76 int row; //row counter
rottenegg 21:f3b0ce18b44f 77 int colomn; // colomn counter
rottenegg 21:f3b0ce18b44f 78 //Internal Functions
rottenegg 21:f3b0ce18b44f 79 void readDIB(FILE *bmp); //reads DIB header for image Information
rottenegg 21:f3b0ce18b44f 80 void swapEndian(FILE *bmp, unsigned char *buffer, std::bitset<32> &bits);
rottenegg 21:f3b0ce18b44f 81 void halfLoop(unsigned const int x, unsigned const int y, std::bitset<32> bits); //Skips packing Bits and prints what's left
rottenegg 21:f3b0ce18b44f 82 void fullLoop(unsigned const int x, unsigned const int y, std::bitset<32> bits); //prints full DWORD of image
rottenegg 21:f3b0ce18b44f 83 //Aiding Functions
rottenegg 17:7d4d8905b608 84 void renderDWORD(std::bitset<32> bits , unsigned int const x, unsigned int const y);
rottenegg 21:f3b0ce18b44f 85
rottenegg 17:7d4d8905b608 86 };
rottenegg 17:7d4d8905b608 87
rottenegg 17:7d4d8905b608 88 #endif