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 22:59:12 2019 +0000
Revision:
12:a1c1991835ca
Parent:
11:63e54f6e7939
Child:
13:d04a6caba40d
Sprite is now controlled and stored inside each entity's files;

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