A simple one-level platform game. Developed as part of ELEC2645 at University of Leeds, spring 2015.

Dependencies:   N5110 PinDetect PowerControl mbed

An ARM mbed LPC1768 microcontroller have been used to develop a handheld arcade game in the style of an old-school platformer. This project is entirely my own independent work in all stages of the development; including design, defining project specifications, breadboard prototyping, schematic and PCB layout using CAD, assembly, testing and software development. Due to this being part of the ELEC2645 Embedded Systems Project module at University of Leeds, spring 2015, limitations were given on the available hardware components. Credit is due to the authors of the dependent libraries (N5110, Pin Detect, PowerControl and mbed). I would also like to thank the author of Game Programming Patterns as well as the authors of SFML Game Development for providing me with useful sources for programming design patterns.

/media/uploads/Siriagus/game_assembled.jpg

Project aims

  • Implement simple gameplay:
    • A single, fixed (no scrolling) level.
    • Player can move left to right, jump and shoot.
    • Enemies will drop from the top of the screen.
    • The player gets points for shooting enemies.
    • The player dies when it gets hits by an enemy.
  • Implement a simple menu system.
  • Enable the user to adjust the brightness of the display.
  • Output sound to enhance the user experience.

Software

The program flow is controlled by a finite state machine. The implemented design was inspired by the State design pattern from the books Game Programming Patterns and SFML Game Development. The StateManager class is responsible for updating and rendering the current selected state. It also changes the state based on request from the current state. The framework built for the state machine used in this project makes it easy to add new screens. The different main states (indicated by the background colour) and how the user interaction is shown below: /media/uploads/Siriagus/arcadegameuserinteraction.png

Hardware

Schematic:

/media/uploads/Siriagus/schematic.png

Printed circuit board (PCB):

/media/uploads/Siriagus/pcb.png

Images

A seperate program was written to convert images (png) to text-representation of the maps. Enemies and numbers on the screen are also collected from a sprite-sheet created in the same manner.

/media/uploads/Siriagus/unileeds3.png /media/uploads/Siriagus/newmap2.png

Committer:
Siriagus
Date:
Sat May 09 13:56:14 2015 +0000
Revision:
13:7ab71c7c311b
Parent:
10:f2488a0ecab7
Child:
14:b4fed570abaf
Expanded functionallity of drawImage - inverse, flipX, flipY. Collision test for all entities. Added simple enemy.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Siriagus 0:1f92de30d43e 1 /**
Siriagus 10:f2488a0ecab7 2 * @file main.cpp
Siriagus 10:f2488a0ecab7 3 * @brief Simple platform game developed for ELEC2645 Embedded Systems Project at University of Leeds
Siriagus 10:f2488a0ecab7 4 * @author Andreas Garmannslund
Siriagus 10:f2488a0ecab7 5 */
Siriagus 0:1f92de30d43e 6
Siriagus 0:1f92de30d43e 7 #include "mbed.h"
Siriagus 0:1f92de30d43e 8 #include "N5110.h"
Siriagus 1:0cfe2255092a 9 #include "PowerControl.h"
Siriagus 1:0cfe2255092a 10 #include "PinDetect.h"
Siriagus 4:d6661b976359 11 #include <string>
Siriagus 7:678873947b29 12 #include <sstream>
Siriagus 4:d6661b976359 13 #include <ctime>
Siriagus 1:0cfe2255092a 14
Siriagus 0:1f92de30d43e 15 #include "Joystick.h"
Siriagus 1:0cfe2255092a 16
Siriagus 5:100d960fc6d5 17 #include "StateManager.h"
Siriagus 1:0cfe2255092a 18 #include "State.h"
Siriagus 1:0cfe2255092a 19 #include "images.h"
Siriagus 4:d6661b976359 20 #include "InputManager.h"
Siriagus 1:0cfe2255092a 21
Siriagus 4:d6661b976359 22
Siriagus 0:1f92de30d43e 23
Siriagus 1:0cfe2255092a 24 // Redefine pin names for simple access.
Siriagus 1:0cfe2255092a 25 #define JOY_H p17
Siriagus 1:0cfe2255092a 26 #define JOY_V p16
Siriagus 1:0cfe2255092a 27 #define JOY_BTN p15
Siriagus 1:0cfe2255092a 28
Siriagus 1:0cfe2255092a 29 #define LED_POT p20
Siriagus 1:0cfe2255092a 30
Siriagus 2:0ae5ac8b0cac 31 #define BUTTON_A p28
Siriagus 2:0ae5ac8b0cac 32 #define BUTTON_B p27
Siriagus 1:0cfe2255092a 33 #define BUTTON_C p29
Siriagus 1:0cfe2255092a 34
Siriagus 4:d6661b976359 35 // Input and Output
Siriagus 10:f2488a0ecab7 36 N5110 *lcd; /// Display
Siriagus 4:d6661b976359 37
Siriagus 10:f2488a0ecab7 38 InputManager *input; /// Responsible for managing user input
Siriagus 4:d6661b976359 39
Siriagus 0:1f92de30d43e 40 // Brightness potentiometer
Siriagus 1:0cfe2255092a 41 AnalogIn ledPot(LED_POT);
Siriagus 0:1f92de30d43e 42
Siriagus 0:1f92de30d43e 43 // Debugging
Siriagus 0:1f92de30d43e 44 BusOut leds(LED1, LED2, LED3, LED4);
Siriagus 0:1f92de30d43e 45
Siriagus 10:f2488a0ecab7 46 void init(); /// Set up initial variables
Siriagus 10:f2488a0ecab7 47 void cleanUp(); /// Frees remaining allocated memory
Siriagus 1:0cfe2255092a 48
Siriagus 5:100d960fc6d5 49 StateManager* fsm;
Siriagus 5:100d960fc6d5 50
Siriagus 1:0cfe2255092a 51 int main()
Siriagus 1:0cfe2255092a 52 {
Siriagus 1:0cfe2255092a 53 init();
Siriagus 1:0cfe2255092a 54
Siriagus 7:678873947b29 55 Timer timer;
Siriagus 7:678873947b29 56 timer.start();
Siriagus 4:d6661b976359 57
Siriagus 0:1f92de30d43e 58 while(true)
Siriagus 7:678873947b29 59 {
Siriagus 8:9ac6a428fa26 60 // We need to call Sleep() repeatedly, because periodic interrupts in InputManager will cause it to wake up every 20 ms.
Siriagus 8:9ac6a428fa26 61 while (timer.read() < 0.08)
Siriagus 8:9ac6a428fa26 62 Sleep();
Siriagus 8:9ac6a428fa26 63
Siriagus 7:678873947b29 64 // update
Siriagus 0:1f92de30d43e 65 lcd->setBrightness(1.0 - ledPot); // Update brightness of screen
Siriagus 7:678873947b29 66 fsm->update(timer.read());
Siriagus 7:678873947b29 67 input->joystick->update();
Siriagus 4:d6661b976359 68
Siriagus 4:d6661b976359 69 // render
Siriagus 5:100d960fc6d5 70 lcd->clear();
Siriagus 7:678873947b29 71 fsm->render();
Siriagus 5:100d960fc6d5 72 lcd->refresh();
Siriagus 1:0cfe2255092a 73
Siriagus 7:678873947b29 74 fsm->processRequest(); // Change the state if requested.
Siriagus 7:678873947b29 75
Siriagus 7:678873947b29 76 timer.reset();
Siriagus 0:1f92de30d43e 77 }
Siriagus 0:1f92de30d43e 78
Siriagus 10:f2488a0ecab7 79 cleanUp(); // Not really reached as the program never terminates. Added for completeness.
Siriagus 0:1f92de30d43e 80
Siriagus 0:1f92de30d43e 81 return 0;
Siriagus 3:4e3f342a135c 82 }
Siriagus 3:4e3f342a135c 83
Siriagus 3:4e3f342a135c 84 void init()
Siriagus 3:4e3f342a135c 85 {
Siriagus 3:4e3f342a135c 86 // Init LCD
Siriagus 3:4e3f342a135c 87 lcd = new N5110(p7, p8, p9, p10, p11, p13, p26);
Siriagus 3:4e3f342a135c 88 lcd->init();
Siriagus 3:4e3f342a135c 89 lcd->normalMode();
Siriagus 3:4e3f342a135c 90 lcd->setBrightness(1.0 - ledPot); // Update brightness of screen
Siriagus 3:4e3f342a135c 91
Siriagus 4:d6661b976359 92 // Input
Siriagus 8:9ac6a428fa26 93 input = new InputManager(BUTTON_A, BUTTON_B, BUTTON_C, JOY_H, JOY_V, JOY_BTN);
Siriagus 3:4e3f342a135c 94
Siriagus 8:9ac6a428fa26 95 fsm = new StateManager(lcd, input, TITLE_SCREEN);
Siriagus 3:4e3f342a135c 96 }
Siriagus 3:4e3f342a135c 97
Siriagus 3:4e3f342a135c 98 void cleanUp()
Siriagus 3:4e3f342a135c 99 {
Siriagus 3:4e3f342a135c 100 delete lcd;
Siriagus 4:d6661b976359 101 delete input;
Siriagus 1:0cfe2255092a 102 }