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 08 23:51:26 2015 +0000
Revision:
12:8178fad5e660
Parent:
10:f2488a0ecab7
Child:
13:7ab71c7c311b
Added template drawImage function which can draw images of any dimension.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Siriagus 5:100d960fc6d5 1 #include "MainMenu.h"
Siriagus 5:100d960fc6d5 2
Siriagus 10:f2488a0ecab7 3 /// States for the Main Menu's internal finite state machine
Siriagus 6:edb48de563a9 4 enum MenuState {SELECT_PLAY, SELECT_HIGHSCORES, SELECT_CONTROLS, LOAD_GAME, HIGHSCORES, CONTROLS};
Siriagus 10:f2488a0ecab7 5
Siriagus 10:f2488a0ecab7 6 /// Static variables for internal fsm.
Siriagus 10:f2488a0ecab7 7
Siriagus 6:edb48de563a9 8 const int MainMenu::MENU_FSM[6][3] = {
Siriagus 6:edb48de563a9 9 {LOAD_GAME, SELECT_PLAY, SELECT_HIGHSCORES}, // State: SELECT_PLAY
Siriagus 6:edb48de563a9 10 {HIGHSCORES, SELECT_HIGHSCORES, SELECT_CONTROLS}, // State: SELECT_HIGHSCORES
Siriagus 6:edb48de563a9 11 {CONTROLS, SELECT_CONTROLS, SELECT_PLAY}, // State: SELECT_CONTROLS
Siriagus 6:edb48de563a9 12 {LOAD_GAME, LOAD_GAME, LOAD_GAME}, // State: LOAD_GAME
Siriagus 6:edb48de563a9 13 {SELECT_HIGHSCORES, SELECT_HIGHSCORES, HIGHSCORES}, // State: HIGHSCORES
Siriagus 6:edb48de563a9 14 {SELECT_CONTROLS, SELECT_CONTROLS, CONTROLS} // State: CONTROLS
Siriagus 6:edb48de563a9 15 };
Siriagus 6:edb48de563a9 16
Siriagus 10:f2488a0ecab7 17 int MainMenu::currentState; /// Current state for the state machine
Siriagus 6:edb48de563a9 18
Siriagus 6:edb48de563a9 19 // Callback functions (needs to be static)
Siriagus 6:edb48de563a9 20 void MainMenu::btnAPress()
Siriagus 6:edb48de563a9 21 {
Siriagus 6:edb48de563a9 22 currentState = MENU_FSM[currentState][0];
Siriagus 6:edb48de563a9 23 }
Siriagus 6:edb48de563a9 24
Siriagus 6:edb48de563a9 25 void MainMenu::btnBPress()
Siriagus 6:edb48de563a9 26 {
Siriagus 6:edb48de563a9 27 currentState = MENU_FSM[currentState][1];
Siriagus 6:edb48de563a9 28 }
Siriagus 6:edb48de563a9 29
Siriagus 6:edb48de563a9 30 void MainMenu::btnCPress()
Siriagus 6:edb48de563a9 31 {
Siriagus 6:edb48de563a9 32 currentState = MENU_FSM[currentState][2];
Siriagus 6:edb48de563a9 33 }
Siriagus 6:edb48de563a9 34
Siriagus 5:100d960fc6d5 35 void MainMenu::init()
Siriagus 5:100d960fc6d5 36 {
Siriagus 6:edb48de563a9 37 MainMenu::currentState = SELECT_PLAY;
Siriagus 10:f2488a0ecab7 38 input->addBtnPressInterrupt(Input::ButtonA, &btnAPress);
Siriagus 10:f2488a0ecab7 39 input->addBtnPressInterrupt(Input::ButtonB, &btnBPress);
Siriagus 10:f2488a0ecab7 40 input->addBtnPressInterrupt(Input::ButtonC, &btnCPress);
Siriagus 5:100d960fc6d5 41 }
Siriagus 5:100d960fc6d5 42
Siriagus 10:f2488a0ecab7 43 void MainMenu::update(float dt) {} // Does not do anything as program flow is controlled by interrupts, but needs to be defined as it is a virtual function.
Siriagus 5:100d960fc6d5 44
Siriagus 5:100d960fc6d5 45 void MainMenu::render()
Siriagus 5:100d960fc6d5 46 {
Siriagus 12:8178fad5e660 47 drawImage(Border::DotsColumn, 0, 0);
Siriagus 12:8178fad5e660 48
Siriagus 6:edb48de563a9 49 switch (currentState)
Siriagus 6:edb48de563a9 50 {
Siriagus 6:edb48de563a9 51 case SELECT_PLAY:
Siriagus 6:edb48de563a9 52 lcd->printString(">Play", 10, 1);
Siriagus 6:edb48de563a9 53 lcd->printString("High Scores", 10, 2);
Siriagus 6:edb48de563a9 54 lcd->printString("Controls", 10, 3);
Siriagus 6:edb48de563a9 55 break;
Siriagus 6:edb48de563a9 56
Siriagus 6:edb48de563a9 57 case SELECT_HIGHSCORES:
Siriagus 6:edb48de563a9 58 lcd->printString("Play", 10, 1);
Siriagus 6:edb48de563a9 59 lcd->printString(">High Scores", 10, 2);
Siriagus 6:edb48de563a9 60 lcd->printString("Controls", 10, 3);
Siriagus 6:edb48de563a9 61 break;
Siriagus 6:edb48de563a9 62
Siriagus 6:edb48de563a9 63 case SELECT_CONTROLS:
Siriagus 6:edb48de563a9 64 lcd->printString("Play", 10, 1);
Siriagus 6:edb48de563a9 65 lcd->printString("High Scores", 10, 2);
Siriagus 6:edb48de563a9 66 lcd->printString(">Controls", 10, 3);
Siriagus 6:edb48de563a9 67 break;
Siriagus 6:edb48de563a9 68
Siriagus 6:edb48de563a9 69 case HIGHSCORES:
Siriagus 6:edb48de563a9 70 // Placeholder TODO: Actually high scores
Siriagus 6:edb48de563a9 71 lcd->printString("High Scores", 10, 0);
Siriagus 6:edb48de563a9 72 lcd->printString("AND 1000000", 10, 1);
Siriagus 6:edb48de563a9 73 lcd->printString("AND 500000", 10, 2);
Siriagus 6:edb48de563a9 74 lcd->printString("AND 100", 10, 3);
Siriagus 6:edb48de563a9 75 lcd->printString(">Back", 10, 4);
Siriagus 6:edb48de563a9 76 break;
Siriagus 6:edb48de563a9 77
Siriagus 6:edb48de563a9 78 case CONTROLS:
Siriagus 6:edb48de563a9 79 lcd->printString("Controls", 10, 0);
Siriagus 6:edb48de563a9 80 lcd->printString("A: Jump", 10, 1);
Siriagus 6:edb48de563a9 81 lcd->printString("B: Shoot", 10, 2);
Siriagus 6:edb48de563a9 82 lcd->printString("C: Pause", 10, 3);
Siriagus 6:edb48de563a9 83 lcd->printString(">Back", 10, 4);
Siriagus 6:edb48de563a9 84 break;
Siriagus 6:edb48de563a9 85
Siriagus 6:edb48de563a9 86 case LOAD_GAME:
Siriagus 6:edb48de563a9 87 lcd->printString("Loading...", 10, 2);
Siriagus 7:678873947b29 88 requestStateChange(GAME);
Siriagus 6:edb48de563a9 89 break;
Siriagus 6:edb48de563a9 90
Siriagus 6:edb48de563a9 91 default:
Siriagus 6:edb48de563a9 92 error("MainMenu: Invalid internal state");
Siriagus 6:edb48de563a9 93
Siriagus 6:edb48de563a9 94 }
Siriagus 5:100d960fc6d5 95 }