void cMovingSprite :: Collide_Move( void ) { if( !m_valid_update || !Is_In_Player_Range() ) { return; } // move and create collision data Col_Move( m_velx, m_vely ); Move_With_Ground(); }
void cMovingSprite :: Update_Anti_Stuck( void ) { // collision count cObjectCollisionType *col_list = Collision_Check( &m_col_rect, COLLIDE_ONLY_BLOCKING ); // check collisions for( cObjectCollision_List::iterator itr = col_list->objects.begin(), itr_end = col_list->objects.end(); itr != itr_end; ++itr ) { cObjectCollision *collision = (*itr); cSprite *col_obj = collision->obj; if( collision->m_array == ARRAY_ENEMY || ( collision->m_array == ARRAY_ACTIVE && ( col_obj->m_massive_type == MASS_HALFMASSIVE || col_obj->m_massive_type == MASS_CLIMBABLE ) ) ) { continue; } debug_print( "Anti Stuck detected object %s on %s side\n", col_obj->m_name.c_str(), Get_Direction_Name( collision->direction ).c_str() ); if( collision->direction == DIR_LEFT ) { Col_Move( 1.0f, 0.0f, 0, 1 ); } else if( collision->direction == DIR_RIGHT ) { Col_Move( -1.0f, 0.0f, 0, 1 ); } else if( collision->direction == DIR_UP ) { Col_Move( 0.0f, 1.0f, 0, 1 ); } else if( collision->direction == DIR_DOWN ) { Col_Move( 0.0f, -1.0f, 0, 1 ); } } delete col_list; }
void cEnemy::Update(void) { cMovingSprite::Update(); if (m_dead && m_active) { Update_Dying(); } if (m_freeze_counter) { if (m_type == TYPE_FURBALL || m_type == TYPE_TURTLE || m_type == TYPE_KRUSH || m_type == TYPE_SPIKA || m_type == TYPE_SPIKEBALL) { Update_Gravity(); Col_Move(0.0f, m_vely); } } }
void cMovingSprite :: Move_With_Ground( void ) { if( !m_ground_object || ( m_ground_object->m_sprite_array != ARRAY_ACTIVE && m_ground_object->m_sprite_array != ARRAY_ENEMY ) ) // || m_ground_object->sprite_array == ARRAY_MASSIVE { return; } cMovingSprite *moving_ground_object = dynamic_cast<cMovingSprite *>(m_ground_object); // invalid moving sprite if( !moving_ground_object ) { return; } // does not move if( Is_Float_Equal( moving_ground_object->m_velx, 0.0f ) && Is_Float_Equal( moving_ground_object->m_vely, 0.0f ) ) { return; } // check ground first because of the moving object velocity Check_on_Ground(); // save posx for possible can not move test float posy_orig = m_pos_y; /* stop object from getting stopped of the moving object which did not yet move itself * for example the player always moves as last */ bool is_massive = 0; if( moving_ground_object->m_massive_type == MASS_MASSIVE ) { moving_ground_object->m_massive_type = MASS_PASSIVE; is_massive = 1; } // move Col_Move( moving_ground_object->m_velx, moving_ground_object->m_vely, 0, 0, 0 ); if( is_massive ) { moving_ground_object->m_massive_type = MASS_MASSIVE; } // if ground object is moving up if( moving_ground_object->m_vely < -0.01f ) { // test if we could not move upwards because something did block us in Col_Move() if( Is_Float_Equal( m_pos_y, posy_orig ) ) { // massive if( moving_ground_object->m_massive_type == MASS_MASSIVE ) { // got crunched DownGrade( 1 ); } // halfmassive else if( moving_ground_object->m_massive_type == MASS_HALFMASSIVE ) { // lost ground Move( 0.0f, 1.9f, 1 ); Reset_On_Ground(); } } } }