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 17:d6a3b29cab31 1 /// @file SubmitHighscore.cpp
Siriagus 17:d6a3b29cab31 2
Siriagus 17:d6a3b29cab31 3 #include "SubmitHighscore.h"
Siriagus 17:d6a3b29cab31 4
Siriagus 17:d6a3b29cab31 5 int SubmitHighscore::letters[3] = {0, 0, 0};
Siriagus 17:d6a3b29cab31 6 int SubmitHighscore::currentState = LETTER1;
Siriagus 17:d6a3b29cab31 7
Siriagus 17:d6a3b29cab31 8 void SubmitHighscore::init()
Siriagus 17:d6a3b29cab31 9 {
Siriagus 17:d6a3b29cab31 10 input->addBtnPressInterrupt(Input::ButtonA, &btnAPress);
Siriagus 17:d6a3b29cab31 11 input->addBtnPressInterrupt(Input::ButtonB, &btnBPress);
Siriagus 17:d6a3b29cab31 12 input->addBtnPressInterrupt(Input::ButtonC, &btnCPress);
Siriagus 17:d6a3b29cab31 13
Siriagus 17:d6a3b29cab31 14 SubmitHighscore::currentState = LETTER1;
Siriagus 17:d6a3b29cab31 15 }
Siriagus 17:d6a3b29cab31 16
Siriagus 17:d6a3b29cab31 17 void SubmitHighscore::changeLetter(int index, bool next)
Siriagus 17:d6a3b29cab31 18 {
Siriagus 17:d6a3b29cab31 19 int letter = (SubmitHighscore::letters[index] + ((next) ? 1 : - 1) + 26) % 26; // + 26 in case it is negative, % => wrap around from Z->A
Siriagus 17:d6a3b29cab31 20 SubmitHighscore::letters[index] = letter;
Siriagus 17:d6a3b29cab31 21 }
Siriagus 17:d6a3b29cab31 22
Siriagus 17:d6a3b29cab31 23 void SubmitHighscore::btnAPress()
Siriagus 17:d6a3b29cab31 24 {
Siriagus 17:d6a3b29cab31 25 switch (currentState)
Siriagus 17:d6a3b29cab31 26 {
Siriagus 17:d6a3b29cab31 27 case LETTER1:
Siriagus 17:d6a3b29cab31 28 changeLetter(0, true);
Siriagus 17:d6a3b29cab31 29 break;
Siriagus 17:d6a3b29cab31 30
Siriagus 17:d6a3b29cab31 31 case LETTER2:
Siriagus 17:d6a3b29cab31 32 changeLetter(1, true);
Siriagus 17:d6a3b29cab31 33 break;
Siriagus 17:d6a3b29cab31 34
Siriagus 17:d6a3b29cab31 35 case LETTER3:
Siriagus 17:d6a3b29cab31 36 changeLetter(2, true);
Siriagus 17:d6a3b29cab31 37 break;
Siriagus 17:d6a3b29cab31 38
Siriagus 17:d6a3b29cab31 39 case SEL_SUBMIT:
Siriagus 17:d6a3b29cab31 40 currentState = WRITE_TO_FILE;
Siriagus 17:d6a3b29cab31 41 break;
Siriagus 17:d6a3b29cab31 42 }
Siriagus 17:d6a3b29cab31 43 }
Siriagus 17:d6a3b29cab31 44
Siriagus 17:d6a3b29cab31 45 void SubmitHighscore::btnBPress()
Siriagus 17:d6a3b29cab31 46 {
Siriagus 17:d6a3b29cab31 47 // Change to previous letter
Siriagus 17:d6a3b29cab31 48 switch (currentState)
Siriagus 17:d6a3b29cab31 49 {
Siriagus 17:d6a3b29cab31 50 case LETTER1:
Siriagus 17:d6a3b29cab31 51 changeLetter(0, false);
Siriagus 17:d6a3b29cab31 52 break;
Siriagus 17:d6a3b29cab31 53
Siriagus 17:d6a3b29cab31 54 case LETTER2:
Siriagus 17:d6a3b29cab31 55 changeLetter(1, false);
Siriagus 17:d6a3b29cab31 56 break;
Siriagus 17:d6a3b29cab31 57
Siriagus 17:d6a3b29cab31 58 case LETTER3:
Siriagus 17:d6a3b29cab31 59 changeLetter(2, false);
Siriagus 17:d6a3b29cab31 60 break;
Siriagus 17:d6a3b29cab31 61 }
Siriagus 17:d6a3b29cab31 62 }
Siriagus 17:d6a3b29cab31 63
Siriagus 17:d6a3b29cab31 64 void SubmitHighscore::btnCPress()
Siriagus 17:d6a3b29cab31 65 {
Siriagus 17:d6a3b29cab31 66 switch (currentState)
Siriagus 17:d6a3b29cab31 67 {
Siriagus 17:d6a3b29cab31 68 case LETTER1:
Siriagus 17:d6a3b29cab31 69 currentState = LETTER2;
Siriagus 17:d6a3b29cab31 70 break;
Siriagus 17:d6a3b29cab31 71
Siriagus 17:d6a3b29cab31 72 case LETTER2:
Siriagus 17:d6a3b29cab31 73 currentState = LETTER3;
Siriagus 17:d6a3b29cab31 74 break;
Siriagus 17:d6a3b29cab31 75
Siriagus 17:d6a3b29cab31 76 case LETTER3:
Siriagus 17:d6a3b29cab31 77 currentState = SEL_SUBMIT;
Siriagus 17:d6a3b29cab31 78 break;
Siriagus 17:d6a3b29cab31 79
Siriagus 17:d6a3b29cab31 80 case SEL_SUBMIT:
Siriagus 17:d6a3b29cab31 81 currentState = LETTER1;
Siriagus 17:d6a3b29cab31 82 break;
Siriagus 17:d6a3b29cab31 83 }
Siriagus 17:d6a3b29cab31 84 }
Siriagus 17:d6a3b29cab31 85
Siriagus 17:d6a3b29cab31 86
Siriagus 17:d6a3b29cab31 87 void SubmitHighscore::update(float dt)
Siriagus 17:d6a3b29cab31 88 {
Siriagus 17:d6a3b29cab31 89 if (currentState == WRITE_TO_FILE)
Siriagus 17:d6a3b29cab31 90 {
Siriagus 17:d6a3b29cab31 91 char s0 = 'A' + static_cast<char>(letters[0]);
Siriagus 17:d6a3b29cab31 92 char s1 = 'A' + static_cast<char>(letters[1]);
Siriagus 17:d6a3b29cab31 93 char s2 = 'A' + static_cast<char>(letters[2]);
Siriagus 17:d6a3b29cab31 94
Siriagus 17:d6a3b29cab31 95 std::stringstream ss;
Siriagus 17:d6a3b29cab31 96 ss << s0 << s1 << s2;
Siriagus 17:d6a3b29cab31 97
Siriagus 17:d6a3b29cab31 98 std::string initials = ss.str();
Siriagus 17:d6a3b29cab31 99
Siriagus 17:d6a3b29cab31 100 // update high score list
Siriagus 17:d6a3b29cab31 101 FILE *fp = fopen("/local/highscores.txt", "w");
Siriagus 17:d6a3b29cab31 102
Siriagus 17:d6a3b29cab31 103 if (Global::score > Global::highscores[0].score)
Siriagus 17:d6a3b29cab31 104 {
Siriagus 17:d6a3b29cab31 105 Global::highscores[2] = Global::highscores[1];
Siriagus 17:d6a3b29cab31 106 Global::highscores[1] = Global::highscores[0];
Siriagus 17:d6a3b29cab31 107 Global::highscores[0].initials = initials;
Siriagus 17:d6a3b29cab31 108 Global::highscores[0].score = Global::score;
Siriagus 17:d6a3b29cab31 109 }
Siriagus 17:d6a3b29cab31 110 else if (Global::score > Global::highscores[1].score)
Siriagus 17:d6a3b29cab31 111 {
Siriagus 17:d6a3b29cab31 112 Global::highscores[2] = Global::highscores[1];
Siriagus 17:d6a3b29cab31 113 Global::highscores[1].initials = initials;
Siriagus 17:d6a3b29cab31 114 Global::highscores[1].score = Global::score;
Siriagus 17:d6a3b29cab31 115 }
Siriagus 17:d6a3b29cab31 116 else if (Global::score > Global::highscores[2].score)
Siriagus 17:d6a3b29cab31 117 {
Siriagus 17:d6a3b29cab31 118 Global::highscores[2].initials = initials;
Siriagus 17:d6a3b29cab31 119 Global::highscores[2].score = Global::score;
Siriagus 17:d6a3b29cab31 120 }
Siriagus 17:d6a3b29cab31 121
Siriagus 17:d6a3b29cab31 122 for (int i = 0; i < 3; ++i)
Siriagus 17:d6a3b29cab31 123 fprintf(fp, "%s %d ", Global::highscores[i].initials, Global::highscores[i].score);
Siriagus 17:d6a3b29cab31 124
Siriagus 17:d6a3b29cab31 125 fclose(fp);
Siriagus 17:d6a3b29cab31 126
Siriagus 17:d6a3b29cab31 127 currentState = LOAD_GAME_OVER;
Siriagus 17:d6a3b29cab31 128 }
Siriagus 17:d6a3b29cab31 129
Siriagus 17:d6a3b29cab31 130 if (currentState == LOAD_GAME_OVER)
Siriagus 17:d6a3b29cab31 131 requestStateChange(GAME_OVER);
Siriagus 17:d6a3b29cab31 132 }
Siriagus 17:d6a3b29cab31 133
Siriagus 17:d6a3b29cab31 134 void SubmitHighscore::render()
Siriagus 17:d6a3b29cab31 135 {
Siriagus 17:d6a3b29cab31 136 if (currentState == WRITE_TO_FILE)
Siriagus 17:d6a3b29cab31 137 {
Siriagus 17:d6a3b29cab31 138 lcd->printString("Writing...", 12, 2);
Siriagus 17:d6a3b29cab31 139 }
Siriagus 17:d6a3b29cab31 140 else // Entering initials
Siriagus 17:d6a3b29cab31 141 {
Siriagus 17:d6a3b29cab31 142 lcd->printString("New high score!", 0, 0);
Siriagus 17:d6a3b29cab31 143
Siriagus 17:d6a3b29cab31 144 const char charLetters[6] = {'A' + letters[0], '\0', 'A' + letters[1], '\0', 'A' + letters[2], '\0'};
Siriagus 17:d6a3b29cab31 145
Siriagus 17:d6a3b29cab31 146 lcd->printString(&charLetters[0], 25, 2);
Siriagus 17:d6a3b29cab31 147 lcd->printString(&charLetters[2], 40, 2);
Siriagus 17:d6a3b29cab31 148 lcd->printString(&charLetters[4], 55, 2);
Siriagus 17:d6a3b29cab31 149 lcd->printString("Submit", 25, 4);
Siriagus 17:d6a3b29cab31 150
Siriagus 17:d6a3b29cab31 151 switch(currentState)
Siriagus 17:d6a3b29cab31 152 {
Siriagus 17:d6a3b29cab31 153 case LETTER1:
Siriagus 17:d6a3b29cab31 154 lcd->printString("^", 25, 3);
Siriagus 17:d6a3b29cab31 155 break;
Siriagus 17:d6a3b29cab31 156
Siriagus 17:d6a3b29cab31 157 case LETTER2:
Siriagus 17:d6a3b29cab31 158 lcd->printString("^", 40, 3);
Siriagus 17:d6a3b29cab31 159 break;
Siriagus 17:d6a3b29cab31 160
Siriagus 17:d6a3b29cab31 161 case LETTER3:
Siriagus 17:d6a3b29cab31 162 lcd->printString("^", 55, 3);
Siriagus 17:d6a3b29cab31 163 break;
Siriagus 17:d6a3b29cab31 164
Siriagus 17:d6a3b29cab31 165 case SEL_SUBMIT:
Siriagus 17:d6a3b29cab31 166 lcd->printString(">",25-6 , 4);
Siriagus 17:d6a3b29cab31 167 break;
Siriagus 17:d6a3b29cab31 168 }
Siriagus 18:709ea375b0df 169 }
Siriagus 17:d6a3b29cab31 170 }