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 MotionSensor
Entity.h@7:4aaa37a711a1, 2019-04-20 (annotated)
- Committer:
- el17sm
- Date:
- Sat Apr 20 22:17:24 2019 +0000
- Revision:
- 7:4aaa37a711a1
- Parent:
- 6:104c2506237e
- Child:
- 8:27244a0c3414
Implementation of Entity.h and Person.h;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17sm | 7:4aaa37a711a1 | 1 | #ifndef ENTITY_H |
| el17sm | 7:4aaa37a711a1 | 2 | #define ENTITY_H |
| el17sm | 7:4aaa37a711a1 | 3 | #include "sprites.h" |
| el17sm | 7:4aaa37a711a1 | 4 | #include "math.h" |
| el17sm | 7:4aaa37a711a1 | 5 | |
| el17sm | 7:4aaa37a711a1 | 6 | class Entity |
| el17sm | 7:4aaa37a711a1 | 7 | { |
| el17sm | 7:4aaa37a711a1 | 8 | protected: |
| el17sm | 7:4aaa37a711a1 | 9 | bool moving; |
| el17sm | 7:4aaa37a711a1 | 10 | struct Hitbox { |
| el17sm | 7:4aaa37a711a1 | 11 | int width; |
| el17sm | 7:4aaa37a711a1 | 12 | int height; |
| el17sm | 7:4aaa37a711a1 | 13 | }; |
| el17sm | 7:4aaa37a711a1 | 14 | Hitbox hitbox; |
| el17sm | 7:4aaa37a711a1 | 15 | struct SpriteSize { |
| el17sm | 7:4aaa37a711a1 | 16 | int width; |
| el17sm | 7:4aaa37a711a1 | 17 | int height; |
| el17sm | 7:4aaa37a711a1 | 18 | // Top-left corner of sprite is offset_x |
| el17sm | 7:4aaa37a711a1 | 19 | // to the right of top-left corner of hitbox |
| el17sm | 7:4aaa37a711a1 | 20 | int offset_x; |
| el17sm | 7:4aaa37a711a1 | 21 | // Top-left corner of sprite is offset_y |
| el17sm | 7:4aaa37a711a1 | 22 | // above of top-left corner of hitbox |
| el17sm | 7:4aaa37a711a1 | 23 | int offset_y; |
| el17sm | 7:4aaa37a711a1 | 24 | }; |
| el17sm | 7:4aaa37a711a1 | 25 | SpriteSize sprite_size; |
| el17sm | 7:4aaa37a711a1 | 26 | struct Position { |
| el17sm | 7:4aaa37a711a1 | 27 | float x; |
| el17sm | 7:4aaa37a711a1 | 28 | float y; |
| el17sm | 7:4aaa37a711a1 | 29 | }; |
| el17sm | 7:4aaa37a711a1 | 30 | Position position; |
| el17sm | 7:4aaa37a711a1 | 31 | int hp; |
| el17sm | 7:4aaa37a711a1 | 32 | int face; |
| el17sm | 7:4aaa37a711a1 | 33 | |
| el17sm | 7:4aaa37a711a1 | 34 | public: |
| el17sm | 7:4aaa37a711a1 | 35 | // Functions |
| el17sm | 7:4aaa37a711a1 | 36 | virtual void move(float mapped_x, float mapped_y) = 0; |
| el17sm | 7:4aaa37a711a1 | 37 | bool matrix_collision_test(float pos_x, float pos_y, int map_no){ |
| el17sm | 7:4aaa37a711a1 | 38 | for (int j = pos_y; j < (int)pos_y + hitbox.height; j++){ |
| el17sm | 7:4aaa37a711a1 | 39 | for(int i = pos_x; i < (int)pos_x + hitbox.width; i++){ |
| el17sm | 7:4aaa37a711a1 | 40 | if ((j>=48) || (i>=84) || (j<0) || (i<0)) {} |
| el17sm | 7:4aaa37a711a1 | 41 | else if ((level_map[0][j][i] == 1)) { |
| el17sm | 7:4aaa37a711a1 | 42 | return true; |
| el17sm | 7:4aaa37a711a1 | 43 | } |
| el17sm | 7:4aaa37a711a1 | 44 | } |
| el17sm | 7:4aaa37a711a1 | 45 | } |
| el17sm | 7:4aaa37a711a1 | 46 | return false; |
| el17sm | 7:4aaa37a711a1 | 47 | } |
| el17sm | 7:4aaa37a711a1 | 48 | |
| el17sm | 7:4aaa37a711a1 | 49 | // Accessors |
| el17sm | 7:4aaa37a711a1 | 50 | bool get_moving(); |
| el17sm | 7:4aaa37a711a1 | 51 | int get_face(); |
| el17sm | 7:4aaa37a711a1 | 52 | int get_sprite_width(); |
| el17sm | 7:4aaa37a711a1 | 53 | int get_sprite_height(); |
| el17sm | 7:4aaa37a711a1 | 54 | int get_offset_x(); |
| el17sm | 7:4aaa37a711a1 | 55 | int get_offset_y(); |
| el17sm | 7:4aaa37a711a1 | 56 | int get_pos_x(); |
| el17sm | 7:4aaa37a711a1 | 57 | int get_pos_y(); |
| el17sm | 7:4aaa37a711a1 | 58 | |
| el17sm | 7:4aaa37a711a1 | 59 | }; |
| el17sm | 7:4aaa37a711a1 | 60 | |
| el17sm | 7:4aaa37a711a1 | 61 | #endif |