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:
Fri May 01 09:44:38 2015 +0000
Revision:
6:edb48de563a9
Parent:
5:100d960fc6d5
Child:
7:678873947b29
Implemented MainMenu in new finite state machine. Implemented internal fsm in MainMenu.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Siriagus 0:1f92de30d43e 1 /**
Siriagus 0:1f92de30d43e 2 @brief Simple platform game developed for ELEC2645 Embedded Systems Project at University of Leeds
Siriagus 0:1f92de30d43e 3
Siriagus 0:1f92de30d43e 4 @author Andreas Garmannslund
Siriagus 0:1f92de30d43e 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 4:d6661b976359 12 #include <ctime>
Siriagus 1:0cfe2255092a 13
Siriagus 0:1f92de30d43e 14 #include "Joystick.h"
Siriagus 1:0cfe2255092a 15
Siriagus 5:100d960fc6d5 16 #include "StateManager.h"
Siriagus 1:0cfe2255092a 17 #include "State.h"
Siriagus 1:0cfe2255092a 18 #include "images.h"
Siriagus 4:d6661b976359 19 #include "InputManager.h"
Siriagus 1:0cfe2255092a 20
Siriagus 4:d6661b976359 21
Siriagus 0:1f92de30d43e 22
Siriagus 1:0cfe2255092a 23 // Redefine pin names for simple access.
Siriagus 1:0cfe2255092a 24 #define JOY_H p17
Siriagus 1:0cfe2255092a 25 #define JOY_V p16
Siriagus 1:0cfe2255092a 26 #define JOY_BTN p15
Siriagus 1:0cfe2255092a 27
Siriagus 1:0cfe2255092a 28 #define LED_POT p20
Siriagus 1:0cfe2255092a 29
Siriagus 2:0ae5ac8b0cac 30 #define BUTTON_A p28
Siriagus 2:0ae5ac8b0cac 31 #define BUTTON_B p27
Siriagus 1:0cfe2255092a 32 #define BUTTON_C p29
Siriagus 1:0cfe2255092a 33
Siriagus 4:d6661b976359 34 // Input and Output
Siriagus 0:1f92de30d43e 35 N5110 *lcd; // VCC, SCE, RST, D/C, MOSI, SCLK and LED
Siriagus 4:d6661b976359 36
Siriagus 4:d6661b976359 37 InputManager *input;
Siriagus 4:d6661b976359 38
Siriagus 0:1f92de30d43e 39 // Brightness potentiometer
Siriagus 1:0cfe2255092a 40 AnalogIn ledPot(LED_POT);
Siriagus 0:1f92de30d43e 41
Siriagus 0:1f92de30d43e 42 // Debugging
Siriagus 0:1f92de30d43e 43 Serial pc(USBTX, USBRX);
Siriagus 0:1f92de30d43e 44 BusOut leds(LED1, LED2, LED3, LED4);
Siriagus 0:1f92de30d43e 45
Siriagus 1:0cfe2255092a 46 // @brief Clears the screen and fill it with the image in the argument.
Siriagus 1:0cfe2255092a 47 void clearAndDrawImage(const int img[BANKS][WIDTH])
Siriagus 0:1f92de30d43e 48 {
Siriagus 0:1f92de30d43e 49 for (int i = 0; i < BANKS; ++i)
Siriagus 0:1f92de30d43e 50 {
Siriagus 0:1f92de30d43e 51 for (int j = 0; j < WIDTH; ++j)
Siriagus 0:1f92de30d43e 52 {
Siriagus 1:0cfe2255092a 53 lcd->buffer[j][i] = img[i][j];
Siriagus 0:1f92de30d43e 54 }
Siriagus 0:1f92de30d43e 55 }
Siriagus 0:1f92de30d43e 56 lcd->refresh();
Siriagus 0:1f92de30d43e 57 }
Siriagus 0:1f92de30d43e 58
Siriagus 2:0ae5ac8b0cac 59 // States
Siriagus 2:0ae5ac8b0cac 60
Siriagus 3:4e3f342a135c 61
Siriagus 1:0cfe2255092a 62
Siriagus 2:0ae5ac8b0cac 63
Siriagus 3:4e3f342a135c 64 void init();
Siriagus 3:4e3f342a135c 65 void cleanUp();
Siriagus 1:0cfe2255092a 66
Siriagus 5:100d960fc6d5 67 StateManager* fsm;
Siriagus 5:100d960fc6d5 68
Siriagus 1:0cfe2255092a 69 int main()
Siriagus 1:0cfe2255092a 70 {
Siriagus 1:0cfe2255092a 71 init();
Siriagus 1:0cfe2255092a 72
Siriagus 4:d6661b976359 73 time_t dt = time(NULL);
Siriagus 4:d6661b976359 74
Siriagus 0:1f92de30d43e 75 while(true)
Siriagus 0:1f92de30d43e 76 {
Siriagus 5:100d960fc6d5 77
Siriagus 4:d6661b976359 78 input->joystick->update();
Siriagus 0:1f92de30d43e 79 lcd->setBrightness(1.0 - ledPot); // Update brightness of screen
Siriagus 0:1f92de30d43e 80
Siriagus 4:d6661b976359 81 // update
Siriagus 5:100d960fc6d5 82 fsm->update(dt);
Siriagus 4:d6661b976359 83
Siriagus 4:d6661b976359 84 // render
Siriagus 5:100d960fc6d5 85 lcd->clear();
Siriagus 5:100d960fc6d5 86 fsm->render();
Siriagus 5:100d960fc6d5 87 lcd->refresh();
Siriagus 1:0cfe2255092a 88
Siriagus 2:0ae5ac8b0cac 89 Sleep();
Siriagus 0:1f92de30d43e 90 }
Siriagus 0:1f92de30d43e 91
Siriagus 1:0cfe2255092a 92 cleanUp();
Siriagus 0:1f92de30d43e 93
Siriagus 0:1f92de30d43e 94 return 0;
Siriagus 3:4e3f342a135c 95 }
Siriagus 3:4e3f342a135c 96
Siriagus 4:d6661b976359 97 void ledToggle()
Siriagus 4:d6661b976359 98 {
Siriagus 4:d6661b976359 99 leds[0] = !leds[0];
Siriagus 4:d6661b976359 100 }
Siriagus 4:d6661b976359 101
Siriagus 4:d6661b976359 102 int ctr = 0;
Siriagus 4:d6661b976359 103 void ledToggle4() {leds[3] = !leds[3];}
Siriagus 4:d6661b976359 104 void ledToggle2()
Siriagus 4:d6661b976359 105 {
Siriagus 4:d6661b976359 106 leds[1] = !leds[1];
Siriagus 4:d6661b976359 107
Siriagus 4:d6661b976359 108 if (++ctr > 4)
Siriagus 4:d6661b976359 109 input->addBtnPressInterrupt(input->btnB, ledToggle4);
Siriagus 4:d6661b976359 110
Siriagus 4:d6661b976359 111 }
Siriagus 4:d6661b976359 112
Siriagus 4:d6661b976359 113
Siriagus 4:d6661b976359 114 void ledToggle3() {leds[2] = !leds[2];}
Siriagus 4:d6661b976359 115
Siriagus 3:4e3f342a135c 116 void init()
Siriagus 3:4e3f342a135c 117 {
Siriagus 3:4e3f342a135c 118 // Init LCD
Siriagus 3:4e3f342a135c 119 lcd = new N5110(p7, p8, p9, p10, p11, p13, p26);
Siriagus 3:4e3f342a135c 120 lcd->init();
Siriagus 3:4e3f342a135c 121 lcd->normalMode();
Siriagus 3:4e3f342a135c 122 lcd->setBrightness(1.0 - ledPot); // Update brightness of screen
Siriagus 3:4e3f342a135c 123
Siriagus 4:d6661b976359 124 // Input
Siriagus 4:d6661b976359 125 input = new InputManager(BUTTON_A, BUTTON_B, BUTTON_C, JOY_V, JOY_H, JOY_BTN);
Siriagus 6:edb48de563a9 126 //input->addBtnPressInterrupt(input->btnA, ledToggle);
Siriagus 6:edb48de563a9 127 // input->addBtnPressInterrupt(input->btnB, ledToggle2);
Siriagus 6:edb48de563a9 128 //input->addBtnPressInterrupt(input->btnC, ledToggle3);
Siriagus 3:4e3f342a135c 129
Siriagus 5:100d960fc6d5 130 fsm = new StateManager(lcd, input);
Siriagus 5:100d960fc6d5 131 fsm->changeState(MAIN_MENU);
Siriagus 3:4e3f342a135c 132 }
Siriagus 3:4e3f342a135c 133
Siriagus 3:4e3f342a135c 134 void cleanUp()
Siriagus 3:4e3f342a135c 135 {
Siriagus 3:4e3f342a135c 136 delete lcd;
Siriagus 4:d6661b976359 137 delete input;
Siriagus 1:0cfe2255092a 138 }