void entity::process(level& lvl) { if(prev_feet_x_ != INT_MIN) { last_move_x_ = feet_x() - prev_feet_x_; last_move_y_ = feet_y() - prev_feet_y_; } prev_feet_x_ = feet_x(); prev_feet_y_ = feet_y(); prev_platform_rect_ = platform_rect_; }
void entity::set_face_right(bool facing) { if(facing == face_right_) { return; } const int start_x = feet_x(); face_right_ = facing; const int delta_x = feet_x() - start_x; x_ -= delta_x*100; assert(feet_x() == start_x); calculate_solid_rect(); }
int entity::last_move_x() const { if(prev_feet_x_ == INT_MIN) { return 0; } return feet_x() - prev_feet_x_; }
int entity::map_platform_pos(int xpos) const { if(platform_rect_.w() > 0 && platform_rect_.h() > 0 && xpos >= prev_platform_rect_.x() && xpos < prev_platform_rect_.x() + prev_platform_rect_.w()) { const int proportion = xpos - prev_platform_rect_.x(); int maps_to = (1024*proportion*platform_rect_.w())/prev_platform_rect_.w(); if(maps_to%1024 >= 512) { maps_to = platform_rect_.x() + maps_to/1024 + 1; } else { maps_to = platform_rect_.x() + maps_to/1024; } return maps_to - xpos - (feet_x() - prev_feet_x_); } return 0; }
void entity::draw_debug_rects() const { if(preferences::show_debug_hitboxes() == false) { return; } const rect& body = solid_rect(); if(body.w() > 0 && body.h() > 0) { const SDL_Rect rect = { body.x(), body.y(), body.w(), body.h() }; graphics::draw_rect(rect, graphics::color_black(), 0xAA); } const rect& hit = hit_rect(); if(hit.w() > 0 && hit.h() > 0) { const SDL_Rect rect = { hit.x(), hit.y(), hit.w(), hit.h() }; graphics::draw_rect(rect, graphics::color_red(), 0xAA); } const SDL_Rect rect = { feet_x() - 1, feet_y() - 1, 3, 3 }; graphics::draw_rect(rect, graphics::color_white(), 0xFF); }
void entity::process(level& lvl) { prev_feet_x_ = feet_x(); prev_feet_y_ = feet_y(); prev_platform_rect_ = platform_rect_; }