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
Revision 51:4d0cd75e7ed3, committed 2019-05-09
- Comitter:
- el17sm
- Date:
- Thu May 09 07:39:49 2019 +0000
- Parent:
- 50:2c5cb92a5361
- Child:
- 52:7d05e5472022
- Commit message:
- Removed moving boolean from entity, finished commenting room.cpp
Changed in this revision
--- a/Entity/Bosses/Skull/Skull.cpp Thu May 09 06:33:28 2019 +0000
+++ b/Entity/Bosses/Skull/Skull.cpp Thu May 09 07:39:49 2019 +0000
@@ -8,7 +8,6 @@
_dash = false;
_dash_counter = 0;
- moving = true;
hitbox.width = 19;
hitbox.height = 9;
--- a/Entity/Entity.cpp Thu May 09 06:33:28 2019 +0000
+++ b/Entity/Entity.cpp Thu May 09 07:39:49 2019 +0000
@@ -1,15 +1,15 @@
#include "Entity.h"
// Functions
-void Entity::undo_move_x(bool status_x)
+void Entity::undo_move_x(bool condition)
{
- if (status_x) {
+ if (condition) {
position.x = prev_pos.x;
}
}
-void Entity::undo_move_y(bool status_y)
+void Entity::undo_move_y(bool condition)
{
- if (status_y) {
+ if (condition) {
position.y = prev_pos.y;
}
}
@@ -18,12 +18,12 @@
prev_pos = position;
}
-bool Entity::entity_to_map_collision_test(float pos_x, float pos_y, char * map, bool * doorways)
+bool Entity::entity_to_map_collision_test(float pos_x, float pos_y, char * two_d_map, bool * doorways) // Returns true if the entity clashes a wall
{
for (int j = pos_y; j < (int)pos_y + hitbox.height; j++) {
for(int i = pos_x; i < (int)pos_x + hitbox.width; i++) {
if ((j>=screen_height) || (i>=screen_width) || (j<0) || (i<0)) {} // To allow movement towards outside of the map
- else if (*((map+j*screen_width)+i) == 1) {
+ else if (*((two_d_map+j*screen_width)+i) == 1) { // if entity clashes the 2d map
return true;
}
@@ -62,11 +62,7 @@
position.y += change_y;
}
-// accessors
-bool Entity::get_moving()
-{
- return moving;
-}
+// Accessors
int Entity::get_hp_drop_chance()
{
return _hp_drop_chance;
--- a/Entity/Entity.h Thu May 09 06:33:28 2019 +0000
+++ b/Entity/Entity.h Thu May 09 07:39:49 2019 +0000
@@ -7,7 +7,6 @@
class Entity
{
protected:
- bool moving;
struct Hitbox {
int width;
int height;
@@ -47,18 +46,17 @@
virtual void move(float, float, char * map, bool * doorways) = 0; // movement control and miscellaneous updates
virtual void take_damage(int) = 0;
virtual void draw(N5110 &lcd) = 0;
- void undo_move_x(bool);
- void undo_move_y(bool);
+ void undo_move_x(bool condition);
+ void undo_move_y(bool condition);
void update_prev_pos();
- bool entity_to_map_collision_test(float pos_x, float pos_y, char * map, bool * doorways);
+ bool entity_to_map_collision_test(float pos_x, float pos_y, char * two_d_map, bool * doorways);
// Mutator
void set_position(float x, float y);
- void position_add_x(float);
- void position_add_y(float);
+ void position_add_x(float change_x);
+ void position_add_y(float change_y);
// Accessors
- bool get_moving();
int get_hp_drop_chance();
int get_hitbox_width();
int get_hitbox_height();
--- a/Entity/Mobs/Headless/Headless.cpp Thu May 09 06:33:28 2019 +0000
+++ b/Entity/Mobs/Headless/Headless.cpp Thu May 09 07:39:49 2019 +0000
@@ -5,7 +5,6 @@
Headless::Headless(float pos_x, float pos_y)
{
_hp_drop_chance = 10; // out of 100
- moving = true;
face = 0;
hp = 4;
attack = 1;
--- a/Entity/Mobs/Mobs.h Thu May 09 06:33:28 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-#ifndef MOBS_H
-#define MOBS_H
-#include "Entity.h"
-
-//class Mobs : public Entity
-//{
-//
-//}
-
-#endif
\ No newline at end of file
--- a/Entity/Mobs/Snake/Snake.cpp Thu May 09 06:33:28 2019 +0000
+++ b/Entity/Mobs/Snake/Snake.cpp Thu May 09 07:39:49 2019 +0000
@@ -6,7 +6,6 @@
Snake::Snake(float pos_x, float pos_y)
{
_hp_drop_chance = 10; // out of 100
- moving = true;
_prev_face = 0;
face = 0;
hp = 4;
--- a/Entity/Player/Bullets/Bullets.cpp Thu May 09 06:33:28 2019 +0000
+++ b/Entity/Player/Bullets/Bullets.cpp Thu May 09 07:39:49 2019 +0000
@@ -2,7 +2,6 @@
Bullets::Bullets(float pos_x, float pos_y, int dir)
{
- moving = true;
face = 0;
hp = 1;
hitbox.width = 3;
--- a/Entity/Player/Player.cpp Thu May 09 06:33:28 2019 +0000
+++ b/Entity/Player/Player.cpp Thu May 09 07:39:49 2019 +0000
@@ -4,30 +4,34 @@
// Constructor
Player::Player(float pos_x, float pos_y)
{
- moving = false;
- face = 0;
hp = 3;
attack = 1;
+ face = 2;
+
hitbox.width = 6;
hitbox.height = 5;
+
position.x = pos_x;
position.y = pos_y;
+
sprite_size.width = 6;
sprite_size.height = 12;
sprite_size.offset_x = 0;
sprite_size.offset_y = -7;
+
frame.count = 0;
frame.number = 0;
frame.max = 4;
+
for (int i = 0; i < bullets_max; i++) {
valid_bullets[i] = false;
}
- fire_rate_counter = 0;
invulnerability_counter = INVULNERABILITY_PERIOD;
// Upgradable status
fire_rate_delay = 30;
+ fire_rate_counter = fire_rate_delay;
velocity = 0.7;
_bullet_speed = 1;
}
@@ -72,8 +76,6 @@
undo_move_x(entity_to_map_collision_test(position.x, prev_pos.y, map, doorways));
undo_move_y(entity_to_map_collision_test(prev_pos.x, position.y, map, doorways));
-
- moving = false;
}
void Player::move_bullets()
@@ -88,7 +90,6 @@
void Player::increment_frames(float mapped_x, float mapped_y)
{
if (abs(mapped_x) + abs(mapped_y) > 0.1f) {
- moving = true;
if (mapped_y < 0 && abs(mapped_y) > abs(mapped_x)) {
face = 2;
} else if (mapped_y > 0 && abs(mapped_y) > abs(mapped_x)) {
--- a/RoomEngine/Room/Room.cpp Thu May 09 06:33:28 2019 +0000
+++ b/RoomEngine/Room/Room.cpp Thu May 09 07:39:49 2019 +0000
@@ -3,29 +3,25 @@
// Constructor
Room::Room(int no_of_enemies, int room_type)
{
+ _before_boss_room = 4;
+
_room_type = room_type;
- for(int i = 0; i < 4; i++) {
- _doorways[i] = false;
- _doorways_memory[i] = false;
+ for(int side = 0; side < 4; side++) {
+ _doorways[side] = false;
}
-
-
- _before_boss_room = 4;
for(int id = 0; id < MAX_ENEMIES; id++) {
valid_collectibles[id] = false;
}
- if(room_type == 10) {
+
+ if(room_type >= 10) { // Special Case for Boss rooms
init_boss_room();
- for (int id = 1; id < MAX_ENEMIES; id++) {
- valid_enemies[id] = id - 1 < no_of_enemies;
- }
} else {
for (int id = 0; id < MAX_ENEMIES; id++) {
valid_enemies[id] = id < no_of_enemies;
- if (id < no_of_enemies) {
+ if (id < no_of_enemies) { // For every undefined valid enemy, define:
enemies_type[id] = (int)(rand() % 3)/2; // 2/3 chance headless 1/3 chance snake
- rand_enemy_coordinate(id);
+ rand_enemy_coordinate(id); // define random spawn coordinate
}
}
if (room_type == 0){
@@ -38,17 +34,14 @@
}
}
-// Deconstructor
-Room::~Room()
-{
-
-}
-
void Room::init_boss_room()
{
valid_walls[0] = false;
valid_walls[1] = false;
valid_enemies[0] = true;
+ for (int id = 1; id < MAX_ENEMIES; id++) { // Updating valid_enemies to be false for all the others
+ valid_enemies[id] = false;
+ }
}
void Room::init_normal_room()
@@ -83,14 +76,19 @@
_wall_stat[1][3] = 19;
}
+// Deconstructor
+Room::~Room()
+{
+
+}
+
// Mutator
-void Room::set_doorway(int index, bool doorway_value)
+void Room::set_doorway(int index, bool doorway_value) // Sets doorways to the needed value at index
{
- _doorways_memory[index] = doorway_value;
_doorways[index] = doorway_value;
}
-void Room::set_boss_doorway(int before_boss_room)
+void Room::set_boss_doorway(int before_boss_room) // Sets the boss doorway
{
_before_boss_room = before_boss_room;
}
@@ -107,7 +105,7 @@
bool Room::get_doorway(int index)
{
- return _doorways_memory[index];
+ return _doorways[index];
}
char Room::get_room_type()
@@ -123,24 +121,24 @@
// Functions
void Room::rand_enemy_coordinate(int id)
{
- _spawn_point_coord = rand() % n_spawn_points[_room_type];
+ _spawn_point_coord = rand() % n_spawn_points[_room_type]; // Random available spawning coordinate ID
_spawn_point_counter = 0;
for(int i = 0; i < WIDTH; i++) {
for(int j = 0; j < HEIGHT; j++) {
- if(spawn_area[_room_type][j][i] == 0){
- _spawn_point_counter++;
+ if(spawn_area[_room_type][j][i] == 0){ // Locate available spawning coordinate
+ _spawn_point_counter++; // Increment counter ID
}
- if(_spawn_point_counter >= _spawn_point_coord){
- _enemy_coord[id][0] = i;
+ if(_spawn_point_counter >= _spawn_point_coord){ // If counter ID reaches the random coordinate ID
+ _enemy_coord[id][0] = i; // Set the random coordinate
_enemy_coord[id][1] = j;
goto enemy_coord_set;
}
}
}
- enemy_coord_set:{}
+ enemy_coord_set:{} // Acts as a break since there are two for loops
}
-void Room::load()
+void Room::load() // Spawns all Mobs and Walls with reset status (HP, Attack etc) given that they have not died yet (still valid)
{
if(_room_type == 10) {
if (valid_enemies[0]) {
@@ -151,11 +149,9 @@
if (valid_enemies[id]) {
switch(enemies_type[id]){
case 0 :
- enemies[id] = new Headless(_enemy_coord[id][0], _enemy_coord[id][1]);
- break;
+ enemies[id] = new Headless(_enemy_coord[id][0], _enemy_coord[id][1]); break;
case 1 :
- enemies[id] = new Snake(_enemy_coord[id][0], _enemy_coord[id][1]);
- break;
+ enemies[id] = new Snake(_enemy_coord[id][0], _enemy_coord[id][1]); break;
}
}
}
@@ -167,7 +163,7 @@
}
}
-void Room::unload()
+void Room::unload() // Delete existing enemies and walls
{
for (int i = 0; i < MAX_ENEMIES; i++) {
if (valid_enemies[i]) {
@@ -181,18 +177,13 @@
}
}
-void Room::update_doorways()
+void Room::update_doorways() // If it's a boss, close the doorways, else,
{
if(_room_type == 10) {
_doorways[0] = false;
_doorways[1] = false;
_doorways[2] = false;
_doorways[3] = false;
- } else {
- _doorways[0] = _doorways_memory[0];
- _doorways[1] = _doorways_memory[1];
- _doorways[2] = _doorways_memory[2];
- _doorways[3] = _doorways_memory[3];
}
}
@@ -238,7 +229,7 @@
void Room::draw_room(N5110 &lcd)
{
lcd.drawSprite(0, 0, screen_height, screen_width, (char *)level_map[1]); // drawing 3d map
- draw_doorways(lcd);
+ draw_doorways(lcd); // Draw walls that are behind the player
if (_before_boss_room == 0) { // Displaying Special Doorway to Boss room
lcd.drawSprite(35, 0, 12, 14, (char *)boss_doorway_n[0]);
}
@@ -266,7 +257,7 @@
}
}
-void Room::draw_doorways_overlay(N5110 &lcd)
+void Room::draw_doorways_overlay(N5110 &lcd) // Draw walls that are in front of the player
{
if(!_doorways[1]) { // E
lcd.drawSpriteTransparent(81, 15, 11, 3, (char *)wall_x[0]);
@@ -279,7 +270,7 @@
}
}
-bool Room::enemies_exist()
+bool Room::enemies_exist() // Returns true if valid enemies exist
{
for (int i = 0; i < MAX_ENEMIES; i++) {
if (valid_enemies[i]) {
--- a/RoomEngine/Room/Room.h Thu May 09 06:33:28 2019 +0000
+++ b/RoomEngine/Room/Room.h Thu May 09 07:39:49 2019 +0000
@@ -17,7 +17,6 @@
{
private:
bool _doorways[4];
- bool _doorways_memory[4];
int _room_type;
int _enemy_coord[MAX_ENEMIES][2]; // _enemy_coord[EnemyID][x/y]
char _wall_stat[2][4]; // _wall_coord[WallID][x/y/width/height]
@@ -26,16 +25,19 @@
short int _spawn_point_coord;
// Functions
+ void init_boss_room();
+ void init_normal_room();
+ void init_middle_walled_room();
+ void init_side_walled_room();
+
+ void rand_enemy_coordinate(int id);
+
void draw_doorways(N5110 &lcd);
void draw_doorways_overlay(N5110 &lcd);
void draw_enemies(N5110 &lcd, int j);
void draw_collectibles(N5110 &lcd, int j);
void draw_walls(N5110 &lcd, int j);
- void init_normal_room();
- void init_middle_walled_room();
- void init_side_walled_room();
- void init_boss_room();
- void rand_enemy_coordinate(int id);
+
public:
// Constructors
--- a/main.cpp Thu May 09 06:33:28 2019 +0000
+++ b/main.cpp Thu May 09 07:39:49 2019 +0000
@@ -237,16 +237,16 @@
void game_unload()
{
+ delete room_engine;
// Deletes every generated rooms
for (int i = 0; i < MAX_ROOMS_MAP_X; i++) {
for (int j = 0; j < MAX_ROOMS_MAP_Y; j++) {
- if (valid_rooms[j][j]){
+ if (valid_rooms[j][i]){
delete rooms[j][i];
- valid_rooms[i][j] = false;
+ valid_rooms[j][i] = false;
}
}
}
- delete room_engine;
delete player;
}