Ejemplo n.º 1
0
//---------------------------------------------------------
CSG_Shape * CSG_PointCloud::Get_Shape(TSG_Point Point, double Epsilon)
{
    CSG_Rect	r(Point.x - Epsilon, Point.y - Epsilon, Point.x + Epsilon, Point.y + Epsilon);

    if( r.Intersects(Get_Extent()) != INTERSECTION_None )
    {
        int		iPoint		= -1;
        double	iDistance	= -1.0;

        for(int iRecord=0; iRecord<Get_Count(); iRecord++)
        {
            Set_Cursor(iRecord);

            if( r.Contains(Get_X(), Get_Y()) )
            {
                if( iPoint < 0 || iDistance > SG_Get_Distance(Point.x, Point.y, Get_X(), Get_Y()) )
                {
                    iPoint		= iRecord;
                    iDistance	= SG_Get_Distance(Point.x, Point.y, Get_X(), Get_Y());
                }
            }
        }

        if( iPoint >= 0 )
        {
            return( CSG_Shapes::Get_Shape(iPoint) );
        }
    }

    return( NULL );
}
Ejemplo n.º 2
0
// Cross product. Finds perpendicular direction to plane defined by 2. Also useful for lighting and angles
Direction Direction::Cross(const Direction& direction) const
{
	return Direction::Coordinates(
		Get_Y() * direction.Get_Z() - Get_Z() * direction.Get_Y(),
		Get_Z() * direction.Get_X() - Get_X() * direction.Get_Z(),
		Get_X() * direction.Get_Y() - Get_Y() * direction.Get_X());
}
Ejemplo n.º 3
0
//---------------------------------------------------------
const CSG_Rect & CSG_PointCloud::Get_Selection_Extent(void)
{
    if( Get_Selection_Count() > 0 && Set_Cursor(Get_Selection_Index(0)) )
    {
        TSG_Rect	r;

        r.xMin	= r.xMax	= Get_X();
        r.yMin	= r.yMax	= Get_Y();

        for(size_t i=1; i<Get_Selection_Count(); i++)
        {
            if( Set_Cursor(Get_Selection_Index(i)) )
            {
                if( Get_X() < r.xMin )	r.xMin	= Get_X();
                else if( Get_X() > r.xMax )	r.xMax	= Get_X();
                if( Get_Y() < r.yMin )	r.yMin	= Get_Y();
                else if( Get_Y() > r.yMax )	r.yMax	= Get_Y();
            }
        }

        m_Extent_Selected.Assign(r);
    }
    else
    {
        m_Extent_Selected.Assign(0.0, 0.0, 0.0, 0.0);
    }

    return( m_Extent_Selected );
}
Ejemplo n.º 4
0
//---------------------------------------------------------
const CSG_Rect & CSG_PointCloud::Get_Selection_Extent(void)
{
	if( m_nSelected > 0 && Set_Cursor(m_Selected[0]) )
	{
		TSG_Rect	r;

		r.xMin	= r.xMax	= Get_X();
		r.yMin	= r.yMax	= Get_Y();

		for(int i=1; i<m_nSelected; i++)
		{
			if( Set_Cursor(m_Selected[i]) )
			{
				if( Get_X() < r.xMin )	r.xMin	= Get_X();	else if( Get_X() > r.xMax )	r.xMax	= Get_X();
				if( Get_Y() < r.yMin )	r.yMin	= Get_Y();	else if( Get_Y() > r.yMax )	r.yMax	= Get_Y();
			}
		}

		m_Extent_Selected.Assign(r);
	}
	else
	{
		m_Extent_Selected.Assign(0.0, 0.0, 0.0, 0.0);
	}

	return( m_Extent_Selected );
}
Ejemplo n.º 5
0
void Monster::Rand_Move()
{
	int idx[4] = { -1,0,1,0 };
	int idy[4] = { 0,-1,0,1 };
	int rand_dir = Singleton::getSingleton().Rand_Dir();
	int temp = Singleton::getSingleton().Search(Get_X() + idx[rand_dir], Get_Y() + idy[rand_dir]);

	if (temp == -1) Set_X(Get_X() + idx[rand_dir]), Set_Y(Get_Y() + idy[rand_dir]);
	else if (Singleton::getSingleton().obj_list[temp]->Get_Type() == T_item)
	{
		Set_X(Get_X() + idx[rand_dir]), Set_Y(Get_Y() + idy[rand_dir]);
		Singleton::getSingleton().Delete(temp);
		Set_Have_Bomb(true);
	}
	else
	{
		bool Is_Move = false;
		for (int i = 0; i < 4; i++)if (Singleton::getSingleton().Search(Get_X() + idx[i], Get_Y() + idy[i]) == -1)Is_Move = true;
		if (Is_Move) Rand_Move();
	}
}
Ejemplo n.º 6
0
//---------------------------------------------------------
bool CSG_PointCloud::Select(TSG_Rect Extent, bool bInvert)
{
    if( !bInvert )	// clear selection
    {
        Select(-1, false);
    }

    if( Get_Extent().Intersects(Extent) != INTERSECTION_None )
    {
        for(int i=0; i<Get_Count(); i++)
        {
            Set_Cursor(i);

            if(	Extent.xMin <= Get_X() && Get_X() <= Extent.xMax
                    &&	Extent.yMin <= Get_Y() && Get_Y() <= Extent.yMax )
            {
                Select(i, true);
            }
        }
    }

    return( Get_Selection_Count() > 0 );
}
Ejemplo n.º 7
0
void Monster::Attack()
{
	int idx[4] = { 0,-1,0,1 };
	int idy[4] = { -1,0,1,0 };
	for (int i = 0; i < 4; i++)
	{
		int temp = Singleton::getSingleton().Search(Get_X() + idx[i], Get_Y() + idy[i]);
		if (temp == -1) continue;
		if (Singleton::getSingleton().obj_list[temp]->Get_Type() == T_player)
		{
			Singleton::getSingleton().Lose();
			Singleton::getSingleton().End_Flag = true;
		}
	}
}
Ejemplo n.º 8
0
void Monster::Update()
{
	Set_Frame_Cnt(Get_Frame_Cnt() + 1);
	Get_Frame_Cnt() % 2 == 0 ? Set_Shape(MONSTER_EMPTY) : Set_Shape(MONSTER_FILL);
	Rand_Move();
	Attack();
	if (Get_Frame_Cnt() % Bomb_Put_delay == 0 && Get_Have_Bomb())
	{
		int idx[4] = { -1,0,1,0 };
		int idy[4] = { 0,-1,0,1 };
		int rand_dir = Singleton::getSingleton().Rand_Dir();
		int n_x = Get_X() + idx[rand_dir];
		int n_y = Get_Y() + idy[rand_dir];
		int temp = Singleton::getSingleton().Search(n_x, n_y);

		if (temp == -1) Singleton::getSingleton().obj_list.push_back(new Bomb(n_x, n_y, T_monster));
		else if (Singleton::getSingleton().obj_list[temp]->Get_Type() == T_item)
		{
			Singleton::getSingleton().Delete(temp);
			Singleton::getSingleton().obj_list.push_back(new Bomb(n_x, n_y, T_monster));
		}
	}
}
void CrossHairClass::Update_Calibration(float tx,float ty,float area)
{

    // two point calibration.  We know that the area of the target when we are near the goal is 0.033
    // The area of the target when we're far from the goal is 0.01
    // We're going to maintain a line segment for the CrossHairY defined by two points:
    // (0.033,m_CrossHairYNear)  (0.01,m_CrossHairYFar)
    // When we get a calibration request, we decide which point we are closer to and update that
    // point, proportionally to the current area.

    // if we are closer to 'AREA_NEAR' we update YNear, otherwise update YFar
    if (area > AREA_MID)
    {
        //Updating YNear, assume YFar is fixed, compute YNear which would give us ty,area
        // (YFar - YNear*) / (AREA_FAR - AREA_NEAR) == (YFar - ty) / (AREA_FAR - area)
        float slope = (YFar - ty) / (AREA_FAR - area);
        YNear = -slope * (AREA_FAR - AREA_NEAR) + YFar;

        slope = (XFar - tx) / (AREA_FAR - area);
        XNear = -slope * (AREA_FAR - AREA_NEAR) + XFar;
    }
    else
    {
        //Updating YFar. assume YNear is fixed, compute YFar which would give us ty,area
        // (YFar* - YNear) / (AREA_FAR - AREA_NEAR) == (ty - YNear) / (area - AREA_NEAR)
        float slope = (ty - YNear) / (area - AREA_NEAR);
        YFar = slope * (AREA_FAR - AREA_NEAR) + YNear;

        slope = (tx - XNear) / (area - AREA_NEAR);
        XFar = slope * (AREA_FAR - AREA_NEAR) + XNear;
    }

    // double check
    float xcheck = Get_X(area);
    float ycheck = Get_Y(area);
    printf("Calibrated!  XIn: %f  XCheck: %f YIn: %f  YCheck: %f\r\n",tx,xcheck,ty,ycheck);
}
Ejemplo n.º 10
0
void C_Player1::Move()
{
	//MOVE PLAYER/////////////////////
	

	//LIMITS to keep things from getting stupid
	if(Get_xSpeed() > m_xMaxSpeed)
		Set_xSpeed(m_xMaxSpeed);
	if(Get_xSpeed() < -m_xMaxSpeed)
		Set_xSpeed(-m_xMaxSpeed);

	if(Get_ySpeed() > m_yMaxSpeed)
		Set_ySpeed(m_yMaxSpeed);
	if(Get_ySpeed() < -m_yMaxSpeed)
		Set_ySpeed(-m_yMaxSpeed);

	//Update the position TODO: Make variable 'requested position' for future collision checking
	Set_X(Get_X() + Get_xSpeed());
	Set_Y(Get_Y() + Get_ySpeed());

	//Window collision
	if(Get_X() + Get_xSpeed() < 0)
		Set_X(0);
	if(Get_X() + Get_xSpeed() > LEVEL_WIDTH - PLAYER_WIDTH)//factor in player height/width TODO
		m_X = (m_X - m_xSpeed);
	if(Get_Y() + Get_ySpeed() < 0)
		Set_Y(0);
	if(Get_Y() + Get_ySpeed() > LEVEL_HEIGHT - PLAYER_HEIGHT)
		m_Y = (m_Y - m_ySpeed);
	 
	//If there's a sword swing, move the shield
	for(int i = 0; i < Weapons.size(); i++)
		if(Weapons[i]->Get_weaponType() == SWORD)//if sword found
			Controls.key_S = true;//simulate shield



				

	//***************************************************ZONING STUFF /Scroll the screen and load in new zones when player hits an edge
			//  16 X 8  sized map!!!!


	if(m_Y < 10 && TileManager.Get_transitionDirection() == -1)//ZONE UP if not already zoning  // THE -1 means no transition is happening
		if(TileManager.Get_mapPosition().y != 1){//if not at the top
			TileManager.MapTransition(UP);	
			SDL_Rect updateMapPosition = {TileManager.Get_mapPosition().x, TileManager.Get_mapPosition().y - 1};
			TileManager.Set_mapPosition(updateMapPosition);
		}
	if(m_Y > 930 && TileManager.Get_transitionDirection() == -1)//ZONE DOWN if not already zoning
		if(TileManager.Get_mapPosition().y != 4){//if not at the bottom (16 x 8 map)
			TileManager.MapTransition(DOWN);	
			SDL_Rect updateMapPosition = {TileManager.Get_mapPosition().x, TileManager.Get_mapPosition().y + 1};
			TileManager.Set_mapPosition(updateMapPosition);
		}
	if(m_X < 10 && TileManager.Get_transitionDirection() == -1)//zone LEFT if not already zoning
		if(TileManager.Get_mapPosition().x != 1){//if not at far left
			TileManager.MapTransition(LEFT);	
			SDL_Rect updateMapPosition = {TileManager.Get_mapPosition().x - 1, TileManager.Get_mapPosition().y};
			TileManager.Set_mapPosition(updateMapPosition);
		}
	if(m_X > 1250 && TileManager.Get_transitionDirection() == -1)//zone RIGHT if not already zoning
		if(TileManager.Get_mapPosition().x != 8){//if not at far right
			TileManager.MapTransition(RIGHT);
			SDL_Rect updateMapPosition = {TileManager.Get_mapPosition().x + 1, TileManager.Get_mapPosition().y};
			TileManager.Set_mapPosition(updateMapPosition);
		}


	if(TileManager.Get_transitionDirection() == UP){
		m_Y = TileManager.Get_offsetCounterY();
		if(m_Y > SCREEN_HEIGHT - PLAYER_HEIGHT )//keep player from going into another transition
			m_Y = LEVEL_HEIGHT - PLAYER_HEIGHT - 11;
	}
	if(TileManager.Get_transitionDirection() == DOWN){
		m_Y = LEVEL_HEIGHT + TileManager.Get_offsetCounterY();
		if(m_Y < LEVEL_HEIGHT - SCREEN_HEIGHT + PLAYER_HEIGHT/2)
			m_Y = 11;
	}
	if(TileManager.Get_transitionDirection() == LEFT){
		m_X = TileManager.Get_offsetCounterX();
		if(m_X > SCREEN_WIDTH - PLAYER_WIDTH/2)
			m_X = LEVEL_WIDTH - PLAYER_WIDTH -11;
	}
	if(TileManager.Get_transitionDirection() == RIGHT){
		m_X = LEVEL_WIDTH + TileManager.Get_offsetCounterX();
		if(m_X < LEVEL_WIDTH - SCREEN_WIDTH + PLAYER_WIDTH/3)
			m_X = 11;
	}
	

}
Ejemplo n.º 11
0
//---------------------------------------------------------
bool CSG_PRQuadTree_Node::Add_Point(double x, double y, double z)
{
	if( Contains(x, y) )
	{
		if( has_Statistics() )
		{
			Get_X()->Add_Value(x);
			Get_Y()->Add_Value(y);
			Get_Z()->Add_Value(z);
		}

		int		i	=  y < m_yCenter ? (x < m_xCenter ? 0 : 3) : (x < m_xCenter ? 1 : 2);

		//-------------------------------------------------
		if( m_pChildren[i] == NULL )
		{
			double	Size	= 0.5 * m_Size;

			switch( i )
			{
			case 0:	m_pChildren[i]	= new CSG_PRQuadTree_Leaf(m_xCenter - Size, m_yCenter - Size, Size, x, y, z);	break;
			case 1:	m_pChildren[i]	= new CSG_PRQuadTree_Leaf(m_xCenter - Size, m_yCenter + Size, Size, x, y, z);	break;
			case 2:	m_pChildren[i]	= new CSG_PRQuadTree_Leaf(m_xCenter + Size, m_yCenter + Size, Size, x, y, z);	break;
			case 3:	m_pChildren[i]	= new CSG_PRQuadTree_Leaf(m_xCenter + Size, m_yCenter - Size, Size, x, y, z);	break;
			}

			return( true );
		}

		//-----------------------------------------------------
		if( m_pChildren[i]->is_Leaf() )
		{
			CSG_PRQuadTree_Leaf	*pLeaf	= m_pChildren[i]->asLeaf();

			if( x != pLeaf->Get_X() || y != pLeaf->Get_Y() )
			{
				if( has_Statistics() )
				{
					m_pChildren[i]	= new CSG_PRQuadTree_Node_Statistics	(pLeaf);
				}
				else
				{
					m_pChildren[i]	= new CSG_PRQuadTree_Node				(pLeaf);
				}

				((CSG_PRQuadTree_Node *)m_pChildren[i])->Add_Point(x, y, z);
			}
			else
			{
				if( !pLeaf->has_Statistics() )
				{
					m_pChildren[i]	= new CSG_PRQuadTree_Leaf_List(pLeaf->m_xCenter, pLeaf->m_yCenter, pLeaf->m_Size, x, y, pLeaf->Get_Z());

					delete(pLeaf);
				}

				((CSG_PRQuadTree_Leaf_List *)m_pChildren[i])->Add_Value(z);
			}

			return( true );
		}

		//-------------------------------------------------
	//	if( m_pChildren[i]->is_Node() )
		{
			return( ((CSG_PRQuadTree_Node *)m_pChildren[i])->Add_Point(x, y, z) );
		}
	}

	return( false );
}
Ejemplo n.º 12
0
void Direction::Set_Z(const float z)
{
	Set_Coordinates(Get_X(), Get_Y(), z);
}
Ejemplo n.º 13
0
// Add values to the coordinates of the direction
void Direction::Add_Coordinates(const float x, const float y, const float z)
{
	Set_Coordinates(Get_X() + x, Get_Y() + y, Get_Z() + z);
	return;
}
Ejemplo n.º 14
0
//---------------------------------------------------------
CSG_Shape * CSG_PointCloud::_Set_Shape(int iPoint)
{
    SG_UI_Progress_Lock(true);

    CSG_Shape	*pShape	= m_Shapes.Get_Shape(0);

    if( pShape->is_Modified() && m_Shapes_Index >= 0 && m_Shapes_Index < Get_Count() )
    {
        m_Cursor	= m_Points[m_Shapes_Index];

        for(int i=0; i<Get_Field_Count(); i++)
        {
            switch( Get_Field_Type(i) )
            {
            default:
                Set_Value(i, pShape->asDouble(i));
                break;

            case SG_DATATYPE_Date:
            case SG_DATATYPE_String:
                Set_Value(i, pShape->asString(i));
                break;
            }
        }

        Set_Value(0, pShape->Get_Point(0).x);
        Set_Value(1, pShape->Get_Point(0).y);
        Set_Value(2, pShape->Get_Z    (0)  );
    }

    if( iPoint >= 0 && iPoint < Get_Count() )
    {
        if(1|| iPoint != m_Shapes_Index )
        {
            m_Cursor	= m_Points[iPoint];

            pShape->Set_Point(Get_X(), Get_Y(), 0, 0);
            pShape->Set_Z    (Get_Z()         , 0, 0);

            for(int i=0; i<Get_Field_Count(); i++)
            {
                switch( Get_Field_Type(i) )
                {
                default:
                    pShape->Set_Value(i, Get_Value(i));
                    break;

                case SG_DATATYPE_Date:
                case SG_DATATYPE_String:
                {
                    CSG_String	s;

                    Get_Value(i, s);

                    pShape->Set_Value(i, s);
                }
                break;
                }
            }

            m_Shapes_Index	= iPoint;
            pShape->m_Index	= iPoint;
            pShape->Set_Selected(is_Selected(iPoint));
        }

        m_Shapes.Set_Modified(false);

        SG_UI_Progress_Lock(false);

        return( pShape );
    }

    m_Shapes_Index	= -1;

    SG_UI_Progress_Lock(false);

    return( NULL );
}
Ejemplo n.º 15
0
void C_Player1::Render()
{
	SDL_Rect offset = {Get_X() - Camera.Get_XYWH()->x, Get_Y() - Camera.Get_XYWH()->y, PLAYER_WIDTH, PLAYER_HEIGHT};
	Uint32 color = SDL_MapRGB(screen->format,  255, 0, 0);
	SDL_FillRect(screen, &offset, color);
}
Ejemplo n.º 16
0
// Set the relative coordinates of the direction
void Direction::Set_X(const float x)
{
	Set_Coordinates(x, Get_Y(), Get_Z());
}
Ejemplo n.º 17
0
// Find the distance between this direction and another
Direction Direction::Distance(const Direction& to) const
{
	Direction copy = to;
	copy.Add_Coordinates(-1 * Get_X(), -1 * Get_Y(), -1 * Get_Z());
	return (copy);
}
Ejemplo n.º 18
0
// Dot product. Useful for lighting
float Direction::Dot(const Direction& direction) const
{
	float answer = (Get_X() * direction.Get_X()) + (Get_Y() * direction.Get_Y()) + (Get_Z() * direction.Get_Z());
	return (answer);
}
Ejemplo n.º 19
0
// Makes a vertex with the X, Y, and Z values
glm::vec3 Direction::To_Vertex(void) const
{
	return (glm::vec3(Get_X(), Get_Y(), Get_Z()));
}