• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ prand函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: entityWait

static void entityWait()
{
	int x, y;
	Entity *e;

	if (prand() % 60 == 0)
	{
		x = self->x + self->w / 2 + ((prand() % 6) * (prand() % 2 == 0 ? -1 : 1));
		y = self->y + self->h - prand() % 10;

		e = addProjectile("enemy/slime_drip", self, x, y, 0, 0);

		e->x -= e->w / 2;

		e->touch = NULL;
	}

	x = self->x - 16;

	if (player.health > 0 && collision(x, self->y, self->w + 32, self->endY, player.x, player.y, player.w, player.h) == 1)
	{
		self->action = &bite;

		self->touch = &trapEntity;

		setEntityAnimation(self, "WALK");

		self->flags &= ~FLY;

		self->dirY = self->speed;
	}
}
开发者ID:polluks,项目名称:edgar,代码行数:32,代码来源:ceiling_snapper.c


示例17: shudder

static void shudder()
{
	Entity *smoke;

	self->endX += 90;

	if (self->endX >= 360)
	{
		self->endX = 0;
	}

	self->x = self->startX + sin(DEG_TO_RAD(self->endX)) * 4;

	checkToMap(self);

	if (self->mental == 2)
	{
		smoke = addSmoke(0, 0, "decoration/dust");

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

			smoke->dirY = 0;
		}
	}

	else if (self->mental == 0)
	{
		self->x = self->startX;

		self->action = &entityWait;
	}
}
开发者ID:revcozmo,项目名称:edgar,代码行数:35,代码来源:cauldron.c


示例18: doIntro

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

	self->thinkTime--;

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

		setEntityAnimation(self, "STAND");

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

		for (i=0;i<11;i++)
		{
			e = addTemporaryItem("boss/fly_boss_cocoon_piece", self->x, self->y, RIGHT, 0, 0);

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

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

			setEntityAnimationByID(e, i);

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

		self->draw = &drawLoopingAnimationToMap;

		playSoundToMap("sound/boss/fly_boss/buzz", BOSS_CHANNEL, self->x, self->y, 0);

		self->takeDamage = &takeDamage;

		self->action = &introPause;

		self->touch = &entityTouch;

		self->thinkTime = 120;

		self->startY = self->y;

		self->dirY = self->dirX = 0;

		self->startX = 0;

		facePlayer();
	}

	else
	{
		if (self->x == self->startX || (self->thinkTime % 2 == 0))
		{
			self->x = self->startX + (3 * (self->x < self->startX ? 1 : -1));
		}
	}
}
开发者ID:LibreGames,项目名称:edgar,代码行数:59,代码来源:fly_boss.c


示例19: entityWait

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

	dirX = self->dirX;

	if (dirX != 0)
	{
		for (e=self->target;e!=NULL;e=e->target)
		{
			if (e->x > self->startX)
			{
				e->flags &= ~NO_DRAW;
			}

			else
			{
				e->flags |= NO_DRAW;
			}
		}
	}

	checkToMap(self);

	if (self->dirX == 0 && dirX != 0)
	{
		playSoundToMap("sound/common/crumble", -1, self->x, self->y, 0);

		self->mental = 1;

		self->touch = &pushEntity;

		self->x += TILE_SIZE / 2;

		for (e=self->target;e!=NULL;e=e->target)
		{
			e->x += TILE_SIZE / 2;

			e->dirX = 0;

			e->touch = &pushEntity;
		}

		for (i=0;i<6;i++)
		{
			e = addSmallRock(self->x, self->y, "common/small_rock");

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

			e->dirX = -(prand() % 4 + 1);
			e->dirY = -(prand() % 3 + 3);
		}

		shakeScreen(MEDIUM, 15);
	}
}
开发者ID:polluks,项目名称:edgar,代码行数:59,代码来源:crossbow_bolt.c


示例20: doIntro

static void doIntro()
{
	Entity *e;

	self->thinkTime--;

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

		if (e == NULL)
		{
			showErrorAndExit("No free slots to add a Blob Boss Part");
		}

		loadProperties("boss/blob_boss_part", e);

		setEntityAnimation(e, "STAND");

		e->flags |= LIMIT_TO_SCREEN;

		e->draw = &drawLoopingAnimationToMap;

		e->type = ENEMY;

		e->damage = 0;

		e->head = self;

		e->action = &reform;

		e->health = 600;

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

		e->y = self->startY + self->h / 2 - e->h / 2;

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

		e->dirX /= 10;

		e->thinkTime = 120;

		e->targetX = self->x + self->w / 2;

		self->maxThinkTime--;

		if (self->maxThinkTime <= 0)
		{
			self->action = &introPause;
		}

		self->thinkTime = 6;
	}

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ prandom_u32函数代码示例发布时间:2022-05-30
下一篇:
C++ pr_warning函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap