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:
Tue Apr 23 03:10:09 2019 +0000
Revision:
11:63e54f6e7939
Parent:
10:1a3499f6b583
Child:
12:a1c1991835ca
Added move checks (for entity to group of entity collision checks);; Added a plausible way to update each entity;

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 11:63e54f6e7939 31 Position prev_pos;
el17sm 10:1a3499f6b583 32 int hp;
el17sm 10:1a3499f6b583 33 int face;
el17sm 10:1a3499f6b583 34
el17sm 10:1a3499f6b583 35 public:
el17sm 10:1a3499f6b583 36 // Functions
el17sm 10:1a3499f6b583 37 virtual void move(float, float) = 0;
el17sm 10:1a3499f6b583 38
el17sm 10:1a3499f6b583 39 bool matrix_collision_test(float pos_x, float pos_y, int map_no){
el17sm 10:1a3499f6b583 40 for (int j = pos_y; j < (int)pos_y + hitbox.height; j++){
el17sm 10:1a3499f6b583 41 for(int i = pos_x; i < (int)pos_x + hitbox.width; i++){
el17sm 10:1a3499f6b583 42 if ((j>=48) || (i>=84) || (j<0) || (i<0)) {}
el17sm 10:1a3499f6b583 43 else if ((level_map[0][j][i] == 1)) {
el17sm 10:1a3499f6b583 44 return true;
el17sm 10:1a3499f6b583 45 }
el17sm 10:1a3499f6b583 46 }
el17sm 10:1a3499f6b583 47 }
el17sm 10:1a3499f6b583 48 return false;
el17sm 10:1a3499f6b583 49 }
el17sm 10:1a3499f6b583 50
el17sm 10:1a3499f6b583 51 virtual void chkdmg() = 0;
el17sm 10:1a3499f6b583 52
el17sm 11:63e54f6e7939 53 void undo_move_x(bool status_x){
el17sm 11:63e54f6e7939 54 if (status_x){
el17sm 11:63e54f6e7939 55 position.x = prev_pos.x;
el17sm 11:63e54f6e7939 56 }
el17sm 11:63e54f6e7939 57 }
el17sm 11:63e54f6e7939 58
el17sm 11:63e54f6e7939 59 void undo_move_y(bool status_y){
el17sm 11:63e54f6e7939 60 if (status_y){
el17sm 11:63e54f6e7939 61 position.y = prev_pos.y;
el17sm 11:63e54f6e7939 62 }
el17sm 11:63e54f6e7939 63 }
el17sm 11:63e54f6e7939 64
el17sm 11:63e54f6e7939 65 void update_prev_pos();
el17sm 11:63e54f6e7939 66
el17sm 10:1a3499f6b583 67 // Accessors
el17sm 10:1a3499f6b583 68 bool get_moving();
el17sm 10:1a3499f6b583 69 int get_hitbox_width();
el17sm 10:1a3499f6b583 70 int get_hitbox_height();
el17sm 10:1a3499f6b583 71 int get_face();
el17sm 10:1a3499f6b583 72 int get_sprite_width();
el17sm 10:1a3499f6b583 73 int get_sprite_height();
el17sm 10:1a3499f6b583 74 int get_offset_x();
el17sm 10:1a3499f6b583 75 int get_offset_y();
el17sm 10:1a3499f6b583 76 int get_pos_x();
el17sm 10:1a3499f6b583 77 int get_pos_y();
el17sm 11:63e54f6e7939 78 int get_prev_pos_x();
el17sm 11:63e54f6e7939 79 int get_prev_pos_y();
el17sm 10:1a3499f6b583 80
el17sm 10:1a3499f6b583 81 };
el17sm 10:1a3499f6b583 82
el17sm 10:1a3499f6b583 83 #endif