A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.

Dependencies:   mbed MotionSensor

Committer:
el17sm
Date:
Sun Apr 21 23:23:35 2019 +0000
Revision:
10:1a3499f6b583
Child:
11:63e54f6e7939
Added entity_collision, Added start of Bullets,; ; Problems:; Headless can be inside player without detected by entity_collision if on the same y level

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17sm 10:1a3499f6b583 1 #ifndef ENTITY_H
el17sm 10:1a3499f6b583 2 #define ENTITY_H
el17sm 10:1a3499f6b583 3 #include "sprites.h"
el17sm 10:1a3499f6b583 4 #include "math.h"
el17sm 10:1a3499f6b583 5
el17sm 10:1a3499f6b583 6 class Entity
el17sm 10:1a3499f6b583 7 {
el17sm 10:1a3499f6b583 8 protected:
el17sm 10:1a3499f6b583 9 bool moving;
el17sm 10:1a3499f6b583 10 struct Hitbox {
el17sm 10:1a3499f6b583 11 int width;
el17sm 10:1a3499f6b583 12 int height;
el17sm 10:1a3499f6b583 13 };
el17sm 10:1a3499f6b583 14 Hitbox hitbox;
el17sm 10:1a3499f6b583 15 struct SpriteSize {
el17sm 10:1a3499f6b583 16 int width;
el17sm 10:1a3499f6b583 17 int height;
el17sm 10:1a3499f6b583 18 // Top-left corner of sprite is offset_x
el17sm 10:1a3499f6b583 19 // to the right of top-left corner of hitbox
el17sm 10:1a3499f6b583 20 int offset_x;
el17sm 10:1a3499f6b583 21 // Top-left corner of sprite is offset_y
el17sm 10:1a3499f6b583 22 // above of top-left corner of hitbox
el17sm 10:1a3499f6b583 23 int offset_y;
el17sm 10:1a3499f6b583 24 };
el17sm 10:1a3499f6b583 25 SpriteSize sprite_size;
el17sm 10:1a3499f6b583 26 struct Position {
el17sm 10:1a3499f6b583 27 float x;
el17sm 10:1a3499f6b583 28 float y;
el17sm 10:1a3499f6b583 29 };
el17sm 10:1a3499f6b583 30 Position position;
el17sm 10:1a3499f6b583 31 int hp;
el17sm 10:1a3499f6b583 32 int face;
el17sm 10:1a3499f6b583 33
el17sm 10:1a3499f6b583 34 public:
el17sm 10:1a3499f6b583 35 // Functions
el17sm 10:1a3499f6b583 36 virtual void move(float, float) = 0;
el17sm 10:1a3499f6b583 37
el17sm 10:1a3499f6b583 38 bool matrix_collision_test(float pos_x, float pos_y, int map_no){
el17sm 10:1a3499f6b583 39 for (int j = pos_y; j < (int)pos_y + hitbox.height; j++){
el17sm 10:1a3499f6b583 40 for(int i = pos_x; i < (int)pos_x + hitbox.width; i++){
el17sm 10:1a3499f6b583 41 if ((j>=48) || (i>=84) || (j<0) || (i<0)) {}
el17sm 10:1a3499f6b583 42 else if ((level_map[0][j][i] == 1)) {
el17sm 10:1a3499f6b583 43 return true;
el17sm 10:1a3499f6b583 44 }
el17sm 10:1a3499f6b583 45 }
el17sm 10:1a3499f6b583 46 }
el17sm 10:1a3499f6b583 47 return false;
el17sm 10:1a3499f6b583 48 }
el17sm 10:1a3499f6b583 49
el17sm 10:1a3499f6b583 50 virtual void chkdmg() = 0;
el17sm 10:1a3499f6b583 51
el17sm 10:1a3499f6b583 52 // Accessors
el17sm 10:1a3499f6b583 53 bool get_moving();
el17sm 10:1a3499f6b583 54 int get_hitbox_width();
el17sm 10:1a3499f6b583 55 int get_hitbox_height();
el17sm 10:1a3499f6b583 56 int get_face();
el17sm 10:1a3499f6b583 57 int get_sprite_width();
el17sm 10:1a3499f6b583 58 int get_sprite_height();
el17sm 10:1a3499f6b583 59 int get_offset_x();
el17sm 10:1a3499f6b583 60 int get_offset_y();
el17sm 10:1a3499f6b583 61 int get_pos_x();
el17sm 10:1a3499f6b583 62 int get_pos_y();
el17sm 10:1a3499f6b583 63
el17sm 10:1a3499f6b583 64 };
el17sm 10:1a3499f6b583 65
el17sm 10:1a3499f6b583 66 #endif