本文整理汇总了C++中CCRANDOM_0_1函数的典型用法代码示例。如果您正苦于以下问题:C++ CCRANDOM_0_1函数的具体用法?C++ CCRANDOM_0_1怎么用?C++ CCRANDOM_0_1使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CCRANDOM_0_1函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CCRANDOM_0_1
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);
}
示例2: switch
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();
}
}
}
示例3: switch
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;
}
示例4: an
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));
}
示例5: menuRandomFormation
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));
}
}
示例6: abs
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;
}
示例7: crossover
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];
}
}
示例8: autoCreateEnemy
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层中
}
示例9: Point
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);
}
}
示例10: CCRANDOM_0_1
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"));
}
示例11: CCRANDOM_0_1
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);
}
示例12: rand
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);
}
示例13: addChild
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);
//.........这里部分代码省略.........
示例14: log
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);
//.........这里部分代码省略.........
示例15: CCRANDOM_0_1
void RenderTextureSave::clearImage(cocos2d::CCObject *pSender)
{
m_pTarget->clear(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1());
}