A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
Diff: Entity/Bosses/Skull/Skull.cpp
- Revision:
- 57:1c12361b6e3d
- Parent:
- 56:ef9521b7ed78
--- a/Entity/Bosses/Skull/Skull.cpp Thu May 09 08:42:52 2019 +0000 +++ b/Entity/Bosses/Skull/Skull.cpp Thu May 09 09:50:19 2019 +0000 @@ -2,35 +2,35 @@ #include <complex> Skull::Skull(float pos_x, float pos_y) { - hp = 20; - attack = 1; + _hp = 20; + _attack = 1; _dash = false; _dash_counter = 0; - hitbox.width = 19; - hitbox.height = 9; + _hitbox.width = 19; + _hitbox.height = 9; - sprite_size.width = 21; - sprite_size.height = 23; - sprite_size.offset_x = -1; - sprite_size.offset_y = -14; + _sprite_size.width = 21; + _sprite_size.height = 23; + _sprite_size.offset_x = -1; + _sprite_size.offset_y = -14; _shadow.width = 19; _shadow.height = 5; _shadow.offset_x = 0; _shadow.offset_y = 5; - position.x = pos_x; - position.y = pos_y; + _position.x = pos_x; + _position.y = pos_y; update_prev_pos(); - frame.count = 0; - frame.number = 0; - frame.max = 2; - face = 2; + _frame.count = 0; + _frame.number = 0; + _frame.max = 2; + _face = 2; - velocity = 0.2; + _velocity = 0.2; _hp_drop_chance = 0; } @@ -42,10 +42,10 @@ dash_movement(); } else { _dash_counter = 0; - velocity = 0.2; + _velocity = 0.2; } - 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)); + 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)); _dash_counter++; increment_frames(); @@ -54,21 +54,21 @@ void Skull::approaching_movement(float player_x, float player_y) { _dash = false; - std::complex<double> pos_diff(player_x - position.x, player_y - position.y); // defining difference in position as a vector for simplicity, similar to Headless - position.x += velocity * pos_diff.real() / std::abs(pos_diff); - position.y += velocity * pos_diff.imag() / std::abs(pos_diff); + std::complex<double> pos_diff(player_x - _position.x, player_y - _position.y); // defining difference in position as a vector for simplicity, similar to Headless + _position.x += _velocity * pos_diff.real() / std::abs(pos_diff); + _position.y += _velocity * pos_diff.imag() / std::abs(pos_diff); // Setting Face if (abs(pos_diff.real()) > abs(pos_diff.imag())) { if (pos_diff.real() > 0) { - face = 1; + _face = 1; } else { - face = 3; + _face = 3; } } else { if (pos_diff.imag() > 0) { - face = 2; + _face = 2; } else { - face = 0; + _face = 0; } } } @@ -76,55 +76,55 @@ void Skull::dash_movement() // Changes velocity over time using the velocity pattern { _dash = true; - velocity = skull_velocity_pattern[(int)((_dash_counter - DASH_DELAY)/4)]; - if (face == 0){ - position.y -= velocity; - } else if (face == 1){ - position.x += velocity; - } else if (face == 2){ - position.y += velocity; - } else if (face == 3){ - position.x -= velocity; + _velocity = skull_velocity_pattern[(int)((_dash_counter - DASH_DELAY)/4)]; + if (_face == 0){ + _position.y -= _velocity; + } else if (_face == 1){ + _position.x += _velocity; + } else if (_face == 2){ + _position.y += _velocity; + } else if (_face == 3){ + _position.x -= _velocity; } } void Skull::draw(N5110 &lcd) { update_offsets(); - lcd.drawSpriteTransparent(position.x+_shadow.offset_x, - position.y+_shadow.offset_y, + lcd.drawSpriteTransparent(_position.x+_shadow.offset_x, + _position.y+_shadow.offset_y, _shadow.height, _shadow.width, - (char *)skull_shadow_sprite[frame.number]); - lcd.drawSpriteTransparent(position.x+sprite_size.offset_x, - position.y+sprite_size.offset_y, - sprite_size.height, - sprite_size.width, - (char *)skull_sprite[face][_dash]); + (char *)skull_shadow_sprite[_frame.number]); + lcd.drawSpriteTransparent(_position.x+_sprite_size.offset_x, + _position.y+_sprite_size.offset_y, + _sprite_size.height, + _sprite_size.width, + (char *)skull_sprite[_face][_dash]); } void Skull::take_damage(int damage) { - hp -= 1; + _hp -= 1; } // Methods void Skull::increment_frames() { - if (frame.number < frame.max) { - frame.count++; + if (_frame.number < _frame.max) { + _frame.count++; } else { - frame.count = 0; + _frame.count = 0; } - frame.number = (frame.count/20) % frame.max; + _frame.number = (_frame.count/20) % _frame.max; } void Skull::update_offsets() // Animates the shadows by offsetting the skull from the shadow periodically { - if (frame.number == 0) { - sprite_size.offset_y = -14; - } else if (frame.number == 1) { - sprite_size.offset_y = -15; + if (_frame.number == 0) { + _sprite_size.offset_y = -14; + } else if (_frame.number == 1) { + _sprite_size.offset_y = -15; } } \ No newline at end of file