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

C++ rand函数代码示例

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

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



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

示例1: rand

void Snake_t::gen_target(){
	target.set_coordinates(rand()%d_width, rand()%d_height);
}
开发者ID:nikonikolov,项目名称:lab_switch,代码行数:3,代码来源:Snake_t.cpp


示例2: random

 inline float random(int howbig) {
   return (float) (((float) (fmod(rand(),RAND_MAX))/RAND_MAX))*howbig;
 }
开发者ID:TLeaves,项目名称:cprocessing,代码行数:3,代码来源:random.hpp


示例3: getRandom

float Map::getRandom()
{
	random = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);// Random value between 0.0f -> 1.0f
	return random;
}
开发者ID:Chringo,项目名称:LitetSpelprojekt,代码行数:5,代码来源:Map.cpp


示例4: main

int main(int argc, char **argv)
{
  double timeA, timeB;
  Sphere *spheres;
  Vec3 p,c,e;
  int n;
  
  timeA = omp_get_wtime();
  n = argc>1 ? atoi(argv[1]) : N; if(n<N)n=100;
  spheres = malloc(n*sizeof(*spheres));
  // position, radius, surface color, reflectivity, transparency, emission color
  Vec3_new(&p, 0, -10004, -20);
  Vec3_new1(&c, 0.2);
  Sphere_new0(&spheres[0], &p, 10000, &c, 0, 0.0);
  Vec3_new(&p, 0, 0, -20);
  Vec3_new(&c, 1.00, 0.32, 0.36);
  Sphere_new0(&spheres[1], &p, 4, &c, 1, 0.5);
  Vec3_new(&p, 5, -1, -15);
  Vec3_new(&c, 0.90, 0.76, 0.46);
  Sphere_new0(&spheres[2], &p, 2, &c, 1, 0.0);
  Vec3_new(&p, 5, 0, -25);
  Vec3_new(&c, 0.65, 0.77, 0.97);
  Sphere_new0(&spheres[3], &p, 3, &c, 1, 0.0);
  Vec3_new(&p, -5.5, 0, -15);
  Vec3_new(&c, 0.90, 0.90, 0.90);
  Sphere_new0(&spheres[4], &p, 3, &c, 1, 0.0);
  // light
  Vec3_new(&p, 0, 20, -30);
  Vec3_new0(&c);
  Vec3_new1(&e, 3);
  Sphere_new(&spheres[5], &p, 3, &c, 0, 0, &e);
  if(n>N){ int i,j,k; Real r,d; Vec3 v;
    srand48(13);
    for(i=N;i<n;i++){
      k=0;
      do{
        Vec3_new(&p, 12*drand48()-6,9*drand48()-4,-35*drand48()-15);
        r = 0.1 + drand48();
        for(j=0;j<i && r>=0.1;j++){
          Vec3_subs(&v,&spheres[j].center,&p);
          d=Vec3_length(&v)-spheres[j].radius;
          if(d<r)r=d;
        }
      }while(r<0.1 && ++k<1000);
      if(r>=0.1){
        Vec3_new(&c, rand()%4/3.0,rand()%4/3.0,rand()%4/3.0);
        Sphere_new0(&spheres[i], &p, r, &c,
          drand48()<0.8?0:1, drand48()<0.8?0:0.8);
      }else printf("#");
    }
  }
  if(argc>2){spheres[1].radius=0.4; spheres[1].radius2=0.16;}

  printf("Calculando...\n"); fflush(stdout);
  
  render(n, spheres);
  timeB = omp_get_wtime();
  double timeC = timeB - timeA;
  printf("Se ha calculado en %f segundos\n",timeC);
  free(spheres);

  return 0;
}
开发者ID:adanto,项目名称:CPA,代码行数:63,代码来源:rayFirst.c


示例5: Reset

 void Reset()
 {
     MortalWound_Timer = 10000 + rand()%5000;
     SpawnHatchlings_Timer = 6000 + rand()%6000;
     SpawnSpawns_Timer = 15000 + rand()%30000;
 }
开发者ID:deremix,项目名称:darmixcore,代码行数:6,代码来源:boss_fankriss.cpp


示例6: rand_my

double rand_my()
{
    double v = ((double) rand() / (RAND_MAX));
    return v;
}
开发者ID:alekseysidorov,项目名称:playground,代码行数:5,代码来源:polygons.c


示例7: main

int
main(int argc, char *argv[], char *envp[])
{
  FILE *fdata;			/* .data file (input)*/
  FILE *fmodel;			/* .model file (output) */
  FILE *fauc;				/* .model.1st file (output) */

  int atnl;				/* at newline (flag) */
  char *aucname;			/* file name of the AUC file */
  double baseline;
  char c;
  int divider;			/* #of bins to divide in this round */
  int failures_seen;			/* in this bin */
  int i, j, k, l;
  int maxrounds;			/* max(@ROUNDS) */
  int numbins;			/* misnomer, really "this round" */
  char *sca0, *sca, *scc;		/* tmp variables */
  int t;				/* XXX - some kind of counter? */
  int this_first, this_last;
  double this_pauc;
  double randnum;
  int *rand_seed = NULL;
  int total_failures;
  int num_scores;
  int init_permute_flag = 1;
  int unknown_meth = REL_ORDER;
  Score *p;
  Score *best;
  double min_auc;

  gargc = argc;
  gargv = argv;
  genvp = envp;

  /*
   * Make sure we grok NaNs
   * (unknown entries in the input file, given as '?', are
   *  stored as not-a-number values)
   */

  if (!isnan(nan("")))
    errx(1, "Implementation does not understand NaNs");

  /*
   * PARSE ARGUMENTS
   */

  if (argc < 3)
    usage();

  if ((fdata = fopen(argv[1], "r")) == NULL)
    err(1, "cannot open %s for reading", argv[1]);

  if ((fmodel = fopen(argv[2], "w")) == NULL)
    err(1, "cannot open %s for writing", argv[2]);

  if ((aucname = (char *)calloc(strlen(argv[2]) + sizeof (".1st"), 1)) == NULL)
    err(1, "allocating aucname");

  strcpy(aucname, argv[2]);
  strcat(aucname, ".1st");
  if ((fauc = fopen(aucname, "w")) == NULL)
    err(1, "cannot open %s for writing", aucname);

  argc -= 3;
  argv += 3;

  while (argc > 0) {    
    if (!strcmp(argv[0], "rounds") || !strcmp(argv[0], "--rounds")) {
      if (argc < 2)
        usage();
      if ((sca0 = sca = strdup(argv[1])) == NULL)
        err(1, "strdup: copying %s", argv[1]);

      while (*sca == ',')	    /* strip leading commas, if any */
        sca++;

      scc = sca + strlen(sca);
      if (scc == sca)  /* must have at least one digit! */
        usage();

      while (*--scc == ',')	/* strip trailing commas */
        *scc = '\0';

      if (strchr(sca, ',')) {
        /*
         * comma-separated list of rounds, parse
         */

        n_rounds = 0;
        for (scc = sca; *scc; scc++)
          if (*scc == ',')
            n_rounds++;
        n_rounds++;
        if ((rounds = (int *)calloc(n_rounds, sizeof (*rounds))) == NULL)
          err(1, "calloc %d rounds", n_rounds);
        for (i = 0; i < n_rounds; i++) {
          rounds[i] = strtol(sca, &scc, 10);
          if (rounds[i] <= 0)
            errx(1, "round %d must be positive", i);
//.........这里部分代码省略.........
开发者ID:chmanchester,项目名称:calico,代码行数:101,代码来源:ml3.c


示例8: UpdateAI

    void UpdateAI(const uint32 diff)
    {
        if (!m_creature->SelectHostilTarget() || !m_creature->getVictim())
            return;

        //Check for Frost Bolt
        if (FrostBolt_Timer < diff)
        {
            DoCast(m_creature->getVictim(),SPELL_FROST_BOLT);
            FrostBolt_Timer = (rand()%60)*1000;
        }else FrostBolt_Timer -= diff;

        //Check for Frost Bolt Nova
        if (FrostBoltNova_Timer < diff)
        {
            DoCast(m_creature->getVictim(),SPELL_FROST_BOLT_NOVA);
            FrostBoltNova_Timer = 15000;
        }else FrostBoltNova_Timer -= diff;

        //Check for Chains Of Kelthuzad
        if (ChainsOfKelthuzad_Timer < diff)
        {
            //DoCast(m_creature->getVictim(),SPELL_CHAINS_OF_KELTHUZAD);

            //if (rand()%2)
                //DoScriptText(SAY_CHAIN1, m_creature);
            //else
                //DoScriptText(SAY_CHAIN2, m_creature);

            ChainsOfKelthuzad_Timer = (rand()%30+30)*1000;
        }else ChainsOfKelthuzad_Timer -= diff;

        //Check for Mana Detonation
        if (ManaDetonation_Timer < diff)
        {
            DoCast(m_creature->getVictim(),SPELL_MANA_DETONATION);

            if (rand()%2)
                DoScriptText(SAY_SPECIAL1_MANA_DET, m_creature);

            ManaDetonation_Timer = 20000;
        }else ManaDetonation_Timer -= diff;

        //Check for Shadow Fissure
        if (ShadowFisure_Timer < diff)
        {
            DoCast(m_creature->getVictim(),SPELL_SHADOW_FISURE);

            if (rand()%2)
                DoScriptText(SAY_SPECIAL3_MANA_DET, m_creature);

            ShadowFisure_Timer = 25000;
        }else ShadowFisure_Timer -= diff;

        //Check for Frost Blast
        if (FrostBlast_Timer < diff)
        {
            DoCast(m_creature->getVictim(),SPELL_FROST_BLAST);

            if (rand()%2)
                DoScriptText(SAY_FROST_BLAST, m_creature);

            FrostBlast_Timer = (rand()%30+30)*1000;
        }else FrostBlast_Timer -= diff;

        //start phase 3 when we are 40% health
        if (!Phase3 && (m_creature->GetHealth()*100 / m_creature->GetMaxHealth()) < 40)
        {
            Phase3 = true;
            DoScriptText(SAY_REQUEST_AID, m_creature);
            //here Lich King should respond to KelThuzad but I don't know which creature to make talk
            //so for now just make Kelthuzad says it.
            DoScriptText(SAY_ANSWER_REQUEST, m_creature);
        }

        if (Phase3 && (GuardiansOfIcecrown_Count < 5))
        {
            if (GuardiansOfIcecrown_Timer < diff)
            {
                //Summon a Guardian of Icecrown in a random alcove (Creature # 16441)
                //uint32 TimeToWalk;
                Creature* pUnit = NULL;

                float Walk_Pos_X;
                float Walk_Pos_Y;
                float Walk_Pos_Z;

                switch(rand()%6)
                {
                    case 0:
                        pUnit = m_creature->SummonCreature(16441,ADDX_LEFT_FAR,ADDY_LEFT_FAR,ADDZ_LEFT_FAR,ADDO_LEFT_FAR,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,1000);
                        //Setting walk position
                        Walk_Pos_X = WALKX_LEFT_FAR;
                        Walk_Pos_Y = WALKY_LEFT_FAR;
                        Walk_Pos_Z = WALKZ_LEFT_FAR;
                        break;
                    case 1:
                        pUnit = m_creature->SummonCreature(16441,ADDX_LEFT_MIDDLE,ADDY_LEFT_MIDDLE,ADDZ_LEFT_MIDDLE,ADDO_LEFT_MIDDLE,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,1000);
                        //Start moving guardian towards the center of the room
                        Walk_Pos_X = WALKX_LEFT_MIDDLE;
//.........这里部分代码省略.........
开发者ID:wk23,项目名称:tst,代码行数:101,代码来源:boss_kelthuzad.cpp


示例9: maths_rand

double maths_rand(double a, double b)
{
	return (b - a) * ((double)rand() / RAND_MAX) + a;
}
开发者ID:LesOCR,项目名称:mediocr,代码行数:4,代码来源:maths.c


示例10: main

int main(int argc, char *argv[])
{
    srand(time(NULL));
    bool giveme = false;
    long zero = 0;
    char buf[100];
    bool gotflag = false;
    puts("Welcome to hell, we have real strong JumpFu here");
start:
    DBUG("start")
    puts("Where to?");
    fflush(0);
    zero = 0;
    fgets(buf, 117, stdin);
    buf[99] = 0;
    if (strncmp(buf+10, "WHO GOES THERE", strlen("WHO GOES THERE")) == 10)
        goto six;
    else
        goto two;
one:
    DBUG("one")
    puts("WELCOME BACK");
    goto start;
two:
    DBUG("two")
    puts("Who are you? Where are you even going?");
    fflush(0);
    if (buf[69]=='8')
        goto eleven;
    if (buf[69]=='9')
        goto five;
    goto one;
three:
    DBUG("three")
    puts("Here we go again...");
    fflush(0);
    goto eight;
four:
    DBUG("four")
    if (!zero)
        goto nine;
five:
    DBUG("five")
    giveme = true;
    if (!zero)
        goto eight;
six:
    DBUG("six")
    giveme = false;
seven: //lucky number seven
    DBUG("seven")
    if (giveme){
        gotflag = true;
        print_flag();
        goto end;
    }else{
        puts("NO!!! GO AWAY");
        fflush(0);
    }
eight:
    DBUG("eight")
    puts("Goodnight! See you later!");
    fflush(0);
    sleep(1);
    if (rand() % 2)
        goto one;
    else
        goto twelve;
nine:
    DBUG("nine")
    goto two;
ten:
    DBUG("ten")
    if (!zero)
        goto end;
    goto one;
eleven:
    DBUG("eleven")
    if (strncmp(&zero, "risky!", strlen("risky")))
        goto eight;
    goto six;
twelve:
    DBUG("twelve")
    if (zero)
        goto seven;
    else
        goto ten;
end:
    DBUG("end")
    if (!gotflag)
        puts("Looks like you are leavin here empty handed.");
    else
        puts("Nice work. You won.");
    fflush(0);
    return 0;
}
开发者ID:RITC3,项目名称:rc3ctf-2015,代码行数:96,代码来源:JumpFu.c


示例11: moveAction

// CONSTRUCTOR FOR BABIES (born creatures)
Creature::Creature(sf::Vector2u& w, Creature* dad, Creature* mum)
	: moveAction(w, position)
{
	windowSize = &w;
	init();
  
  
  // POSITION OF MUM
	position = sf::Vector2f(mum->getPosition().x, mum->getPosition().y);
  
  // INHERIT CHARACTERISTICS FROM MUM OR DAD CREATURE

  // SIZE: INTERPOLATION OF MUM AND DAD
	int mutationRisk = rand()%100;
	size = (dad->getSize() + mum->getSize()) / 2;
	if(mutationRisk > 95) size = rand()%5 + 10.f;

  // SIGHT: INTERPOLATION OF MUM AND DAD
	mutationRisk = rand()%100;
	sightRadius = (dad->getSightRadius() + mum->getSightRadius()) / 2;
	if(mutationRisk > 95) sightRadius = size + rand()%100;

  // COLOR: RANDOM MUM OR DAD
	mutationRisk = rand()%100;
	body.setFillColor((rand()%2 == 0) ? dad->getColor() : mum->getColor());
	if(mutationRisk > 95) body.setFillColor(sf::Color(rand()%255, rand()%255, rand()%255, 200));

  // LIFETIME: RANDOM MUM OR DAD
	mutationRisk = rand()%100;
	timeToLive = (rand()%2 == 0) ? dad->getTTL() : mum->getTTL();
	if(mutationRisk > 95) timeToLive = rand()%10000 + 100;

  // REPLICATION TIMER: RANDOM MUM OR DAD
	mutationRisk = rand()%100;
	timeToReplicate = (rand()%2 == 0) ? dad->getTTR() : mum->getTTR();
	if(mutationRisk > 95) timeToReplicate = rand()%800 + 200;

  // REPLICATION DURATION:INTERPOLATION OF MUM AND DAD
	mutationRisk = rand()%100;
	replicationDuration = (dad->getReplicationDuration() + mum->getReplicationDuration()) / 2;
	if(mutationRisk > 95) replicationDuration = rand()%1000 + 200;
}
开发者ID:barzb,项目名称:CodeSamples,代码行数:43,代码来源:Creature.cpp


示例12: random

int random(int a,int b)	//returns a pseudo random integer between a and b
{
	int d=b-a;
	return a+rand()%d;
}
开发者ID:reubenjohn,项目名称:global_assets,代码行数:5,代码来源:random.hpp


示例13: UpdateAI

    void UpdateAI(const uint32 diff)
    {
        if (!UpdateVictim())
            return;

        if (Assassins_Timer)
        {
            if (Assassins_Timer <= diff)
            {
                SpawnAssassin();
                Assassins_Timer = 0;
            }
            else Assassins_Timer -= diff;
        }
        if (InBlade)
        {
            if (Wait_Timer)
            {
                if (Wait_Timer <= diff)
                {
                    if (target_num <= 0)
                    {
                        // stop bladedance
                        InBlade = false;
                        me->SetSpeed(MOVE_RUN, 2);
                        (*me).GetMotionMaster()->MoveChase(me->getVictim());
                        Blade_Dance_Timer = 30000;
                        Wait_Timer = 0;
                        if (HeroicMode)
                            Charge_timer = 5000;
                    }
                    else
                    {
                        //move in bladedance
                        float x, y, randx, randy;
                        randx = float(rand() % 40);
                        randy = float(rand() % 40);
                        x = 210 + randx ;
                        y = -60 - randy ;
                        (*me).GetMotionMaster()->MovePoint(1, x, y, me->GetPositionZ());
                        Wait_Timer = 0;
                    }
                }
                else Wait_Timer -= diff;
            }
        }
        else
        {
            if (Blade_Dance_Timer)
            {
                if (Blade_Dance_Timer <= diff)
                {
                    target_num = TARGET_NUM;
                    Wait_Timer = 1;
                    InBlade = true;
                    Blade_Dance_Timer = 0;
                    me->SetSpeed(MOVE_RUN, 4);
                    return;
                }
                else Blade_Dance_Timer -= diff;
            }
            if (Charge_timer)
            {
                if (Charge_timer <= diff)
                {
                    DoCast(SelectUnit(SELECT_TARGET_RANDOM, 0), H_SPELL_CHARGE);
                    Charge_timer = 0;
                }
                else Charge_timer -= diff;
            }
            if (Summon_Assistant_Timer <= diff)
            {
                for (uint32 i = 0; i < summoned; i++)
                {
                    switch (rand() % 3)
                    {
                    case 0:
                        me->SummonCreature(MOB_HEARTHEN_GUARD, AddsEntrance[0], AddsEntrance[1], AddsEntrance[2], 0, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000);
                        break;
                    case 1:
                        me->SummonCreature(MOB_SHARPSHOOTER_GUARD, AddsEntrance[0], AddsEntrance[1], AddsEntrance[2], 0, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000);
                        break;
                    case 2:
                        me->SummonCreature(MOB_REAVER_GUARD, AddsEntrance[0], AddsEntrance[1], AddsEntrance[2], 0, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000);
                        break;
                    }
                }
                if (rand() % 100 < 6) summoned++;
                Summon_Assistant_Timer = 15000 + (rand() % 5000) ;
            }
            else Summon_Assistant_Timer -= diff;

            DoMeleeAttackIfReady();
        }

        if (resetcheck_timer <= diff)
        {
            float tempx;
            tempx = me->GetPositionX();
            if (tempx > 255 || tempx < 205)
//.........这里部分代码省略.........
开发者ID:Zaffy,项目名称:OregonCore,代码行数:101,代码来源:boss_warchief_kargath_bladefist.cpp


示例14: UpdateAI

    void UpdateAI(const uint32 diff)
    {
        if (!UpdateVictim())
        {
            if(UnsummonCheck < diff && m_creature->isAlive())
            {
                m_creature->SetLootRecipient(NULL);
                m_creature->SetVisibility(VISIBILITY_OFF);
                m_creature->DealDamage(m_creature, m_creature->GetMaxHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
                m_creature->RemoveCorpse();
            }else UnsummonCheck -= diff;
            return;
        }

        if(Fireball_Timer < diff)
        {
            if(Unit *victim = SelectUnit(SELECT_TARGET_RANDOM,0))
                DoCast(victim, SPELL_FIREBALL,true);
            Fireball_Timer = 4000+rand()%3000;
        }else Fireball_Timer -= diff;

        if(flight) // phase 1 - the flight
        {
            Creature *Vazruden = Unit::GetCreature(*m_creature,VazrudenGUID);
            if(Fly_Timer < diff || !(Vazruden && Vazruden->isAlive() && (Vazruden->GetHealth()*5 > Vazruden->GetMaxHealth())))
            {
                flight = false;
                BellowingRoar_Timer = 6000;
                ConeOfFire_Timer = 12000;
                m_creature->RemoveUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT + MOVEMENTFLAG_LEVITATING);
                m_creature->AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
                m_creature->GetMotionMaster()->Clear();
                if(Unit *victim = SelectUnit(SELECT_TARGET_NEAREST,0))
                    m_creature->AI()->AttackStart(victim);
                DoStartMovement(m_creature->getVictim());
                DoScriptText(EMOTE, m_creature);
                return;
            }else Fly_Timer -= diff;

            if(Turn_Timer < diff)
            {
                uint32 waypoint = (Fly_Timer/10000)%2;
                if(m_creature->GetDistance(VazrudenRing[waypoint][0],VazrudenRing[waypoint][1],VazrudenRing[waypoint][2]) > 5)
                    m_creature->GetMotionMaster()->MovePoint(0,VazrudenRing[waypoint][0],VazrudenRing[waypoint][1],VazrudenRing[waypoint][2]);
                Turn_Timer = 10000;
            }else Turn_Timer -= diff;
        }
        else // phase 2 - land fight
        {
            if(ConeOfFire_Timer < diff)
            {
                DoCast(m_creature, SPELL_CONE_OF_FIRE);
                ConeOfFire_Timer = 12000;
                Fireball_Timer = 4000;
            }else ConeOfFire_Timer -= diff;

            if(HeroicMode && BellowingRoar_Timer < diff)
            {
                DoCast(m_creature, SPELL_BELLOWING_ROAR);
                BellowingRoar_Timer = 45000;
            }else BellowingRoar_Timer -= diff;

            DoMeleeAttackIfReady();
        }
    }
开发者ID:Denominator13,项目名称:NeoCore,代码行数:65,代码来源:boss_vazruden_the_herald.cpp


示例15: random

float random(float minimum, float maximum)
{
    return minimum + static_cast <float> (rand()) / ( static_cast <float> (RAND_MAX/(maximum - minimum)));
}
开发者ID:idea-foundry,项目名称:moon,代码行数:4,代码来源:utils.cpp


示例16: pdgl_main_body

int pdgl_main_body()
{
    static float hull_planes[]= {
        1, 0, 0, 1,
        1, 1, 0, 1,
        0, 1, 0, 1,
        -1, 1, 0, 1,
        -1, 0, 0, 1,
        -1, -1, 0, 1,
        0, -1, 0, 1,
        1, -1, 0, 1,
        0, 0, 1, 1,
        0, 0, -1, 1,
    };

    static int t;
    char buf[64];
    float mins[3], maxs[3];
    float io[3], iv[4], fw[2], pt[4], f, g, v;
    float im[16], im1[16];
    int i, j, k;
    unsigned short *kcur;

    main_time+=pdgl_dt_f;
    V3F_COPY(main_cam_org, main_dlight_org);

    V3F_ZERO(main_dlight_org+3);
    main_dlight_org[3]=sin(main_time*0.25)*75;
    main_dlight_org[4]=cos(main_time*0.25)*75;
    main_dlight_org[5]=10;

    kcur=pdgl_keybuf;

    f=main_cam_ang[2]*(M_PI/180);
    fw[0]=-sin(f);
    fw[1]=cos(f);

    bsdeGetAttrFV(main_cam_id, BSDE_ORIGIN, main_cam_org, 3);
    bsdeGetAttrFV(main_cam_id, BSDE_VELOCITY, main_cam_vel, 3);

    if(main_cam_raw)
    {
        bsdeHide(main_cam_id);
    } else
    {
        bsdeUnhide(main_cam_id);
    }

    io[0]=main_cam_org[0]-10*sin(f);
    io[1]=main_cam_org[1]+10*cos(f);
    io[2]=main_cam_org[2];

    f=(((rand()&0xFFF)/2048.0)-1)*0.1;
    g=(((rand()&0xFFF)/2048.0)-1)*0.1;
    io[0]+=f;
    io[1]+=g;

    v=1000;

    while(*kcur)
    {
        if(*kcur==K_ESCAPE)
        {
            main_kill=1;
            return(-1);
        }
        if(*kcur==K_F10)
        {
//			Tex_DoScreenshot();
        }

        if(*kcur==K_F2)
        {
            main_cam_raw=!main_cam_raw;
        }

        if(*kcur=='a')
        {
            i=bsdeNewOBB(-1, -1, -1, 1, 1, 1);
            main_objs[main_nobjs++]=i;
            main_addsolid(i);
//			bsdeSetAttrFV(i, BSDE_ORIGIN, VEC3(f, g, 10), 3);
            bsdeSetAttrFV(i, BSDE_ORIGIN, io, 3);
            bsdeSetAttrF(i, BSDE_DENSITY, 1);

            bsdeSetAttrFV(i, BSDE_VELOCITY, main_cam_vel, 3);

            if(PDGL_KeyDown(K_ALT))
                bsdeSetAttrFV(i, BSDE_VELOCITY,
                              VEC3(v*fw[0], v*fw[1], 0), 3);
        }

        if(*kcur=='A')
        {
            i=bsdeNewAABB(-2, -2, -2, 2, 2, 2);
            main_objs[main_nobjs++]=i;
            main_addsolid(i);
//			bsdeSetAttrFV(i, BSDE_ORIGIN, VEC3(f, g, 10), 3);
            bsdeSetAttrFV(i, BSDE_ORIGIN, io, 3);
            bsdeSetAttrF(i, BSDE_DENSITY, 1);
//.........这里部分代码省略.........
开发者ID:cr88192,项目名称:bgbtech_engine,代码行数:101,代码来源:bsde_app2.c


示例17: UpdateAI

    void UpdateAI(const uint32 diff)
    {
        //Return since we have no target
        if (!UpdateVictim())
            return;

        //MortalWound_Timer
        if (MortalWound_Timer <= diff)
        {
            DoCast(me->getVictim(),SPELL_MORTAL_WOUND);
            MortalWound_Timer = 10000 + rand()%10000;
        } else MortalWound_Timer -= diff;

        //Summon 1-3 Spawns of Fankriss at random time.
        if (SpawnSpawns_Timer <= diff)
        {
            switch (rand()%3)
            {
                case 0:
                    SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0));
                    break;
                case 1:
                    SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0));
                    SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0));
                    break;
                case 2:
                    SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0));
                    SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0));
                    SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0));
                    break;
            }
            SpawnSpawns_Timer = 30000 + rand()%30000;
        } else SpawnSpawns_Timer -= diff;

        // Teleporting Random Target to one of the three tunnels and spawn 4 hatchlings near the gamer.
        //We will only telport if fankriss has more than 3% of hp so teleported gamers can always loot.
        if (me->GetHealth()*100 / me->GetMaxHealth() > 3)
        {
            if (SpawnHatchlings_Timer <= diff)
            {
                Unit* pTarget = NULL;
                pTarget = SelectUnit(SELECT_TARGET_RANDOM,0);
                if (pTarget && pTarget->GetTypeId() == TYPEID_PLAYER)
                {
                    DoCast(pTarget, SPELL_ROOT);

                    if (DoGetThreat(pTarget))
                        DoModifyThreatPercent(pTarget, -100);

                    switch (rand()%3)
                    {
                        case 0:
                            DoTeleportPlayer(pTarget, -8106.0142f,1289.2900f,-74.419533f,5.112f);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()-3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()+3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()-5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()+5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            break;
                        case 1:
                            DoTeleportPlayer(pTarget, -7990.135354f,1155.1907f,-78.849319f,2.608f);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()-3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()+3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()-5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()+5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            break;
                        case 2:
                            DoTeleportPlayer(pTarget,-8159.7753f,1127.9064f,-76.868660f,0.675f);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()-3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()+3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()-5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()+5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000);
                            if (Hatchling)
                                ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget);
                            break;
                    }
                }
                SpawnHatchlings_Timer = 45000 + rand()%15000;
            } else SpawnHatchlings_Timer -= diff;
//.........这里部分代码省略.........
开发者ID:deremix,项目名称:darmixcore,代码行数:101,代码来源:boss_fankriss.cpp


示例18: KilledUnit

 void KilledUnit(Unit* Victim)
 {
     if(!(rand()%5))
         DoScriptText(SAY_SLAY, me);
 }
开发者ID:adan830,项目名称:QuaDCore,代码行数:5,代码来源:boss_heigan.cpp


示例19: GUIDEMO_Speed

/*********************************************************************
*
*       GUIDEMO_Speed
*/
void GUIDEMO_Speed(void) {
  int      TimeStart, i;
  U32      PixelsPerSecond;
  unsigned aColorIndex[8];
  int      xSize, ySize, vySize;
  GUI_RECT Rect, ClipRect;
  char     cText[40] = { 0 };

  xSize  = LCD_GetXSize();
  ySize  = LCD_GetYSize();
  vySize = LCD_GetVYSize();
#if GUI_SUPPORT_CURSOR
  GUI_CURSOR_Hide();
#endif
  if (vySize > ySize) {
    ClipRect.x0 = 0;
    ClipRect.y0 = 0;
    ClipRect.x1 = xSize;
    ClipRect.y1 = ySize;
    GUI_SetClipRect(&ClipRect);
  }
  GUIDEMO_ShowIntro("High speed",
                    "Multi layer clipping\n"
                    "Highly optimized drivers");
  for (i = 0; i< 8; i++) {
    aColorIndex[i] = GUI_Color2Index(_aColor[i]);
  }  
  TimeStart = GUIDEMO_GetTime();
  for (i = 0; ((GUIDEMO_GetTime() - TimeStart) < 5000) && (GUIDEMO_CheckCancel() == 0); i++) {
    GUI_SetColorIndex(aColorIndex[i&7]);
    //
    // Calculate random positions
    //
    Rect.x0 = rand() % xSize - xSize / 2;
    Rect.y0 = rand() % ySize - ySize / 2;
    Rect.x1 = Rect.x0 + 20 + rand() % xSize;
    Rect.y1 = Rect.y0 + 20 + rand() % ySize;
    GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
    //
    // Clip rectangle to visible area and add the number of pixels (for speed computation)
    //
    if (Rect.x1 >= xSize) {
      Rect.x1 = xSize - 1;
    }
    if (Rect.y1 >= ySize) {
      Rect.y1 = ySize - 1;
    }
    if (Rect.x0 < 0 ) {
      Rect.x0 = 0;
    }
    if (Rect.y1 < 0) {
      Rect.y1 = 0;
    }
    GUI_Exec();
    //
    // Allow short breaks so we do not use all available CPU time ...
    //
  }
  GUIDEMO_NotifyStartNext();
  PixelsPerSecond = _GetPixelsPerSecond();
  GUI_SetClipRect(NULL);
  GUIDEMO_DrawBk(0);
  GUI_SetColor(GUI_WHITE);
  GUI_SetTextMode(GUI_TM_TRANS);
  GUI_SetFont(&GUI_FontRounded22);
  GUI_DrawBitmap(&bmSTLogo70x35, 5, 5);
  GUIDEMO_AddStringToString(cText, "Pixels/sec: ");
  GUIDEMO_AddIntToString(cText, PixelsPerSecond);
  GUI_DispStringHCenterAt(cText, xSize >> 1, (ySize - GUI_GetFontSizeY()) >> 1);
  GUIDEMO_Delay(4000);
#if GUI_SUPPORT_CURSOR
  GUI_CURSOR_Show();
#endif
}
开发者ID:pierreroth64,项目名称:STM32Cube_FW_F4,代码行数:78,代码来源:GUIDEMO_Speed.c


示例20: UpdateAI

        void UpdateAI(const uint32 diff)
        {
            //Only if not incombat check if the event is started
            if (!me->isInCombat() && pInstance && pInstance->GetData(DATA_KARATHRESSEVENT))
            {
                Unit *pTarget = Unit::GetUnit((*me), pInstance->GetData64(DATA_KARATHRESSEVENT_STARTER));

                if (pTarget)
                {
                    AttackStart(pTarget);
                    GetAdvisors();
                }
            }

            //Return since we have no target
            if (!UpdateVictim())
                return;

            //someone evaded!
            if (pInstance && !pInstance->GetData(DATA_KARATHRESSEVENT))
            {
                EnterEvadeMode();
                return;
            }

            //CataclysmicBolt_Timer
            if (CataclysmicBolt_Timer <= diff)
            {
                //select a random unit other than the main tank
                Unit *pTarget = SelectUnit(SELECT_TARGET_RANDOM, 1);

                //if there aren't other units, cast on the tank
                if (!pTarget)
                    pTarget = me->getVictim();

                if (pTarget)
                    DoCast(pTarget, SPELL_CATACLYSMIC_BOLT);
                CataclysmicBolt_Timer = 10000;
            } else CataclysmicBolt_Timer -= diff;

            //SearNova_Timer
            if (SearNova_Timer <= diff)
            {
                DoCast(me->getVictim(), SPELL_SEAR_NOVA);
                SearNova_Timer = 20000+rand()%40000;
            } else SearNova_Timer -= diff;

            //Enrage_Timer
            if (Enrage_Timer <= diff)
            {
                DoCast(me, SPELL_ENRAGE);
                Enrage_Timer = 90000;
            } else Enrage_Timer -= diff;

            //Blessing of Tides Trigger
            if (!HealthAbovePct(75) && !BlessingOfTides)
            {
                BlessingOfTides = true;
                bool continueTriggering = false;
                Creature* Advisor;
                for (uint8 i = 0; i < MAX_ADVISORS; ++i)
                    if (Advisors[i])
                    {
                        Advisor = (Unit::GetCreature(*me, Advisors[i]));
                        if (Advisor && Advisor->isAlive())
                        {
                            continueTriggering = true;
                            break;
                        }
                    }
                if (continueTriggering)
                {
                    DoCast(me, SPELL_BLESSING_OF_THE_TIDES);
                    me->MonsterYell(SAY_GAIN_BLESSING_OF_TIDES, LANG_UNIVERSAL, NULL);
                    DoPlaySoundToSet(me, SOUND_GAIN_BLESSING_OF_TIDES);
                }
            }

            DoMeleeAttackIfReady();
        }
开发者ID:1024wow,项目名称:TrinityCore,代码行数:80,代码来源:boss_fathomlord_karathress.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ rand32函数代码示例发布时间:2022-05-30
下一篇:
C++ ran1函数代码示例发布时间: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