PuzzleSDK
NavMeshTest.h
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2013 cocos2d-x.org
3 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
4
5 http://www.cocos2d-x.org
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 ****************************************************************************/
25
26#ifndef _NAVMESH_TEST_H_
27#define _NAVMESH_TEST_H_
28
29#include "../BaseTest.h"
30#include "navmesh/CCNavMesh.h"
31#include <string>
32
33DEFINE_TEST_SUITE(NavMeshTests);
34
35#if ( CC_USE_NAVMESH == 0 ) || ( CC_USE_PHYSICS == 0 )
37{
38public:
40
41 virtual void onEnter() override;
42};
43#else
44
45class NavMeshBaseTestDemo : public TestCase
46{
47public:
48 CREATE_FUNC(NavMeshBaseTestDemo);
49 NavMeshBaseTestDemo();
50 virtual ~NavMeshBaseTestDemo();
51
52 // overrides
53 virtual bool init() override;
54 virtual void update(float delta) override;
55 virtual void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event);
56 virtual void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event);
57 virtual void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event);
58
59protected:
60
61 void initScene();
62 void createAgent(const cocos2d::Vec3 &pos);
63 void createObstacle(const cocos2d::Vec3 &pos);
64 void moveAgents(const cocos2d::Vec3 &des);
65 virtual void touchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event){};
66 virtual void touchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event){};
67 virtual void touchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event){};
68
69protected:
70 cocos2d::Camera *_camera;
71 float _angle;
72 std::vector<std::pair<cocos2d::NavMeshAgent *, cocos2d::Animate3D *> > _agents;
73 bool _needMoveAgents;
74};
75
76class NavMeshBasicTestDemo : public NavMeshBaseTestDemo
77{
78public:
79 CREATE_FUNC(NavMeshBasicTestDemo);
80 NavMeshBasicTestDemo();
81 virtual ~NavMeshBasicTestDemo();
82
83 // overrides
84 virtual bool init() override;
85 virtual std::string title() const override;
86 virtual std::string subtitle() const override;
87
88 virtual void onEnter() override;
89
90protected:
91
92 virtual void touchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event)override{};
93 virtual void touchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event)override{};
94 virtual void touchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event)override;
95
96protected:
97 cocos2d::Label *_debugLabel;
98};
99
100class NavMeshAdvanceTestDemo : public NavMeshBaseTestDemo
101{
102public:
103 CREATE_FUNC(NavMeshAdvanceTestDemo);
104 NavMeshAdvanceTestDemo();
105 virtual ~NavMeshAdvanceTestDemo();
106
107 // overrides
108 virtual bool init() override;
109 virtual std::string title() const override;
110 virtual std::string subtitle() const override;
111
112 virtual void onEnter() override;
113
114protected:
115
116 virtual void touchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event)override{};
117 virtual void touchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event)override{};
118 virtual void touchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event)override;
119
120protected:
121 cocos2d::Label *_obstacleLabel;
122 cocos2d::Label *_agentLabel;
123 cocos2d::Label *_debugLabel;
124};
125
126#endif
127
128#endif
DEFINE_TEST_SUITE(NavMeshTests)
CREATE_FUNC(NavMeshDisabled)
virtual void onEnter() override
Definition: NavMeshTest.cpp:52