2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
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:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "IntervalTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2015-04-09 08:37:30 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
#define SID_STEP1 100
|
|
|
|
#define SID_STEP2 101
|
|
|
|
#define SID_STEP3 102
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
#define IDC_PAUSE 200
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
IntervalTests::IntervalTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(IntervalTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
IntervalTest::IntervalTest()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_time0 = _time1 = _time2 = _time3 = _time4 = 0.0f;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
// sun
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sun = ParticleSun::create();
|
2013-11-07 21:48:39 +08:00
|
|
|
sun->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
|
2021-12-28 16:06:23 +08:00
|
|
|
sun->setPosition(VisibleRect::rightTop().x - 32, VisibleRect::rightTop().y - 32);
|
2010-09-06 17:14:41 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
sun->setTotalParticles(130);
|
|
|
|
sun->setLife(0.6f);
|
|
|
|
this->addChild(sun);
|
2010-09-06 17:14:41 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// timers
|
2014-03-28 10:28:44 +08:00
|
|
|
_label0 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
|
|
|
|
_label1 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
|
|
|
|
_label2 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
|
|
|
|
_label3 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
|
|
|
|
_label4 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
|
2010-09-25 11:54:33 +08:00
|
|
|
|
|
|
|
scheduleUpdate();
|
2021-12-28 16:06:23 +08:00
|
|
|
schedule(
|
|
|
|
[&](float dt) {
|
|
|
|
_time1 += dt;
|
|
|
|
|
|
|
|
char str[10] = {0};
|
|
|
|
sprintf(str, "%2.1f", _time1);
|
|
|
|
_label1->setString(str);
|
|
|
|
},
|
|
|
|
"step_1");
|
|
|
|
|
|
|
|
schedule(
|
|
|
|
[&](float dt) {
|
|
|
|
_time2 += dt;
|
|
|
|
|
|
|
|
char str[10] = {0};
|
|
|
|
sprintf(str, "%2.1f", _time2);
|
|
|
|
_label2->setString(str);
|
|
|
|
},
|
|
|
|
0.5, "step_2");
|
|
|
|
|
|
|
|
schedule(
|
|
|
|
[&](float dt) {
|
|
|
|
_time3 += dt;
|
|
|
|
|
|
|
|
char str[10] = {0};
|
|
|
|
sprintf(str, "%2.1f", _time3);
|
|
|
|
_label3->setString(str);
|
|
|
|
},
|
|
|
|
1, "step_3");
|
|
|
|
|
|
|
|
schedule(
|
|
|
|
[&](float dt) {
|
|
|
|
_time4 += dt;
|
|
|
|
|
|
|
|
char str[10] = {0};
|
|
|
|
sprintf(str, "%2.1f", _time4);
|
|
|
|
_label4->setString(str);
|
|
|
|
},
|
|
|
|
2, "step_4");
|
|
|
|
|
|
|
|
_label0->setPosition(s.width * 1 / 6, s.height / 2);
|
|
|
|
_label1->setPosition(s.width * 2 / 6, s.height / 2);
|
|
|
|
_label2->setPosition(s.width * 3 / 6, s.height / 2);
|
|
|
|
_label3->setPosition(s.width * 4 / 6, s.height / 2);
|
|
|
|
_label4->setPosition(s.width * 5 / 6, s.height / 2);
|
2010-09-25 11:54:33 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_label0);
|
|
|
|
addChild(_label1);
|
|
|
|
addChild(_label2);
|
|
|
|
addChild(_label3);
|
|
|
|
addChild(_label4);
|
2010-09-25 11:54:33 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Sprite
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create(s_pathGrossini);
|
2014-08-28 11:41:18 +08:00
|
|
|
sprite->setPosition(VisibleRect::left().x + 40, VisibleRect::bottom().y + 50);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto jump = JumpBy::create(3, Vec2(s.width - 80, 0.0f), 50, 4);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sprite);
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite->runAction(RepeatForever::create(Sequence::create(jump, jump->reverse(), nullptr)));
|
2012-04-19 14:35:52 +08:00
|
|
|
// pause button
|
2014-02-20 10:53:49 +08:00
|
|
|
auto item1 = MenuItemFont::create("Pause", [&](Ref* sender) {
|
2021-12-28 16:06:23 +08:00
|
|
|
if (Director::getInstance()->isPaused())
|
|
|
|
Director::getInstance()->resume();
|
|
|
|
else
|
|
|
|
Director::getInstance()->pause();
|
|
|
|
});
|
|
|
|
auto menu = Menu::create(item1, nullptr);
|
|
|
|
menu->setPosition(s.width / 2, s.height - 50);
|
|
|
|
|
|
|
|
addChild(menu);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
IntervalTest::~IntervalTest()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
if (Director::getInstance()->isPaused())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->resume();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
void IntervalTest::update(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
_time0 += dt;
|
2012-04-19 14:35:52 +08:00
|
|
|
char time[10] = {0};
|
2013-06-15 14:03:30 +08:00
|
|
|
sprintf(time, "%2.1f", _time0);
|
|
|
|
_label0->setString(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|