void Add(const char *str, size_t len) { CheckWrap(len + NeedSpace); if (NeedSpace) { Str << ' '; } Str.AppendCStrPart(str, len); Column += len + NeedSpace; NeedSpace = true; }
void AddName(FName name) { size_t namelen = strlen(name.GetChars()); CheckWrap(namelen + 2 + NeedSpace); if (NeedSpace) { NeedSpace = false; Str << ' '; } Str << '\'' << name.GetChars() << '\''; Column += namelen + 2 + NeedSpace; NeedSpace = true; }
void Open(const char *label) { size_t labellen = label != NULL ? strlen(label) : 0; CheckWrap(labellen + 1 + NeedSpace); if (NeedSpace) { Str << ' '; ConsecOpens = 0; } Str << '('; ConsecOpens++; if (label != NULL) { Str.AppendCStrPart(label, labellen); } Column += labellen + 1 + NeedSpace; NestDepth++; NeedSpace = (label != NULL); }
void GameBase::Update(void) { unsigned int i; unsigned int j; Ship *ship; Shot *shot; Rock *rock; GameObject **po1; GameObject **po2; GameObject *o1; GameObject *o2; double dist; bool hit; double dx,dy,maxsum; bool pauserequest=false; unsigned int pauseuser=0; bool thrust; if(m_paused || m_gameover) return; if(m_title==false) { if(++m_beatcount==m_beatdelay) { m_beatcount=0; PlaySound(SOUND_BEAT1+m_beat); m_beat^=1; } /* update ships */ for(i=0;i<m_numplayers;++i) { ship=&m_ship[i]; if(IsPressed(i,GAMEINPUT_PAUSE)) { pauserequest=true; pauseuser=i; } thrust=false; if(ship->m_active) { switch(ship->m_state) { case STATE_APPEAR: /* flash so they know they are in 'invincible mode' */ ship->m_draw=((ship->m_statedelay&2)!=0); if(++(ship->m_statedelay)==60) { ship->m_state=STATE_PLAY; ship->m_draw=true; } /* fall through */ case STATE_PLAY: if(IsPressed(i,GAMEINPUT_LEFT)) ship->m_heading-=3.0f/360.0f; else if(IsPressed(i,GAMEINPUT_RIGHT)) ship->m_heading+=3.0f/360.0f; if(IsPressed(i,GAMEINPUT_THRUST)) { GameMatrix33 mat; GameVector3 vin; GameVector3 vout; double newspeedx,newspeedy,newspeed,scale; thrust=true; /* add to speed vector based on current heading */ mat.SetRotZ(ship->m_heading); vin.m_x=0.0f; vin.m_y=-0.5f; vin.m_z=0.0f; mat.Transform(&vin,&vout); newspeedx=ship->m_speedx+vout.m_x; newspeedy=ship->m_speedy+vout.m_y; newspeed=hypot(newspeedx,newspeedy); if(newspeed>MAXSPEED) { /* scale */ scale=MAXSPEED/newspeed; newspeedx*=scale; newspeedy*=scale; } ship->m_speedx=newspeedx; ship->m_speedy=newspeedy; if(++(ship->m_showthrust)>=4) ship->m_showthrust=0; } else { /* decel */ ship->m_speedx*=0.975f; ship->m_speedy*=0.975f; ship->m_showthrust=0; } ship->m_x+=ship->m_speedx; ship->m_y+=ship->m_speedy; CheckWrap(&ship->m_x,&ship->m_y); if(ship->m_shotdelay) --ship->m_shotdelay; else if(IsPressed(i,GAMEINPUT_FIRE)) { shot=0; /* fire a shot if we have an available shot slot */ for(j=0;j<MAXSHOTS;++j) { if(ship->m_shot[j].m_active==false) { shot=&ship->m_shot[j]; break; } } if(shot) { GameMatrix33 mat; GameVector3 vin; GameVector3 vout; PlaySound(SOUND_SHOT); ship->m_shotdelay=SHOTDELAY; shot->m_active=true; /* calc position of shot and direction */ mat.SetRotZ(ship->m_heading); vin.m_x=0.0f; vin.m_y=-10.0f; vin.m_z=0.0f; mat.Transform(&vin,&vout); shot->m_x=ship->m_x+vout.m_x; shot->m_y=ship->m_y+vout.m_y; shot->m_heading=ship->m_heading; shot->m_speedx=vout.m_x; shot->m_speedy=vout.m_y; shot->m_life=0; } } break; case STATE_DIE: ++(ship->m_statedelay); switch(ship->m_statedelay) { case 20: break; case 40: break; case 60: if(ship->m_life) { ship->m_state=STATE_APPEAR; ship->m_statedelay=0; ship->m_x=0.0f; ship->m_y=0.0f; ship->m_heading=0.0f; ship->m_speedx=0.0f; ship->m_speedy=0.0f; } else { ship->m_active=false; --m_numplayersleft; if(!m_numplayersleft) { /* game over */ GameOver(); m_gameover=true; } } break; } } } /* move all shots */ for(j=0;j<MAXSHOTS;++j) { shot=&ship->m_shot[j]; if(shot->m_active) { shot->m_x+=shot->m_speedx; shot->m_y+=shot->m_speedy; CheckWrap(&shot->m_x,&shot->m_y); if(++shot->m_life==SHOTLIFE) shot->m_active=false; } } if(ship->m_thrustsound==false && thrust==true) { ship->m_thrustsound=true; ship->m_thrusthandle=StartSound(SOUND_THRUST); } else if(ship->m_thrustsound==true && thrust==false) { ship->m_thrustsound=false; StopSound(ship->m_thrusthandle); } } /* UFO update */ if(m_ufo.m_active) { if(!m_ufo.m_segmentlen) { /* randonly move straight or on a 45 up or down */ m_ufo.m_segmentlen=Rand((int)(m_cy*0.5f))+(int)(m_cy*0.25f); switch(Rand(9)) { case 0: case 1: m_ufo.m_curheading=m_ufo.m_heading-0.125f; break; case 2: case 3: m_ufo.m_curheading=m_ufo.m_heading+0.125f; break; default: m_ufo.m_curheading=m_ufo.m_heading; break; } } else --(m_ufo.m_segmentlen); m_ufo.m_x+=cos(m_ufo.m_curheading*(2.0f*PI))*3.0f; m_ufo.m_y+=sin(m_ufo.m_curheading*(2.0f*PI))*3.0f; CheckWrap(0,&m_ufo.m_y); /* done? */ if(fabs(m_ufo.m_x)>=(m_cx+m_ufo.m_maxradius)) { m_ufo.m_active=false; } else { /* time to fire any new shots? */ if(++(m_ufo.m_shotdelay)==(30)) { m_ufo.m_shotdelay=0; shot=0; /* fire a shot if we have an available shot slot */ for(j=0;j<MAXSHOTS;++j) { if(m_ufo.m_shot[j].m_active==false) { shot=&m_ufo.m_shot[j]; break; } } if(shot) { unsigned int n; double h; double err; GameMatrix33 mat; GameVector3 delta; GameVector3 vin; GameVector3 vout; PlaySound(SOUND_SHOT); /* calc vector between UFO and a random SHIP */ n=Rand(m_numplayers); delta.m_x=m_ufo.m_x-m_ship[n].m_x; delta.m_y=m_ufo.m_y-m_ship[n].m_y; h=(atan2(delta.m_y,delta.m_x)*(1.0f/(2.0f*PI)))-0.25f; /* add more randomness for lower levels */ err=(6-m_level)*(0.10f/6.0f); if(err>0.0f) { err=Rand(-err,err); h+=err; } shot->m_active=true; shot->m_heading=h; /* calc position of shot and direction */ mat.SetRotZ(h); vin.m_x=0.0f; vin.m_y=-10.0f; vin.m_z=0.0f; mat.Transform(&vin,&vout); shot->m_x=m_ufo.m_x+vout.m_x; shot->m_y=m_ufo.m_y+vout.m_y; shot->m_speedx=vout.m_x; shot->m_speedy=vout.m_y; shot->m_life=0; } } } } else { /* make delay vary based on level?? */ if(++m_ufo.m_appeardelay==(20*60)) { m_ufo.m_active=true; m_ufo.m_appeardelay=0; m_ufo.m_appearside=!m_ufo.m_appearside; if(m_ufo.m_appearside==false) { m_ufo.m_x=-(m_cx+m_ufo.m_maxradius); m_ufo.m_heading=0.0f; /* left to right */ } else { m_ufo.m_x=(m_cx+m_ufo.m_maxradius); m_ufo.m_heading=0.5f; /* right to left */ } m_ufo.m_y=Rand(-m_cy*0.9f,m_cy*0.9f); m_ufo.m_segmentlen=0; } } /* move all ufo shots */ for(j=0;j<MAXSHOTS;++j) { shot=&m_ufo.m_shot[j]; if(shot->m_active) { shot->m_x+=shot->m_speedx; shot->m_y+=shot->m_speedy; CheckWrap(&shot->m_x,&shot->m_y); if(++shot->m_life==SHOTLIFE) shot->m_active=false; } } /* update all used particles */ { GameParticle *gp; GameParticle *pp; GameParticle *np; GameParticle *sp; gp=m_usedphead.m_next; while(gp!=&m_usedptail) { --gp->m_life; if(!gp->m_life) { /* save pointer to next particle */ sp=gp->m_next; /* done, remove from used list */ pp=gp->m_prev; np=gp->m_next; pp->m_next=np; np->m_prev=pp; /* add me to the free list */ pp=&m_freephead; np=pp->m_next; pp->m_next=gp; gp->m_prev=pp; gp->m_next=np; np->m_prev=gp; /* continue with next particle */ gp=sp; } else { gp->m_x+=gp->m_speedx; gp->m_y+=gp->m_speedy; gp=gp->m_next; } } } } /* update rocks */ for(i=0;i<MAXROCKS;++i) { rock=&m_rock[i]; if(rock->m_active) { rock->m_heading+=rock->m_headingspeed; rock->m_x+=rock->m_speedx; rock->m_y+=rock->m_speedy; CheckWrap(&rock->m_x,&rock->m_y); } } /* check for collisions */ po1=m_objects; for(i=0;i<TOTALOBJECTS-1;++i,++po1) { o1=*(po1); if(o1->m_active) { po2=po1+1; for(j=i+1;j<TOTALOBJECTS;++j,++po2) { o2=*(po2); if(o2->m_active) { if(o1->m_type!=o2->m_type) { maxsum=o1->m_maxradius+o2->m_maxradius; /* do a quick exclude without hypot */ dx=o1->m_x-o2->m_x; if(fabs(dx)>maxsum) continue; dy=o1->m_y-o2->m_y; if(fabs(dy)>maxsum) continue; /* two active objects, check distance between them */ dist=hypot(dx,dy); if(dist<(maxsum)) { if(dist<(o1->m_minradius+o2->m_minradius)) hit=true; else { /* possible hit */ hit=IsInside(o1,o2); if(!hit) hit=IsInside(o2,o1); } if(hit) { /* yes, objects collided */ o1->Collide(o2); o2->Collide(o1); if(o1->m_active==false) goto skiprest; } } } } } } skiprest:; } /* call virtual function too let them know that the game is now paused */ if(pauserequest) PauseRequest(pauseuser); }