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:
- 36:92d131695e7c
- Parent:
- 34:1d5b4da3935e
- Child:
- 37:a404860171a9
diff -r 06cd6be999ad -r 92d131695e7c Entity/Bosses/Skull/Skull.cpp --- a/Entity/Bosses/Skull/Skull.cpp Mon May 06 20:05:14 2019 +0000 +++ b/Entity/Bosses/Skull/Skull.cpp Tue May 07 01:11:07 2019 +0000 @@ -1,43 +1,124 @@ #include "Skull.h" +#include <complex> Skull::Skull(float pos_x, float pos_y) { - hp = 5; + hp = 25; attack = 1; - moving = false; - hitbox.width = 0; - hitbox.height = 0; + _dash = false; + _dash_counter = 0; + + moving = true; + hitbox.width = 19; + hitbox.height = 9; - sprite_size.width = 0; - sprite_size.height = 0; - sprite_size.offset_x = 0; - sprite_size.offset_y = 0; + sprite_size.width = 21; + sprite_size.height = 23; + sprite_size.offset_x = -1; + sprite_size.offset_y = -14; - position.x = 31; - position.y = 12; + _shadow.width = 19; + _shadow.height = 5; + _shadow.offset_x = 0; + _shadow.offset_y = 5; + + position.x = pos_x; + position.y = pos_y; update_prev_pos(); frame.count = 0; frame.number = 0; - frame.max = 4; + frame.max = 2; face = 0; - velocity = 0.1; + velocity = 0.2; _damage_self_upon_collision = false; _hp_drop_chance = 30; } void Skull::move(float player_x, float player_y, char * map, bool * doorways) { + // Approaching Movement + if (_dash_counter < DASH_DELAY) { + _dash = false; + std::complex<double> pos_diff(player_x - position.x, player_y - position.y); // defining difference in position as a vector + 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; + } else { + face = 3; + } + } else { + if (pos_diff.imag() > 0) { + face = 2; + } else { + face = 0; + } + } + } else if (_dash_counter < DASH_DELAY + 28){ + _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; + } + } else { + _dash_counter = 0; + 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)); + _dash_counter++; + increment_frames(); } void Skull::draw(N5110 &lcd) { - + update_offsets(); + 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]); } void Skull::take_damage(int damage) { - + hp -= 1; +} + +// Private Functions + +void Skull::increment_frames() +{ + if (frame.number < frame.max) { + frame.count++; + } else { + frame.count = 0; + } + frame.number = (frame.count/20) % frame.max; +} + +void Skull::update_offsets() +{ + 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