Пример #1
0
 void cBaseBox::Update_Collision(void)
 {
     if (move_col_dir == DIR_UNDEFINED)
     {
         return;
     }
     
     if (move_col_dir != DIR_UP && move_col_dir != DIR_DOWN && move_col_dir != DIR_RIGHT && move_col_dir != DIR_LEFT)
     {
         printf("Warning : wrong box collision direction %d\n", move_col_dir);
         move_col_dir = DIR_UNDEFINED;
         Update_Valid_Update();
         return;
     }
     
     float mod = pFramerate->m_speed_factor * 0.05f;
     
     move_counter += pFramerate->m_speed_factor * 0.2f;
     
     if (!move_back)
     {
         Add_Scale(mod);
         
         Generate_Activation_Particles();
         
         if (move_counter > 1.0f)
         {
             move_back = 1;
             move_counter = 0.0f;
         }
     }
     else
     {
         Add_Scale(-mod);
         
         if (move_counter > 1.0f)
         {
             move_col_dir = DIR_UNDEFINED;
             Update_Valid_Update();
             move_back = 0;
             move_counter = 0.0f;
             
             m_col_pos = m_image->m_col_pos;
             
             Set_Scale(1);
             Set_Scale_Directions(1, 1, 1, 1);
             
             Set_Pos(m_start_pos_x, m_start_pos_y);
         }
     }
 }
Пример #2
0
void cSpinBox :: Stop( void )
{
	// already stopped spinning
	if( !m_spin )
	{
		return;
	}

	// disabled image
	if( !m_useable_count )
	{
		Set_Image_Num( 0 );
	}
	// default image
	else
	{
		Set_Image_Num( 1 );
	}
	// reset
	m_spin = 0;
	Update_Valid_Update();
	m_spin_counter = 0.0f;

	// back to a massive box
	m_massive_type = MASS_MASSIVE;
	// disable animation
	Set_Animation( 0 );
	Reset_Animation();
}
Пример #3
0
void cMovingSprite :: Freeze( float freeze_time /* = speedfactor_fps * 10 */ )
{
	m_freeze_counter = freeze_time;

	// apply resistance
	if( m_ice_resistance > 0.0f )
	{
		m_freeze_counter *= ( m_ice_resistance * -1 ) + 1;
	}

	Update_Valid_Update();
}
Пример #4
0
void cBonusBox :: Update( void )
{
	if( !m_valid_update || !Is_In_Range() )
	{
		return;
	}

	// update active items
	for( MovingSpriteList::iterator itr = m_active_items.begin(); itr != m_active_items.end(); )
	{
		cPowerUp *powerup = static_cast<cPowerUp *>(*itr);

		if( !powerup->m_active )
		{
			++itr;
			continue;
		}

		float diff = powerup->m_pos_y - (m_pos_y - powerup->m_col_rect.m_h - powerup->m_col_pos.m_y);

		// position over the box reached
		if( diff < 0.0f )
		{
			// clear animation counter
			powerup->m_counter = 0.0f;

			// set powerup default posz
			powerup->m_pos_z = 0.05f;

			// set the item on top
			powerup->Set_On_Top( this, 0 );
			// add the item to the level objects
			m_sprite_manager->Add( powerup );

			// remove from array
			itr = m_active_items.erase( itr );
			Update_Valid_Update();
		}
		// move upwards
		else
		{
			powerup->m_counter += pFramerate->m_speed_factor;
			powerup->Move( 0.0f, -1.0f - (diff * 0.1f) );

			++itr;
		}
	}

	cBaseBox::Update();
}
Пример #5
0
void cMovingSprite :: Update( void )
{
	if( m_freeze_counter > 0.0f )
	{
		m_freeze_counter -= pFramerate->m_speed_factor;

		if( m_freeze_counter <= 0.0f )
		{
			// todo : Event_Freeze_Ended()
			m_freeze_counter = 0.0f;
			Update_Valid_Update();
		}
	}
}
Пример #6
0
 void cBaseBox::Activate_Collision(ObjectDirection cdirection)
 {
     if (move_col_dir != DIR_UNDEFINED)
     {
         return;
     }
     
     if (useable_count == 0)
     {
         return;
     }
     
     if (box_invisible)
     {
         if (box_invisible == BOX_INVISIBLE_SEMI_MASSIVE)
         {
             m_massive_type = MASS_MASSIVE;
         }
     }
     
     if (cdirection == DIR_UP)
     {
         Set_Scale_Directions(1, 0, 1, 1);
     }
     else if (cdirection == DIR_DOWN)
     {
         Set_Scale_Directions(0, 1, 1, 1);
     }
     else if (cdirection == DIR_LEFT)
     {
         Set_Scale_Directions(1, 0, 1, 0);
     }
     else if (cdirection == DIR_RIGHT)
     {
         Set_Scale_Directions(1, 0, 0, 1);
     }
     
     move_col_dir = cdirection;
     Update_Valid_Update();
     
     Check_Collision(Get_Opposite_Direction(move_col_dir));
     Activate();
     
     if (useable_count > 0 || useable_count == -1)
     {
         Set_Useable_Count(useable_count - 1);
     }
 }
Пример #7
0
void cBonusBox::Set_Useable_Count(int count, bool new_startcount /* = 0 */)
{
    cBaseBox::Set_Useable_Count(count, new_startcount);

    // disable
    if (!m_useable_count) {
        Reset_Animation();
        Set_Animation(0);
        Set_Image_Num(0);
    }
    // enable
    else {
        Set_Animation(1);
    }

    Update_Valid_Update();
}
Пример #8
0
void cSpinBox :: Activate( void )
{
	// already spinning
	if( m_spin )
	{
		return;
	}

	m_spin = 1;
	Update_Valid_Update();
	// passive box for spinning
	m_massive_type = MASS_PASSIVE;

	m_spin_counter = 0.0f;
	// enable animation
	Set_Animation( 1 );
	Reset_Animation();
}
Пример #9
0
void cRandom_Sound::Update(void)
{
    Update_Valid_Update();

    if (!m_valid_update) {
        return;
    }

    bool play = 0;

    if (m_continuous) {
        m_volume_update_counter -= pFramerate->m_elapsed_ticks;

        // get the sound
        cAudio_Sound* sound = pAudio->Get_Playing_Sound(m_filename);

        // if not playing
        if (!sound) {
            // play it
            play = 1;
        }
        // update volume
        else if (m_volume_update_counter <= 0.0f) {
            // volume based on maximum
            float sound_volume = m_volume_max * 0.01f;
            // apply distance modifier
            sound_volume *= Get_Distance_Volume_Mod();
            // set to mixer volume
            sound_volume *= static_cast<float>(MIX_MAX_VOLUME);
            // set volume
            pAudio->Set_Sound_Volume(static_cast<Uint8>(sound_volume), sound->m_channel);

            // update volume every 100 ms
            m_volume_update_counter = 100.0f;
        }
    }
    else {
        // subtract duration of this frame in milliseconds
        m_next_play_delay -= pFramerate->m_elapsed_ticks;

        // play it
        if (m_next_play_delay <= 0.0f) {
            play = 1;

            // set next delay
            m_next_play_delay = static_cast<float>(m_delay_min);

            if (m_delay_max > m_delay_min) {
                m_next_play_delay += Get_Random_Float(0.0f, static_cast<float>(m_delay_max - m_delay_min));
            }
        }
    }

    if (play) {
        float sound_volume = 0.0f;

        // always maximum volume
        if (m_continuous) {
            sound_volume = m_volume_max;
        }
        // set random volume
        else {
            // random
            if (m_volume_max > m_volume_min) {
                sound_volume = Get_Random_Float(m_volume_min, m_volume_max);
            }
            // static
            else {
                sound_volume = m_volume_max;
            }
        }

        sound_volume *= 0.01f;

        // adjust volume based on distance
        sound_volume *= Get_Distance_Volume_Mod();

        int loops = 0;

        if (m_continuous) {
            // unlimited
            loops = -1;
        }

        sound_volume *= static_cast<float>(MIX_MAX_VOLUME);

        // play sound
        pAudio->Play_Sound(m_filename, -1, static_cast<int>(sound_volume), loops);
    }
}
Пример #10
0
 void cEnemy::Set_Dead(bool enable)
 {
     m_dead = enable;
     
     Update_Valid_Update();
 }
Пример #11
0
void cBonusBox::Activate(void)
{
    cBaseBox::Activate();

    bool random = 0;

    // random
    if (box_type == TYPE_POWERUP) {
        int r = rand() % 5;

        if (r == 0) {
            box_type = TYPE_MUSHROOM_DEFAULT;
        }
        else if (r == 1) {
            box_type = TYPE_FIREPLANT;
        }
        else if (r == 2) {
            box_type = TYPE_MUSHROOM_BLUE;
        }
        else if (r == 3) {
            box_type = TYPE_MUSHROOM_GHOST;
        }
        else if (r == 4) {
            box_type = TYPE_STAR;
        }

        random = 1;
    }

    Maryo_type current_maryo_type;

    // use original type
    if (pLevel_Player->m_maryo_type == MARYO_GHOST) {
        current_maryo_type = pLevel_Player->m_maryo_type_temp_power;
    }
    // already using original type
    else {
        current_maryo_type = pLevel_Player->m_maryo_type;
    }

    // the item from this box
    cMovingSprite* box_item = NULL;

    // no item
    if (box_type == TYPE_UNDEFINED) {
        pAudio->Play_Sound("item/empty_box.wav");
    }
    // check if lower item should be used if no force best item
    else if (!m_force_best_item && (box_type == TYPE_FIREPLANT || box_type == TYPE_MUSHROOM_BLUE) &&
             (current_maryo_type == MARYO_SMALL || ((current_maryo_type == MARYO_FIRE || current_maryo_type == MARYO_ICE) && !pHud_Itembox->m_item_id))) {
        pAudio->Play_Sound("sprout_1.ogg");

        cMushroom* mushroom = new cMushroom(m_sprite_manager);
        mushroom->Set_Pos(m_start_pos_x - ((m_item_image->m_w - m_rect.m_w) / 2), m_start_pos_y - ((m_item_image->m_h - m_rect.m_h) / 2), 1);
        box_item = static_cast<cMovingSprite*>(mushroom);
    }
    else if (box_type == TYPE_FIREPLANT) {
        pAudio->Play_Sound("sprout_1.ogg");
        box_item = static_cast<cMovingSprite*>(new cFirePlant(m_sprite_manager));
        box_item->Set_Pos(m_start_pos_x - ((m_item_image->m_w - m_rect.m_w) / 2), m_start_pos_y, 1);
    }
    else if (box_type == TYPE_MUSHROOM_DEFAULT || box_type == TYPE_MUSHROOM_LIVE_1 || box_type == TYPE_MUSHROOM_POISON || box_type == TYPE_MUSHROOM_BLUE || box_type == TYPE_MUSHROOM_GHOST) {
        pAudio->Play_Sound("sprout_1.ogg");

        cMushroom* mushroom = new cMushroom(m_sprite_manager);
        mushroom->Set_Pos(m_start_pos_x - ((m_item_image->m_w - m_rect.m_w) / 2), m_start_pos_y - ((m_item_image->m_h - m_rect.m_h) / 2), 1);
        mushroom->Set_Type(box_type);
        box_item = static_cast<cMovingSprite*>(mushroom);
    }
    else if (box_type == TYPE_STAR) {
        pAudio->Play_Sound("sprout_1.ogg");
        cjStar* star = new cjStar(m_sprite_manager);
        star->Set_Pos(m_start_pos_x - ((m_item_image->m_w - m_rect.m_w) / 2), m_start_pos_y, 1);
        star->Set_On_Top(this);
        star->Set_Spawned(1);
        // add to global objects
        m_sprite_manager->Add(star);
    }
    else if (box_type == TYPE_GOLDPIECE) {
        pAudio->Play_Sound("item/jewel_1.ogg");

        cJGoldpiece* goldpiece = new cJGoldpiece(m_sprite_manager);
        goldpiece->Set_Pos(m_start_pos_x - ((m_item_image->m_w - m_rect.m_w) / 2), m_pos_y, 1);
        goldpiece->Set_Gold_Color(m_gold_color);
        // add to global objects
        m_sprite_manager->Add(goldpiece);
    }
    else {
        printf("Error : Unknown bonusbox item type %d\n", box_type);
        return;
    }

    // set back random state
    if (random) {
        box_type = TYPE_POWERUP;
    }

    if (box_item) {
        // set posz behind box
        box_item->m_pos_z = m_pos_z - 0.000001f;
        // set spawned
        box_item->Set_Spawned(1);

        // add to item list
        m_active_items.push_back(box_item);
        Update_Valid_Update();
    }
}