千炮金蝉捕鱼【源码】

[复制链接]

该用户从未签到

2380

主题

2433

帖子

9139

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
9139
QQ
跳转到指定楼层
楼主
发表于 2017-6-13 11:03:54 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

想要查看内容赶紧注册登陆吧!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
#include "stdafx.h"
#include "Exception.h"
#include "ActionInterval.h"
#include "ActionCombine.h"

/////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////
Action_Sequence::Sequence::Sequence(Action *act1, Action *act2)
:Action_Interval(0)
{
    actions_[0] = (Action_Interval *)act1;
    actions_[1] = (Action_Interval *)act2;

    duration_ = actions_[0]->duration() + actions_[1]->duration();
}

Action_Sequence::Sequence::~Sequence()
{
    delete actions_[0];
    delete actions_[1];
}

void Action_Sequence::Sequence::update(float time)
{
    int found = 0;
    float new_t = 0.0f;   

    if( time >= split_ )
    {        
        found = 1;
        if ( split_ == 1 )
            new_t = 1;
        else
            new_t = (time-split_) / (1 - split_ );
    } else
    {
        found = 0;
        if( split_ != 0 )
            new_t = time / split_;
        else
            new_t = 1;
    }

    if (last_ == -1 && found==1)
    {
        actions_[0]->start_with_target(target_);
        actions_[0]->update(1.0f);
        actions_[0]->stop();
    }

    if (last_ != found )
    {
        if( last_ != -1 )
        {
            actions_[last_]->update(1.0f);
            actions_[last_]->stop();
        }

        actions_[found]->start_with_target(target_);
    }

    actions_[found]->update(new_t);

    last_ = found;
}

void Action_Sequence::Sequence::stop()
{
    actions_[0]->stop();
    actions_[1]->stop();

    __super::stop();
}

void Action_Sequence::Sequence::start_with_target(Entity *target)
{
    __super:: start_with_target(target);   

    split_ = actions_[0]->duration() / duration_;
    last_ = -1;
}

Action_Sequence::Action_Sequence(Action *act1, ...)
:Action_Interval(0)
{
    va_list params;
    va_start(params,act1);   

    Action_Interval *now;
    Action_Interval *prev = (Action_Interval *)act1;

    while( act1 )
    {
        now = va_arg(params,Action_Interval*);
        if ( now )
        {
            prev = new Sequence(prev, now);
        }
        else
            break;
    }

    va_end(params);

    duration_ = prev->duration();

    sequence_ = (Sequence *)prev;
}

Action_Sequence::~Action_Sequence()
{
    delete sequence_;
}

void Action_Sequence::stop()
{
    sequence_->stop();

    __super::stop();
}

void Action_Sequence::update(float time)
{
    sequence_->update(time);
}

void Action_Sequence::start_with_target(Entity *target)
{
    __super::start_with_target(target);

    sequence_->start_with_target(target);
}

///////////////////////////////////////////////////////////////////////////////////////////
Action_Spawn::Spawn::Spawn(Action *act1, Action *act2)
:Action_Interval(0)
{
    actions_[0] = (Action_Interval *)act1;
    actions_[1] = (Action_Interval *)act2;

    float d1, d2;

    d1 = actions_[0]->duration();
    d2 = actions_[1]->duration();

    if (d1 > d2)
    {
        actions_[1] = new Action_Sequence(actions_[1], Action_Delay(d1 - d2), 0);
    }
    else if (d1 < d2)
    {
        actions_[0] = new Action_Sequence(actions_[0], Action_Delay(d2 - d1), 0);
    }

    duration_ = max((actions_[0]->duration()), (actions_[1]->duration()));
}

Action_Spawn::Spawn::~Spawn()
{
    delete actions_[0];
    delete actions_[1];
}

void Action_Spawn::Spawn::update(float time)
{
    actions_[0]->update(time);
    actions_[1]->update(time);
}

void Action_Spawn::Spawn::stop()
{
    actions_[0]->stop();
    actions_[1]->stop();

    __super::stop();
}

void Action_Spawn::Spawn::start_with_target(Entity *target)
{
    __super:: start_with_target(target);   

    actions_[0]->start_with_target(target);
    actions_[1]->start_with_target(target);
}

Action_Spawn::Action_Spawn(Action *act1, ...)
:Action_Interval(0)
{
    va_list params;
    va_start(params,act1);   

    Action_Interval *now;
    Action_Interval *prev = (Action_Interval *)act1;

    while( act1 )
    {
        now = va_arg(params,Action_Interval*);
        if ( now )
        {
            prev = new Spawn(prev, now);
        }
        else
            break;
    }

    va_end(params);

    duration_ = prev->duration();

    spawn_ = (Spawn *)prev;
}

Action_Spawn::~Action_Spawn()
{
    delete spawn_;
}

void Action_Spawn::stop()
{
    spawn_->stop();

    __super::stop();
}

void Action_Spawn::update(float time)
{
    spawn_->update(time);
}

void Action_Spawn::start_with_target(Entity *target)
{
    __super::start_with_target(target);

    spawn_->start_with_target(target);
}

/////////////////////////////////////////////////////////////////////////////////////////
Action_Repeat_Forever::Action_Repeat_Forever(Action *a)
:stop_(false),
other_(a)
{
}

Action_Repeat_Forever::~Action_Repeat_Forever()
{
    if (other_)
    {
        delete other_;
    }
}

void Action_Repeat_Forever::step(float dt)
{
    other_->step(dt);
    if( other_->is_done())
    {
        other_->stop();
        other_->start_with_target(target_);
    }
}

void Action_Repeat_Forever::start_with_target(Entity *target)
{
    other_->start_with_target(target);
    __super::start_with_target(target);
}

/////////////////////////////////////////////////////////////////////////////////////////

千炮金蝉捕鱼【源码】.txt

138 Bytes, 下载次数: 3

售价: 2 代码豆  [记录]

分享到:  QQ好友和群QQ好友和群
收藏收藏
回复

使用道具 举报

快速回复高级模式
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表