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:
12:8178fad5e660
Child:
17:d6a3b29cab31
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 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 13:7ab71c7c311b 46 {
Siriagus 13:7ab71c7c311b 47 for (int i = 0; i < HEIGHT/3; ++i)
Siriagus 13:7ab71c7c311b 48 {
Siriagus 13:7ab71c7c311b 49 drawImage(Image::Cross3, 0, 3*i); // left border
Siriagus 13:7ab71c7c311b 50 drawImage(Image::Cross3, (WIDTH-3), 3*i); // right border
Siriagus 13:7ab71c7c311b 51 }
Siriagus 12:8178fad5e660 52
Siriagus 13:7ab71c7c311b 53 for (int j = 0; j < WIDTH/3; ++j)
Siriagus 13:7ab71c7c311b 54 {
Siriagus 13:7ab71c7c311b 55 drawImage(Image::Cross3, 3 * j, (HEIGHT-3)); // bottom border
Siriagus 13:7ab71c7c311b 56
Siriagus 13:7ab71c7c311b 57 if (currentState != HIGHSCORES && currentState != CONTROLS)
Siriagus 13:7ab71c7c311b 58 drawImage(Image::Cross3, 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 6:edb48de563a9 84 // Placeholder TODO: Actually high scores
Siriagus 13:7ab71c7c311b 85 lcd->printString("High Scores", xMargin, 0);
Siriagus 13:7ab71c7c311b 86 lcd->printString("AND 1000000", xMargin, 1);
Siriagus 13:7ab71c7c311b 87 lcd->printString("AND 500000", xMargin, 2);
Siriagus 13:7ab71c7c311b 88 lcd->printString("AND 100", xMargin, 3);
Siriagus 13:7ab71c7c311b 89 lcd->printString(">Back", xMargin, 4);
Siriagus 6:edb48de563a9 90 break;
Siriagus 6:edb48de563a9 91
Siriagus 6:edb48de563a9 92 case CONTROLS:
Siriagus 13:7ab71c7c311b 93 lcd->printString("Controls", xMargin, 0);
Siriagus 13:7ab71c7c311b 94 lcd->printString("A: Jump", xMargin, 1);
Siriagus 13:7ab71c7c311b 95 lcd->printString("B: Shoot", xMargin, 2);
Siriagus 13:7ab71c7c311b 96 lcd->printString("C: Pause", xMargin, 3);
Siriagus 13:7ab71c7c311b 97 lcd->printString(">Back", xMargin, 4);
Siriagus 6:edb48de563a9 98 break;
Siriagus 6:edb48de563a9 99
Siriagus 6:edb48de563a9 100 case LOAD_GAME:
Siriagus 13:7ab71c7c311b 101 lcd->printString("Loading...", xMargin, 2);
Siriagus 7:678873947b29 102 requestStateChange(GAME);
Siriagus 6:edb48de563a9 103 break;
Siriagus 6:edb48de563a9 104
Siriagus 6:edb48de563a9 105 default:
Siriagus 13:7ab71c7c311b 106 ;
Siriagus 13:7ab71c7c311b 107 //error("MainMenu: Invalid internal state");
Siriagus 6:edb48de563a9 108
Siriagus 6:edb48de563a9 109 }
Siriagus 5:100d960fc6d5 110 }