Ejemplo n.º 1
0
GrahamScan::GrahamScan(voro::voronoicell_neighbor& voro_cell, unsigned int cellID, double* partPos)
{
	vector<double> vv;
	double x1[2], x2[2];
	set<SPoint>	pointset;
	//Iterate over the voro++ structure and produce unique points on the contour.
	voro_cell.vertices(partPos[3*(cellID-1)],partPos[3*(cellID-1)+1],partPos[3*(cellID-1)+2],vv);
	for (int ii = 0; ii < voro_cell.p; ii++)
	{
		for (int jj = 0; jj < voro_cell.nu[ii]; jj++)
		{

			int k = voro_cell.ed[ii][jj];
			x1[0] = vv[3 * ii];
			x1[1] = vv[3 * ii + 1];
			x2[0] = vv[3 * k];
			x2[1] = vv[3 * k + 1];
			pointset.insert(SPoint(x1[1], x1[0], 0, 1));
			pointset.insert(SPoint(x2[1], x2[0], 0, 1));
		}
	}
	std::copy(pointset.begin(), pointset.end(), std::back_inserter(m_sortedPoints));

	ComparisonFunctor comparator;
	comparator.compareReference = &(*pointset.begin());

	vector<SPoint>::iterator start = m_sortedPoints.begin(); start++;
	sort(start, m_sortedPoints.end(), comparator);
}
Ejemplo n.º 2
0
//-----------------------------ctor---------------------------------------
//
//------------------------------------------------------------------------
CController::CController(int cxClient,
                         int cyClient):
                                       m_bSuccess(false),                                  
                                       m_vPadPos(SVector2D(RandFloat()*cxClient, 50)),
                                       m_cxClient(cxClient),
                                       m_cyClient(cyClient)
                                       
{


  //create a starting postion for the landers
  SVector2D vStartPos = SVector2D(WINDOW_WIDTH/2, cyClient-50);

  //create the user controlled lander
  m_pUserLander = new CLander(cxClient, cyClient, PI, vStartPos, m_vPadPos);

  //set up the VB for the landing pad
  for (int i=0; i<NumPadVerts; ++i)
  {
    m_vecPadVB.push_back(Pad[i]);
  }

  //setup the stars
  for (int i=0; i<NumStars; ++i)
  {
    m_vecStarVB.push_back(SPoint(RandInt(0, cxClient), RandInt(100, cyClient)));
  }

}
Ejemplo n.º 3
0
bool PointInArea( const TSPoint* _pgn, const TSPoint& _pt )
{
	TSPoint v1;		// 四角形の頂点から対象頂点へのベクトル
	TSPoint v2;      // 四角形の辺のベクトル
	for( u32 i  =  0 ; i <= 3; i++ ) {
		v1  =  SPoint(_pt.x - _pgn[i].x, _pt.y - _pgn[i].y);
		v2  =  SPoint(_pgn[(i + 1) & 3].x - _pgn[i].x,
			_pgn[(i + 1) & 3].y - _pgn[i].y);
		if( (v1.x * v2.y - v1.y * v2.x) < 0 ) {  	// 外積をとって領域内チェック
			return false;
		}
	}

	return true;

}
//-------------------------------------------------------------------------------------------------
void QGraphicsItemPointList::add(qreal x, qreal y)
{
    if (!m_bounds.contains(x, y))
    {
        prepareGeometryChange();
        m_bounds = m_bounds.united(QRect(x, y, 1, 1));
    }

    m_vPoints.push_back(SPoint(x,y));
}
Ejemplo n.º 5
0
void Application::HandleEvents()
{
    SDL_Event event;

    while (SDL_PollEvent(&event))
    {
        switch (event.type)
        {
            case SDL_QUIT:
                fprintf(stderr,"QUIT!\n");
                m_running = false;
                break;
	    case SDL_VIDEORESIZE:
		Settings::Instance()->SetResolution(UPoint(event.resize.w, event.resize.h));
		break;
            case SDL_MOUSEMOTION:
                m_cursorX = event.motion.x;
                m_cursorY = event.motion.y;

                m_rootWidget->handleMotion(SPoint(event.motion.x, event.motion.y)); 
                break;
            case SDL_MOUSEBUTTONDOWN:
                gpaloff++;
                m_rootWidget->handleButtonDown( event.button.button,
                                                SPoint(event.button.x, event.button.y));
                break;
            case SDL_MOUSEBUTTONUP:
                m_rootWidget->handleButtonUp(   event.button.button,
                                                SPoint(event.button.x, event.button.y));
                break;
            case SDL_KEYDOWN:
                if (event.key.keysym.sym == SDLK_F11)
                    Settings::Instance()->ToggleFullscreen();
            
                m_rootWidget->handleKeyDown(&(event.key.keysym));
                break;
            case SDL_KEYUP:
                m_rootWidget->handleKeyUp(&(event.key.keysym));
                break;
        }
    }
}
Ejemplo n.º 6
0
void SkirmishMenuState::resize()
{
    MainMenuBaseState::resize();
    UPoint resolution = set->GetResolution();

    m_missionLabel->setPosition(SPoint(8,8));
    m_missionCounter->setPosition(m_missionLabel->getPosition() + SPoint(m_missionLabel->getSize().x + 5, 0));
    m_butPlus->setPosition(m_missionCounter->getPosition() + SPoint(m_missionCounter->getSize().x + 5, -2));
    m_butMinus->setPosition(m_missionCounter->getPosition() + SPoint(m_missionCounter->getSize().x + 5, 8));

    ImagePtr tmp(new Image(m_missionLabel->getSize() + m_missionLabel->getPosition() + SPoint(m_missionCounter->getSize().x + m_butPlus->getSize().x + 20, 5)));
    tmp->setColorKey();
    tmp->drawBorders1();

    m_missionFrame->changeBackground(tmp);

    SPoint midPos = m_menuFrame->getPosition() + SPoint(m_menuFrame->getSize().x, m_menuBottomFrame->getPosition().y);
    SPoint pos = midPos + (UPoint(resolution.x - midPos.x,m_menuBottomFrame->getSize().y)/2) - (m_missionFrame->getSize()/2);

    m_missionFrame->setPosition(pos);
}
Ejemplo n.º 7
0
SkirmishMenuState::SkirmishMenuState() : MainMenuBaseState()
{
    m_house = HOUSE_ATREIDES;

    m_butStart = new BoringButton("Start");
    m_butStart->setSize(SPoint(bw, bh));
    m_butStart->onClick.connect(
            boost::bind(&SkirmishMenuState::doStart, this) );
    m_vbox->addChild(m_butStart);

    m_butCancel = new BoringButton("Cancel");
    m_butCancel->setSize(SPoint(bw, bh));
    m_butCancel->onClick.connect(
            boost::bind(&SkirmishMenuState::doCancel, this) );
    m_vbox->addChild(m_butCancel);

    m_selectionBox = new SelectionBox(false);

    m_missionLabel = new TransparentLabel("Mission");

    m_missionCounter = new Counter(1, 22, 1);
    m_butPlus = new BoringButton(" ");
    m_butPlus->setSize(SPoint(10, 10));
    m_butPlus->onClick.connect(
            boost::bind(&Counter::increase, m_missionCounter) );

    m_butMinus = new BoringButton(" ");
    m_butMinus->setSize(SPoint(10,10));
    m_butMinus->onClick.connect(
            boost::bind(&Counter::decrease, m_missionCounter) );

    m_missionFrame = new Frame();

    m_missionFrame->addChild(m_missionLabel);
    m_missionFrame->addChild(m_butMinus);
    m_missionFrame->addChild(m_butPlus);
    m_missionFrame->addChild(m_missionCounter);
    m_backgroundFrame->addChild(m_missionFrame);

}
Ejemplo n.º 8
0
void GameMan::TakeMapScreenshot(std::string filename)
{
    int w = m_map->w;
    int h = m_map->h;
    Image img(UPoint(w * 16, h * 16));


    for (int i = 0 ; i < w; i++)
	for (int j = 0 ; j < h; j++)
	    m_map->getCell(UPoint(i, j))->draw(img, SPoint(16*i, 16*j));

    img.saveBMP(filename);

}
Ejemplo n.º 9
0
bool CBobsMap::GetOneValidPath(vector<int> &vecBits,int chromolen)
{
	int testCount=0;
	int iChromoLength=chromolen;
	int iCutCount=iChromoLength+1;

	Coordinate cord(m_spA,m_spB);

	SPoint spPre=m_spA;
	
	int randomY = 0;
	//divied space 
	SVector2D line(m_spA.x-m_spB.x,m_spA.y-m_spB.y);
	int diffX = (int) Vec2DLength(line)/iCutCount;
	for(int i=1;i<=iChromoLength;i++)
	{	
		randomY = RandInt(-150,150);
		SPoint spRelative(i*diffX,randomY);
		SPoint spPathAbsolute=cord.GetCoordinate(spRelative.x,spRelative.y);
		while(true)
		{			

			if(!BarrierIntersection(spPre,spPathAbsolute)&&IsValidPoint(spPathAbsolute))
			{
				break;
				
			}else
			{
				testCount++;
				if(testCount>100) 
				{
					return false;
				}
			}
			
			randomY = RandInt(-150,150);
			spRelative=SPoint(i*diffX,randomY);
			spPathAbsolute=cord.GetCoordinate(spRelative.x,spRelative.y);
		}	
		//save waypoint
		vecBits.push_back(randomY);
		spPre=spPathAbsolute;
	}

	
	return true;
}
Ejemplo n.º 10
0
  void PSym_Test::Test_PSymTemplates()
  {
    const SPoint in(3,5);

    // The eight symmetries map as expected
    assert(Map<PSYM_DEG000L>(in) == SPoint( 3, 5));
    assert(Map<PSYM_DEG090L>(in) == SPoint(-5, 3));
    assert(Map<PSYM_DEG180L>(in) == SPoint(-3,-5));
    assert(Map<PSYM_DEG270L>(in) == SPoint( 5,-3));
    assert(Map<PSYM_DEG000R>(in) == SPoint( 3,-5));
    assert(Map<PSYM_DEG090R>(in) == SPoint( 5, 3));
    assert(Map<PSYM_DEG180R>(in) == SPoint(-3, 5));
    assert(Map<PSYM_DEG270R>(in) == SPoint(-5,-3));

    // Alternate symmetry names act the same as the canonical
    assert(Map<PSYM_FLIPX>(in) == Map<PSYM_DEG180R>(in));
    assert(Map<PSYM_FLIPY>(in) == Map<PSYM_DEG000R>(in));
    assert(Map<PSYM_FLIPXY>(in)== Map<PSYM_DEG180L>(in));

  }
Ejemplo n.º 11
0
  void PSym_Test::Test_PSymMap()
  {
    const SPoint in(1,2);
    const SPoint err(9,10);

    // The eight symmetries map as expected
    assert(Map(in, PSYM_DEG000L, err) == SPoint( 1, 2));
    assert(Map(in, PSYM_DEG090L, err) == SPoint(-2, 1));
    assert(Map(in, PSYM_DEG180L, err) == SPoint(-1,-2));
    assert(Map(in, PSYM_DEG270L, err) == SPoint( 2,-1));
    assert(Map(in, PSYM_DEG000R, err) == SPoint( 1,-2));
    assert(Map(in, PSYM_DEG090R, err) == SPoint( 2, 1));
    assert(Map(in, PSYM_DEG180R, err) == SPoint(-1, 2));
    assert(Map(in, PSYM_DEG270R, err) == SPoint(-2,-1));

    // Point symmetries don't move the origin
    const SPoint o(0,0);
    assert(Map(o, PSYM_DEG000L, err) == o);
    assert(Map(o, PSYM_DEG090L, err) == o);
    assert(Map(o, PSYM_DEG180L, err) == o);
    assert(Map(o, PSYM_DEG270L, err) == o);
    assert(Map(o, PSYM_DEG000R, err) == o);
    assert(Map(o, PSYM_DEG090R, err) == o);
    assert(Map(o, PSYM_DEG180R, err) == o);
    assert(Map(o, PSYM_DEG270R, err) == o);

    // Error cases report given error
    assert(Map(in, (PointSymmetry) -1, err) == err);
    assert(Map(in, (PointSymmetry) 1000, err) == err);

    // Which is not always the same
    const SPoint err2(90,100);
    assert(Map(in, (PointSymmetry) -1, err) != err2);
    assert(Map(in, (PointSymmetry) 1000, err) != err2);

    // Alternate symmetry names act the same as the canonical
    assert(Map(in,PSYM_FLIPX,err) == Map(in, PSYM_DEG180R,err2));
    assert(Map(in,PSYM_FLIPY,err) == Map(in, PSYM_DEG000R,err2));
    assert(Map(in,PSYM_FLIPXY,err)== Map(in, PSYM_DEG180L,err2));

  }
Ejemplo n.º 12
0
void  SComponentWidget::paintEvent ( QPaintEvent * event )
{
    QRect rcClip = event->rect();
    QPainter painter(this);

    painter.eraseRect(rcClip);
    SRect srcClip(rcClip.x(),rcClip.y(),rcClip.width(),rcClip.height());
    if(!m_pComponentIndex) return;

    int w = getContentsSize().width();
    int h = getContentsSize().height();
    SSize size(0,0);

    g_drawComponentBase(&painter,
                        m_pComponentIndex,
                        SPoint(w-40,h-40),
                        size,//compIndex がNULLのときだけ使う
                        0,
                        m_block,
                        DRAW_ON,
                        &srcClip,
                        1,
                        true);
}
Ejemplo n.º 13
0
std::string CGameMap::initialize()
{
	assert( !mCells );

	/*
	Format of map data:

	string	Tissue Name
	int32	Tissue Bitmap Length
	byte[]	Tissue Bitmap (200*200)
	string	Entites text file
	string	Streams text file
	string	Walls text files
	*/

	const BYTE* data;

	//
	// parse name

	mName = bu::receiveStr();
	// TBD: workaround around Richard's funky stuff
	int lastSlash = mName.find_last_of( "\\//" );
	if( lastSlash >= 0 )
		mName = mName.substr( lastSlash+1, mName.length()-lastSlash );
	CONS << "Game map name: " << mName << endl;

	//
	// read map bitmap

	int bmpSize = bu::receiveInt();
	net::receiveChunk( data, bmpSize, true );
	// compute CRC of the bitmap
	const char* bmpFile = (const char*)data;
	mCRC = boost::crc<32,0xFFFFFFFF,0,0,false,false>( bmpFile, bmpSize );


	HRESULT hr;
	D3DXIMAGE_INFO bitmapInfo;
	hr = D3DXGetImageInfoFromFileInMemory( bmpFile, bmpSize, &bitmapInfo );
	if( FAILED(hr) ) {
		return "Error in game map - incorrect tissue bitmap format";
	}
	assert( bitmapInfo.Width > 10 && bitmapInfo.Height > 10 );
	assert( bitmapInfo.Width * bitmapInfo.Height <= 256*256 );
	if( bitmapInfo.Width < 10 || bitmapInfo.Height < 10 ) {
		return "Error in game map - map is too small";
	}
	if( bitmapInfo.Width * bitmapInfo.Height > 256*256 ) {
		return "Error in game map - map is too large";
	}

	mCellsX = bitmapInfo.Width;
	mCellsY = bitmapInfo.Height;
	mCells = new SCell[ mCellsX * mCellsY ];

	CD3DDevice& dx = CD3DDevice::getInstance();
	IDirect3DSurface9* surface = 0;
	hr = dx.getDevice().CreateOffscreenPlainSurface( bitmapInfo.Width, bitmapInfo.Height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, NULL );
	assert( SUCCEEDED(hr) );

	hr = D3DXLoadSurfaceFromFileInMemory( surface, NULL, NULL, bmpFile, bmpSize, NULL, D3DX_DEFAULT, 0, NULL );
	if( FAILED(hr) ) {
		return "Error in game map - incorrect cells map format";
	}

	D3DLOCKED_RECT lr;
	surface->LockRect( &lr, NULL, D3DLOCK_READONLY );
	const char* linePtr = (const char*)lr.pBits;
	for( int y = 0; y < mCellsY; ++y ) {
		const D3DCOLOR* p = (const D3DCOLOR*)linePtr;
		for( int x = 0; x < mCellsX; ++x ) {
			SCell& cell = mCells[y*mCellsX+x];
			switch( *p ) {
			case 0xFFff0000:
				cell.type = CELL_BLOOD1;
				cell.color = CCOLOR_BLOOD;
				break;
			case 0xFF00ff00:
				cell.type = CELL_BLOOD2;
				cell.color = CCOLOR_BLOOD;
				break;
			case 0xFF0000ff:
				cell.type = CELL_BLOOD3;
				cell.color = CCOLOR_BLOOD;
				break;
			case 0xFF800000:
				cell.type = CELL_BLOOD1;
				cell.color = CCOLOR_BONE;
				break;
			case 0xFF008000:
				cell.type = CELL_BLOOD2;
				cell.color = CCOLOR_BONE;
				break;
			case 0xFF000080:
				cell.type = CELL_BLOOD3;
				cell.color = CCOLOR_BONE;
				break;
			case 0xFFC80000:
				cell.type = CELL_BLOOD1;
				cell.color = CCOLOR_NEURON;
				break;
			case 0xFF00C800:
				cell.type = CELL_BLOOD2;
				cell.color = CCOLOR_NEURON;
				break;
			case 0xFF0000C8:
				cell.type = CELL_BLOOD3;
				cell.color = CCOLOR_NEURON;
				break;
			default:
				cell.type = CELL_BONE;
				cell.color = CCOLOR_BLOOD;
			}
			cell.height = MIN_CELL_HEIGHT;
			cell.nearBone = true;
			++p;
		}
		linePtr += lr.Pitch;
	}
	surface->UnlockRect();
	surface->Release();

	// check map validity
	if( !checkMapValidity() )
		return "Tissue contains invalid topology (cells adjacent only diagonally)";

	//
	// read entities

	std::string pts = bu::receiveStr();
	char* ptsFile = (char*)pts.c_str(); // HACK
	const char* tokens = "\n\r";
	const char* pline = strtok( ptsFile, tokens );
	do {
		if( !pline )
			break;
		int etype, eposx, eposy;
		int fread = sscanf( pline, "%i:%i:%i", &eposx, &eposy, &etype );
		if( fread != 3 )
			break;
		mPoints.push_back( SPoint(ePointType(etype), eposx, eposy ) );
	} while( pline = strtok( NULL, tokens ) );

	//
	// read streams

	std::string strms = bu::receiveStr(); // streams
	char* strmsFile = (char*)strms.c_str(); // HACK
	pline = strtok( strmsFile, tokens );
	do {
		if( !pline )
			break;
		int sx, sy, sw, sh, sdir;
		int fread = sscanf( pline, "%i:%i:%i:%i:%i", &sx, &sy, &sw, &sh, &sdir );
		assert( sx >= 0 && sx < mCellsX );
		assert( sy >= 0 && sy < mCellsY );
		assert( sx+sw <= mCellsX );
		assert( sy+sh <= mCellsY );
		assert( sdir >= 0 && sdir <= 3 );
		assert( fread == 5 );
		if( fread != 5 )
			break;
		SStream strm;
		strm.x = sx;
		strm.y = sy;
		strm.width = sw;
		strm.height = sh;
		switch( sdir ) {
		case 0:	strm.deltaX =  0; strm.deltaY =  1; break;
		case 1:	strm.deltaX =  0; strm.deltaY = -1; break;
		case 2:	strm.deltaX =  1; strm.deltaY =  0; break;
		case 3:	strm.deltaX = -1; strm.deltaY =  0; break;
		}
		mStreams.push_back( strm );
	} while( pline = strtok( NULL, tokens ) );

	// TBD:  walls
	bu::receiveStr(); // walls

	//
	// all is loaded now
	
	// calculate cell heights
	calcCellHeights();

	// add some decorative elements
	static int DECOR_TYPES_IN_TISSUE[DECOR_POINT_TYPE_COUNT] = {
		(1<<CCOLOR_BLOOD), (1<<CCOLOR_BLOOD), (1<<CCOLOR_BLOOD),
		(1<<CCOLOR_BONE), (1<<CCOLOR_BONE), (1<<CCOLOR_BONE) | (1<<CCOLOR_BLOOD),
		(1<<CCOLOR_NEURON), (1<<CCOLOR_NEURON), (1<<CCOLOR_NEURON),
		(1<<CCOLOR_NEURON), (1<<CCOLOR_NEURON), (1<<CCOLOR_NEURON)|(1<<CCOLOR_BLOOD)|(1<<CCOLOR_BONE),
	};
	const int DECOR_PTS_COUNT = 125;
	const int MAX_TRY_COUNT = DECOR_PTS_COUNT * 10;
	int decPtsCounter = 0;
	int tryCounter = 0;
	while( decPtsCounter < DECOR_PTS_COUNT && tryCounter < MAX_TRY_COUNT ) {
		++tryCounter;

		int x = gRandom.getUInt() % mCellsX;
		int y = gRandom.getUInt() % mCellsY;
		const SCell& cell = mCells[pos2index(x,y)];
		if( !isBlood(cell.type) || cell.nearBone )
			continue;
		if( cell.height < 2.0f )
			continue;

		int ptType = gRandom.getUInt() % DECOR_POINT_TYPE_COUNT;
		if( !(DECOR_TYPES_IN_TISSUE[ptType] & (1<<cell.color)) )
			continue;

		mPoints.push_back( SPoint(PT_DECORATIVE,x,y, ptType) );
		decPtsCounter++;
	}

	// register level texture
	CSharedTextureBundle::getInstance().registerTexture( RID_TEX_LEVEL, *new CGameMapTextureCreator( *this ) );

	return ""; // all ok!
}
Ejemplo n.º 14
0
//----------------------- TestSensors ------------------------------------
//
//  This function checks for any intersections between the sweeper's 
//  sensors and the objects in its environment
//------------------------------------------------------------------------
void CMinesweeper::TestSensors(vector<SPoint> &objects)
{
  m_bCollided = false;  
  
  //first we transform the sensors into world coordinates
  m_tranSensors = m_Sensors;

  WorldTransform(m_tranSensors, 1);  //scale is 1

  //flush the sensors
  m_vecdSensors.clear();
  m_vecFeelers.clear();

  //now to check each sensor against the objects in the world
  for (int sr=0; sr<m_tranSensors.size(); ++sr)
  {
    bool bHit = false;

    double dist = 0;

    for (int seg=0; seg<objects.size(); seg+=2)
    {
      if (LineIntersection2D(SPoint(m_vPosition.x, m_vPosition.y),
                             m_tranSensors[sr],
                             objects[seg],
                             objects[seg+1],
                             dist))
      {
        bHit = true;

        break;        
      }
    }
      
    if (bHit)
    {
      m_vecdSensors.push_back(dist);

      //implement very simple collision detection
      if (dist < CParams::dCollisionDist)
      {
        m_bCollided = true;
      }
    }
    
    else
    {
      m_vecdSensors.push_back(-1);
    } 
    
    //check how many times the minesweeper has visited the cell
    //at the current position
    int HowOften = m_MemoryMap.TicksLingered(m_tranSensors[sr].x,
                                             m_tranSensors[sr].y);

    
    //Update the memory info according to HowOften. The maximum
    //value is 1 (because we want all the inputs into the
    //ANN to be scaled between -1 < n < 1)
    if (HowOften == 0)
    {
      m_vecFeelers.push_back(-1);

      continue;
    }
    
    if (HowOften < 10) 
    {
      m_vecFeelers.push_back(0);

      continue;
    }

    if (HowOften < 20)
    {
      m_vecFeelers.push_back(0.2);

      continue;
    }

    if (HowOften < 30)
    {
      m_vecFeelers.push_back(0.4);

      continue;
    }

    if (HowOften < 50)
    {
      m_vecFeelers.push_back(0.6);

      continue;
    }

    if (HowOften < 80) 
    {
      m_vecFeelers.push_back(0.8);

      continue;
    }

     m_vecFeelers.push_back(1);   

  }//next sensor
}
Ejemplo n.º 15
0
SPtnObjCircle::SPtnObjCircle(void)
{
    m_p0 = SPoint(-1,-1);
    m_p1 = SPoint(-1,-1);
    //m_nFill    = -1;
}
Ejemplo n.º 16
0
bool SPtnObjCircle::readCe3(SReadCE3& rce3)
{
    bool f_y1 = false;
    int i;

    int width = 1;
    int style = 0;
    int fill  = -1;
    int x0    = 0;
    int y0    = 0;
    int x1    = 0;
    int y1    = 0;

    string str("");
    while(rce3.ReadRecord(str) != EOF) {
        if(str[0] == '-') {
            if(str != "-C") {
                return false;
            } else {
                break;
            }
        } else if(str[0] == '+') {
            str[0]='-';
            if(rce3.SkipTo(str) == EOF) return false;
        } else {
            int n;
            int l = str.length();
            for(n = 0; n < l; n++) {
                if(str[n] == ':') break;
            }
            if(0 < n && n<(l-1)) {    // : で分けられたレコードである
                string var = str.substr(0,n);    	    	//先頭から:の手前まで
                //int nParam = atoi(str.substr(n+1).c_str()); //:から終端までを数値に変換
                if(var == "W") {
                    width = atoi(str.substr(n+1).c_str()); //:から終端までを数値に変換
                } else if(var == "S") {
                    style = atoi(str.substr(n+1).c_str()); //:から終端までを数値に変換
                } else if(var == "F") {
                    fill = atoi(str.substr(n+1).c_str()); //:から終端までを数値に変換
                } else if(var == "X") {
                    i = atoi(str.substr(n+1).c_str()); //:から終端までを数値に変換
                    if(!f_y1) {
                        x0 = i;
                    } else {
                        x1 = i;
                    }
                } else if(var == "Y") {
                    i = atoi(str.substr(n+1).c_str()); //:から終端までを数値に変換
                    if(!f_y1) {
                        y0 = i;
                        f_y1 = true;
                    } else {
                        y1 = i;
                    }
                }
            }
        }
    }
    m_width = width;
    m_style = style;
    m_nFill = fill;
    m_p0 = SPoint(x0,y0);
    m_p1 = SPoint(x1,y1);
    return true;
}
Ejemplo n.º 17
0
SPoint SRect::center() const
{
    return SPoint((m_l+m_r)/2,(m_t+m_b)/2);
}
Ejemplo n.º 18
0
SPoint SPoint::flipped(const int & a_flip, const SPoint & dim) const
{
	int nx = ((a_flip&VSDL_FLIP_X)?(( -((a_flip&VSDL_FLIP_XY)?dim.y:dim.x)-1)-x):x), 
		ny = ((a_flip&VSDL_FLIP_Y)?(( -((a_flip&VSDL_FLIP_XY)?dim.x:dim.y)-1)-y):y);
	return ((a_flip&VSDL_FLIP_XY)?(SPoint(ny,nx)):(SPoint(nx,ny)));
}
Ejemplo n.º 19
0
#include "CController.h"


//these hold the geometry of the sweepers and the mines
const int	 NumSweeperVerts = 16;
const SPoint sweeper[NumSweeperVerts] = {SPoint(-1, -1),
                                         SPoint(-1, 1),
                                         SPoint(-0.5, 1),
                                         SPoint(-0.5, -1),

                                         SPoint(0.5, -1),
                                         SPoint(1, -1),
                                         SPoint(1, 1),
                                         SPoint(0.5, 1),
                                         
                                         SPoint(-0.5, -0.5),
                                         SPoint(0.5, -0.5),

                                         SPoint(-0.5, 0.5),
                                         SPoint(-0.25, 0.5),
                                         SPoint(-0.25, 1.75),
                                         SPoint(0.25, 1.75),
                                         SPoint(0.25, 0.5),
                                         SPoint(0.5, 0.5)};



const int NumMineVerts = 4;
const SPoint mine[NumMineVerts] = {SPoint(-1, -1),
                                   SPoint(-1, 1),
                                   SPoint(1, 1),
Ejemplo n.º 20
0
SPoint SPoint::flipped(const int & a_flip) const
{
	int nx = ((a_flip&VSDL_FLIP_X)?(-x):x), 
		ny = ((a_flip&VSDL_FLIP_Y)?(-y):y);
	return ((a_flip&VSDL_FLIP_XY)?(SPoint(ny,nx)):(SPoint(nx,ny)));
}
Ejemplo n.º 21
0
#include "CBobsMap.h"

const int CBobsMap::m_iStartX = START_X;
const int CBobsMap::m_iStartY = START_Y;

const int CBobsMap::m_iEndX =END_X;
const int CBobsMap::m_iEndY = END_Y;

//lhx dirct path
const SPoint CBobsMap::m_spA(m_iStartX,m_iStartY);
const SPoint CBobsMap::m_spB(m_iEndX,m_iEndY);

const SPoint CBobsMap::m_sp1[BARRIER_COUNT1]=
{
	SPoint(290, 58),
	SPoint(267 ,89),
	SPoint(295 ,109),
	SPoint(318 ,79),
	
};
const SPoint CBobsMap::m_sp2[BARRIER_COUNT2]=
{
	SPoint(258,123),
	SPoint(217,119),
	SPoint(242,182),
	
};
const SPoint CBobsMap::m_sp3[BARRIER_COUNT3]=
{
	SPoint(317,143),
	SPoint(327,173),
Ejemplo n.º 22
0
#include "CLander.h"

//this defines the vertices for the lander shape
const int	 NumLanderVerts = 30;

const SPoint lander[NumLanderVerts] = {//middle of lander
                                       SPoint(-1, 0),
                                       SPoint(1, 0),    
                                       SPoint(1, -0.5),
                                       SPoint(-1, -0.5),
                                       //top of lander
                                       SPoint(-0.5, 0),
                                       SPoint(-1, 0.3),
                                       SPoint(-1, 0.7),
                                       SPoint(-0.5, 1),
                                       SPoint(0.5, 1),
                                       SPoint(1, 0.7),
                                       SPoint(1, 0.3),
                                       SPoint(0.5, 0),
                                       //legs
                                       SPoint(-1, -0.4),
                                       SPoint(-1.3, -0.8),
                                       SPoint(-1.3, -1.2),
                                       SPoint(-1.5, -1.2),
                                       SPoint(-1.1, -1.2),
                                       SPoint(-0.9, -0.5),
                                       SPoint(-1.3, -0.8),

                                       SPoint(1, -0.4),
                                       SPoint(1.3, -0.8),
                                       SPoint(1.3, -1.2),
Ejemplo n.º 23
0
//----------------------- TestSensors ------------------------------------
//
//  This function checks for any intersections between the sweeper's 
//  sensors and the objects in its environment
//------------------------------------------------------------------------
void CMinesweeper::TestSensors(vector<SPoint> &objects)
{
	m_bCollided = false;  

	//first we transform the sensors into world coordinates
	m_tranSensors = m_Sensors;

	WorldTransform(m_tranSensors, 1);  //scale is 1

	//flush the sensors
	m_vecdSensors.clear();
	m_vecFeelers.clear();

	//now to check each sensor against the objects in the world
	for (int sr=0; sr<m_tranSensors.size(); ++sr)
	{
		bool bHit = false;

		double dist = 0;

		for (int seg=0; seg<objects.size(); seg+=2)
		{
			if (LineIntersection2D(SPoint(m_vPosition.x, m_vPosition.y),
				m_tranSensors[sr],
				objects[seg],
				objects[seg+1],
				dist))
			{
				bHit = true;

				break;        
			}
		}

		if (bHit)
		{
			m_vecdSensors.push_back(dist);

			//implement very simple collision detection
			if (dist < CParams::dCollisionDist)
			{
				m_bCollided = true;
			}
		}

		else
		{
			m_vecdSensors.push_back(-1);
		} 

		 

	}//next sensor

	if (!m_bCollided) {
		if (m_vPosition.y < 15) {
			m_bCollided = true;
			return;
		}
		if (m_vPosition.y > 170) {
			m_bCollided = true;
			return;
		}
		if (m_vPosition.y < 100) {
			if (m_vPosition.x > 230) {
				m_bCollided = true;
				return;
			}
			if (m_vPosition.x < 150) {
				m_bCollided = true;
				return;
			}
		}
	}
}
Ejemplo n.º 24
0
#include "CController.h"


//these hold the geometry of the sweepers and the mines
const int	 NumSweeperVerts = 16;
const SPoint sweeper[NumSweeperVerts] = {SPoint(-1, -1),
	SPoint(-1, 1),
	SPoint(-0.5, 1),
	SPoint(-0.5, -1),

	SPoint(0.5, -1),
	SPoint(1, -1),
	SPoint(1, 1),
	SPoint(0.5, 1),

	SPoint(-0.5, -0.5),
	SPoint(0.5, -0.5),

	SPoint(-0.5, 0.5),
	SPoint(-0.25, 0.5),
	SPoint(-0.25, 1.75),
	SPoint(0.25, 1.75),
	SPoint(0.25, 0.5),
	SPoint(0.5, 0.5)};



const int NumMineVerts = 4;
const SPoint mine[NumMineVerts] = {SPoint(-1, -1),
	SPoint(-1, 1),
	SPoint(1, 1),
Ejemplo n.º 25
0
bool GameMan::LoadScenario(std::string scenarioName)
{
    eastwood::IniFile *myInifile = new eastwood::IniFile(ResMan::Instance()->getFile(scenarioName));

    int tacticalPos = myInifile->getIntValue("BASIC", "TacticalPos", 0);
    m_tacticalPos = SPoint(tacticalPos % 64, tacticalPos / 64);

    int SeedNum = myInifile->getIntValue("MAP", "Seed", -1);

    if (SeedNum == -1)
    {
	LOG(LV_ERROR, "GameMan", "Cannot find Seednum in %s!", scenarioName.c_str());
	delete m_map;
	return false;
    }

    std::string FieldString = myInifile->getStringValue("MAP", "Field");
    std::string BloomString = myInifile->getStringValue("MAP", "Bloom");

    m_map = MapGenerator::Instance()->createOldMap(FieldString, SeedNum, BloomString);
    // now set up all the players

    AddPlayer(HOUSE_ATREIDES, false, 1);
    AddPlayer(HOUSE_ORDOS, false, 2);
    AddPlayer(HOUSE_HARKONNEN, false, 2);
    AddPlayer(HOUSE_SARDAUKAR, false, 2);
    AddPlayer(HOUSE_FREMEN, false, 2);
    AddPlayer(HOUSE_MERCENARY, false, 2);

    eastwood::IniFile::KeyListHandle myListHandle;

    myListHandle = myInifile->KeyList_Open("UNITS");

    while (!myInifile->KeyList_EOF(myListHandle))
    {
	std::string tmpkey = myInifile->KeyList_GetNextKey(&myListHandle);
	std::string tmp = myInifile->getStringValue("UNITS", tmpkey);
	std::string HouseStr, UnitStr;
	int health, pos;
	sScanf(tmp, "%S,%S,%d,%d", &HouseStr, &UnitStr, &health, &pos);

	int house;

	if ((HouseStr == "Atreides") || (HouseStr == "ATREIDES"))
	    house = HOUSE_ATREIDES;
	else if ((HouseStr == "Ordos") || (HouseStr == "ORDOS"))
	    house = HOUSE_ORDOS;
	else if ((HouseStr == "Harkonnen") || (HouseStr == "HARKONNEN"))
	    house = HOUSE_HARKONNEN;
	else if ((HouseStr == "Fremen") || (HouseStr == "FREMEN"))
	    house = HOUSE_FREMEN;
	else if ((HouseStr == "Sardaukar") || (HouseStr == "SARDAUKAR"))
	    house = HOUSE_SARDAUKAR;
	else if ((HouseStr == "Mercenary") || (HouseStr == "MERCENARY"))
	    house = HOUSE_MERCENARY;
	else
	{
	    LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid house string: %s", HouseStr.c_str());
	    house = HOUSE_ATREIDES;
	}

	if (pos <= 0)
	{
	    LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid position string: %d", pos);
	    pos = 0;
	}

	ObjectPtr newUnit = m_players[house].placeUnit(UnitStr, UPoint(pos % 64, pos / 64));
	if (!newUnit)
	    LOG(LV_WARNING, "GameMan", "LoadScenario: This file is not a valid unit entry: %d. (invalid unit position)", pos);
    }

    myInifile->KeyList_Close(&myListHandle);


    myListHandle = myInifile->KeyList_Open("STRUCTURES");

    while (!myInifile->KeyList_EOF(myListHandle))
    {
	std::string tmpkey = myInifile->KeyList_GetNextKey(&myListHandle);
	std::string tmp = myInifile->getStringValue("STRUCTURES", tmpkey);

	if (tmpkey.find("GEN") == 0)
	{
	    // Gen Object/Structure
	    std::string PosStr = tmpkey.substr(3, tmpkey.size() - 3);
	    int pos = atoi(PosStr.c_str());

	    std::string HouseStr, BuildingStr;
	    sScanf(tmp, "%S,%S", &HouseStr, &BuildingStr);

	    int house;

	    if ((HouseStr == "Atreides") || (HouseStr == "ATREIDES"))
		house = HOUSE_ATREIDES;
	    else if ((HouseStr == "Ordos") || (HouseStr == "ORDOS"))
		house = HOUSE_ORDOS;
	    else if ((HouseStr == "Harkonnen") || (HouseStr == "HARKONNEN"))
		house = HOUSE_HARKONNEN;
	    else if ((HouseStr == "Fremen") || (HouseStr == "FREMEN"))
		house = HOUSE_FREMEN;
	    else if ((HouseStr == "Sardaukar") || (HouseStr == "SARDAUKAR"))
		house = HOUSE_SARDAUKAR;
	    else if ((HouseStr == "Mercenary") || (HouseStr == "MERCENARY"))
		house = HOUSE_MERCENARY;
	    else
	    {
		LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid house string: %s", HouseStr.c_str());
		house = HOUSE_ATREIDES;
	    }

	    /*
	    //FIXME: Fix this here and in addPlayer
	    if(m_players->size() > house) {
	    LOG(LV_ERROR, "MapGenerator","player[%d]== NULL",(int) house);
	    exit(EXIT_FAILURE);
	    }
	    */


	    //Using INVALID_POS instead of NONE to avoid warnings.
	    //FIXME: Maybe we should rename INVALID_POS to INVALID or sth
	    if (BuildingStr == "Concrete")
		m_players[house].placeStructure(INVALID_POS, INVALID_POS, "Slab1", UPoint(pos % 64, pos / 64));
	    else if (BuildingStr == "Wall")
		m_players[house].placeStructure(INVALID_POS, INVALID_POS, "Wall", UPoint(pos % 64, pos / 64));
	    else
		LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid building string: %s", BuildingStr.c_str());
	}
	
	else
	{
	    // other structure
	    std::string HouseStr, BuildingStr;
	    int health, pos;
	    sScanf(tmp, "%S,%S,%d,%d", &HouseStr, &BuildingStr, &health, &pos);

	    int house;

	    if ((HouseStr == "Atreides") || (HouseStr == "ATREIDES"))
		house = HOUSE_ATREIDES;
	    else if ((HouseStr == "Ordos") || (HouseStr == "ORDOS"))
		house = HOUSE_ORDOS;
	    else if ((HouseStr == "Harkonnen") || (HouseStr == "HARKONNEN"))
		house = HOUSE_HARKONNEN;
	    else if ((HouseStr == "Fremen") || (HouseStr == "FREMEN"))
		house = HOUSE_FREMEN;
	    else if ((HouseStr == "Sardaukar") || (HouseStr == "SARDAUKAR"))
		house = HOUSE_SARDAUKAR;
	    else if ((HouseStr == "Mercenary") || (HouseStr == "MERCENARY"))
		house = HOUSE_MERCENARY;
	    else
	    {
		LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid house string: %s", HouseStr.c_str());
		house = HOUSE_ATREIDES;
	    }

	    //Using INVALID_POS instead of NONE to avoid warnings.
	    //FIXME: Maybe we should rename INVALID_POS to INVALID or sth
	    ObjectPtr newStructure = m_players[house].placeStructure(INVALID_POS, INVALID_POS, BuildingStr, UPoint(pos % 64, pos / 64));

	    if (newStructure == NULL)
		LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid position: %d", pos);
	}
    }

    myInifile->KeyList_Close(&myListHandle);
    return true;
}
Ejemplo n.º 26
0
#include "CController.h"


//these hold the geometry of the sweepers and the mines
const int	 NumSweeperVerts = 16;
const SPoint sweeper[NumSweeperVerts] = {SPoint(-1, -1),
	SPoint(-1, 1),
	SPoint(-0.5, 1),
	SPoint(-0.5, -1),

	SPoint(0.5, -1),
	SPoint(1, -1),
	SPoint(1, 1),
	SPoint(0.5, 1),

	SPoint(-0.5, -0.5),
	SPoint(0.5, -0.5),

	SPoint(-0.5, 0.5),
	SPoint(-0.25, 0.5),
	SPoint(-0.25, 1.75),
	SPoint(0.25, 1.75),
	SPoint(0.25, 0.5),
	SPoint(0.5, 0.5)};



const int NumMineVerts = 4;
const SPoint mine[NumMineVerts] = {SPoint(-1, -1),
	SPoint(-1, 1),
	SPoint(1, 1),
Ejemplo n.º 27
0
void Application::Run()
{
    uint32_t now = SDL_GetTicks();
    uint32_t then;
    // keep the frame rate down to around 25 fps
    const uint32_t min_frame_duration = 40; 

    uint32_t fps_start = now;
    int fps_frames = 0;
    const int fps_interval = 10 * 1000; // 10 seconds
    float fps;

//    Font* fnt = FontManager::Instance()->getFont("INTRO:INTRO.FNT");
    
    m_running = true;

    assert(m_rootWidget != NULL);

    gpaloff = 0 ;


    while (m_running)
    {
        m_screen->fillRect(m_clearColor);

        HandleEvents();
        
        then = now;
        now = SDL_GetTicks();

        #if 1
        // dont steal all the processing time 
        // FIXME: If user clicks when SDL_Delay is run, input will be ignored.
        if (now - then < min_frame_duration)
        {
            SDL_Delay(min_frame_duration - (now - then));
            now = SDL_GetTicks();
        };
        #endif
        float dt = float(now - then) / 1000.0f;

        if (m_rootState->Execute(dt) == -1) m_running = false;

        m_rootWidget->draw(*m_screen, SPoint(0, 0));

        BlitCursor();
#if 0 
        fnt->render((const char*)"ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen->getSurface(), 10, 10, gpaloff);
        fnt->render((const char*)"abcdefghijklmnopqrstuvwxz", m_screen->getSurface(), 10, 30, gpaloff);

        SDL_Rect pdest = {10, 10, 5, 10};

        for (uint32_t i=0; i!=256; i++)
        {
            pdest.x = 7 * i;
            SDL_FillRect(m_screen->getSurface(), &pdest, i);
        }    
#endif
	m_screen->flip();

        fps_frames ++;

        if (now > fps_start + fps_interval)
        {
            fps = fps_frames / (float(now - fps_start) / 1000.0);

            printf("fps: %f\n", fps);

            fps_frames = 0;
            fps_start = now;
        };
    };
    
    LOG(LV_INFO, "Application", "done");
}
Ejemplo n.º 28
0
//グリップの位置を動かす
void SPtnObjCircle::setGripPos(int grip,int x,int y)
{
    if(grip == 0) m_p0 = SPoint(x,y);
    else    	m_p1 = SPoint(x,y);
}
Ejemplo n.º 29
0
#include "CGun.h"


const int NumGunVerts = 8;
const SPoint gun[NumGunVerts] = {SPoint(2,1),
                                 SPoint(2,-1),
                                 SPoint(-2,-1),
                                 SPoint(-2,1),
                                 SPoint(-1,1),
                                 SPoint(-1,2),
                                 SPoint(1,2),
                                 SPoint(1,1)};

//--------------------------------- ctor ---------------------------------
//
//------------------------------------------------------------------------
CGun::CGun(double x,
           double y,
           double scale,
           double rot): m_dPosX(x),
                        m_dPosY(y),
                        m_dRotation(rot),
                        m_dScale(scale)
{
  //create the vertex buffer
  for (int i=0; i<NumGunVerts; ++i)
  {
    m_vecGunVB.push_back(gun[i]);
  }
}
Ejemplo n.º 30
0
#include "CController.h"

//number of stars
const int NumStars = 20;

//this defines the vertices for the lander shape
const int	 NumPadVerts = 4;

const SPoint Pad[NumPadVerts] = {SPoint(-20, 0),
                                 SPoint(20, 0),
                                 SPoint(20, 5),
                                 SPoint(-20, 5)};
                                      
//------------------------------dtor -------------------------------------
//
//------------------------------------------------------------------------
CController::~CController()
{
  if (m_pUserLander)
  {
    delete m_pUserLander;
  }
}
//-----------------------------ctor---------------------------------------
//
//------------------------------------------------------------------------
CController::CController(int cxClient,
                         int cyClient):
                                       m_bSuccess(false),                                  
                                       m_vPadPos(SVector2D(RandFloat()*cxClient, 50)),
                                       m_cxClient(cxClient),