void Body::move(Map *map) { float tw = float(map->get_tile_width()); float th = float(map->get_tile_height()); m_vx += m_ax; if (m_vx < -tw) { m_vx = -tw; } else if (m_vx > tw) { m_vx = tw; } m_vy += m_ay; if (m_vy < -th) { m_vy = -th; } else if (m_vy > th) { m_vy = th; } if (m_vx > 0.0f) { m_dx = int(m_vx); if (!m_lock_dir) { set_dir(Right); if (m_solid) { if (check_ahead(map)) { m_vx = 0.0f; } } } else if (m_dir == Right) { if (m_solid) { if (check_ahead(map)) { m_vx = 0.0f; } } } else if (m_dir == Left) { if (m_solid) { if (check_behind(map)) { m_vx = 0.0f; } } } m_x += m_dx; } else if (m_vx < 0.0f) { m_dx = -int(m_vx); if (!m_lock_dir) { set_dir(Left); if (m_solid) { if (check_ahead(map)) { m_vx = 0.0f; } } } else if (m_dir == Right) { if (m_solid) { if (check_behind(map)) { m_vx = 0.0f; } } } else if (m_dir == Left) { if (m_solid) { if (check_ahead(map)) { m_vx = 0.0f; } } } m_x -= m_dx; } else { set_dir(Keep); m_dx = 0; } if (m_vy > 0.0f) { m_dy = int(m_vy); if (m_solid) { if (check_below(map)) { m_vy = 0.0f; } } if (m_dy) { m_vert_dir = VerticalDown; m_y += m_dy; } } else if (m_vy < 0.0f) { m_dy = -int(m_vy); if (m_solid) { if (check_above(map)) { m_vy = 0.0f; } } if (m_dy) { m_vert_dir = VerticalUp; m_y -= m_dy; } } else { m_dy = 0; } if (!m_dy) { m_vert_dir = VerticalNone; } }
void MekaDragon::move(Map *map) { Monster::move(map); switch(m_action) { case Still: set_action(Move); break; case Move: face_reference(get_attribute("turn_width")); set_lock_direction(true); if (m_horizontal_dir == HorizontalForward) { if (m_dir == Right) { set_vx(get_attribute("move_speed")); } else { set_vx(-get_attribute("move_speed")); } animate_move(); if (abs(m_xref - m_x) < get_attribute("attack_distance")) { m_horizontal_dir = HorizontalBackward; } } else if (m_horizontal_dir == HorizontalBackward) { if (m_dir == Right) { set_vx(-get_attribute("move_speed")); } else { set_vx(get_attribute("move_speed")); } animate_move(); if (abs(m_xref - m_x) > get_attribute("retreat_distance") || check_behind(map)) { m_horizontal_dir = HorizontalForward; } } if (m_attack_now || m_attack_timer.expired(get_attribute("attack_timer"))) { m_attack_timer.reset(); m_attack_now = false; set_attack(); } break; case Attack: if (m_idle_timer.check(get_attribute("attack_idle"))){ fire(); } break; case Hit: m_idle_timer.reset(); m_attack_now = true; break; default: break; } unsigned n = m_bullets.size(); for (unsigned i = 0; i < n; i++) { m_bullets[i]->move(map); } }
void LockFlyer::move(Map *map) { Monster::move(map); if (m_hit == HitOne) { if (m_hit_timer.expired(get_attribute("hit_time"))) { m_dx = 0; reset_hit(); } else { // Move backwards m_dx = get_attribute("move_speed"); // Check for collision with map check_behind(map); // Right of player if (get_reference() == Right) { m_x -= m_dx; } else { m_x += m_dx; } } } switch(m_action) { case Still: if (m_hit == HitNone) { if (m_attack_timer.check(get_attribute("attack_timer"))) { const Sprite *spr = get_sprite(); int dist = get_attribute("attack_distance"); int x = m_xref - get_front(); int y = m_yref - (get_y() + spr->get_height() / 2); if (x * x + y * y < dist * dist) { m_attack_timer.reset(); set_move_dir(); m_lock_y = m_yref + spr->get_height() / 2; } } } break; case Move: if (m_hit == HitNone) { const Sprite *spr = get_sprite(); if (abs(m_lock_y - m_y) > get_attribute("move_speed")) { if (m_y < m_lock_y) { m_vertical_dir = VerticalDown; } else if (m_y > m_lock_y) { m_vertical_dir = VerticalUp; } } else { m_vertical_dir = VerticalNone; } // Move if (m_vertical_dir == VerticalDown) { m_dy = get_attribute("move_speed"); check_below(map); if (!m_dy) { set_action(Still); } else { m_y += m_dy; } } else if (m_vertical_dir == VerticalUp) { m_dy = get_attribute("move_speed"); check_above(map); if (!m_dy) { set_action(Still); } else { m_y -= m_dy; } } else { m_dx = get_attribute("move_speed"); face_reference(get_attribute("turn_width")); check_ahead(map); if (!m_dx) { set_action(Still); } else { if (m_dir == Right) { m_x += m_dx; } else if (m_dir == Left) { m_x -= m_dx; } } } animate_move(); } break; default: break; } }