Adam Baker 201166301
Dependencies: mbed Gamepad N5110
Blockhead/Blockhead.h@50:9fc8edf722a8, 2019-05-09 (annotated)
- Committer:
- adambakerwa
- Date:
- Thu May 09 12:10:41 2019 +0000
- Revision:
- 50:9fc8edf722a8
- Child:
- 52:beeffd296ea3
Final Submission. I have read and agreed with Statement of Academic Integrity
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adambakerwa | 50:9fc8edf722a8 | 1 | #ifndef RUNNER_H |
adambakerwa | 50:9fc8edf722a8 | 2 | #define RUNNER_H |
adambakerwa | 50:9fc8edf722a8 | 3 | |
adambakerwa | 50:9fc8edf722a8 | 4 | #include "mbed.h" |
adambakerwa | 50:9fc8edf722a8 | 5 | #include "Gamepad.h" |
adambakerwa | 50:9fc8edf722a8 | 6 | #include "N5110.h" |
adambakerwa | 50:9fc8edf722a8 | 7 | #include "Levels.h" |
adambakerwa | 50:9fc8edf722a8 | 8 | #include "Animation.h" |
adambakerwa | 50:9fc8edf722a8 | 9 | |
adambakerwa | 50:9fc8edf722a8 | 10 | |
adambakerwa | 50:9fc8edf722a8 | 11 | /** Blockhead Class |
adambakerwa | 50:9fc8edf722a8 | 12 | * @brief Class for controlling the main mechanics of the Blockhead character |
adambakerwa | 50:9fc8edf722a8 | 13 | * @author Adam P. Baker |
adambakerwa | 50:9fc8edf722a8 | 14 | * @date 9 May 2019 |
adambakerwa | 50:9fc8edf722a8 | 15 | */ |
adambakerwa | 50:9fc8edf722a8 | 16 | class Blockhead |
adambakerwa | 50:9fc8edf722a8 | 17 | { |
adambakerwa | 50:9fc8edf722a8 | 18 | public: |
adambakerwa | 50:9fc8edf722a8 | 19 | /** Constructorn */ |
adambakerwa | 50:9fc8edf722a8 | 20 | Blockhead(); |
adambakerwa | 50:9fc8edf722a8 | 21 | |
adambakerwa | 50:9fc8edf722a8 | 22 | /** Deconstructor */ |
adambakerwa | 50:9fc8edf722a8 | 23 | ~Blockhead(); |
adambakerwa | 50:9fc8edf722a8 | 24 | |
adambakerwa | 50:9fc8edf722a8 | 25 | /** initialises all variables for new game */ |
adambakerwa | 50:9fc8edf722a8 | 26 | void init(); |
adambakerwa | 50:9fc8edf722a8 | 27 | |
adambakerwa | 50:9fc8edf722a8 | 28 | /** initialises variables for continue game (does not intialise level) */ |
adambakerwa | 50:9fc8edf722a8 | 29 | void continue_init(); |
adambakerwa | 50:9fc8edf722a8 | 30 | |
adambakerwa | 50:9fc8edf722a8 | 31 | /** changes level when character reaches side of screen |
adambakerwa | 50:9fc8edf722a8 | 32 | *@returs level blockhead is on (int) |
adambakerwa | 50:9fc8edf722a8 | 33 | */ |
adambakerwa | 50:9fc8edf722a8 | 34 | int next_level(); |
adambakerwa | 50:9fc8edf722a8 | 35 | |
adambakerwa | 50:9fc8edf722a8 | 36 | /** contrlls blockhead depending on position in game, and user input |
adambakerwa | 50:9fc8edf722a8 | 37 | *@param pos struct which contains cordinates and direction of moving platforms |
adambakerwa | 50:9fc8edf722a8 | 38 | *@param N5110 class which controlls lcd screen |
adambakerwa | 50:9fc8edf722a8 | 39 | *@param Gamepad class for working with the gamepad |
adambakerwa | 50:9fc8edf722a8 | 40 | */ |
adambakerwa | 50:9fc8edf722a8 | 41 | void blockhead(Pos pos, N5110 &lcd, Gamepad &pad); |
adambakerwa | 50:9fc8edf722a8 | 42 | |
adambakerwa | 50:9fc8edf722a8 | 43 | /** contrlls blockhead depending on position in game, and user input |
adambakerwa | 50:9fc8edf722a8 | 44 | *@param Gamepad class for working with the gamepad |
adambakerwa | 50:9fc8edf722a8 | 45 | *@returns gameover (0 when alive, 1 once died) (int) |
adambakerwa | 50:9fc8edf722a8 | 46 | */ |
adambakerwa | 50:9fc8edf722a8 | 47 | int gameover_flag(Gamepad &pad); |
adambakerwa | 50:9fc8edf722a8 | 48 | |
adambakerwa | 50:9fc8edf722a8 | 49 | |
adambakerwa | 50:9fc8edf722a8 | 50 | private: |
adambakerwa | 50:9fc8edf722a8 | 51 | |
adambakerwa | 50:9fc8edf722a8 | 52 | void movement(N5110 &lcd, Gamepad &pad); //controlls movement of blockhead |
adambakerwa | 50:9fc8edf722a8 | 53 | void gameover(Pos pos, N5110 &lcd); //starts death sequence is spike hit or platform crush |
adambakerwa | 50:9fc8edf722a8 | 54 | |
adambakerwa | 50:9fc8edf722a8 | 55 | float get_speed(Gamepad &pad); //changes speed depending on joystick position |
adambakerwa | 50:9fc8edf722a8 | 56 | void button_press(N5110 &lcd, Gamepad &pad); //intiates jump/wj if button pressed at correct time |
adambakerwa | 50:9fc8edf722a8 | 57 | void jump(N5110 &lcd); //peformes jump if right condtions met |
adambakerwa | 50:9fc8edf722a8 | 58 | void wall_jump_right(N5110 &lcd, float speed); //peformes wall jump right if right conditions met |
adambakerwa | 50:9fc8edf722a8 | 59 | void wall_jump_left(N5110 &lcd, float speed); //peformes wall jump left if right conditions met |
adambakerwa | 50:9fc8edf722a8 | 60 | void fall(N5110 &lcd); //falls if right condistions met |
adambakerwa | 50:9fc8edf722a8 | 61 | void run_right(N5110 &lcd, float speed); //runs right at certain speed depenign on speed variable |
adambakerwa | 50:9fc8edf722a8 | 62 | void run_left(N5110 &lcd, float speed); //runs left at certain speed depenign on speed variable |
adambakerwa | 50:9fc8edf722a8 | 63 | void cancel_sprint(N5110 &lcd, float speed); //cancels sprint if obstical hit |
adambakerwa | 50:9fc8edf722a8 | 64 | |
adambakerwa | 50:9fc8edf722a8 | 65 | void move_up(N5110 &lcd, int n); //moves blockhead n pixels up |
adambakerwa | 50:9fc8edf722a8 | 66 | void move_down(N5110 &lcd, int n); //moves blockhead n pixels down |
adambakerwa | 50:9fc8edf722a8 | 67 | void move_right(N5110 &lcd, int n); //moves blockhead n pixels right |
adambakerwa | 50:9fc8edf722a8 | 68 | void move_left(N5110 &lcd, int n); //moves blockhead n pixels left |
adambakerwa | 50:9fc8edf722a8 | 69 | |
adambakerwa | 50:9fc8edf722a8 | 70 | void runner_state(N5110 &lcd, Gamepad &pad, float _speed); //what animation displayed depending if alive or died |
adambakerwa | 50:9fc8edf722a8 | 71 | void alive_sequence(N5110 &lcd, float _speed); //what animations displayed when alive |
adambakerwa | 50:9fc8edf722a8 | 72 | void run_sequence_right(N5110 &lcd); //peforms running right animation |
adambakerwa | 50:9fc8edf722a8 | 73 | void run_sequence_left(N5110 &lcd); //peforms running left animation |
adambakerwa | 50:9fc8edf722a8 | 74 | void walk_sequence_right(N5110 &lcd); //peforms walking right animation |
adambakerwa | 50:9fc8edf722a8 | 75 | void walk_sequence_left(N5110 &lcd); //performes walking left animation |
adambakerwa | 50:9fc8edf722a8 | 76 | void death_sequence(N5110 &lcd, Gamepad &pad); //peformes death animation |
adambakerwa | 50:9fc8edf722a8 | 77 | |
adambakerwa | 50:9fc8edf722a8 | 78 | int on_hoz_check(Pos pos); //checks if on horizontal (hoz) platfrom |
adambakerwa | 50:9fc8edf722a8 | 79 | int by_hoz_check_right(Pos pos); //checks if by hoz plat right |
adambakerwa | 50:9fc8edf722a8 | 80 | int by_hoz_check_left(Pos pos); //checks if by hoz plat left |
adambakerwa | 50:9fc8edf722a8 | 81 | int on_hoz_2_check(Pos pos); //checks if by hoz plat 2 |
adambakerwa | 50:9fc8edf722a8 | 82 | int by_hoz_2_check_right(Pos pos); //checks if by hoz plat right 2 |
adambakerwa | 50:9fc8edf722a8 | 83 | int by_hoz_2_check_left(Pos pos); //checks if by hoz plat left 2 |
adambakerwa | 50:9fc8edf722a8 | 84 | int on_ver_check(Pos pos); //checks if on vertical platform |
adambakerwa | 50:9fc8edf722a8 | 85 | int on_ver_2_check(Pos pos); //checks if on vertical platform 2 |
adambakerwa | 50:9fc8edf722a8 | 86 | |
adambakerwa | 50:9fc8edf722a8 | 87 | void platform_check(Pos pos); //checks if on platforms, |
adambakerwa | 50:9fc8edf722a8 | 88 | void on_platform(N5110 &lcd); //moves blockhead accordingly if so |
adambakerwa | 50:9fc8edf722a8 | 89 | |
adambakerwa | 50:9fc8edf722a8 | 90 | int crushed_by_ver(Pos pos); //returns one if crushed by platform |
adambakerwa | 50:9fc8edf722a8 | 91 | int crushed_by_ver_2(Pos pos); //returns one if crushed by platform 2 |
adambakerwa | 50:9fc8edf722a8 | 92 | int spike_hit(N5110 &lcd, Pos pos); //returns one if spike is hit |
adambakerwa | 50:9fc8edf722a8 | 93 | int fallen(Gamepad &pad); //returns one if fallen off screen |
adambakerwa | 50:9fc8edf722a8 | 94 | |
adambakerwa | 50:9fc8edf722a8 | 95 | void fall_tune(Gamepad &pad); //plays tune when fallen off screen |
adambakerwa | 50:9fc8edf722a8 | 96 | |
adambakerwa | 50:9fc8edf722a8 | 97 | Animation _ani; //animation class |
adambakerwa | 50:9fc8edf722a8 | 98 | |
adambakerwa | 50:9fc8edf722a8 | 99 | float _speed; //speed of blockhead |
adambakerwa | 50:9fc8edf722a8 | 100 | int _gameover; //gameover flag (0 when alive, 1 once died) |
adambakerwa | 50:9fc8edf722a8 | 101 | |
adambakerwa | 50:9fc8edf722a8 | 102 | int _x; /**< x cord of blockhead */ |
adambakerwa | 50:9fc8edf722a8 | 103 | int _y; /**< y cord of blockhead */ |
adambakerwa | 50:9fc8edf722a8 | 104 | int _jump; /**< jump counter */ |
adambakerwa | 50:9fc8edf722a8 | 105 | int _wjr; /**< wall jump right counter */ |
adambakerwa | 50:9fc8edf722a8 | 106 | int _wjl; /**< wall jump left counter */ |
adambakerwa | 50:9fc8edf722a8 | 107 | int _fall; /**< fall counter */ |
adambakerwa | 50:9fc8edf722a8 | 108 | int _sprintright; /**< sprint left counter */ |
adambakerwa | 50:9fc8edf722a8 | 109 | int _sprintleft; /**< sprint right counter */ |
adambakerwa | 50:9fc8edf722a8 | 110 | int _level; /**< what level */ |
adambakerwa | 50:9fc8edf722a8 | 111 | int _runani; /**< run animation counter */ |
adambakerwa | 50:9fc8edf722a8 | 112 | int _walkani; /**< walk animation counter */ |
adambakerwa | 50:9fc8edf722a8 | 113 | int _death; /**< death counter */ |
adambakerwa | 50:9fc8edf722a8 | 114 | |
adambakerwa | 50:9fc8edf722a8 | 115 | int _d; /**< direction of horizontal moving platform one */ |
adambakerwa | 50:9fc8edf722a8 | 116 | int _r; /**< by the right of horizontal moving platform one */ |
adambakerwa | 50:9fc8edf722a8 | 117 | int _l; /**< by the left of horizontal moving platform one */ |
adambakerwa | 50:9fc8edf722a8 | 118 | int _d2; /**< direction of horizontal moving platform two */ |
adambakerwa | 50:9fc8edf722a8 | 119 | int _r2; /**< by the right of horizontal moving platform two */ |
adambakerwa | 50:9fc8edf722a8 | 120 | int _l2; /**< by the left of horizontal moving platform two */ |
adambakerwa | 50:9fc8edf722a8 | 121 | int _d3; /**< direction of vertical moving platform one */ |
adambakerwa | 50:9fc8edf722a8 | 122 | int _d4; /**< direction of vertical moving platform one */ |
adambakerwa | 50:9fc8edf722a8 | 123 | |
adambakerwa | 50:9fc8edf722a8 | 124 | }; |
adambakerwa | 50:9fc8edf722a8 | 125 | |
adambakerwa | 50:9fc8edf722a8 | 126 | #endif |