Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Committer:
el17sm
Date:
Sat Apr 20 22:51:55 2019 +0000
Revision:
8:27244a0c3414
Parent:
7:4aaa37a711a1
trauma;

Who changed what in which revision?

UserRevisionLine numberNew 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 8:27244a0c3414 37
el17sm 7:4aaa37a711a1 38 bool matrix_collision_test(float pos_x, float pos_y, int map_no){
el17sm 7:4aaa37a711a1 39 for (int j = pos_y; j < (int)pos_y + hitbox.height; j++){
el17sm 7:4aaa37a711a1 40 for(int i = pos_x; i < (int)pos_x + hitbox.width; i++){
el17sm 7:4aaa37a711a1 41 if ((j>=48) || (i>=84) || (j<0) || (i<0)) {}
el17sm 7:4aaa37a711a1 42 else if ((level_map[0][j][i] == 1)) {
el17sm 7:4aaa37a711a1 43 return true;
el17sm 7:4aaa37a711a1 44 }
el17sm 7:4aaa37a711a1 45 }
el17sm 7:4aaa37a711a1 46 }
el17sm 7:4aaa37a711a1 47 return false;
el17sm 7:4aaa37a711a1 48 }
el17sm 7:4aaa37a711a1 49
el17sm 7:4aaa37a711a1 50 // Accessors
el17sm 7:4aaa37a711a1 51 bool get_moving();
el17sm 7:4aaa37a711a1 52 int get_face();
el17sm 7:4aaa37a711a1 53 int get_sprite_width();
el17sm 7:4aaa37a711a1 54 int get_sprite_height();
el17sm 7:4aaa37a711a1 55 int get_offset_x();
el17sm 7:4aaa37a711a1 56 int get_offset_y();
el17sm 7:4aaa37a711a1 57 int get_pos_x();
el17sm 7:4aaa37a711a1 58 int get_pos_y();
el17sm 7:4aaa37a711a1 59
el17sm 7:4aaa37a711a1 60 };
el17sm 7:4aaa37a711a1 61
el17sm 7:4aaa37a711a1 62 #endif