Magic_Game/core/base/ActionInterval.h

428 lines
8.2 KiB
C
Raw Normal View History

2018-10-03 22:02:46 +08:00
// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "Action.hpp"
2018-11-15 17:59:18 +08:00
#include "logs.h"
2017-10-19 00:50:04 +08:00
2018-10-16 14:13:15 +08:00
namespace easy2d
2017-10-19 00:50:04 +08:00
{
2018-11-20 13:48:49 +08:00
class IntervalAction
2018-09-10 20:55:20 +08:00
: public Action
2018-09-05 13:33:39 +08:00
{
public:
2018-11-20 13:48:49 +08:00
explicit IntervalAction(
Duration const& duration
2018-09-05 13:33:39 +08:00
);
2018-09-05 13:33:39 +08:00
virtual void Reset() override;
2018-09-05 13:33:39 +08:00
protected:
virtual void Init(Node* target) override;
virtual void Update(Node* target, Duration const& dt) override;
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
protected:
Duration duration_;
float process_;
2018-09-05 13:33:39 +08:00
};
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
// <20><><EFBFBD><EFBFBD>λ<EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>
2018-09-10 20:55:20 +08:00
class MoveBy
2018-11-20 13:48:49 +08:00
: public IntervalAction
2018-09-05 13:33:39 +08:00
{
public:
explicit MoveBy(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
Point const& vector /* <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD> */
2018-09-05 13:33:39 +08:00
);
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override;
2018-09-05 13:33:39 +08:00
protected:
virtual void Init(Node* target) override;
2017-10-19 00:50:04 +08:00
virtual void Update(Node* target, Duration const& dt) override;
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
protected:
Point start_pos_;
Point prev_pos_;
Point delta_pos_;
};
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
// λ<>ƶ<EFBFBD><C6B6><EFBFBD>
2018-09-10 20:55:20 +08:00
class MoveTo
: public MoveBy
2018-05-14 00:36:01 +08:00
{
2018-09-05 13:33:39 +08:00
public:
explicit MoveTo(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
Point const& pos /* Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
2018-09-05 13:33:39 +08:00
);
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override
2018-09-05 13:33:39 +08:00
{
2018-11-15 17:59:18 +08:00
logs::Errorln("Reverse() not supported in MoveTo");
2018-09-05 13:33:39 +08:00
return nullptr;
}
2018-05-10 14:03:54 +08:00
2018-09-05 13:33:39 +08:00
protected:
virtual void Init(Node* target) override;
2018-05-10 14:03:54 +08:00
2018-09-05 13:33:39 +08:00
protected:
Point end_pos_;
};
2018-05-10 14:03:54 +08:00
2018-09-05 13:33:39 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ծ<EFBFBD><D4BE><EFBFBD><EFBFBD>
2018-09-10 20:55:20 +08:00
class JumpBy
2018-11-20 13:48:49 +08:00
: public IntervalAction
2018-09-05 13:33:39 +08:00
{
public:
explicit JumpBy(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
Point const& vec, /* <20><>Ծ<EFBFBD><D4BE><EFBFBD><EFBFBD> */
float height, /* <20><>Ծ<EFBFBD>߶<EFBFBD> */
int jumps = 1 /* <20><>Ծ<EFBFBD><D4BE><EFBFBD><EFBFBD> */
2018-09-05 13:33:39 +08:00
);
2018-05-10 14:03:54 +08:00
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
2018-05-10 14:03:54 +08:00
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override;
2018-05-10 14:03:54 +08:00
2018-09-05 13:33:39 +08:00
protected:
virtual void Init(Node* target) override;
virtual void Update(Node* target, Duration const& dt) override;
2018-05-10 14:03:54 +08:00
2018-09-05 13:33:39 +08:00
protected:
Point start_pos_;
Point delta_pos_;
float height_;
int jumps_;
Point prev_pos_;
};
2018-05-10 14:03:54 +08:00
2018-09-05 13:33:39 +08:00
// <20><>Ծ<EFBFBD><D4BE><EFBFBD><EFBFBD>
2018-09-10 20:55:20 +08:00
class JumpTo
: public JumpBy
2018-09-05 13:33:39 +08:00
{
public:
explicit JumpTo(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
Point const& pos, /* Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
float height, /* <20><>Ծ<EFBFBD>߶<EFBFBD> */
int jumps = 1 /* <20><>Ծ<EFBFBD><D4BE><EFBFBD><EFBFBD> */
2018-09-05 13:33:39 +08:00
);
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override
2018-09-05 13:33:39 +08:00
{
2018-11-15 17:59:18 +08:00
logs::Errorln("Reverse() not supported in JumpTo");
2018-09-05 13:33:39 +08:00
return nullptr;
}
protected:
virtual void Init(Node* target) override;
2018-09-05 13:33:39 +08:00
protected:
Point end_pos_;
};
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6><EFBFBD>
2018-09-10 20:55:20 +08:00
class ScaleBy
2018-11-20 13:48:49 +08:00
: public IntervalAction
2018-09-05 13:33:39 +08:00
{
public:
explicit ScaleBy(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
float scale /* <20><><EFBFBD>Ա仯ֵ */
2018-09-05 13:33:39 +08:00
);
2017-10-21 19:09:31 +08:00
2018-09-05 13:33:39 +08:00
explicit ScaleBy(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
float scale_x, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա仯ֵ */
float scale_y /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա仯ֵ */
2018-09-05 13:33:39 +08:00
);
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override;
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
protected:
virtual void Init(Node* target) override;
virtual void Update(Node* target, Duration const& dt) override;
2018-09-05 13:33:39 +08:00
protected:
float start_scale_x_;
float start_scale_y_;
float delta_x_;
float delta_y_;
};
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
// <20><><EFBFBD>Ŷ<EFBFBD><C5B6><EFBFBD>
2018-09-10 20:55:20 +08:00
class ScaleTo
: public ScaleBy
2018-09-05 13:33:39 +08:00
{
public:
explicit ScaleTo(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
float scale /* Ŀ<><C4BF>ֵ */
2018-09-05 13:33:39 +08:00
);
explicit ScaleTo(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
float scale_x, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ֵ */
float scale_y /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ֵ */
2018-09-05 13:33:39 +08:00
);
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override
2018-09-05 13:33:39 +08:00
{
2018-11-15 17:59:18 +08:00
logs::Errorln("Reverse() not supported in ScaleTo");
2018-09-05 13:33:39 +08:00
return nullptr;
}
protected:
virtual void Init(Node* target) override;
2018-09-05 13:33:39 +08:00
protected:
float end_scale_x_;
float end_scale_y_;
};
// ͸<><CDB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><E4B6AF>
2018-09-10 20:55:20 +08:00
class OpacityBy
2018-11-20 13:48:49 +08:00
: public IntervalAction
2018-05-14 00:36:01 +08:00
{
2018-09-05 13:33:39 +08:00
public:
explicit OpacityBy(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
float opacity /* <20><><EFBFBD>Ա仯ֵ */
2018-09-05 13:33:39 +08:00
);
2018-05-14 00:36:01 +08:00
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override;
2018-09-05 13:33:39 +08:00
protected:
virtual void Init(Node* target) override;
2017-10-19 00:50:04 +08:00
virtual void Update(Node* target, Duration const& dt) override;
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
protected:
float start_val_;
float delta_val_;
};
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
// ͸<><CDB8><EFBFBD>Ƚ<EFBFBD><C8BD><EFBFBD><E4B6AF>
2018-09-10 20:55:20 +08:00
class OpacityTo
: public OpacityBy
2018-09-05 13:33:39 +08:00
{
public:
explicit OpacityTo(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
float opacity /* Ŀ<><C4BF>ֵ */
2018-09-05 13:33:39 +08:00
);
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override
2018-09-05 13:33:39 +08:00
{
2018-11-15 17:59:18 +08:00
logs::Errorln("Reverse() not supported in OpacityTo");
2018-09-05 13:33:39 +08:00
return nullptr;
}
2018-09-05 13:33:39 +08:00
protected:
virtual void Init(Node* target) override;
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
protected:
float end_val_;
};
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
// <20><><EFBFBD><EFBFBD><EBB6AF>
2018-09-10 20:55:20 +08:00
class FadeIn
: public OpacityTo
2018-05-14 00:36:01 +08:00
{
2018-09-05 13:33:39 +08:00
public:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB6AF>
explicit FadeIn(
Duration const& duration /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
2018-09-05 13:33:39 +08:00
);
};
2018-09-05 13:33:39 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-09-10 20:55:20 +08:00
class FadeOut
: public OpacityTo
2018-09-05 13:33:39 +08:00
{
public:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
explicit FadeOut(
Duration const& duration /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
2018-09-05 13:33:39 +08:00
);
};
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
2018-09-10 20:55:20 +08:00
class RotateBy
2018-11-20 13:48:49 +08:00
: public IntervalAction
2018-09-05 13:33:39 +08:00
{
public:
explicit RotateBy(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
float rotation /* <20><><EFBFBD>Ա仯ֵ */
2018-09-05 13:33:39 +08:00
);
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override;
2018-09-05 13:33:39 +08:00
protected:
virtual void Init(Node* target) override;
virtual void Update(Node* target, Duration const& dt) override;
2018-09-05 13:33:39 +08:00
protected:
float start_val_;
float delta_val_;
};
2018-09-05 13:33:39 +08:00
// <20><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
2018-09-10 20:55:20 +08:00
class RotateTo
: public RotateBy
2018-09-05 13:33:39 +08:00
{
public:
explicit RotateTo(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
float rotation /* Ŀ<><C4BF>ֵ */
2018-09-05 13:33:39 +08:00
);
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override
2018-09-05 13:33:39 +08:00
{
2018-11-15 17:59:18 +08:00
logs::Errorln("Reverse() not supported in RotateTo");
2018-09-05 13:33:39 +08:00
return nullptr;
}
2018-09-05 13:33:39 +08:00
protected:
virtual void Init(Node* target) override;
2018-09-05 13:33:39 +08:00
protected:
float end_val_;
};
2018-11-20 13:48:49 +08:00
// ·<><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class PathAction
: public IntervalAction
{
public:
explicit PathAction(
Duration const& duration, /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
spGeometry const& geo, /* <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC> */
bool rotating = false, /* <20><>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD><DFB7><EFBFBD><EFBFBD><EFBFBD>ת */
float start = 0.f, /* <20><><EFBFBD><EFBFBD> */
float end = 1.f /* <20>յ<EFBFBD> */
);
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override;
protected:
virtual void Update(Node* target, Duration const& dt) override;
protected:
bool rotating_;
float start_;
float end_;
spGeometry geo_;
};
2018-09-05 13:33:39 +08:00
// <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
2018-09-10 20:55:20 +08:00
class Delay
: public Action
2018-05-14 00:36:01 +08:00
{
2018-09-05 13:33:39 +08:00
public:
explicit Delay(
Duration const& duration /* <20>ӳ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>룩 */
2018-09-05 13:33:39 +08:00
);
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual spAction Clone() const override;
2017-10-19 00:50:04 +08:00
2018-09-05 13:33:39 +08:00
// <20><>ȡ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
virtual spAction Reverse() const override;
2018-05-14 00:36:01 +08:00
2018-09-05 13:33:39 +08:00
// <20><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD>
virtual void Reset() override;
2018-09-05 13:33:39 +08:00
protected:
virtual void Init(Node* target) override;
virtual void Update(Node* target, Duration const& dt) override;
2018-09-05 13:33:39 +08:00
protected:
Duration delay_;
Duration delta_;
2018-09-05 13:33:39 +08:00
};
}