Joe Body 201215898

Dependencies:   mbed

Navigation

  • From the Main Menu the A button will take you into one of the play, highscore or instructions options.
  • The B button will return you to the Main Menu from either the highscore or instruction screens, though this is prompted on screen.
  • When in the Main Menu Pot1 can be used to adjust the contrast and the volume control by the speaker is active.
  • When the game is over the B button can be used to return to the Main Menu, again this is prompted.
  • To return to the Main Menu while the game is being played the reset button must be pressed, this will not save your score or anything about the game.

In Game

  • While in the game the A button is used to shoot while you aim with the Joystick.
  • You have control over the cross while the objective of the game is to rack up as many points shooting the moving head.
  • There is a slight reload time on each shot so you are unable to spam A if you miss.
  • Once you miss 6 times the game will end and your score will be saved.
  • When hit by a falling spike the game will transition and the head will vanish.
  • 4 new spikes will spawn which you need to avoid, being hit by 1 of these will decrease your remaining miss chances by 5.
  • When the game is in this state you must avoid these spikes by tilting the device, the Joystick will have no effect.
  • The head will move progressively faster as the game goes on, make use of the clock power up by shooting it when it appears, this will slow the head down to a more manageable level hopefully helping you to reach a higher score.

Highscore

  • If you have a SD card inserted into the device the game can save your highest score.
  • A decent score is somewhere around 25.
Committer:
el18jgb
Date:
Sun May 24 11:24:57 2020 +0000
Revision:
23:0e8155320571
Parent:
21:a0f3651f56c4
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18jgb 13:cfdfe60a2327 1 #include "Heston.h"
el18jgb 13:cfdfe60a2327 2
el18jgb 21:a0f3651f56c4 3
el18jgb 21:a0f3651f56c4 4
el18jgb 21:a0f3651f56c4 5 const int hest [11][11] =
el18jgb 13:cfdfe60a2327 6 {
el18jgb 21:a0f3651f56c4 7 {0,0,1,1,1,1,1,1,1,0,0},//any resemblance to the celebrity chef is purely coincidental...honestly
el18jgb 21:a0f3651f56c4 8 {0,1,0,0,0,0,0,0,0,1,0},//other celebrity chefs are available
el18jgb 13:cfdfe60a2327 9 {1,1,1,1,1,1,1,1,1,1,1},
el18jgb 23:0e8155320571 10 {1,0,1,0,1,0,1,0,1,0,1},//unfortunetly i got the lockdown shaved head
el18jgb 23:0e8155320571 11 {1,0,1,1,1,0,1,1,1,0,1},//this is a referance to a mate saying i look like
el18jgb 23:0e8155320571 12 {0,1,0,0,0,1,0,0,0,1,0},//heston with my specs on
el18jgb 13:cfdfe60a2327 13 {0,1,0,0,0,0,0,0,0,1,0},
el18jgb 13:cfdfe60a2327 14 {0,1,0,1,1,1,1,1,0,1,0},
el18jgb 21:a0f3651f56c4 15 {0,1,0,0,1,1,1,0,0,1,0},
el18jgb 13:cfdfe60a2327 16 {0,0,1,0,0,0,0,0,1,0,0},
el18jgb 13:cfdfe60a2327 17 {0,0,0,1,1,1,1,1,0,0,0},
el18jgb 13:cfdfe60a2327 18
el18jgb 13:cfdfe60a2327 19 };
el18jgb 13:cfdfe60a2327 20
el18jgb 13:cfdfe60a2327 21
el18jgb 13:cfdfe60a2327 22 Heston::Heston()
el18jgb 13:cfdfe60a2327 23 {
el18jgb 13:cfdfe60a2327 24
el18jgb 13:cfdfe60a2327 25 }
el18jgb 13:cfdfe60a2327 26
el18jgb 13:cfdfe60a2327 27 Heston::~Heston()
el18jgb 13:cfdfe60a2327 28 {
el18jgb 13:cfdfe60a2327 29
el18jgb 13:cfdfe60a2327 30 }
el18jgb 13:cfdfe60a2327 31
el18jgb 13:cfdfe60a2327 32
el18jgb 13:cfdfe60a2327 33
el18jgb 13:cfdfe60a2327 34
el18jgb 13:cfdfe60a2327 35 void Heston::init()
el18jgb 13:cfdfe60a2327 36 {
el18jgb 21:a0f3651f56c4 37 _y = 24; // middle of the screen
el18jgb 21:a0f3651f56c4 38 _x = 42;
el18jgb 17:18ae81180853 39 _height = 12;
el18jgb 17:18ae81180853 40 _width = 11;
el18jgb 13:cfdfe60a2327 41 score = 0;
el18jgb 21:a0f3651f56c4 42 strike = 6;
el18jgb 13:cfdfe60a2327 43 _speed = 1; // scale is arbitrary, could be changed in future
el18jgb 13:cfdfe60a2327 44 }
el18jgb 13:cfdfe60a2327 45
el18jgb 13:cfdfe60a2327 46 void Heston::draw(N5110 &lcd)
el18jgb 13:cfdfe60a2327 47 {
el18jgb 20:6db651a3cfec 48 // draw sprite
el18jgb 13:cfdfe60a2327 49
el18jgb 21:a0f3651f56c4 50 lcd.drawSprite(_x,_y,11,11,(int*)hest);
el18jgb 13:cfdfe60a2327 51 }
el18jgb 13:cfdfe60a2327 52
el18jgb 13:cfdfe60a2327 53 void Heston::update(Gamepad &pad)
el18jgb 13:cfdfe60a2327 54 {
el18jgb 13:cfdfe60a2327 55
el18jgb 13:cfdfe60a2327 56
el18jgb 13:cfdfe60a2327 57
el18jgb 13:cfdfe60a2327 58 // generate random number between 1 and 8:
el18jgb 20:6db651a3cfec 59 int d = rand() % 8 + 1;
el18jgb 13:cfdfe60a2327 60 //printf("direction = %d\n", d);
el18jgb 13:cfdfe60a2327 61
el18jgb 21:a0f3651f56c4 62 // update x and y value depending on d
el18jgb 13:cfdfe60a2327 63 // North is decrement as origin is at the top-left so decreasing moves up
el18jgb 13:cfdfe60a2327 64 if (d == 1) {
el18jgb 13:cfdfe60a2327 65 _y+=_speed;
el18jgb 13:cfdfe60a2327 66 } else if (d == 2) {
el18jgb 13:cfdfe60a2327 67 _x+=_speed;
el18jgb 13:cfdfe60a2327 68 _y+=_speed;
el18jgb 13:cfdfe60a2327 69 } else if (d == 3) {
el18jgb 13:cfdfe60a2327 70 _x+=_speed;
el18jgb 13:cfdfe60a2327 71 } else if (d == 4) {
el18jgb 13:cfdfe60a2327 72 _x+=_speed;
el18jgb 13:cfdfe60a2327 73 _y-=_speed;
el18jgb 13:cfdfe60a2327 74 } else if (d == 5) {
el18jgb 13:cfdfe60a2327 75 _y-=_speed;
el18jgb 13:cfdfe60a2327 76 } else if (d == 6) {
el18jgb 13:cfdfe60a2327 77 _x-=_speed;
el18jgb 13:cfdfe60a2327 78 _y-=_speed;
el18jgb 13:cfdfe60a2327 79 } else if (d == 7) {
el18jgb 13:cfdfe60a2327 80 _x-=_speed;
el18jgb 13:cfdfe60a2327 81 } else if (d == 8) {
el18jgb 13:cfdfe60a2327 82 _x-=_speed;
el18jgb 13:cfdfe60a2327 83 _y+=_speed;
el18jgb 13:cfdfe60a2327 84 }
el18jgb 13:cfdfe60a2327 85
el18jgb 13:cfdfe60a2327 86 // check the x origin to ensure that the sprite doesn't go off screen
el18jgb 13:cfdfe60a2327 87 if (_x < 1) {
el18jgb 13:cfdfe60a2327 88 _x = 1;
el18jgb 13:cfdfe60a2327 89 }
el18jgb 13:cfdfe60a2327 90 if (_x > 84 - _width - 1) {
el18jgb 13:cfdfe60a2327 91 _x = 84 - _width - 1;
el18jgb 13:cfdfe60a2327 92 }
el18jgb 13:cfdfe60a2327 93 // check the y origin to ensure that the sprite doesn't go off screen
el18jgb 13:cfdfe60a2327 94 if (_y < 1) {
el18jgb 13:cfdfe60a2327 95 _y = 1;
el18jgb 13:cfdfe60a2327 96 }
el18jgb 13:cfdfe60a2327 97 if (_y > 48 - _height - 1) {
el18jgb 13:cfdfe60a2327 98 _y = 48 - _height - 1;
el18jgb 13:cfdfe60a2327 99 }
el18jgb 13:cfdfe60a2327 100 //printf("heston x position = %d\n", _x);
el18jgb 13:cfdfe60a2327 101 //printf("heston y position = %d\n", _y);
el18jgb 13:cfdfe60a2327 102 }
el18jgb 13:cfdfe60a2327 103
el18jgb 13:cfdfe60a2327 104 Vector2D Heston::get_pos() {
el18jgb 13:cfdfe60a2327 105 Vector2D p = {_x,_y};
el18jgb 13:cfdfe60a2327 106 return p;
el18jgb 13:cfdfe60a2327 107 //printf("hest co-ordinates = %d\n", p);
el18jgb 13:cfdfe60a2327 108 }
el18jgb 13:cfdfe60a2327 109
el18jgb 17:18ae81180853 110 void Heston::hit(Gamepad &pad, int x, int y)
el18jgb 13:cfdfe60a2327 111 {
el18jgb 17:18ae81180853 112 int a_x = x;
el18jgb 17:18ae81180853 113 int a_y = y;
el18jgb 13:cfdfe60a2327 114 pad.led(3,1);
el18jgb 13:cfdfe60a2327 115 pad.led(6,1);
el18jgb 13:cfdfe60a2327 116 _x = rand() % 84 + 1;
el18jgb 13:cfdfe60a2327 117 _y = rand() % 48 + 1;
el18jgb 17:18ae81180853 118 if (
el18jgb 17:18ae81180853 119 (a_x >= _x) && //left
el18jgb 17:18ae81180853 120 (a_x <= _x + 10) //right
el18jgb 17:18ae81180853 121 ){
el18jgb 17:18ae81180853 122 _x = a_x *2;
el18jgb 17:18ae81180853 123 if (_x > 84 - _width - 1) {
el18jgb 17:18ae81180853 124 _x = 1;
el18jgb 17:18ae81180853 125 }
el18jgb 17:18ae81180853 126 }
el18jgb 17:18ae81180853 127 if (
el18jgb 20:6db651a3cfec 128 (a_y >= _y) && //top
el18jgb 17:18ae81180853 129 (a_y <= _y + 11) //bottom
el18jgb 17:18ae81180853 130 ){
el18jgb 17:18ae81180853 131 _y = a_y *2;
el18jgb 17:18ae81180853 132 if (_x > 48 - _height- 1) {
el18jgb 17:18ae81180853 133 _x = 1;
el18jgb 17:18ae81180853 134 }
el18jgb 17:18ae81180853 135 }
el18jgb 17:18ae81180853 136
el18jgb 13:cfdfe60a2327 137 score+=1;
el18jgb 13:cfdfe60a2327 138 //printf("new x = %d\n", _x);
el18jgb 13:cfdfe60a2327 139 //printf("new y = %d\n", _y);
el18jgb 13:cfdfe60a2327 140 }
el18jgb 13:cfdfe60a2327 141
el18jgb 13:cfdfe60a2327 142 void Heston::miss(Gamepad &pad)
el18jgb 13:cfdfe60a2327 143 {
el18jgb 13:cfdfe60a2327 144
el18jgb 13:cfdfe60a2327 145 pad.led(1,1);
el18jgb 13:cfdfe60a2327 146 pad.led(4,1);
el18jgb 13:cfdfe60a2327 147 strike-=1;
el18jgb 18:c600a6545e81 148
el18jgb 18:c600a6545e81 149 }
el18jgb 13:cfdfe60a2327 150
el18jgb 18:c600a6545e81 151 void Heston::negfive()
el18jgb 18:c600a6545e81 152 {
el18jgb 21:a0f3651f56c4 153 strike-=5; //for when a spike hits in spike mode
el18jgb 13:cfdfe60a2327 154 }
el18jgb 13:cfdfe60a2327 155
el18jgb 13:cfdfe60a2327 156 int Heston::checkscore()
el18jgb 13:cfdfe60a2327 157 {
el18jgb 13:cfdfe60a2327 158 return score;
el18jgb 13:cfdfe60a2327 159 }
el18jgb 13:cfdfe60a2327 160
el18jgb 13:cfdfe60a2327 161 int Heston::checkstrike()
el18jgb 13:cfdfe60a2327 162 {
el18jgb 13:cfdfe60a2327 163 return strike;
el18jgb 13:cfdfe60a2327 164 }
el18jgb 13:cfdfe60a2327 165
el18jgb 13:cfdfe60a2327 166 void Heston::set_speed(int state)
el18jgb 13:cfdfe60a2327 167 {
el18jgb 13:cfdfe60a2327 168 if (state == 1){
el18jgb 20:6db651a3cfec 169 _speed = (_speed + 1); //increase speed
el18jgb 13:cfdfe60a2327 170 if (_speed == 8){
el18jgb 13:cfdfe60a2327 171 _speed = 7;
el18jgb 13:cfdfe60a2327 172 }
el18jgb 13:cfdfe60a2327 173 }
el18jgb 13:cfdfe60a2327 174 if (state == 0){
el18jgb 21:a0f3651f56c4 175 _speed = (_speed - 3); //decrease speed
el18jgb 13:cfdfe60a2327 176 if (_speed <= 0){
el18jgb 13:cfdfe60a2327 177 _speed = 1;
el18jgb 13:cfdfe60a2327 178 }
el18jgb 13:cfdfe60a2327 179 }
el18jgb 13:cfdfe60a2327 180 }
el18jgb 19:33c77517cb88 181
el18jgb 19:33c77517cb88 182 void Heston::set_pos(int x, int y) {
el18jgb 19:33c77517cb88 183 _x = x;
el18jgb 19:33c77517cb88 184 _y = y;
el18jgb 19:33c77517cb88 185 }