当前位置: 首页>>代码示例>>C++>>正文


C++ prand函数代码示例

本文整理汇总了C++中prand函数的典型用法代码示例。如果您正苦于以下问题:C++ prand函数的具体用法?C++ prand怎么用?C++ prand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了prand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: appleWait

static void appleWait()
{
	Entity *e;

	self->thinkTime--;

	if (self->thinkTime <= 0)
	{
		self->x += self->dirX;

		if (abs(self->startX - self->x) > 1)
		{
			self->dirX *= -1;
		}

		self->thinkTime = 20;
	}

	if (self->mental > self->head->mental)
	{
		e = addKeyItem("item/apple", self->x, self->y);

		e->dirX = 10 + prand() % 10;

		e->dirX *= prand() % 2 == 0 ? -0.1 : 0.1;

		e->dirY = -10;

		self->inUse = FALSE;
	}
}
开发者ID:LibreGames,项目名称:edgar,代码行数:31,代码来源:apple_tree.c

示例2: dropOnPlayer

static void dropOnPlayer()
{
	int i;
	long onGround;

	self->thinkTime--;

	if (self->thinkTime <= 0)
	{
		self->flags &= ~FLY;

		onGround = (self->flags & ON_GROUND);

		checkToMap(self);

		if (onGround == 0 && (self->flags & ON_GROUND))
		{
			playSoundToMap("sound/common/crash", BOSS_CHANNEL, self->x, self->y, 0);

			shakeScreen(LIGHT, 15);

			self->thinkTime = 15;

			self->action = &dropWait;

			for (i=0;i<20;i++)
			{
				addSmoke(self->x + prand() % self->w, self->y + self->h - prand() % 10, "decoration/dust");
			}
		}
	}
}
开发者ID:revcozmo,项目名称:edgar,代码行数:32,代码来源:skull.c

示例3: headDie

static void headDie()
{
	Entity *e;

	e = self;

	self = self->target;

	while (self != NULL)
	{
		self->die();

		self->dirX = (prand() % 5) * (prand() % 2 == 0 ? -1 : 1);
		self->dirY = ITEM_JUMP_HEIGHT;

		self = self->target;
	}

	self = e;

	entityDieNoDrop();

	self->dirX = (prand() % 5) * (prand() % 2 == 0 ? -1 : 1);
	self->dirY = ITEM_JUMP_HEIGHT;
}
开发者ID:LibreGames,项目名称:edgar,代码行数:25,代码来源:fly_trap.c

示例4: entityWait

static void entityWait()
{
	int i;

	checkToMap(self);

	if (self->flags & ON_GROUND)
	{
		if (self->active == TRUE)
		{
			self->touch = &touch;

			self->activate = &activate;
		}

		if (self->mental == 0)
		{
			fireTrigger(self->objectiveName);

			fireGlobalTrigger(self->objectiveName);

			fadeBossMusic();

			for (i=0;i<20;i++)
			{
				addSmoke(self->x + prand() % self->w, self->y + self->h - prand() % 10, "decoration/dust");
			}

			playSoundToMap("sound/enemy/red_grub/thud", BOSS_CHANNEL, self->x, self->y, 0);

			self->mental = 1;
		}
	}
}
开发者ID:revcozmo,项目名称:edgar,代码行数:34,代码来源:black_book_3.c

示例5: entityWait

static void entityWait()
{
	Entity *e;

	if (self->mental > 0)
	{
		self->thinkTime--;

		if (self->thinkTime <= 0)
		{
			self->thinkTime = 5;

			e = addExplosion(0, 0);

			e->x = self->x + self->w / 2 - e->w / 2;
			e->y = self->y + self->h / 2 - e->h / 2;

			e->x += prand() % e->w * (prand() % 2 == 0 ? 1 : -1);
			e->y += prand() % e->h * (prand() % 2 == 0 ? 1 : -1);

			e->damage = 0;

			self->mental--;
		}
	}

	checkToMap(self);
}
开发者ID:LibreGames,项目名称:edgar,代码行数:28,代码来源:containment_unit_controls.c

示例6: Replicate

void Organism::Replicate(Organism *Target)
{
	int i;
	
	Target->age = 0;
	Target->alive = 1;
	
	for (i=0;i<GENELEN;i++)
	{
		Target->Genome[i]=Genome[i];
		
		if (prand(MUTATION))
		{
			Target->Genome[i]=rand()%(2*LETTERS);
		}
	}
	
	if (prand(GENEDUP))
	{
		int start=rand()%GENELEN, end=rand()%GENELEN, newstart=rand()%GENELEN;
		int buf=0;
		
		if (start>end)
		{
			buf=end; end=start; start=buf;
		}
		
		for (i=newstart;(i<newstart+(end-start))&&(i<GENELEN);i++)
		{
			Genome[i]=Genome[i-newstart+start];
		}
	}
}
开发者ID:ModelingOriginsofLife,项目名称:Guttenberg-model,代码行数:33,代码来源:foodchain.cpp

示例7: iceBlockDie

static void iceBlockDie()
{
	int i;
	Entity *e;

	for (i=0;i<8;i++)
	{
		e = addTemporaryItem("common/ice_piece", self->x, self->y, RIGHT, 0, 0);

		e->x += self->w / 2 - e->w / 2;
		e->y += self->h / 2 - e->h / 2;

		e->dirX = (prand() % 10) * (prand() % 2 == 0 ? -1 : 1);
		e->dirY = ITEM_JUMP_HEIGHT + (prand() % ITEM_JUMP_HEIGHT);

		setEntityAnimationByID(e, i);

		e->thinkTime = 60 + (prand() % 60);

		e->touch = NULL;
	}

	playSoundToMap("sound/common/shatter", -1, player.x, player.y, 0);

	self->inUse = FALSE;
}
开发者ID:LibreGames,项目名称:edgar,代码行数:26,代码来源:large_book.c

示例8: entityWait

static void entityWait()
{
    int i;
    Entity *e;

    if (self->mental == 1)
    {
        for (i=0; i<4; i++)
        {
            e = addTemporaryItem("boss/azriel_grave_piece", self->x, self->y, RIGHT, 0, 0);

            e->x += self->w / 2 - e->w / 2;
            e->y += self->h / 2 - e->h / 2;

            e->dirX = (prand() % 10) * (prand() % 2 == 0 ? -1 : 1);
            e->dirY = ITEM_JUMP_HEIGHT + (prand() % ITEM_JUMP_HEIGHT);

            setEntityAnimationByID(e, i);

            e->thinkTime = 60 + (prand() % 60);
        }

        playSoundToMap("sound/common/crumble", -1, self->x, self->y, 0);

        self->inUse = FALSE;
    }

    checkToMap(self);
}
开发者ID:revcozmo,项目名称:edgar,代码行数:29,代码来源:azriel_grave.c

示例9: raiseDeadMoveToTopTarget

static void raiseDeadMoveToTopTarget()
{
	char c;
	int i, j;

	if (atTarget())
	{
		setEntityAnimation(self, "PHANTASMAL_BOLT_FIRE");

		self->thinkTime = 30;

		self->action = &raiseDead;

		self->mental = 2 + prand() % 4;

		STRNCPY(self->description, "123456", sizeof(self->description));

		for (i=0;i<6;i++)
		{
			j = prand() % 6;

			c = self->description[i];

			self->description[i] = self->description[j];

			self->description[j] = c;
		}
	}

	checkToMap(self);

	becomeTransparent();
}
开发者ID:LibreGames,项目名称:edgar,代码行数:33,代码来源:azriel.c

示例10: die

static void die()
{
	int i;

	self->action = &die;

	setCustomAction(self, &invulnerableNoFlash, 240, 0, 0);

	setEntityAnimation(self, "STUNNED");

	self->flags &= ~FLY;

	self->dirX = 0;

	self->mental = self->x < getMapStartX() + SCREEN_WIDTH / 2 ? 0 : 1;

	checkToMap(self);

	if (self->flags & ON_GROUND)
	{
		for (i=0;i<20;i++)
		{
			addSmoke(self->x + prand() % self->w, self->y + self->h - prand() % 10, "decoration/dust");
		}

		playSoundToMap("sound/common/crash", BOSS_CHANNEL, self->x, self->y, 0);

		self->thinkTime = 120;

		self->endY = 0;

		self->action = &dieFinish;
	}
}
开发者ID:LibreGames,项目名称:edgar,代码行数:34,代码来源:cave_boss.c

示例11: prand_array

static void prand_array (double *rate, SLindex_Type *num) /*{{{*/
{
   SLang_Array_Type *at = NULL;
   double *ai;
   SLindex_Type i, n;

   n = *num;

   if (n == 0)
     return;
   else if (n == 1)
     {
        SLang_push_double (prand (*rate));
        return;
     }

   if (NULL == (at = SLang_create_array (SLANG_DOUBLE_TYPE, 0, NULL, &n, 1)))
     {
        isis_vmesg (INTR, I_FAILED, __FILE__, __LINE__, "creating array of random values");
        return;
     }

   ai = (double *) at->data;
   for (i = 0; i < n; i++)
     {
        ai[i] = prand (*rate);
     }

   SLang_push_array (at, 1);
}
开发者ID:hankem,项目名称:ISIS,代码行数:30,代码来源:math.c

示例12: castIceInit

static void castIceInit()
{
	self->thinkTime--;

	if (self->thinkTime <= 0)
	{
		if (self->maxThinkTime == 1)
		{
			self->endX = 5 + prand() % 6;

			self->action = &castIce;
		}

		else if (self->maxThinkTime == 2)
		{
			self->endX = 3 + prand() % 4;

			self->action = &createIceWall;
		}

		else
		{
			self->endX = 5 + prand() % 6;

			self->action = &createIceBlock;
		}
	}

	hover();
}
开发者ID:LibreGames,项目名称:edgar,代码行数:30,代码来源:large_book.c

示例13: rain

static void rain()
{
	int i;

	for (i=0;i<MAX_DROPS;i++)
	{
		if (droplet[i].active == TRUE)
		{
			droplet[i].y += droplet[i].dirY;

			if (droplet[i].y >= SCREEN_HEIGHT)
			{
				droplet[i].y = -8 - prand() % 20;

				droplet[i].dirX = 0;
				droplet[i].dirY = 8 + prand() % 8;
			}
		}

		else
		{
			break;
		}
	}
}
开发者ID:LibreGames,项目名称:edgar,代码行数:25,代码来源:weather.c

示例14: spellMove

static void spellMove()
{
	int i;
	Entity *e;

	checkToMap(self);

	self->thinkTime--;

	if (self->thinkTime <= 0)
	{
		self->inUse = FALSE;
	}

	else
	{
		for (i=0;i<2;i++)
		{
			e = addBasicDecoration(self->x, self->y, "decoration/particle");

			if (e != NULL)
			{
				e->x += prand() % self->w;
				e->y += prand() % self->h;

				e->thinkTime = 5 + prand() % 30;

				setEntityAnimationByID(e, prand() % 5);
			}
		}
	}
}
开发者ID:LibreGames,项目名称:edgar,代码行数:32,代码来源:sorceror.c

示例15: getFreeDecoration

Entity *addParticle(int x, int y)
{
	Entity *e;

	e = getFreeDecoration();

	if (e == NULL)
	{
		return NULL;
	}

	loadProperties("decoration/particle", e);

	e->thinkTime = 20 + (prand() % 30);

	e->x = x;
	e->y = y;

	e->action = &move;
	e->draw = &drawLoopingAnimationToMap;

	setEntityAnimationByID(e, prand() % 5);

	return e;
}
开发者ID:polluks,项目名称:edgar,代码行数:25,代码来源:decoration.c


注:本文中的prand函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。