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:
Mon May 11 04:40:23 2015 +0000
Revision:
18:709ea375b0df
Parent:
17:d6a3b29cab31
Fixed some formatting errors in documentation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Siriagus 5:100d960fc6d5 1 #include "MainMenu.h"
Siriagus 5:100d960fc6d5 2
Siriagus 17:d6a3b29cab31 3 /// @file MainMenu.cpp
Siriagus 17:d6a3b29cab31 4
Siriagus 10:f2488a0ecab7 5 /// States for the Main Menu's internal finite state machine
Siriagus 6:edb48de563a9 6 enum MenuState {SELECT_PLAY, SELECT_HIGHSCORES, SELECT_CONTROLS, LOAD_GAME, HIGHSCORES, CONTROLS};
Siriagus 10:f2488a0ecab7 7
Siriagus 10:f2488a0ecab7 8 /// Static variables for internal fsm.
Siriagus 10:f2488a0ecab7 9
Siriagus 6:edb48de563a9 10 const int MainMenu::MENU_FSM[6][3] = {
Siriagus 6:edb48de563a9 11 {LOAD_GAME, SELECT_PLAY, SELECT_HIGHSCORES}, // State: SELECT_PLAY
Siriagus 6:edb48de563a9 12 {HIGHSCORES, SELECT_HIGHSCORES, SELECT_CONTROLS}, // State: SELECT_HIGHSCORES
Siriagus 6:edb48de563a9 13 {CONTROLS, SELECT_CONTROLS, SELECT_PLAY}, // State: SELECT_CONTROLS
Siriagus 6:edb48de563a9 14 {LOAD_GAME, LOAD_GAME, LOAD_GAME}, // State: LOAD_GAME
Siriagus 6:edb48de563a9 15 {SELECT_HIGHSCORES, SELECT_HIGHSCORES, HIGHSCORES}, // State: HIGHSCORES
Siriagus 6:edb48de563a9 16 {SELECT_CONTROLS, SELECT_CONTROLS, CONTROLS} // State: CONTROLS
Siriagus 6:edb48de563a9 17 };
Siriagus 6:edb48de563a9 18
Siriagus 10:f2488a0ecab7 19 int MainMenu::currentState; /// Current state for the state machine
Siriagus 6:edb48de563a9 20
Siriagus 6:edb48de563a9 21 // Callback functions (needs to be static)
Siriagus 6:edb48de563a9 22 void MainMenu::btnAPress()
Siriagus 6:edb48de563a9 23 {
Siriagus 6:edb48de563a9 24 currentState = MENU_FSM[currentState][0];
Siriagus 6:edb48de563a9 25 }
Siriagus 6:edb48de563a9 26
Siriagus 6:edb48de563a9 27 void MainMenu::btnBPress()
Siriagus 6:edb48de563a9 28 {
Siriagus 6:edb48de563a9 29 currentState = MENU_FSM[currentState][1];
Siriagus 6:edb48de563a9 30 }
Siriagus 6:edb48de563a9 31
Siriagus 6:edb48de563a9 32 void MainMenu::btnCPress()
Siriagus 6:edb48de563a9 33 {
Siriagus 6:edb48de563a9 34 currentState = MENU_FSM[currentState][2];
Siriagus 6:edb48de563a9 35 }
Siriagus 6:edb48de563a9 36
Siriagus 5:100d960fc6d5 37 void MainMenu::init()
Siriagus 5:100d960fc6d5 38 {
Siriagus 6:edb48de563a9 39 MainMenu::currentState = SELECT_PLAY;
Siriagus 10:f2488a0ecab7 40 input->addBtnPressInterrupt(Input::ButtonA, &btnAPress);
Siriagus 10:f2488a0ecab7 41 input->addBtnPressInterrupt(Input::ButtonB, &btnBPress);
Siriagus 10:f2488a0ecab7 42 input->addBtnPressInterrupt(Input::ButtonC, &btnCPress);
Siriagus 5:100d960fc6d5 43 }
Siriagus 5:100d960fc6d5 44
Siriagus 10:f2488a0ecab7 45 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 46
Siriagus 5:100d960fc6d5 47 void MainMenu::render()
Siriagus 13:7ab71c7c311b 48 {
Siriagus 13:7ab71c7c311b 49 for (int i = 0; i < HEIGHT/3; ++i)
Siriagus 13:7ab71c7c311b 50 {
Siriagus 17:d6a3b29cab31 51 drawImage(Image::Pattern3, 0, 3*i); // left border
Siriagus 17:d6a3b29cab31 52 drawImage(Image::Pattern3, (WIDTH-3), 3*i); // right border
Siriagus 13:7ab71c7c311b 53 }
Siriagus 12:8178fad5e660 54
Siriagus 13:7ab71c7c311b 55 for (int j = 0; j < WIDTH/3; ++j)
Siriagus 13:7ab71c7c311b 56 {
Siriagus 17:d6a3b29cab31 57 drawImage(Image::Pattern3, 3 * j, (HEIGHT-3)); // bottom border
Siriagus 17:d6a3b29cab31 58 drawImage(Image::Pattern3, 3 * j, 0); // top border
Siriagus 13:7ab71c7c311b 59 }
Siriagus 13:7ab71c7c311b 60
Siriagus 13:7ab71c7c311b 61 // Check sate
Siriagus 13:7ab71c7c311b 62 int xMargin = 8;
Siriagus 6:edb48de563a9 63 switch (currentState)
Siriagus 6:edb48de563a9 64 {
Siriagus 6:edb48de563a9 65 case SELECT_PLAY:
Siriagus 13:7ab71c7c311b 66 lcd->printString(">Play", xMargin, 1);
Siriagus 13:7ab71c7c311b 67 lcd->printString("High Scores", xMargin, 2);
Siriagus 13:7ab71c7c311b 68 lcd->printString("Controls", xMargin, 3);
Siriagus 6:edb48de563a9 69 break;
Siriagus 6:edb48de563a9 70
Siriagus 6:edb48de563a9 71 case SELECT_HIGHSCORES:
Siriagus 13:7ab71c7c311b 72 lcd->printString("Play", xMargin, 1);
Siriagus 13:7ab71c7c311b 73 lcd->printString(">High Scores", xMargin, 2);
Siriagus 13:7ab71c7c311b 74 lcd->printString("Controls", xMargin, 3);
Siriagus 6:edb48de563a9 75 break;
Siriagus 6:edb48de563a9 76
Siriagus 6:edb48de563a9 77 case SELECT_CONTROLS:
Siriagus 13:7ab71c7c311b 78 lcd->printString("Play", xMargin, 1);
Siriagus 13:7ab71c7c311b 79 lcd->printString("High Scores", xMargin, 2);
Siriagus 13:7ab71c7c311b 80 lcd->printString(">Controls", xMargin, 3);
Siriagus 6:edb48de563a9 81 break;
Siriagus 6:edb48de563a9 82
Siriagus 6:edb48de563a9 83 case HIGHSCORES:
Siriagus 17:d6a3b29cab31 84
Siriagus 17:d6a3b29cab31 85 for (int i = 0; i < 3; ++i)
Siriagus 17:d6a3b29cab31 86 {
Siriagus 17:d6a3b29cab31 87 std::stringstream ss;
Siriagus 17:d6a3b29cab31 88 ss << Global::highscores[i].initials << " " << Global::highscores[i].score;
Siriagus 17:d6a3b29cab31 89 lcd->printString(ss.str().c_str(), xMargin, i+1);
Siriagus 17:d6a3b29cab31 90 }
Siriagus 17:d6a3b29cab31 91
Siriagus 17:d6a3b29cab31 92
Siriagus 13:7ab71c7c311b 93 lcd->printString(">Back", xMargin, 4);
Siriagus 6:edb48de563a9 94 break;
Siriagus 6:edb48de563a9 95
Siriagus 6:edb48de563a9 96 case CONTROLS:
Siriagus 13:7ab71c7c311b 97 lcd->printString("A: Jump", xMargin, 1);
Siriagus 13:7ab71c7c311b 98 lcd->printString("B: Shoot", xMargin, 2);
Siriagus 13:7ab71c7c311b 99 lcd->printString("C: Pause", xMargin, 3);
Siriagus 13:7ab71c7c311b 100 lcd->printString(">Back", xMargin, 4);
Siriagus 6:edb48de563a9 101 break;
Siriagus 6:edb48de563a9 102
Siriagus 6:edb48de563a9 103 case LOAD_GAME:
Siriagus 13:7ab71c7c311b 104 lcd->printString("Loading...", xMargin, 2);
Siriagus 7:678873947b29 105 requestStateChange(GAME);
Siriagus 6:edb48de563a9 106 break;
Siriagus 6:edb48de563a9 107
Siriagus 6:edb48de563a9 108 default:
Siriagus 13:7ab71c7c311b 109 ;
Siriagus 13:7ab71c7c311b 110 //error("MainMenu: Invalid internal state");
Siriagus 6:edb48de563a9 111
Siriagus 6:edb48de563a9 112 }
Siriagus 5:100d960fc6d5 113 }