void Shoot(vector< vector<char> > *GameScreen, int dir, int startX, int startY, 
                                                        int endX,   int endY) {
  InBounds(&startX);
  InBounds(&startY);
  InBounds(&endX);
  InBounds(&endY);

  // direction - an enum w/ switch case?
  switch(dir) {
    case 0: // north ^
      

      break;
    case 1: // east >
      break;
    case 2: // south v
      break;
    case 3: // west <
      break;
  }

  // stop when you hit a game object or edge
  while(start) {

  }
}
void CApp::OnMouseMove(int mX, int mY, int relX, int relY, bool Left,bool Right,bool Middle)
{
    if (Left)
    {
        if(!(mX < TileWindow.Width && mY < TileWindow.Height))
        {
            if(InBounds(mX, mY))
            {
                GetTile( mX, mY);
                Map->SetTile(tile, newTileID, newTypeID);
            }
        }
    }
    if (Right)
    {
        if(!(mX < TileWindow.Width && mY < TileWindow.Height))
        {
            if(InBounds(mX, mY))
            {
                if( ((mX - CCamera::CameraControl.GetX()) < MAP_WIDTH*TILE_SIZE*CArea::AreaControl.areaWidth) &&
                        ((mY - CCamera::CameraControl.GetY()) < MAP_HEIGHT*TILE_SIZE*CArea::AreaControl.areaHeight) &&
                        ((mYold - CCamera::CameraControl.GetY()) < MAP_HEIGHT*TILE_SIZE*CArea::AreaControl.areaHeight) &&
                        ((mXold - CCamera::CameraControl.GetX()) < MAP_WIDTH*TILE_SIZE*CArea::AreaControl.areaWidth))
                {
                    // draws tiles but doesn't erase when you go too far
                    GetTile( mX, mYold);
                    Map->SetTile(tile, newTileID, newTypeID);
                    GetTile(mXold, mY);
                    Map->SetTile(tile, newTileID, newTypeID);
                }
            }
        }
    }
}
//=================================================================================================================
void PlatformerMap::DisableTexture(int x, int y)
{
	if (!InBounds(x, y)) return;

	for (int tileY = 0; tileY < m_MapHeight; tileY++)
	{
		for (int tileX = 0; tileX < m_MapWidth; tileX++)
		{
			PlatformerTile* tile = m_Tiles(tileX, tileY);

			if (tile == NULL) continue;
			
			// Look at the BodyBox for the point x,y to see if it lies inside
			if (tile->Body().Inside(x, y))
			{
				m_Tiles(tileX, tileY)->DisableTexture();
				return;
			}
			
			/*float realTileX = tile->GetPosition().x;
			float realTileY = tile->GetPosition().y;

			if (x >= realTileX && x <= realTileX + m_EngineOptions->TILE_SIZE)
			{
				if (y >= realTileY && y <= realTileY + m_EngineOptions->TILE_SIZE)
				{
					m_Tiles(tileX, tileY)->DisableTexture();
					return;
				}
			}*/
		}
	}
}
NS_IMETHODIMP nsDialogParamBlock::GetInt(int32_t inIndex, int32_t *_retval)
{
  nsresult rv = InBounds(inIndex, kNumInts);
  if (rv == NS_OK)
    *_retval = mInt[inIndex];
  return rv;
}
NS_IMETHODIMP nsDialogParamBlock::SetInt(int32_t inIndex, int32_t inInt)
{
  nsresult rv = InBounds(inIndex, kNumInts);
  if (rv == NS_OK)
    mInt[inIndex]= inInt;
  return rv;
}
Exemple #6
0
void
MovePlayer( LabData& lab, int dx, int dy )
    {
    // All movement logic goes here.
    // Practically all the game logic really.
    int xnew = lab.xplayer + dx;
    int ynew = lab.yplayer + dy;
    Uint32 inew = xnew + ynew * lab.width;
    Uint8& tile = lab.walls[ inew ];
    // Avoid walls.
    if( InBounds( lab, xnew, ynew ) &&
        tile != IsWall )
        {
        lab.xplayer = xnew;
        lab.yplayer = ynew;
        }
    // Pick up tokens.
    if( tile == IsToken )
        {
        tile = IsPath;
        lab.tokens.erase(
            remove( begin(lab.tokens), end(lab.tokens), inew ),
            end(lab.tokens));
        }
    // Generate door when all tokens are gone.
    if( lab.door == 0 && lab.tokens.empty() )
        lab.door = PlaceRandomly( lab, IsDoor );
    // Enter the door!
    if( inew == lab.door )
        lab.win = true;
    }
Exemple #7
0
bool Shred::Tree(const int x, const int y, const int z, const int height) {
    if ( not InBounds(x+2, y+2, height+z) ) return false;
    // check for room
    for (int i=x; i<=x+2; ++i)
    for (int j=y; j<=y+2; ++j)
    for (int k=z; k<z+height; ++k) {
        if ( AIR != GetBlock(i, j, k)->Sub() ) {
            return false;
        }
    }
    const int leaves_level = z+height/2;
    Block * const leaves = Normal(GREENERY);
    for (int i=x; i<=x+2; ++i)
    for (int j=y; j<=y+2; ++j) {
        for (int k=leaves_level; k<z+height; ++k ) {
            PutBlock(leaves, i, j, k);
        }
    }
    for (int k=qMax(z-1, 1); k < z+height-1; ++k) { // trunk
        SetBlock(Normal(WOOD), x+1, y+1, k);
    }
    // branches
    const int r = qrand();
    if ( r & 0x1 ) SetNewBlock(BLOCK, WOOD, x,   y+1, leaves_level, WEST);
    if ( r & 0x2 ) SetNewBlock(BLOCK, WOOD, x+2, y+1, leaves_level, EAST);
    if ( r & 0x4 ) SetNewBlock(BLOCK, WOOD, x+1, y,   leaves_level, NORTH);
    if ( r & 0x8 ) SetNewBlock(BLOCK, WOOD, x+1, y+2, leaves_level, SOUTH);
    return true;
}
//=================================================================================================================
PlatformerTile* PlatformerMap::SelectTile(int x, int y)
{
	if (!InBounds(x, y)) return 0;

	for (int tileY = 0; tileY < m_MapHeight; tileY++)
	{
		for (int tileX = 0; tileX < m_MapWidth; tileX++)
		{
			PlatformerTile* tile = m_Tiles(tileX, tileY);

			if (tile == NULL) continue;

			//float realTileX = tile->GetPosition().x;
			//float realTileY = tile->GetPosition().y;
			
			// Look at the BodyBox for the point x,y to see if it lies inside
			if (tile->Body().Inside(x, y))
				return tile;
			
			/*if (x >= realTileX && x <= realTileX + m_EngineOptions->TILE_SIZE)
			{
				if (y >= realTileY && y <= realTileY + m_EngineOptions->TILE_SIZE)
				{
					return tile;
				}
			}*/
		}
	}

	return 0;
}
Exemple #9
0
float Terrain::Average(int i, int j)
{
	// Function computes the average height of the ij element.
	// It averages itself with its eight neighbor pixels.  Note
	// that if a pixel is missing neighbor, we just don't include it
	// in the average--that is, edge pixels don't have a neighbor pixel.
	//
	// ----------
	// | 1| 2| 3|
	// ----------
	// |4 |ij| 6|
	// ----------
	// | 7| 8| 9|
	// ----------

	float avg = 0.0f;
	float num = 0.0f;

	// Use int to allow negatives.  If we use UINT, @ i=0, m=i-1=UINT_MAX
	// and no iterations of the outer for loop occur.
	for(int m = i-1; m <= i+1; ++m)
	{
		for(int n = j-1; n <= j+1; ++n)
		{
			if( InBounds(m,n) )
			{
				avg += mHeightmap[m*mInfo.HeightmapWidth + n];
				num += 1.0f;
			}
		}
	}

	return avg / num;
}
//=================================================================================================================
void PlatformerMap::RemoveTile(int x, int y)
{
	if (!InBounds(x, y)) return;
	
	m_TileRemovedX = x;
	m_TileRemovedY = y;
	
	//int tileX = PlatformerMap::PixelsToTiles(x);// +m_Offset.x;
	//int tileY = PlatformerMap::PixelsToTiles(y);// +m_Offset.y;
	//delete m_Tiles(tileX, tileY);
	//m_Tiles(tileX, tileY) = NULL;

	int removeX = -1;
	int removeY = -1;

	bool out = false;

	/*for (int tileY = 0; tileY < m_MapHeight; tileY++)
	{
		for (int tileX = 0; tileX < m_MapWidth; tileX++)
		{
			PlatformerTile* tile = m_Tiles(tileX, tileY);

			if (tile == NULL) continue;

			//float realTileX = tile->GetPosition().x;
			//float realTileY = tile->GetPosition().y;
			
			// Look at the BodyBox for the point x,y to see if it lies inside
			if (tile->BBodyBox().InsideEquals(x, y))
			{
				removeX = tileX + 1;// Need to test
				removeY = tileY + 1;
				out = true;
				break;
			}

			/*if (x >= realTileX && x <= realTileX + m_EngineOptions->TILE_SIZE)
			{
				if (y >= realTileY && y <= realTileY + m_EngineOptions->TILE_SIZE)
				{
					removeX = tileX + 1;// Need to test
					removeY = tileY + 1;
					out = true;
					break;
				}
			}
		}
		
		if (out) break;
	}*/

	//if (removeX != -1 && removeY != -1)
	if (m_Tiles(x, y) != NULL)
	{
		delete m_Tiles(x, y);
		m_Tiles(x, y) = NULL;
	}
}
Exemple #11
0
void CCircCtrl::OnSize(UINT nType, int cx, int cy)
{
	COleControl::OnSize(nType, cx, cy);

	// If circle shape is true & cicrle does not fit in new size, reset the offset
	if (m_circleShape && !InBounds(GetCircleOffset()))
		SetCircleOffset(0);

}
Exemple #12
0
void CMyProblem::Set_w(int index, double value)
{
	if (!InBounds(index))
		return;
	if (value<0)
		w[index]=0;
	else
		w[index]=value;
}
NS_IMETHODIMP nsDialogParamBlock::GetString(int32_t inIndex, PRUnichar **_retval)
{
  if (mNumStrings == 0)
    SetNumberStrings(kNumStrings);
  nsresult rv = InBounds(inIndex, mNumStrings);
  if (rv == NS_OK)
    *_retval = ToNewUnicode(mString[inIndex]);
  return rv;
}
Exemple #14
0
void CMyProblem::Set_r(int index, int value)
{
	if (!InBounds(index))
		return;
	if (value<0)
		r[index]=0;
	else
		r[index]=value;
}
NS_IMETHODIMP nsDialogParamBlock::SetString(int32_t inIndex, const PRUnichar *inString)
{
  if (mNumStrings == 0)
    SetNumberStrings(kNumStrings);
  nsresult rv = InBounds(inIndex, mNumStrings);
  if (rv == NS_OK)
    mString[inIndex]= inString;
  return rv;
}
double avtLCSFilter::Value( int x, int y, int z, vtkDataArray *array,
                            int x_max, int y_max, int z_max )
{
  int l = InBounds( x, y, z, x_max, y_max, z_max );

  if( 0 <= l && l < array->GetNumberOfTuples() )
    return array->GetTuple1(l);
  else
    return 0;
}
Exemple #17
0
void CCircCtrl::SetCircleOffset(short nNewValue)
{
	// Validate the specified offset value
	if ((m_circleOffset != nNewValue) && m_circleShape && InBounds(nNewValue))
	{
		m_circleOffset = nNewValue;
		SetModifiedFlag();
		InvalidateControl();
	}
}
void avtLCSFilter::Increment( int x, int y, int z, vtkDataArray *array,
                              int x_max, int y_max, int z_max )
{
  int l = InBounds( x, y, z, x_max, y_max, z_max );
  
  if( 0 <= l && l < array->GetNumberOfTuples() )
  {      
    int cc = array->GetTuple1(l);
    ++cc;
    array->SetTuple1(l, cc);
  }
}
vector<pair<Point, Cell::Direction> > RecursiveBacktrackerMaze::GetUnMarkedNeighbours(Point& cur)
{
  vector<pair<Point, Cell::Direction> > neighbours;

  for (int i = 0; i < Cell::Direction::Size; ++i)
  {
    auto dir = Cell::Direction(i);
    if (InBounds(cur.Direction(dir)) && !marked_.IsMarked(cur.Direction(dir)))
      neighbours.push_back(make_pair(cur.Direction(dir), dir));
  }

  return neighbours;
}
Exemple #20
0
void Shred::NormalCube(
        const int x_start, const int y_start, const int z_start,
        const int x_size,  const int y_size,  const int z_size, const subs sub)
{
    Block * const block = Normal(sub);
    for (int x=x_start; x < x_start+x_size; ++x)
    for (int y=y_start; y < y_start+y_size; ++y)
    for (int z=z_start; z < z_start+z_size; ++z) {
        if ( InBounds(x, y, z) ) {
            PutBlock(block, x, y, z);
        }
    }
}
Exemple #21
0
bool World::CanMove(const ushort x, const ushort y, const ushort z,
		const ushort newx, const ushort newy, const ushort newz,
		const quint8 dir)
{
	if ( !InBounds(x, y, z) ) {
		return false;
	}
	Block * const block = GetBlock(x, y, z);
	if ( NOT_MOVABLE == block->Movable() ) {
		return false;
	}
	Block * block_to = GetBlock(newx, newy, newz);
	if ( ENVIRONMENT == block->Movable() ) {
		if ( *block == *block_to ) {
			return false;
		} else if ( MOVABLE == block_to->Movable() ) {
			NoCheckMove(x, y, z, newx, newy, newz, dir);
			return true;
		}
	}
	switch ( block_to->BeforePush(dir, block) ) {
	case MOVE_SELF: block_to = GetBlock(newx, newy, newz); break;
	case DESTROY:
		DeleteBlock(block_to);
		PutBlock(Normal(AIR), newx, newy, newz);
		return true;
	break;
	case JUMP:
		if ( DOWN!=dir && UP!=dir ) {
			Jump(x, y, z, dir);
			return false;
		}
	break;
	case MOVE_UP:
		if ( DOWN!=dir && UP!=dir ) {
			Move(x, y, z, UP);
			return false;
		}
	break;
	case DAMAGE:
		Damage(x, y, z,
			block_to->DamageLevel(),
			block_to->DamageKind());
		return false;
	break;
	}
	return ( ENVIRONMENT==block_to->Movable() );/* ||
		( (block->Weight() > block_to->Weight()) &&
			Move(newx, newy, newz, dir) ) );*/
} // bool World::CanMove(ushort x, y, z, newx, newy, newz, quint8 dir)
int SetPixel (Image *I, int Row, int Col, Color Value) 
{
  
  if(InBounds(I,Row,Col))
    {
      int slot = Row*(I->NCols)+Col ;
      (&(I->Pixel)[slot])->red = Value.red ;
      (&(I->Pixel)[slot])->green = Value.green ;
      (&(I->Pixel)[slot])->blue = Value.blue ;
    }
  else
    {
      return(0) ;
    }
  return(1) ;
}
Exemple #23
0
Term::Char::char_t
WallSymbol( const LabData& lab, Uint32 itile )
    {
    // Generates the right wall symbol depending on the
    // neighboring tiles in the labyrinth.
    int x = itile % lab.width;
    int y = itile / lab.width;
    int neighbors = 0; // Neighbor bits.
    for( size_t d=0; d<4; ++d )
        {
        int xneighbor = x + dirs[d][0];
        int yneighbor = y + dirs[d][1];
        if( InBounds( lab, xneighbor, yneighbor ) &&
            lab.walls[ xneighbor + yneighbor*lab.width ] == IsWall )
            neighbors |= dirs[d][2]; // add bit
        }
    Term::Char::char_t c;
    switch( neighbors )
        {
        case North: case South: case North|South:
            c = 179; break;
        case East: case West: case East|West:
            c = 196; break;
        case North|East:
            c = 192 ; break;
        case North|West:
            c = 217; break;
        case South|West:
            c = 191; break;
        case South|East:
            c = 218; break;
        case North|West|South:
            c = 180; break;
        case West|North|East:
            c = 193; break;
        case West|South|East:
            c = 194; break;
        case North|East|South:
            c = 195; break;
        case North|East|South|West:
            c = 197; break;
        default:
            c = 254;
        }
    return c;
    }
Exemple #24
0
int World::Temperature(const ushort x, const ushort y, const ushort z) const {
	if ( HEIGHT-1 == z ) {
		return 0;
	}
	short temperature = GetBlock(x, y, z)->Temperature();
	if ( temperature ) {
		return temperature;
	}
	for (short i=x-1; i<=x+1; ++i)
	for (short j=y-1; j<=y+1; ++j)
	for (short k=z-1; k<=z+1; ++k) {
		if ( InBounds(i, j, k) ) {
			temperature += GetBlock(i, j, k)->Temperature();
		}
	}
	return temperature/2;
}
//=================================================================================================================
void PlatformerMap::AddTile(GameDirectory2D* gd, int x, int y)
{
	if (!InBounds(x, y)) return;
	
	int size = m_EngineOptions->TILE_SIZE;
	//int sX = PlatformerMap::PixelsToTiles(x);
	//int sY = PlatformerMap::PixelsToTiles(y);

	//int sX = (x + m_Offset.x) / size;
	//int sY = (y + m_Offset.y) / size;

	AddTile(x, y, size, true, true, gd, "PlatformTile.png", "NONE", 0, size, size);
	/*for (int tileY = 0; tileY < m_MapHeight; tileY++)
	{
		for (int tileX = 0; tileX < m_MapWidth; tileX++)
		{
			PlatformerTile* tile = m_TempTiles(tileX, tileY);

			if (tile == NULL) continue;

			//int realTileX = PlatformerMap::TilesToPixels(tileX) + m_Offset.x;
			//int realTileY = PlatformerMap::TilesToPixels(tileY) + m_Offset.y;
			float realTileX = tile->GetPosition().x;
			float realTileY = tile->GetPosition().y;
			
			// Look at the BodyBox for the point x,y to see if
			// it lies inside
			if (tile->BBodyBox().Inside(x, y))
			{
					AddTile(tile->GetPosition().x, tile->GetPosition().y, size, true, true, gd, "PlatformTile.png", "NONE", 0, size, size, false);
					return;
			}
			
			if (x >= realTileX && x <= realTileX + m_EngineOptions->TILE_SIZE)
			{
				if (y >= realTileY && y <= realTileY + m_EngineOptions->TILE_SIZE)
				{
					AddTile(tile->GetPosition().x, tile->GetPosition().y, size, true, true, gd, "PlatformTile.png", "NONE", 0, size, size, false);
					return;
				}
			}
		}
	}*/
}
Exemple #26
0
bool World::Focus(const ushort x, const ushort y, const ushort z,
		ushort & x_to, ushort & y_to, ushort & z_to, const quint8 dir)
const {
	x_to = x;
	y_to = y;
	z_to = z;
	switch ( dir ) {
	case NORTH: --y_to; break;
	case SOUTH: ++y_to; break;
	case EAST:  ++x_to; break;
	case WEST:  --x_to; break;
	case DOWN:  --z_to; break;
	case UP:    ++z_to; break;
	default:
		fprintf(stderr, "World::Focus: unlisted dir: %d\n", dir);
		return true;
	}
	return !InBounds(x_to, y_to, z_to);
}
Color GetPixel (Image *I, int Row, int Col) 
{
  Color Value ;

  if(InBounds(I,Row,Col))
    {
      int slot = Row*(I->NCols)+Col ;
      Value.red = (&(I->Pixel)[slot])->red ;
      Value.green =(&(I->Pixel)[slot])->green ;
      Value.blue =(&(I->Pixel)[slot])->blue ;
    }
  else
    {
      Value.red = 0 ;
      Value.green = 0 ;
      Value.blue = 0 ;
    }
  return(Value) ;
}
void CApp::OnRButtonDown(int mX, int mY)
{
    if((mX < TileWindow.Width && mY < TileWindow.Height))
    {
        newTileID = TileWindow.GetTileID(mX, mY, newTypeID);
        newTypeID = TileWindow.Active;
    }
    if((!(mX < TileWindow.Width && mY < TileWindow.Height)))
    {
        down = true;
        mXold = mX;
        mYold = mY;
        if(InBounds(mX, mY))
        {
            GetTile( mX, mY);
            Map->SetTile(tile, newTileID, newTypeID);
        }
    }
}
Exemple #29
0
void CEnvironmentGrid::SetTileType (int xTile, int yTile, CSpaceEnvironmentType *pEnv)

//	SetTileType
//
//	Sets a tile.

	{
	int i;

	//	For now there is no way to delete a tile.

	ASSERT(pEnv);

	if (InBounds(xTile, yTile))
		{
		//	Loop over all edges to see if there is a tile there and to tell the
		//	tile that a new tile has appeared on THEIR edge.

		DWORD dwEdgeMask = 0;
		for (i = 0; i < EDGE_COUNT; i++)
			{
			int xEdgeTile = xTile + EDGE_DATA[i].xOffset;
			int yEdgeTile = yTile + EDGE_DATA[i].yOffset;

			DWORD *pTile = m_Map.GetTilePointer(xEdgeTile, yEdgeTile);
			if (pTile && GetSpaceEnvironmentFromTileDWORD(*pTile) == pEnv)
				{
				//	This is an edge for the new tile.

				dwEdgeMask |= EDGE_DATA[i].dwFlag;

				//	Add the new tile as an edge for this tile.

				*pTile = AddEdgeFlag(*pTile, EDGE_DATA[i].dwOppositeFlag);
				}
			}

		//	Set the new tile

		m_Map.SetTile(xTile, yTile, MakeTileDWORD(pEnv, dwEdgeMask));
		}
	}
Exemple #30
0
void
MazeAlgorithm( LabData& lab, int x, int y )
    {
    std::vector<Uint32> path; // Stack for backtracking.
    path.push_back( x + y * lab.width );
    do  {
        int x = path.back() % lab.width;
        int y = path.back() / lab.width;
        // Check neighbors
        size_t d, first;
        d = first = rand()%4;
        bool pathFound = false;
        int ineighbor, xneighbor, yneighbor;
        do  {
            xneighbor = x + dirs[d][0] * 2;
            yneighbor = y + dirs[d][1] * 2;
            ineighbor = xneighbor + yneighbor * lab.width;
            if( InBounds( lab, xneighbor, yneighbor ) &&
                lab.walls[ineighbor] == IsWall )
                {
                pathFound = true;
                break; // Found good neighbor.
                }
            d = (d+1)%4;
            }
        while( d != first );

        if( pathFound )
            {
            lab.walls[ ( x + dirs[d][0] ) + ( y + dirs[d][1] )*lab.width ] = IsPath;
            lab.walls[ (x + dirs[d][0]*2) + (y + dirs[d][1]*2)*lab.width ] = IsPath;
            path.push_back(ineighbor);
            }
        else // Backtrack!
            {
            path.pop_back();
            }
        }
    while( path.size() > 1 );
    }