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 03:52:18 2015 +0000
Revision:
17:d6a3b29cab31
Parent:
13:7ab71c7c311b
Child:
18:709ea375b0df
Added sound effects ++

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 17:d6a3b29cab31 60 // if (currentState != HIGHSCORES && currentState != CONTROLS)
Siriagus 17:d6a3b29cab31 61
Siriagus 13:7ab71c7c311b 62 }
Siriagus 13:7ab71c7c311b 63
Siriagus 13:7ab71c7c311b 64 // Check sate
Siriagus 13:7ab71c7c311b 65 int xMargin = 8;
Siriagus 6:edb48de563a9 66 switch (currentState)
Siriagus 6:edb48de563a9 67 {
Siriagus 6:edb48de563a9 68 case SELECT_PLAY:
Siriagus 13:7ab71c7c311b 69 lcd->printString(">Play", xMargin, 1);
Siriagus 13:7ab71c7c311b 70 lcd->printString("High Scores", xMargin, 2);
Siriagus 13:7ab71c7c311b 71 lcd->printString("Controls", xMargin, 3);
Siriagus 6:edb48de563a9 72 break;
Siriagus 6:edb48de563a9 73
Siriagus 6:edb48de563a9 74 case SELECT_HIGHSCORES:
Siriagus 13:7ab71c7c311b 75 lcd->printString("Play", xMargin, 1);
Siriagus 13:7ab71c7c311b 76 lcd->printString(">High Scores", xMargin, 2);
Siriagus 13:7ab71c7c311b 77 lcd->printString("Controls", xMargin, 3);
Siriagus 6:edb48de563a9 78 break;
Siriagus 6:edb48de563a9 79
Siriagus 6:edb48de563a9 80 case SELECT_CONTROLS:
Siriagus 13:7ab71c7c311b 81 lcd->printString("Play", xMargin, 1);
Siriagus 13:7ab71c7c311b 82 lcd->printString("High Scores", xMargin, 2);
Siriagus 13:7ab71c7c311b 83 lcd->printString(">Controls", xMargin, 3);
Siriagus 6:edb48de563a9 84 break;
Siriagus 6:edb48de563a9 85
Siriagus 6:edb48de563a9 86 case HIGHSCORES:
Siriagus 17:d6a3b29cab31 87
Siriagus 17:d6a3b29cab31 88 for (int i = 0; i < 3; ++i)
Siriagus 17:d6a3b29cab31 89 {
Siriagus 17:d6a3b29cab31 90 std::stringstream ss;
Siriagus 17:d6a3b29cab31 91 ss << Global::highscores[i].initials << " " << Global::highscores[i].score;
Siriagus 17:d6a3b29cab31 92 lcd->printString(ss.str().c_str(), xMargin, i+1);
Siriagus 17:d6a3b29cab31 93 }
Siriagus 17:d6a3b29cab31 94
Siriagus 17:d6a3b29cab31 95
Siriagus 13:7ab71c7c311b 96 lcd->printString(">Back", xMargin, 4);
Siriagus 6:edb48de563a9 97 break;
Siriagus 6:edb48de563a9 98
Siriagus 6:edb48de563a9 99 case CONTROLS:
Siriagus 13:7ab71c7c311b 100 lcd->printString("A: Jump", xMargin, 1);
Siriagus 13:7ab71c7c311b 101 lcd->printString("B: Shoot", xMargin, 2);
Siriagus 13:7ab71c7c311b 102 lcd->printString("C: Pause", xMargin, 3);
Siriagus 13:7ab71c7c311b 103 lcd->printString(">Back", xMargin, 4);
Siriagus 6:edb48de563a9 104 break;
Siriagus 6:edb48de563a9 105
Siriagus 6:edb48de563a9 106 case LOAD_GAME:
Siriagus 13:7ab71c7c311b 107 lcd->printString("Loading...", xMargin, 2);
Siriagus 7:678873947b29 108 requestStateChange(GAME);
Siriagus 6:edb48de563a9 109 break;
Siriagus 6:edb48de563a9 110
Siriagus 6:edb48de563a9 111 default:
Siriagus 13:7ab71c7c311b 112 ;
Siriagus 13:7ab71c7c311b 113 //error("MainMenu: Invalid internal state");
Siriagus 6:edb48de563a9 114
Siriagus 6:edb48de563a9 115 }
Siriagus 5:100d960fc6d5 116 }