void StaticFunc::buttonSound() { int iTemp = CCRANDOM_0_1()* 100; if(iTemp < 25) { iTemp = 1; } else if(iTemp < 50) { iTemp = 1; } else if(iTemp < 75) { iTemp = 1; } else { iTemp = 1; } char cSoundBtn[20]; sprintf(cSoundBtn,"music/button%d.mp3",iTemp); playSound(cSoundBtn); }
void Enemy::update(float time) { switch (type) { case 0: { this->setPosition(this->getPosition()+Point(0, -3)); break; } case 1: { if(isActed){break;} isActed=true; this->runAction(Sequence::create(MoveTo::create(0.8, World::getWorldScene()->getPlayer()->getPosition()),DelayTime::create(1),MoveTo::create(0.6, this->getPosition()), NULL)); break; } case 2: { this->setPosition(this->getPosition()+Point(CCRANDOM_0_1()*10-5, -3)); break; } } if(this->getPositionY()<-this->getContentSize().height) { this->getParent()->removeChild(this,true); World::getWorldScene()->getEnemyArray().eraseObject(this); } Player* player=World::getWorldScene()->getPlayer(); if(!player->isDead) { if(player->boundingBox().intersectsRect(this->boundingBox())) { player->downHp(); } } }
int GameGlobals::GetNumVerticesForFormation(EEnemyFormation type) { switch(type) { case E_FORMATION_RANDOM_EASY: // CCLOG("E_FORMATION_RANDOM_EASY"); return (int)(1 + CCRANDOM_0_1() * 5); case E_FORMATION_RANDOM_MEDIUM: // CCLOG("E_FORMATION_RANDOM_MEDIUM"); return (int)(5 + CCRANDOM_0_1() * 10); case E_FORMATION_RANDOM_HARD: // CCLOG("E_FORMATION_RANDOM_HARD"); return (int)(10 + CCRANDOM_0_1() * 15); case E_FORMATION_VERTICAL_EASY: // CCLOG("E_FORMATION_VERTICAL_EASY"); return 6; case E_FORMATION_VERTICAL_MEDIUM: // CCLOG("E_FORMATION_VERTICAL_MEDIUM"); return 10; case E_FORMATION_VERTICAL_HARD: // CCLOG("E_FORMATION_VERTICAL_HARD"); return 14; case E_FORMATION_HORIZONTAL_EASY: // CCLOG("E_FORMATION_HORIZONTAL_EASY"); return 10; case E_FORMATION_HORIZONTAL_MEDIUM: // CCLOG("E_FORMATION_HORIZONTAL_MEDIUM"); return 14; case E_FORMATION_HORIZONTAL_HARD: // CCLOG("E_FORMATION_HORIZONTAL_HARD"); return 20; case E_FORMATION_POLYGON_EASY: // CCLOG("E_FORMATION_POLYGON_EASY"); return (5 + (int)(CCRANDOM_0_1() * 6)); case E_FORMATION_POLYGON_MEDIUM: // CCLOG("E_FORMATION_POLYGON_MEDIUM"); return 2 * (5 + (int)(CCRANDOM_0_1() * 5)); case E_FORMATION_POLYGON_HARD: // CCLOG("E_FORMATION_POLYGON_HARD"); return 3 * (5 + (int)(CCRANDOM_0_1() * 4)); } return 0; }
void Bat::spawnBat2(cocos2d::Layer * layer) { auto Bat=cocos2d::Sprite::create("Spike.png"); Bat->setScale(0.5, 0.5); auto ran=CCRANDOM_0_1(); auto posi_x=ran*(visibleSize.width/2)+origin.x+visibleSize.width/2; auto posi_y=origin.y+visibleSize.height+Bat->getContentSize().height; /* Vector<SpriteFrame*> an(4); an.pushBack(SpriteFrame::create("Bat (1).png", Rect(0,0,174,118))); an.pushBack(SpriteFrame::create("Bat (2).png", Rect(0,0,174,118))); an.pushBack(SpriteFrame::create("Bat (3).png", Rect(0,0,174,118))); an.pushBack(SpriteFrame::create("Bat (4).png", Rect(0,0,174,118))); auto ann=Animation::createWithSpriteFrames(an,0.1f); auto anim_ll=Animate::create(ann); auto anim_l=RepeatForever::create(anim_ll); Bat->runAction(anim_l); */ auto size=Bat->getContentSize(); //size.width=size.width*0.8; //size.height=size.height*0.8; auto body=cocos2d::PhysicsBody::createCircle(size.height/4); body->setDynamic(false); body->setCollisionBitmask(BAT_COLLISION_BITMASK); body->setContactTestBitmask(BAT_CONTACT_BITMASK); Bat->setPhysicsBody(body); Bat->setPosition(Point(posi_x,posi_y)); layer->addChild(Bat,102); auto move_dis=visibleSize.height+Bat->getContentSize().height+130; auto move_duration=BAT_SPEED*move_dis; auto FireBall_move=cocos2d::MoveBy::create(move_duration,Point(0,-move_dis)); Bat->runAction(Sequence::create(FireBall_move,RemoveSelf::create(true),nullptr)); }
void HelloWorld::menuRandomFormation(bool isPlayer) { int start = 0; int end = 20; if(isPlayer) { // Label index is 0 - 19 } else { // Label index is 20 -39 start = 20; end = 39; } for(int i = start; i < end; i++) { int a = (int)(CCRANDOM_0_1() * 999999); int r = a % 3 + 1; _menuLabels.at(i)->setString(Resources::getInstance()->getStringSquadType((SquadType)r)); } }
bool Soldier::haloSkillTrigger() { Level* level = dynamic_cast<Level*>(this->getParent()); if (level == NULL) { return false; } Miao* miao = level->miao; if (miao == NULL) { return false; } float distance = abs(miao->getPositionY() - this->getPositionY()); if (miao->getHaloRadius() < distance) { return false; } float randValue = CCRANDOM_0_1()*100; haloSkillTriggerResult = randValue >= 0 && randValue < haloSkillRate; return haloSkillTriggerResult; }
void CGenetic::crossover(const std::vector<int> &mum, const std::vector<int> &dad, std::vector<int> &baby1, std::vector<int> &baby2) { if (CCRANDOM_0_1() > m_fCrossoverRate || mum == dad) { baby1 = mum; baby2 = dad; return; } baby1.resize(m_iChromoLength); baby2.resize(m_iChromoLength); int cp = random(0, m_iChromoLength - 1); int i; for (i=0; i<cp; ++i) { baby1[i] = mum[i]; baby2[i] = dad[i]; } for (i=cp; i<m_iChromoLength; ++i) { baby2[i] = mum[i]; baby1[i] = dad[i]; } }
void HWorld::autoCreateEnemy(float time)//创建敌人---1秒调用一次 { int random=CCRANDOM_0_1()*10; int randomType; const char *name; if (random>=0&&random<=2) { randomType=0; name="enemy_bug.png"; }else if(random>=3&&random<=6) { randomType=1; name="enemy_duck.png"; }else if(random>=7&&random<=10) { randomType=2; name="enemy_pig.png"; } HEnemy *enemy=NULL;//防止循环时再次调用同样的指针 enemy=HEnemy::createEnemy(name, randomType);//创建一个怪物精灵 arrayEnemy->pushBack(enemy);//将怪物精灵放入数组 this->addChild(enemy);//将怪物精灵添加到world层中 }
void GameScene::startDrop(float dt,Sprite* em,bool isMoving){ auto winsize = Director::getInstance()->getWinSize(); FiniteTimeAction *actionMove = MoveTo::create(dt, Point(em->getPosition().x, -winsize.height+em->getContentSize().height*.5)); FiniteTimeAction *actionMoveDone = CallFuncN::create([&](Node* node){ for (auto sp : curWave){ sp->removeFromParent(); } auto scene = StartScene::scene(); auto transition=TransitionFade::create(1.0f,scene); Director::getInstance()->replaceScene(transition); }); if (isMoving) { Sequence *emyAction = Sequence::create(actionMove,actionMoveDone, NULL); emyAction->setTag(DropActionTag); em->runAction(emyAction); }else{ DelayTime *delay = DelayTime::create(CCRANDOM_0_1()*1.5f); Sequence *emyAction = Sequence::create(delay,actionMove,actionMoveDone, NULL); emyAction->setTag(DropActionTag); em->runAction(emyAction); } }
void Article::initParam() { int randInt = CCRANDOM_0_1() * 4; //随机纹理 if (randInt == 0) this->setTexture(SD_STRING("article_path_texture")); else this->setTexture(SD_STRING("article_path_texture_1")); this->getBody()->SetSleepingAllowed(true); //允许物理休眠 this->getFixture()->SetRestitution(SD_FLOAT("article_float_restitution")); //弹力 this->getFixture()->SetFriction(SD_FLOAT("article_float_friction")); //摩擦力 int boxWidth = this->getBodyBoundingBoxWidth(); int boxHeight = this->getBodyBoundingBoxHeight(); b2MassData mass; mass.mass = SD_FLOAT("article_float_mass"); mass.I = SD_FLOAT("article_float_i"); //todo mass.center = this->getBody()->GetLocalCenter(); this->getBody()->SetMassData(&mass); this->setType(TYPE_ARTICLE); this->setMask( //碰撞类型 TYPE_ARTICLE | TYPE_BRICK | TYPE_HERO | TYPE_MONSTER | TYPE_WEAPON ); this->setHp(SD_INT("article_int_hp")); }
void GameEnemy::chooseflytype() { type = CCRANDOM_0_1() * 5; switch(type){ case 0: mysprite->initWithFile("gplayer.png"); bezierTo1 = CCBezierTo::actionWithDuration(5, bezier1); mysprite->runAction(bezierTo1); break; case 1: mysprite->initWithFile("gplayer.png"); bezierTo1 = CCBezierTo::actionWithDuration(5, bezier2); mysprite->runAction(bezierTo1); break; case 2: mysprite->initWithFile("gplayer.png"); actionTo1 = CCMoveTo::actionWithDuration(2, CCPointMake(30,300)); actionTo2 = CCMoveTo::actionWithDuration(2, CCPointMake(800,150)); actionTo3 = CCMoveTo::actionWithDuration(1, CCPointMake(400,-20)); mysprite->runAction(CCSequence::actions(actionTo1,actionTo2,actionTo3,NULL)); break; case 3: mysprite->initWithFile("gplayer.png"); actionTo1 = CCMoveTo::actionWithDuration(2, CCPointMake(800,300)); actionTo2 = CCMoveTo::actionWithDuration(2, CCPointMake(30,150)); actionTo3 = CCMoveTo::actionWithDuration(1, CCPointMake(400,-20)); mysprite->runAction(CCSequence::actions(actionTo1,actionTo2,actionTo3,NULL)); break; case 4: mysprite->initWithFile("gplayer.png"); actionTo1 = CCMoveTo::actionWithDuration(5, CCPointMake(122,-20)); mysprite->runAction(actionTo1); break; } mysprite->setRotation(90); }
void LevelFifteen::callbackC(Node* sender) { auto visibleSize = Director::getInstance()->getVisibleSize(); auto pictureName = 1 + rand() % 27; auto str = String::createWithFormat("%d.png", pictureName)->getCString(); auto ballTwo2 = Sprite::createWithSpriteFrameName(str); ballTwo2->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height - 90)); PhysicsBody* ballBodyTwo = nullptr; if (pictureName <= 9) { ballBodyTwo = PhysicsBody::createBox(ballTwo2->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT); } else if (pictureName > 9 && pictureName <= 18) { ballBodyTwo = PhysicsBody::createCircle(ballTwo2->getContentSize().width / 2.0f, PHYSICSBODY_MATERIAL_DEFAULT); } else if (pictureName > 18 && pictureName <= 21) { Vec2 vec[] = { Vec2(-22.50000, 22.00000), Vec2(24.00000, 10.00000), Vec2(-10.00000, -24.00000) }; ballBodyTwo = PhysicsBody::createPolygon(vec, 3); } else if (pictureName > 21 && pictureName <= 24) { Vec2 vec[] = { Vec2(-15.50000, 15.00000), Vec2(15.50000, 6.00000), Vec2(-7.00000, -15.50000) }; ballBodyTwo = PhysicsBody::createPolygon(vec, 3); } else if (pictureName > 24 && pictureName <= 27) { Vec2 vec[] = { Vec2(-8.00000, 8.00000), Vec2(7.50000, 3.00000), Vec2(-4.00000, -7.50000) }; ballBodyTwo = PhysicsBody::createPolygon(vec, 3); } //是否设置物体为静态 //ballBodyTwo->setDynamic(false); ballBodyTwo->getShape(0)->setRestitution(1.0f); ballBodyTwo->getShape(0)->setFriction(0.0f); ballBodyTwo->getShape(0)->setDensity(1.0f); ballBodyTwo->setGravityEnable(false); ballBodyTwo->setCategoryBitmask(2);// 分类掩码 ballBodyTwo->setCollisionBitmask(1 | 2 | 4 | 8);// 碰撞掩码 ballBodyTwo->setContactTestBitmask(1 | 8);// 接触测试掩码 ballBodyTwo->addMass(1000.0f); int flag = CCRANDOM_0_1() * 2; auto num = 0; switch (flag) { case 0: num = -1; break; case 1: num = 1; break; default: break; } auto force1 = Vec2(CCRANDOM_0_1()*10000.0f*num, -300000.0f); ballBodyTwo->applyImpulse(force1); ballTwo2->setPhysicsBody(ballBodyTwo); this->addChild(ballTwo2); }
bool LevelFifteen::init() { if (!Layer::init()) { return false; } // 用于解决刚体穿透问题 this->scheduleUpdate(); // 计时器 this->schedule(schedule_selector(LevelFifteen::timeCounter), 1.0f); auto visibleSize = Director::getInstance()->getVisibleSize(); auto origin = Director::getInstance()->getVisibleOrigin(); // 加载背景贴图 auto spriteBg = Sprite::create("background.png"); spriteBg->setAnchorPoint(Vec2::ZERO); spriteBg->setPosition(Vec2::ZERO); addChild(spriteBg); // 将资源加载到精灵帧缓存 SpriteFrameCache::getInstance()->addSpriteFramesWithFile("threeColor.plist"); ballOne = Sprite::createWithSpriteFrameName("hero.png"); ballOne->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f); auto ballBodyOne = PhysicsBody::createCircle(ballOne->getContentSize().width / 2, PHYSICSBODY_MATERIAL_DEFAULT); //是否设置物理为静态 //ballBodyOne->setDynamic(false); //设置物理的恢复力 ballBodyOne->getShape(0)->setRestitution(0.5f); //设置物体的摩擦力 ballBodyOne->getShape(0)->setFriction(0.0f); ballBodyOne->getShape(0)->setDensity(0.3f); // 设置质量 质量等于密度乘以面积 //ballBodyOne->getShape(0)->setMass(5000); // 设置物体是否受重力系数影响 ballBodyOne->setGravityEnable(true); ballBodyOne->setCategoryBitmask(1);// 分类掩码 ballBodyOne->setCollisionBitmask(1 | 2 | 4 | 8);// 碰撞掩码 ballBodyOne->setContactTestBitmask(2);// 接触测试掩码 // 把物体添加到精灵 ballOne->setPhysicsBody(ballBodyOne); this->addChild(ballOne); // 创建抢食者(黑色) Sprite* black = nullptr; PhysicsBody* blackBody = nullptr; Vec2 arrBlack[] = { Vec2(-34.00000, -32.50000), Vec2(-15.00000, 36.00000), Vec2(35.00000, -15.00000) }; int indexBlack = CCRANDOM_0_1() * 3; switch (indexBlack) { case 0: { black = Sprite::createWithSpriteFrameName("black1.png"); blackBody = PhysicsBody::createBox(black->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT); } break; case 1: { black = Sprite::createWithSpriteFrameName("black2.png"); blackBody = PhysicsBody::createCircle(black->getContentSize().width / 2.0f, PHYSICSBODY_MATERIAL_DEFAULT); } break; case 2: { black = Sprite::createWithSpriteFrameName("black3.png"); blackBody = PhysicsBody::createPolygon(arrBlack, 3, PHYSICSBODY_MATERIAL_DEFAULT); } break; default: break; } black->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f); blackBody->setDynamic(true); blackBody->setGravityEnable(false); blackBody->setCategoryBitmask(8); blackBody->setCollisionBitmask(1 | 2 | 4 | 8); blackBody->setContactTestBitmask(2); black->setPhysicsBody(blackBody); this->addChild(black); //创建一个盒子,用来碰撞 auto edgeSpace = Sprite::create(); auto boundBody = PhysicsBody::createEdgeBox(visibleSize, PHYSICSBODY_MATERIAL_DEFAULT, 3); boundBody->getShape(0)->setFriction(0.0f); boundBody->getShape(0)->setRestitution(1.0f); edgeSpace->setPhysicsBody(boundBody); edgeSpace->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2)); this->addChild(edgeSpace); edgeSpace->setTag(0); boundBody->setCategoryBitmask(4); boundBody->setCollisionBitmask(1 | 2 | 4 | 8); boundBody->setContactTestBitmask(0); // 创建yuan auto white1 = Sprite::createWithSpriteFrameName("white2.png"); auto whiteBody1 = PhysicsBody::createCircle(white1->getContentSize().width / 2.0f, PHYSICSBODY_MATERIAL_DEFAULT); whiteBody1->setDynamic(false); whiteBody1->setCategoryBitmask(4); whiteBody1->setCollisionBitmask(1 | 2 | 4 | 8); whiteBody1->setContactTestBitmask(0); white1->setPhysicsBody(whiteBody1); this->addChild(white1); // 正方形 auto white1_2 = Sprite::createWithSpriteFrameName("white1.png"); auto whiteBody1_2 = PhysicsBody::createBox(white1_2->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT); whiteBody1_2->setDynamic(false); whiteBody1_2->setCategoryBitmask(4); whiteBody1_2->setCollisionBitmask(1 | 2 | 4 | 8); whiteBody1_2->setContactTestBitmask(0); white1_2->setPhysicsBody(whiteBody1_2); this->addChild(white1_2); // 创建三角形 Vec2 arr[] = { Vec2(-16.50000, 36.00000), Vec2(35.50000, -15.00000), Vec2(-34.00000, -32.50000) }; auto white3 = Sprite::createWithSpriteFrameName("white3.png"); auto whiteBody3 = PhysicsBody::createPolygon(arr, 3, PHYSICSBODY_MATERIAL_DEFAULT); whiteBody3->setDynamic(false); whiteBody3->setCategoryBitmask(4); whiteBody3->setCollisionBitmask(1 | 2 | 4 | 8); whiteBody3->setContactTestBitmask(0); white3->setPhysicsBody(whiteBody3); this->addChild(white3); // 随机位置 int index = CCRANDOM_0_1() * 3; switch (index) { case 0: { white1->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f + 200.0f); white1_2->setPosition(visibleSize.width / 2.0f + 200.0f, visibleSize.height / 2.0f); white3->setPosition(visibleSize.width / 2.0f - 200.0f, visibleSize.height / 2.0f); } break; case 1: { white1_2->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f + 200.0f); white1->setPosition(visibleSize.width / 2.0f + 200.0f, visibleSize.height / 2.0f); white3->setPosition(visibleSize.width / 2.0f - 200.0f, visibleSize.height / 2.0f); } break; case 2: { white3->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f + 200.0f); white1->setPosition(visibleSize.width / 2.0f + 200.0f, visibleSize.height / 2.0f); white1_2->setPosition(visibleSize.width / 2.0f - 200.0f, visibleSize.height / 2.0f); } break; default: break; } // 正方形旋转 auto rotation = RotateBy::create(1, 360); auto rotationback = rotation->reverse(); auto seq = Sequence::create(rotation, rotationback, nullptr); auto repeat = RepeatForever::create(seq); white1->runAction(repeat); // // 第二个正方形旋转 auto rotation_1 = RotateBy::create(2, 360); auto rotationback_1 = rotation_1->reverse(); auto seq1 = Sequence::create(rotation_1, rotationback_1, nullptr); auto repeat1 = RepeatForever::create(seq1); white1_2->runAction(repeat1); // 三角形旋转 auto rotation_2 = RotateBy::create(2, 360); auto rotationback_2 = rotation_2->reverse(); auto seq2 = Sequence::create(rotation_2, rotationback_2, nullptr); auto repeat2 = RepeatForever::create(seq2); white3->runAction(repeat2); auto yuantong0 = Sprite::createWithSpriteFrameName("yuantong.png"); yuantong0->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height + yuantong0->getContentSize().height / 2.0f)); auto yuantongBody = PhysicsBody::createBox(yuantong0->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT); yuantongBody->setDynamic(false); yuantongBody->setCategoryBitmask(4); yuantongBody->setCollisionBitmask(1 | 2 | 4 | 8); yuantongBody->setContactTestBitmask(0); yuantong0->setPhysicsBody(yuantongBody); this->addChild(yuantong0); auto moveby0 = MoveBy::create(1.0f, Vec2(0, -90)); auto moveby0back = moveby0->reverse(); auto easein = EaseBackIn::create(moveby0); auto seq0 = Sequence::create(easein, CallFuncN::create(CC_CALLBACK_1(LevelFifteen::callbackC, this)), moveby0back, nullptr); auto repeat0 = RepeatForever::create(seq0); yuantong0->runAction(repeat0); listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [=](Touch* touch, Event* event){ auto touchPosition = touch->getLocation(); Vec2 force = Vec2::ZERO; if ((touchPosition.x > visibleSize.width / 2.0f) && (touchPosition.y < visibleSize.height / 2.0f)) { force = Vec2(50000.0f, 0.0f); } else if ((touchPosition.y < visibleSize.height / 2.0f) && (touchPosition.x < visibleSize.width / 2.0f)) { force = Vec2(-50000.0f, 0.0f); } else { force = Vec2(0.0f, 50000.0f); } ballOne->getPhysicsBody()->applyImpulse(force); return true; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); // 时间显示文本 test = LabelAtlas::create(StringUtils::toString(nGoal), "1.png", 14, 21, '0'); test->setScale(2.0f); test->setAnchorPoint(Vec2::ANCHOR_MIDDLE); test->setPosition(Vec2(test->getContentSize().width + 10, visibleSize.height - test->getContentSize().height)); this->addChild(test); test2 = LabelAtlas::create(StringUtils::toString(newTimes), "1.png", 14, 21, '0'); test2->setScale(2.0f); test2->setAnchorPoint(Vec2::ANCHOR_MIDDLE); test2->setPosition(Vec2(visibleSize.width - test2->getContentSize().width - 10, visibleSize.height - test2->getContentSize().height)); this->addChild(test2); test3 = LabelAtlas::create(StringUtils::toString(nTimes), "1.png", 14, 21, '0'); test3->setScale(2.0f); test3->setAnchorPoint(Vec2::ANCHOR_MIDDLE); test3->setPosition(Vec2(test3->getContentSize().width*4.0f + 40, visibleSize.height - test3->getContentSize().height)); this->addChild(test3); return true; }
bool Bug1174Layer::init() { if (BugsTestBase::init()) { // // seed // std::srand(0); Vec2 A,B,C,D,p1,p2,p3,p4; float s,t; int err=0; int ok=0; // // Test 1. // log("Test1 - Start"); for( int i=0; i < 10000; i++) { // A | b // ----- // c | d float ax = CCRANDOM_0_1() * -5000; float ay = CCRANDOM_0_1() * 5000; // a | b // ----- // c | D float dx = CCRANDOM_0_1() * 5000; float dy = CCRANDOM_0_1() * -5000; // a | B // ----- // c | d float bx = CCRANDOM_0_1() * 5000; float by = CCRANDOM_0_1() * 5000; // a | b // ----- // C | d float cx = CCRANDOM_0_1() * -5000; float cy = CCRANDOM_0_1() * -5000; A = Vec2(ax,ay); B = Vec2(bx,by); C = Vec2(cx,cy); D = Vec2(dx,dy); if( Vec2::isLineIntersect( A, D, B, C, &s, &t) ) { if( check_for_error(A, D, B, C, s, t) ) err++; else ok++; } } log("Test1 - End. OK=%i, Err=%i", ok, err); // // Test 2. // log("Test2 - Start"); p1 = Vec2(220,480); p2 = Vec2(304,325); p3 = Vec2(264,416); p4 = Vec2(186,416); s = 0.0f; t = 0.0f; if( Vec2::isLineIntersect(p1, p2, p3, p4, &s, &t) ) check_for_error(p1, p2, p3, p4, s,t ); log("Test2 - End"); // // Test 3 // log("Test3 - Start"); ok=0; err=0; for( int i=0;i<10000;i++) { // A | b // ----- // c | d float ax = CCRANDOM_0_1() * -500; float ay = CCRANDOM_0_1() * 500; p1 = Vec2(ax,ay); // a | b // ----- // c | D float dx = CCRANDOM_0_1() * 500; float dy = CCRANDOM_0_1() * -500; p2 = Vec2(dx,dy); ////// float y = ay - ((ay - dy) /2.0f); // a | b // ----- // C | d float cx = CCRANDOM_0_1() * -500; p3 = Vec2(cx,y); // a | B // ----- // c | d float bx = CCRANDOM_0_1() * 500; p4 = Vec2(bx,y); s = 0.0f; t = 0.0f; if( Vec2::isLineIntersect(p1, p2, p3, p4, &s, &t) ) { if( check_for_error(p1, p2, p3, p4, s,t ) ) err++; else ok++; } } log("Test3 - End. OK=%i, err=%i", ok, err); return true; } return false; }
void RenderTextureSave::clearImage(cocos2d::CCObject *pSender) { m_pTarget->clear(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1()); }
NS_CC_BEGIN int RpgSkillData::getAtkDistance() { return CCRANDOM_0_1() * (this->atkMaxDistance - this->atkMinDistance) + this->atkMinDistance; }
int Fish::getRand(int start,int end) { float i = CCRANDOM_0_1()*(end-start+1)+start; //产生一个从start到end间的随机数 return (int)i; }
//添加敌机 void GameScene::addEnemy(float dt) { log("add enemy ... ..."); auto config = Config::getInstance(); auto shipSize = config->enemy_list->size(); log("enemy size:% ld", shipSize); if (shipSize >= 5) { return; } auto winSize = Director::getInstance()->getWinSize(); //creat boos //if(config->getScore( ) >= levelScore) //{ // auto boos = Enemy::creatEnemy( this, config->StructEnemyList( )->at( getBoosByLevel( levelNum ) ) ); // config->enemy_list->pushBack( boos ); // this->addChild( boos, SHIP_Z_ORDER ); // //初始化位置 移动位置 // auto initPosition = VisibleRect::top( ); // boos->setPosition( Vec2( CCRANDOM_0_1( )*initPosition.x*1.5, initPosition.y ) ); // auto boosPosition = boos->getPosition( ); // boos->runAction( MoveTo::create( 1.0f, Vec2( CCRANDOM_0_1( )* initPosition.x, 300 ) ) ); // auto nowPsition = boos->getPosition( ); // nowPsition.clamp( Vec2::ZERO, Vec2( winSize.height, winSize.height ) ); // boos->runAction( RepeatForever::create( ActionForEnemy::CreateMoveByOfSequenceX( nowPsition ) ) ); // //this->unschedule( schedule_selector( GameScene::addEnemy ) ); // //移动轨迹 // return; //} int rnd = CCRANDOM_0_1() * 6;// 0~5 之间随机数 auto commonEnemy = Enemy::creatEnemy(this, config->StructEnemyList()->at(rnd)); config->enemy_list->pushBack(commonEnemy); this->addChild(commonEnemy, SHIP_Z_ORDER); auto initPosition = VisibleRect::top(); commonEnemy->setPosition(Vec2(CCRANDOM_0_1()*initPosition.x*1.5, initPosition.y)); commonEnemy->runAction(MoveTo::create(1.0f, Vec2(CCRANDOM_0_1()* initPosition.x, 300))); auto nowPsition = commonEnemy->getPosition(); nowPsition.clamp(Vec2::ZERO, Vec2(winSize.height, winSize.height)); int rndAction = Kit::rnd(0, 1); log("rnd value :%d", rndAction); if (rndAction == 0) { commonEnemy->runAction(RepeatForever::create(ActionForEnemy::CreateMoveByOfSequenceX(nowPsition))); } else{ commonEnemy->runAction(RepeatForever::create(ActionForEnemy::CreateBezierBy())); } }
//Npc-攻击 BevRunningStatus HeroBevTreeNPCAttack::doExecute(const BevNodeInputParam& input, BevNodeOutputParam& output) { const BTNodeInputData& inputData = input.getRealDataType<BTNodeInputData>(); BTNodeOutputData& outputData = output.getRealDataType<BTNodeOutputData>(); //未播放完技能动画直接返回 if (inputData.m_Owner->getBodyState()==GameEnum::BodyState::Skill) { return k_BRS_Executing; } m_WaitingTime+=inputData.m_TimeStep; float attactRandom=CCRANDOM_0_1(); //技能攻击 if (attactRandom < 0.15 && inputData.m_Owner->getBodyState()!=GameEnum::BodyState::Attack) { float skillRandom=CCRANDOM_0_1(); //计算随机NPC播放技能 if (skillRandom > 0.75 && skillRandom < 1.0) { animateName=inputData.m_Owner->getActionFileMode()->SkillName1; }else if (skillRandom > 0.5 && skillRandom < 0.75) { animateName=inputData.m_Owner->getActionFileMode()->SkillName2; }else if (skillRandom > 0.25 && skillRandom < 0.5) { animateName=inputData.m_Owner->getActionFileMode()->SkillName3; }else{ animateName=inputData.m_Owner->getActionFileMode()->SkillName4; } auto event=BaseActionEvent::create(); event->setBaseActionEvent(GameEnum::BaseActionEventType::PlayAnimate); event->setEventArg(__String::create(animateName)); event->setEventBodyState(GameEnum::BodyState::Skill); outputData.m_OutEvent.pushBack(event); }else //普通攻击 { if (m_WaitingTime>0.15) { m_WaitingTime=0; if (inputData.m_CurrPosition2D.x > inputData.m_TargetPosition2D.x) { outputData.m_NextFacing=Vec2(-1,0); }else{ outputData.m_NextFacing=Vec2(1,0); } } inputData.m_Owner->commonAttack(); /* auto heroModel=inputData.m_Owner->getActionFileMode(); std::string strlastAnimateName=inputData.m_Owner->lastPlayAnimateName; std::string strName="null"; std::vector<std::string> strVec; strVec.push_back(heroModel->ActionAttackName1); strVec.push_back(heroModel->ActionAttackName2); strVec.push_back(heroModel->ActionAttackName3); if (heroModel->ActionAttackName4!=strName) { strVec.push_back(heroModel->ActionAttackName4); } if (heroModel->ActionAttackName5!=strName) { strVec.push_back(heroModel->ActionAttackName5); } for (int i=0; i< strVec.size(); i++) { if (strlastAnimateName==strVec.at(i)) { int playIndex=i+1; playIndex= (playIndex==strVec.size()) ? 0 : playIndex; animateName=strVec.at(playIndex); break; } }*/ } outputData.m_vVelocity=Vec2::ZERO; /* //普通攻击 auto event=BaseActionEvent::create(); event->setBaseActionEvent(GameEnum::BaseActionEventType::PlayAnimate); event->setEventArg(__String::create(animateName)); event->setEventBodyState(GameEnum::BodyState::Attack); outputData.m_OutEvent.pushBack(event); */ return k_BRS_Executing; }
Scene* GameSceneMgr::getRandTransitionAction( float t, Scene* s ) { int type = CCRANDOM_0_1()*(TransitionType_Max); return getTransitionAction(t, s, (TransitionType)type ); }
void performanceScale(Sprite* sprite) { auto size = Director::getInstance()->getWinSize(); sprite->setPosition(Point((rand() % (int)size.width), (rand() % (int)size.height))); sprite->setScale(CCRANDOM_0_1() * 100 / 50); }
Sprite* SubTest::createSpriteWithTag(int tag) { TextureCache *cache = Director::getInstance()->getTextureCache(); Sprite* sprite = NULL; switch (subtestNumber) { /// case 1: case 2: { sprite = Sprite::create("Images/grossinis_sister1.png"); _parentNode->addChild(sprite, 0, tag+100); break; } case 3: case 4: { Texture2D *texture = cache->addImage("Images/grossinis_sister1.png"); sprite = Sprite::createWithTexture(texture, Rect(0, 0, 52, 139)); _parentNode->addChild(sprite, 0, tag+100); break; } /// case 5: { int idx = (CCRANDOM_0_1() * 1400 / 100) + 1; char str[32] = {0}; sprintf(str, "Images/grossini_dance_%02d.png", idx); sprite = Sprite::create(str); _parentNode->addChild(sprite, 0, tag+100); break; } case 6: case 7: case 8: { int y,x; int r = (CCRANDOM_0_1() * 1400 / 100); y = r / 5; x = r % 5; x *= 85; y *= 121; Texture2D *texture = cache->addImage("Images/grossini_dance_atlas.png"); sprite = Sprite::createWithTexture(texture, Rect(x,y,85,121)); _parentNode->addChild(sprite, 0, tag+100); break; } /// case 9: { int y,x; int r = (CCRANDOM_0_1() * 6400 / 100); y = r / 8; x = r % 8; char str[40] = {0}; sprintf(str, "Images/sprites_test/sprite-%d-%d.png", x, y); sprite = Sprite::create(str); _parentNode->addChild(sprite, 0, tag+100); break; } case 10: case 11: case 12: { int y,x; int r = (CCRANDOM_0_1() * 6400 / 100); y = r / 8; x = r % 8; x *= 32; y *= 32; Texture2D *texture = cache->addImage("Images/spritesheet1.png"); sprite = Sprite::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32))); _parentNode->addChild(sprite, 0, tag+100); break; } /// case 13: { int test = (CCRANDOM_0_1() * 3); if(test==0) { // Switch case 1 sprite = Sprite::create("Images/grossinis_sister1.png"); _parentNode->addChild(sprite, 0, tag+100); } else if(test==1) { // Switch case 6 int y,x; int r = (CCRANDOM_0_1() * 1400 / 100); y = r / 5; x = r % 5; x *= 85; y *= 121; Texture2D *texture = cache->addImage("Images/grossini_dance_atlas.png"); sprite = Sprite::createWithTexture(texture, Rect(x,y,85,121)); _parentNode->addChild(sprite, 0, tag+100); } else if(test==2) { int y,x; int r = (CCRANDOM_0_1() * 6400 / 100); y = r / 8; x = r % 8; x *= 32; y *= 32; Texture2D *texture = cache->addImage("Images/spritesheet1.png"); sprite = Sprite::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32))); _parentNode->addChild(sprite, 0, tag+100); } } default: break; } return sprite; }
void TestLayer::testLogic(int testIndex) { if (testIndex == 1) { if (m_bSpiderMonkeyInited) { c_addLogToCLI(3, "[C++] %s", "Spidermonkey already inited!!!"); return; } // init spidermonkey ScriptingCore* sc = ScriptingCore::getInstance(); CCScriptEngineProtocol *pEngine = ScriptingCore::getInstance(); CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); sc->addRegisterCallback(register_all_cocos2dx); sc->addRegisterCallback(register_all_cocos2dx_extension); sc->addRegisterCallback(register_cocos2dx_js_extensions); sc->addRegisterCallback(register_all_cocos2dx_extension_manual); sc->addRegisterCallback(jsb_register_system); sc->addRegisterCallback(JSB_register_opengl); sc->start(); if (!JS_DefineFunctions(sc->getGlobalContext(), sc->getGlobalObject(), myjs_global_functions)) { c_addLogToCLI(4, "[C++] JS_DefineFunctions Failed!!!"); return; } sc->runScript("GlobalFuncTest.js"); sc->runScript("SpriteFuncTest.js"); m_bSpiderMonkeyInited = true; //c_addLogToCLI(1, "[C++] %s", "Spidermonkey init success"); return; } if (!m_bSpiderMonkeyInited) { //c_addLogToCLI(4, "[C++] %s", "Init SpiderMonkey First!!!"); return; } if (testIndex == 2) { // call JS function - 0 param, 0 return ScriptingCore* sc = ScriptingCore::getInstance(); sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "MyLogFunc"); c_addLogToCLI(1, "[C++] MyLogFunc called"); } else if (testIndex == 3) { // call JS function - 1 param(Basic Type) , 1 return(Basic Type) ScriptingCore* sc = ScriptingCore::getInstance(); jsval dataVal = INT_TO_JSVAL(10); jsval ret; sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "DubleIntFunc", 1, &dataVal, &ret); c_addLogToCLI(1, "[C++] DubleIntFunc called with result: %d", JSVAL_TO_INT(ret)); } else if (testIndex == 4) { // call JS function - 0 param , 1 return(cocos2d Object) ScriptingCore* sc = ScriptingCore::getInstance(); jsval ret; sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "SpawnIconSprite", 0, NULL, &ret); c_addLogToCLI(1, "[C++] SpawnIconSprite called"); if(!JSVAL_IS_NULL(ret)) { JSObject *obj = JSVAL_TO_OBJECT(ret); js_proxy_t *proxy = jsb_get_js_proxy(obj); CCSprite *sprite = (CCSprite *)(proxy ? proxy->ptr : NULL); if (sprite) { this->addChild(sprite); c_addLogToCLI(1, "[C++] Add sprite from js to c++ layer"); } } } else if (testIndex == 5 ) { // call JS function - 1 param(cocos2d Object) , 0 return ScriptingCore* sc = ScriptingCore::getInstance(); CCSprite *sprite = CCSprite::create("Icon.png"); sprite->setPosition(ccp(CCRANDOM_0_1() * 1000, CCRANDOM_0_1() * 1000)); this->addChild(sprite); js_proxy_t *p = js_get_or_create_proxy<cocos2d::CCSprite>(sc->getGlobalContext(), sprite); jsval dataVal = OBJECT_TO_JSVAL(p->obj); sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "DoubleSpriteSize", 1, &dataVal, NULL); c_addLogToCLI(1, "[C++] Add sprite from js to layer"); } else if (testIndex == 6) { // Bind Simple UI component to c++ CCScene ScriptingCore* sc = ScriptingCore::getInstance(); sc->runScript("CircleLabelTTFTest.js"); c_addLogToCLI(1, "[C++] %s", "Run CircleLabelTTFTest script"); c_addLogToCLI(1, "[C++] %s", "Bind UI Component to CCSCene"); } else if (testIndex == 7) { // Bind Complex UI component to c++ CCScene ScriptingCore* sc = ScriptingCore::getInstance(); sc->runScript("CalendarTest.js"); c_addLogToCLI(1, "[C++] %s", "Run CalendarTest script"); c_addLogToCLI(1, "[C++] %s", "Bind UI Component to CCSCene"); } else if (testIndex == 8) { // call JS function - N param(Mix) , 0 return ScriptingCore* sc = ScriptingCore::getInstance(); js_proxy_t *p = js_get_or_create_proxy<cocos2d::CCLayer>(sc->getGlobalContext(), this); jsval layerVal = OBJECT_TO_JSVAL(p->obj); jsval nowStringVal = c_string_to_jsval(sc->getGlobalContext(), "2013-7-27"); jsval minYearVal = INT_TO_JSVAL(2010); jsval maxYearVal = INT_TO_JSVAL(2016); jsval args[4]; args[0] = layerVal; args[1] = minYearVal; args[2] = maxYearVal; args[3] = nowStringVal; sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "AddCalendarToLayer", 4, args, NULL); c_addLogToCLI(1, "[C++] %s", "Bind Calendar UI to speicfied layer"); } else if (testIndex == 9) { // call JS object function ScriptingCore* sc = ScriptingCore::getInstance(); js_proxy_t *p = js_get_or_create_proxy<cocos2d::CCLayer>(sc->getGlobalContext(), this); jsval layerVal = OBJECT_TO_JSVAL(p->obj); jsval stringVal = c_string_to_jsval(sc->getGlobalContext(), "center"); CCArray *array = CCArray::create(); array->addObject(CCInteger::create(111)); array->addObject(CCInteger::create(222)); array->addObject(CCInteger::create(333)); array->addObject(CCInteger::create(444)); array->addObject(CCInteger::create(555)); array->addObject(CCInteger::create(666)); array->addObject(CCInteger::create(777)); array->addObject(CCInteger::create(888)); jsval arrayVal = ccarray_to_jsval(sc->getGlobalContext(), array); jsval radiusVal = INT_TO_JSVAL(200); jsval args[4]; args[0] = layerVal; args[1] = stringVal; args[2] = arrayVal; args[3] = radiusVal; jsval ret; sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "AddCircleTTFSpriteToLayer", 4, args, &ret); c_addLogToCLI(1, "[C++] %s", "Bind CircleTTF UI to speicfied layer"); if(!JSVAL_IS_NULL(ret)) { sc->executeFunctionWithOwner(ret, "expandTTF", 0, NULL, NULL); c_addLogToCLI(1, "[C++] %s", "Call CircleTTF function expandTTF"); } } else if (testIndex == 10) { // Bind UI Component (CLI) ScriptingCore* sc = ScriptingCore::getInstance(); js_proxy_t *p = js_get_or_create_proxy<cocos2d::CCLayer>(sc->getGlobalContext(), this); jsval layerVal = OBJECT_TO_JSVAL(p->obj); sc->executeFunctionWithOwner(OBJECT_TO_JSVAL(sc->getGlobalObject()), "BindCLILayerTo", 1, &layerVal, &g_cliJSValue); c_addLogToCLI(1, "[C++] %s", "Bind CLI Layer to current layer"); m_bCLIBound = true; } else { c_addLogToCLI(4, "[C++] TEST NOT FOUND!!!"); } }
CCSprite* SubTest::createSpriteWithTag(int tag) { // create CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888); CCSprite* sprite = NULL; switch (subtestNumber) { case 1: { sprite = CCSprite::create("Images/grossinis_sister1.png"); parent->addChild(sprite, 0, tag+100); break; } case 2: case 3: { sprite = CCSprite::create(batchNode->getTexture(), CCRectMake(0, 0, 52, 139)); batchNode->addChild(sprite, 0, tag+100); break; } case 4: { int idx = (CCRANDOM_0_1() * 1400 / 100) + 1; char str[32] = {0}; sprintf(str, "Images/grossini_dance_%02d.png", idx); sprite = CCSprite::create(str); parent->addChild(sprite, 0, tag+100); break; } case 5: case 6: { int y,x; int r = (CCRANDOM_0_1() * 1400 / 100); y = r / 5; x = r % 5; x *= 85; y *= 121; sprite = CCSprite::create(batchNode->getTexture(), CCRectMake(x,y,85,121)); batchNode->addChild(sprite, 0, tag+100); break; } case 7: { int y,x; int r = (CCRANDOM_0_1() * 6400 / 100); y = r / 8; x = r % 8; char str[40] = {0}; sprintf(str, "Images/sprites_test/sprite-%d-%d.png", x, y); sprite = CCSprite::create(str); parent->addChild(sprite, 0, tag+100); break; } case 8: case 9: { int y,x; int r = (CCRANDOM_0_1() * 6400 / 100); y = r / 8; x = r % 8; x *= 32; y *= 32; sprite = CCSprite::create(batchNode->getTexture(), CCRectMake(x,y,32,32)); batchNode->addChild(sprite, 0, tag+100); break; } default: break; } CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default); return sprite; }
int RpgSkillData::getAtkValue() { return CCRANDOM_0_1() * (this->atkMaxValue - this->atkMinValue) + this->atkMinValue; }
int RpgSkillData::getAtkNum() { return CCRANDOM_0_1() * (this->atkMaxNum - this->atkMinNum) + this->atkMinNum; }
void GamePan::initWordList() { _wordList = CCArray::create(); _wordList->retain(); //if(_pinyinStr.size()>0) // _targetStr = DBManager::sharedDBManager()->getRandomWordByLetter(_pinyinStr,_targetStr); //else _targetStr = DBManager::sharedDBManager()->getRandomWord();//GET_STRING(TEXT_JUQING_SPLASH_BEGIN2); //CCLog("Target is %s",_targetStr.c_str()); std::string wordList = _targetStr;//DBManager::sharedDBManager()->getRandomWord();//GET_STRING(TEXT_JUQING_SPLASH_BEGIN2); int maxWord = (MAX_LINE*MAX_ROW)/4+((MAX_LINE*MAX_ROW)%4 ==0 ? 0:1); for (int i =1;i<maxWord;i++) { string temp = DBManager::sharedDBManager()->getRandomWord();//GET_STRING(50+i); if(temp.compare(_targetStr) == 0) { i--; } else { wordList += temp; } } int length = MAX_LINE*MAX_ROW;//wordList->count(); int srcLength = wordList.size(); CCLog("%s",wordList.c_str()); if(_pinyinStr.empty()) { std::string pinyinStr = Utils::getPinyinStr(wordList);//GET_STRING(TEXT_JUQING_SPLASH_BEGIN2); vector<string> arrTotal= Utils::split(Utils::getPinyinLetter(pinyinStr)); vector<string>::iterator iter; vector<string> arr; for (iter = arrTotal.begin(); iter != arrTotal.end(); iter++) { if((*iter).compare("ch") == 0 || (*iter).compare("zh") == 0 || (*iter).compare("sh") == 0) { } else { arr.push_back((*iter)); } } string doublePinyin[] ={"ch","sh","zh"}; string singlePinyin[] ={"b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","w","x","y","z"}; _pinyinStr = doublePinyin[(int)(CCRANDOM_0_1()*2)]; for(int i =0;i<3;i++) { _pinyinStr+= ","+arr.at((int)(CCRANDOM_0_1()*arr.size())); } CCLog("Target is %s,%s,%s",_targetStr.c_str(),_pinyinStr.c_str(),pinyinStr.c_str()); } for(int i = 0;i<srcLength;i=i+3) { CCString* c = CCString::create(wordList.substr(i,3)); c->retain(); _wordList->addObject(c); } }
void performanceScale(CCSprite* pSprite) { CCSize size = CCDirector::sharedDirector()->getWinSize(); pSprite->setPosition(ccp((rand() % (int)size.width), (rand() % (int)size.height))); pSprite->setScale(CCRANDOM_0_1() * 100 / 50); }
void RPGMapSceneLayer::playerMoveEnd() { CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap); RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer); player->stopMove(); player->stopActionByTag(kRPGMapSceneLayerActTagPlayerMove); this->m_playerMoveAct = NULL; //地图切换点的判断 CCTMXObjectGroup *transitionsObjects = bgMap->objectGroupNamed("transitions"); for (int i = 0; i < transitionsObjects->getObjects()->count(); i++) { CCDictionary *transitionsObject = (CCDictionary*)transitionsObjects->getObjects()->objectAtIndex(i); const CCString *x = transitionsObject->valueForKey("x"); const CCString *y = transitionsObject->valueForKey("y"); const CCString *width = transitionsObject->valueForKey("width"); const CCString *height = transitionsObject->valueForKey("height"); const CCString *mapId = transitionsObject->valueForKey("map_id"); const CCString *playerToX = transitionsObject->valueForKey("player_to_x"); const CCString *playerToY = transitionsObject->valueForKey("player_to_y"); const CCString *playerDirection = transitionsObject->valueForKey("player_direction"); CCRect transitionsRect = CCRectMake(stringToNumber<float>(x->getCString()), stringToNumber<float>(y->getCString()), stringToNumber<float>(width->getCString()), stringToNumber<float>(height->getCString())); if(transitionsRect.containsPoint(player->getPosition())) { // CCLog("切换场景%s", mapId->getCString()); //数据库部分,更新进度记录 //修正偏差位置,因为无法得知下一个地图的大小,所以目前只能在tmx上面定死 float toX = stringToNumber<float>(playerToX->getCString()) + 0.5; float toY = stringToNumber<float>(playerToY->getCString()) + 0.5; //保存数据 RPGSaveData *saveDataObj = RPGSaveData::create(); saveDataObj->m_mapId = stringToNumber<int>(mapId->getCString()); saveDataObj->m_playerToX = toX; saveDataObj->m_playerToY = toY; saveDataObj->m_playerDirection = playerDirection->getCString(); saveDataObj->m_gold = this->m_mapData.gold; saveDataObj->m_windowStyle = CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE); saveData(&this->m_db, saveDataObj); CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this); this->unscheduleUpdate(); CCScene *s = RPGMapSceneLayer::scene(0.0); CCTransitionFade *t = CCTransitionFade::create(GAME_SCENE, s); CCDirector::sharedDirector()->replaceScene(t); return; } } //遇敌处理 // this->m_hasEnemy = true; //test if(this->m_hasEnemy) { float val = CCRANDOM_0_1(); val = CCRANDOM_0_1(); if(val >= 0.0 && val <= GAME_MAP_ENCOUNTER) { // CCLog("遇敌!"); CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this); this->unscheduleUpdate(); CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap); CCArray *loadTextures = CCArray::create(); loadTextures->addObject(CCString::create("monsters.png")); loadTextures->addObject(CCString::create("battle_bg.png")); CCArray *releaseTextures = CCArray::create(); releaseTextures->addObject(CCString::create("map.png")); releaseTextures->addObject(CCString::create("joystick.png")); releaseTextures->addObject(CCString::create("actor4_0.png")); releaseTextures->addObject(CCString::create("actor111.png")); releaseTextures->addObject(CCString::create("actor113.png")); releaseTextures->addObject(CCString::create("actor114.png")); releaseTextures->addObject(CCString::create("actor115.png")); releaseTextures->addObject(CCString::create("actor117.png")); releaseTextures->addObject(CCString::create("actor120.png")); CCMenu *mainMenu = (CCMenu*)bgMap->getChildByTag(kRPGMapSceneLayerTagMainMenu); mainMenu->setEnabled(false); SimpleAudioEngine::sharedEngine()->playEffect("audio_battle_start.wav"); // CCLog("%i", this->m_saveData.mapId); RPGMapRoleSprite *player = (RPGMapRoleSprite*)bgMap->getChildByTag(kRPGMapSceneLayerTagPlayer); CCUserDefault::sharedUserDefault()->setIntegerForKey("map_id", this->m_mapData.mapId); CCUserDefault::sharedUserDefault()->setFloatForKey("player_to_x", player->getPosition().x / GAME_TMX_ROLE_WIDTH); CCUserDefault::sharedUserDefault()->setFloatForKey("player_to_y", player->getPosition().y / GAME_TMX_ROLE_HEIGHT); CCUserDefault::sharedUserDefault()->setIntegerForKey("gold", this->m_mapData.gold); switch (player->m_direction) { case kRPGMapRoleSpriteDirectionUp: CCUserDefault::sharedUserDefault()->setStringForKey("player_direction", "up"); break; case kRPGMapRoleSpriteDirectionDown: CCUserDefault::sharedUserDefault()->setStringForKey("player_direction", "down"); break; case kRPGMapRoleSpriteDirectionLeft: CCUserDefault::sharedUserDefault()->setStringForKey("player_direction", "left"); break; case kRPGMapRoleSpriteDirectionRight: CCUserDefault::sharedUserDefault()->setStringForKey("player_direction", "right"); break; default: break; } CCScene *s = RPGLoadingSceneLayer::scene(loadTextures, releaseTextures, "single_battle"); CCTransitionFade *t = CCTransitionFade::create(GAME_SCENE, s); CCDirector::sharedDirector()->replaceScene(t); } } }
KDvoid RenderTextureSave::clearImage ( CCObject* pSender ) { m_pTarget->clear ( CCRANDOM_0_1 ( ), CCRANDOM_0_1 ( ), CCRANDOM_0_1 ( ), 0.5f ); }