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