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:
Thu May 21 13:54:14 2020 +0000
Revision:
19:33c77517cb88
Parent:
18:c600a6545e81
Child:
20:6db651a3cfec
highscore saving and reading from sd card, more testing and better area for collisions based on sprute size;

Who changed what in which revision?

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