Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Gamepad N5110
Blockhead.h
00001 #ifndef RUNNER_H 00002 #define RUNNER_H 00003 00004 #include "mbed.h" 00005 #include "Gamepad.h" 00006 #include "N5110.h" 00007 #include "Levels.h" 00008 #include "Animation.h" 00009 00010 00011 /** Blockhead Class 00012 * @brief Class for controlling the main mechanics of the Blockhead character 00013 * @author Adam P. Baker 00014 * @date 9 May 2019 00015 */ 00016 class Blockhead 00017 { 00018 public: 00019 /** Constructor */ 00020 Blockhead(); 00021 00022 /** Deconstructor */ 00023 ~Blockhead(); 00024 00025 /** initialises all variables for new game */ 00026 void init(); 00027 00028 /** initialises variables for continue game (does not intialise level) */ 00029 void continue_init(); 00030 00031 /** changes level when character reaches side of screen 00032 *@returns level blockhead is on (int) 00033 */ 00034 int next_level(); 00035 00036 /** controlls blockhead depending on position in game, and user input 00037 *@param pos struct which contains cordinates and direction of moving platforms 00038 *@param N5110 class which controlls lcd screen 00039 *@param Gamepad class for working with the gamepad 00040 */ 00041 void blockhead(Pos pos, N5110 &lcd, Gamepad &pad); 00042 00043 /** retruns 1 when gameover occurs 00044 *@param Gamepad class for working with the gamepad 00045 *@returns gameover (0 when alive, 1 once died) (int) 00046 */ 00047 int gameover_flag(Gamepad &pad); 00048 00049 00050 private: 00051 00052 void movement(N5110 &lcd, Gamepad &pad); //controlls movement of blockhead 00053 void gameover(Pos pos, N5110 &lcd); //starts death sequence is spike hit or platform crush 00054 00055 float get_speed(Gamepad &pad); //changes speed depending on joystick position 00056 void button_press(N5110 &lcd, Gamepad &pad); //intiates jump/wj if button pressed at correct time 00057 void jump(N5110 &lcd); //peformes jump if right condtions met 00058 void wall_jump_right(N5110 &lcd, float speed); //peformes wall jump right if right conditions met 00059 void wall_jump_left(N5110 &lcd, float speed); //peformes wall jump left if right conditions met 00060 void fall(N5110 &lcd); //falls if right condistions met 00061 void run_right(N5110 &lcd, float speed); //runs right at certain speed depenign on speed variable 00062 void run_left(N5110 &lcd, float speed); //runs left at certain speed depenign on speed variable 00063 void cancel_sprint(N5110 &lcd, float speed); //cancels sprint if obstical hit 00064 00065 void move_up(N5110 &lcd, int n); //moves blockhead n pixels up 00066 void move_down(N5110 &lcd, int n); //moves blockhead n pixels down 00067 void move_right(N5110 &lcd, int n); //moves blockhead n pixels right 00068 void move_left(N5110 &lcd, int n); //moves blockhead n pixels left 00069 00070 void runner_state(N5110 &lcd, Gamepad &pad, float _speed); //what animation displayed depending if alive or died 00071 void alive_sequence(N5110 &lcd, float _speed); //what animations displayed when alive 00072 void run_sequence_right(N5110 &lcd); //peforms running right animation 00073 void run_sequence_left(N5110 &lcd); //peforms running left animation 00074 void walk_sequence_right(N5110 &lcd); //peforms walking right animation 00075 void walk_sequence_left(N5110 &lcd); //performes walking left animation 00076 void death_sequence(N5110 &lcd, Gamepad &pad); //peformes death animation 00077 00078 int on_hoz_check(Pos pos); //checks if on horizontal (hoz) platfrom 00079 int by_hoz_check_right(Pos pos); //checks if by hoz plat right 00080 int by_hoz_check_left(Pos pos); //checks if by hoz plat left 00081 int on_hoz_2_check(Pos pos); //checks if by hoz plat 2 00082 int by_hoz_2_check_right(Pos pos); //checks if by hoz plat right 2 00083 int by_hoz_2_check_left(Pos pos); //checks if by hoz plat left 2 00084 int on_ver_check(Pos pos); //checks if on vertical platform 00085 int on_ver_2_check(Pos pos); //checks if on vertical platform 2 00086 00087 void platform_check(Pos pos); //checks if on platforms, 00088 void on_platform(N5110 &lcd); //moves blockhead accordingly if so 00089 00090 int crushed_by_ver(Pos pos); //returns one if crushed by platform 00091 int crushed_by_ver_2(Pos pos); //returns one if crushed by platform 2 00092 int spike_hit(N5110 &lcd, Pos pos); //returns one if spike is hit 00093 int fallen(Gamepad &pad); //returns one if fallen off screen 00094 00095 void fall_tune(Gamepad &pad); //plays tune when fallen off screen 00096 00097 Animation _ani; //animation class 00098 00099 float _speed; //speed of blockhead 00100 int _gameover; //gameover flag (0 when alive, 1 once died) 00101 00102 int _x; /**< x cord of blockhead */ 00103 int _y; /**< y cord of blockhead */ 00104 int _jump; /**< jump counter */ 00105 int _wjr; /**< wall jump right counter */ 00106 int _wjl; /**< wall jump left counter */ 00107 int _fall; /**< fall counter */ 00108 int _sprintright; /**< sprint left counter */ 00109 int _sprintleft; /**< sprint right counter */ 00110 int _level; /**< what level */ 00111 int _runani; /**< run animation counter */ 00112 int _walkani; /**< walk animation counter */ 00113 int _death; /**< death counter */ 00114 00115 int _d; /**< direction of horizontal moving platform one */ 00116 int _r; /**< by the right of horizontal moving platform one */ 00117 int _l; /**< by the left of horizontal moving platform one */ 00118 int _d2; /**< direction of horizontal moving platform two */ 00119 int _r2; /**< by the right of horizontal moving platform two */ 00120 int _l2; /**< by the left of horizontal moving platform two */ 00121 int _d3; /**< direction of vertical moving platform one */ 00122 int _d4; /**< direction of vertical moving platform one */ 00123 00124 }; 00125 00126 #endif
Generated on Fri Jul 15 2022 00:42:15 by
