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
Sprites/Sprites.h@51:a4b5ded0b727, 2019-04-24 (annotated)
- Committer:
- el17arm
- Date:
- Wed Apr 24 18:03:30 2019 +0000
- Revision:
- 51:a4b5ded0b727
- Parent:
- 50:65ba437510f8
- Child:
- 52:715791fc08a1
documentation update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17arm | 33:023f57d52b1c | 1 | #ifndef SPRITES_H |
el17arm | 33:023f57d52b1c | 2 | #define SPRITES_H |
el17arm | 33:023f57d52b1c | 3 | |
el17arm | 33:023f57d52b1c | 4 | #include "mbed.h" |
el17arm | 33:023f57d52b1c | 5 | #include "N5110.h" |
el17arm | 33:023f57d52b1c | 6 | #include "Gamepad.h" |
el17arm | 41:0cf320f73424 | 7 | |
el17arm | 45:bad704c546d4 | 8 | /** Sprites Class |
el17arm | 45:bad704c546d4 | 9 | @author Andrew Milner University of Leeds |
el17arm | 45:bad704c546d4 | 10 | @brief Draws sprites and sets all collision rules |
el17arm | 45:bad704c546d4 | 11 | @date April 2019 |
el17arm | 45:bad704c546d4 | 12 | */ |
el17arm | 45:bad704c546d4 | 13 | |
el17arm | 45:bad704c546d4 | 14 | /////////// All sprite bitmaps//////////////// |
el17arm | 33:023f57d52b1c | 15 | |
el17arm | 49:9bea7089b657 | 16 | // right facing miner bitmap |
el17arm | 33:023f57d52b1c | 17 | const int miner_right[24] = { |
el17arm | 41:0cf320f73424 | 18 | |
el17arm | 33:023f57d52b1c | 19 | 1,1,1, |
el17arm | 33:023f57d52b1c | 20 | 1,1,0, |
el17arm | 33:023f57d52b1c | 21 | 1,1,1, |
el17arm | 33:023f57d52b1c | 22 | 0,1,0, |
el17arm | 33:023f57d52b1c | 23 | 1,1,1, |
el17arm | 33:023f57d52b1c | 24 | 1,1,1, |
el17arm | 33:023f57d52b1c | 25 | 0,1,0, |
el17arm | 33:023f57d52b1c | 26 | 0,1,1, |
el17arm | 33:023f57d52b1c | 27 | |
el17arm | 33:023f57d52b1c | 28 | }; |
el17arm | 49:9bea7089b657 | 29 | // left facing miner bitmap |
el17arm | 49:9bea7089b657 | 30 | const int miner_left[24] = { |
el17arm | 41:0cf320f73424 | 31 | |
el17arm | 33:023f57d52b1c | 32 | 1,1,1, |
el17arm | 33:023f57d52b1c | 33 | 0,1,1, |
el17arm | 33:023f57d52b1c | 34 | 1,1,1, |
el17arm | 33:023f57d52b1c | 35 | 0,1,0, |
el17arm | 33:023f57d52b1c | 36 | 1,1,1, |
el17arm | 33:023f57d52b1c | 37 | 1,1,1, |
el17arm | 33:023f57d52b1c | 38 | 0,1,0, |
el17arm | 33:023f57d52b1c | 39 | 1,1,0, |
el17arm | 33:023f57d52b1c | 40 | }; |
el17arm | 49:9bea7089b657 | 41 | // enemy bitmap |
el17arm | 33:023f57d52b1c | 42 | const int enemy[15] = { |
el17arm | 33:023f57d52b1c | 43 | |
el17arm | 33:023f57d52b1c | 44 | 1,1,1, |
el17arm | 33:023f57d52b1c | 45 | 1,0,1, |
el17arm | 33:023f57d52b1c | 46 | 1,1,1, |
el17arm | 33:023f57d52b1c | 47 | 0,1,0, |
el17arm | 33:023f57d52b1c | 48 | 1,1,1, |
el17arm | 33:023f57d52b1c | 49 | }; |
el17arm | 49:9bea7089b657 | 50 | // key bitmap |
el17arm | 33:023f57d52b1c | 51 | const int key[12] = { |
el17arm | 41:0cf320f73424 | 52 | |
el17arm | 33:023f57d52b1c | 53 | 1,1,0,0, |
el17arm | 33:023f57d52b1c | 54 | 1,0,1,1, |
el17arm | 33:023f57d52b1c | 55 | 1,1,0,1, |
el17arm | 33:023f57d52b1c | 56 | }; |
el17arm | 49:9bea7089b657 | 57 | // blank bitmap to show key collected |
el17arm | 33:023f57d52b1c | 58 | const int key_collected[12] = { |
el17arm | 33:023f57d52b1c | 59 | |
el17arm | 33:023f57d52b1c | 60 | 0,0,0,0, |
el17arm | 33:023f57d52b1c | 61 | 0,0,0,0, |
el17arm | 33:023f57d52b1c | 62 | 0,0,0,0, |
el17arm | 33:023f57d52b1c | 63 | }; |
el17arm | 49:9bea7089b657 | 64 | // trap bitmap |
el17arm | 33:023f57d52b1c | 65 | const int spike[9] = { |
el17arm | 33:023f57d52b1c | 66 | |
el17arm | 34:c5a042973e0c | 67 | 1,0,1, |
el17arm | 33:023f57d52b1c | 68 | 0,1,0, |
el17arm | 34:c5a042973e0c | 69 | 1,0,1, |
el17arm | 33:023f57d52b1c | 70 | }; |
el17arm | 49:9bea7089b657 | 71 | // solid block bitmap |
el17arm | 34:c5a042973e0c | 72 | const int solid_block[18] = { |
el17arm | 33:023f57d52b1c | 73 | |
el17arm | 34:c5a042973e0c | 74 | 1,1,1,1,1,1, |
el17arm | 34:c5a042973e0c | 75 | 1,0,1,1,0,1, |
el17arm | 34:c5a042973e0c | 76 | 1,1,1,1,1,1, |
el17arm | 33:023f57d52b1c | 77 | }; |
el17arm | 49:9bea7089b657 | 78 | // level exit bitmap |
el17arm | 33:023f57d52b1c | 79 | const int door[30] = { |
el17arm | 33:023f57d52b1c | 80 | |
el17arm | 33:023f57d52b1c | 81 | 1,1,1,1,1, |
el17arm | 33:023f57d52b1c | 82 | 1,0,1,0,1, |
el17arm | 33:023f57d52b1c | 83 | 1,1,0,1,1, |
el17arm | 33:023f57d52b1c | 84 | 1,0,1,0,1, |
el17arm | 33:023f57d52b1c | 85 | 1,1,0,1,1, |
el17arm | 33:023f57d52b1c | 86 | 1,0,1,0,1, |
el17arm | 33:023f57d52b1c | 87 | }; |
el17arm | 38:55bb9da08a52 | 88 | |
el17arm | 45:bad704c546d4 | 89 | /////////structs for sprite parameters and collision detection////////////// |
el17arm | 38:55bb9da08a52 | 90 | |
el17arm | 49:9bea7089b657 | 91 | /** Keys position struct */ |
el17arm | 49:9bea7089b657 | 92 | |
el17arm | 51:a4b5ded0b727 | 93 | struct Key_init { |
el17arm | 49:9bea7089b657 | 94 | bool key[5]; /**< initialise key flag array identifies each key individually */ |
el17arm | 49:9bea7089b657 | 95 | double kx[5]; /**< key x position*/ |
el17arm | 49:9bea7089b657 | 96 | double ky[5]; /**< key y position*/ |
el17arm | 38:55bb9da08a52 | 97 | }; |
el17arm | 50:65ba437510f8 | 98 | |
el17arm | 49:9bea7089b657 | 99 | /** Enemy position and movement struct */ |
el17arm | 51:a4b5ded0b727 | 100 | struct Enemies_init { |
el17arm | 49:9bea7089b657 | 101 | bool eflag[5]; /**< initialise enemy flag array identifies each key individually */ |
el17arm | 49:9bea7089b657 | 102 | double ex[5]; /**< enemy x position */ |
el17arm | 49:9bea7089b657 | 103 | double ey[5]; /**< enemy y position */ |
el17arm | 49:9bea7089b657 | 104 | int counter[5]; /**< enemy counter, counts pixels moved */ |
el17arm | 49:9bea7089b657 | 105 | int distance[5];/**< distance enemy will travel before turning round */ |
el17arm | 40:913339e324b8 | 106 | }; |
el17arm | 50:65ba437510f8 | 107 | |
el17arm | 49:9bea7089b657 | 108 | /** Solid blocks struct */ |
el17arm | 43:1ec6b6293c6b | 109 | struct Solid_blocks_init { |
el17arm | 49:9bea7089b657 | 110 | double bx[5]; /**< block x position array identifies each block individually */ |
el17arm | 49:9bea7089b657 | 111 | double by[5]; /**< block y position array */ |
el17arm | 49:9bea7089b657 | 112 | bool collision[5]; /**< collision indicator for each individual block */ |
el17arm | 40:913339e324b8 | 113 | |
el17arm | 43:1ec6b6293c6b | 114 | }; |
el17arm | 49:9bea7089b657 | 115 | /////////////structs for populating up to 6 levels////////////////// |
el17arm | 50:65ba437510f8 | 116 | |
el17arm | 50:65ba437510f8 | 117 | /** Enemy locations for each level struct */ |
el17arm | 38:55bb9da08a52 | 118 | struct Enemies { |
el17arm | 49:9bea7089b657 | 119 | double ex[5]; /**< enemy x positions for each level */ |
el17arm | 49:9bea7089b657 | 120 | double ey[5]; /**< enemy y positions for each level */ |
el17arm | 49:9bea7089b657 | 121 | int c[5]; /**< enemy counters for each level */ |
el17arm | 49:9bea7089b657 | 122 | int d[5]; /**< enemy travel distances for each level */ |
el17arm | 49:9bea7089b657 | 123 | double v[5]; /**< varies enemies velocity */ |
el17arm | 38:55bb9da08a52 | 124 | }; |
el17arm | 50:65ba437510f8 | 125 | /** Trap locations for each level struct */ |
el17arm | 38:55bb9da08a52 | 126 | struct Traps { |
el17arm | 49:9bea7089b657 | 127 | double tx[5]; /**< traps x positions for each level */ |
el17arm | 49:9bea7089b657 | 128 | double ty[5]; /**< traps y positions for each level */ |
el17arm | 38:55bb9da08a52 | 129 | }; |
el17arm | 50:65ba437510f8 | 130 | /** Key locations for each level struct*/ |
el17arm | 38:55bb9da08a52 | 131 | struct Keys { |
el17arm | 49:9bea7089b657 | 132 | double kx[5]; /**< keys x positions for each level */ |
el17arm | 49:9bea7089b657 | 133 | double ky[5]; /**< keys y positions for each level */ |
el17arm | 38:55bb9da08a52 | 134 | }; |
el17arm | 50:65ba437510f8 | 135 | /** block locations for each level struct*/ |
el17arm | 38:55bb9da08a52 | 136 | struct Solid_blocks { |
el17arm | 49:9bea7089b657 | 137 | double bx[5]; /**< blocks x positions for each level */ |
el17arm | 49:9bea7089b657 | 138 | double by[5]; /**< blocks y positions for each level */ |
el17arm | 38:55bb9da08a52 | 139 | }; |
el17arm | 50:65ba437510f8 | 140 | /** sinking block locations for each level struct*/ |
el17arm | 38:55bb9da08a52 | 141 | struct Soft_blocks { |
el17arm | 49:9bea7089b657 | 142 | double sx1[5]; /**< sinking blocks x1 positions for each level */ |
el17arm | 49:9bea7089b657 | 143 | double sy[5]; /**< sinking blocks y positions for each level */ |
el17arm | 49:9bea7089b657 | 144 | int sx2[5]; /**< sinking blocks x2 (length) positions for each level */ |
el17arm | 40:913339e324b8 | 145 | }; |
el17arm | 50:65ba437510f8 | 146 | /** Exit location for each level struct */ |
el17arm | 40:913339e324b8 | 147 | struct Level_exit { |
el17arm | 49:9bea7089b657 | 148 | double lx[5]; /**< Exit x position for each level */ |
el17arm | 49:9bea7089b657 | 149 | double ly[5]; /**< Exit y position for each level */ |
el17arm | 33:023f57d52b1c | 150 | }; |
el17arm | 33:023f57d52b1c | 151 | |
el17arm | 33:023f57d52b1c | 152 | class Sprites |
el17arm | 33:023f57d52b1c | 153 | { |
el17arm | 33:023f57d52b1c | 154 | |
el17arm | 33:023f57d52b1c | 155 | public: |
el17arm | 49:9bea7089b657 | 156 | /** constructor |
el17arm | 49:9bea7089b657 | 157 | */ |
el17arm | 33:023f57d52b1c | 158 | Sprites(); |
el17arm | 49:9bea7089b657 | 159 | /** deconstructor |
el17arm | 49:9bea7089b657 | 160 | */ |
el17arm | 33:023f57d52b1c | 161 | ~Sprites(); |
el17arm | 49:9bea7089b657 | 162 | /** gets x and y position of player |
el17arm | 49:9bea7089b657 | 163 | */ |
el17arm | 41:0cf320f73424 | 164 | Vector2D get_pos(); |
el17arm | 49:9bea7089b657 | 165 | /** States starting position of player |
el17arm | 51:a4b5ded0b727 | 166 | @param miner x position |
el17arm | 51:a4b5ded0b727 | 167 | @param miner y position |
el17arm | 49:9bea7089b657 | 168 | */ |
el17arm | 33:023f57d52b1c | 169 | void miner_init(int x, int y); |
el17arm | 45:bad704c546d4 | 170 | void miner_move(Direction d, N5110 &lcd); |
el17arm | 33:023f57d52b1c | 171 | void miner_draw(N5110 &lcd); |
el17arm | 33:023f57d52b1c | 172 | void miner_gravity(N5110 &lcd); |
el17arm | 45:bad704c546d4 | 173 | void miner_jump(N5110 &lcd, Gamepad &pad); |
el17arm | 33:023f57d52b1c | 174 | void miner_land(N5110 &lcd); |
el17arm | 33:023f57d52b1c | 175 | |
el17arm | 33:023f57d52b1c | 176 | void enemy_init(int i, int x, int y, int d); |
el17arm | 33:023f57d52b1c | 177 | void enemy_move(int i, double v, N5110 &lcd); |
el17arm | 33:023f57d52b1c | 178 | bool enemy_collision(int i); |
el17arm | 33:023f57d52b1c | 179 | |
el17arm | 33:023f57d52b1c | 180 | void key_collect(int k, int x, int y, N5110 &lcd, Gamepad &pad); |
el17arm | 40:913339e324b8 | 181 | int keys_collected(); |
el17arm | 33:023f57d52b1c | 182 | |
el17arm | 37:4d525a37d5d2 | 183 | bool trap(int x, int y, N5110 &lcd); |
el17arm | 43:1ec6b6293c6b | 184 | void blocks(Direction d, int i, int x, int y, N5110 &lcd); |
el17arm | 43:1ec6b6293c6b | 185 | bool block_collision(); |
el17arm | 38:55bb9da08a52 | 186 | void soft_blocks(int x, int y, int z, N5110 &lcd); |
el17arm | 33:023f57d52b1c | 187 | |
el17arm | 41:0cf320f73424 | 188 | bool exit_level(int x, int y, N5110 &lcd); |
el17arm | 49:9bea7089b657 | 189 | |
el17arm | 51:a4b5ded0b727 | 190 | Key_init _k; |
el17arm | 51:a4b5ded0b727 | 191 | Enemies_init _enem; |
el17arm | 41:0cf320f73424 | 192 | |
el17arm | 43:1ec6b6293c6b | 193 | |
el17arm | 38:55bb9da08a52 | 194 | |
el17arm | 33:023f57d52b1c | 195 | private: |
el17arm | 33:023f57d52b1c | 196 | |
el17arm | 33:023f57d52b1c | 197 | int _direction; |
el17arm | 33:023f57d52b1c | 198 | int _gravity; |
el17arm | 33:023f57d52b1c | 199 | bool _jump; |
el17arm | 33:023f57d52b1c | 200 | int _y; |
el17arm | 33:023f57d52b1c | 201 | int _x; |
el17arm | 33:023f57d52b1c | 202 | bool _j_flag; |
el17arm | 33:023f57d52b1c | 203 | int _j_counter; |
el17arm | 33:023f57d52b1c | 204 | |
el17arm | 34:c5a042973e0c | 205 | bool block[5]; |
el17arm | 36:203ec93b4cc7 | 206 | bool right_collision; |
el17arm | 36:203ec93b4cc7 | 207 | bool left_collision; |
el17arm | 36:203ec93b4cc7 | 208 | |
el17arm | 36:203ec93b4cc7 | 209 | bool _collision; |
el17arm | 36:203ec93b4cc7 | 210 | int _keys; |
el17arm | 36:203ec93b4cc7 | 211 | |
el17arm | 38:55bb9da08a52 | 212 | |
el17arm | 43:1ec6b6293c6b | 213 | Solid_blocks_init _b; |
el17arm | 44:e29458976114 | 214 | |
el17arm | 33:023f57d52b1c | 215 | }; |
el17arm | 33:023f57d52b1c | 216 | #endif |