예제 #1
0
	bool BeamShotM::DoesColideWithPlayer( const GameUnit& x, const GameUnit& y, const GameUnit& radius )
	{
		Circle c;
		c.SetCenterX( x.GetFloat() );
		c.SetCenterY( y.GetFloat() );
		c.SetRadius( radius.GetFloat() );

		return m_Line.Colided( &c );
	}
예제 #2
0
int main()
{

	Shape s;
	s.Move(100, 100);
	s.Draw();

	Rectangle r;
	r.Move(200, 100);
	r.Resize( 50, 50);
	r.Draw();

	Circle c;
	c.Move( 300, 100);
	c.SetRadius(30);
	c.Draw();

	return 0;
}
예제 #3
0
파일: main.c 프로젝트: lirui79/CProject
void test_three()
{
	Circle   *circle ;
	Point    *point ;
	Shape    *shape ;
	IMethod  *ptr ;
	double area = 0.0 ;
	circle = New(Circle) ;

	circle->Set(circle , 10.0 , 20.0) ;
	circle->Move(circle , 100.0 , 300.0) ;

	circle->Position(circle) ;

	circle->SetRadius(circle , 30.0) ;
	area = circle->Area(circle) ;

	circle->SetCircle(circle , 1.0 , 2.0 , 3.0) ;

	shape = (Shape*)circle ;
	shape->Position(shape) ;
	area = shape->Area(shape) ;

	point = (Point*)circle ;
	point->Move(point , 1000.0 , 2000.0) ;
	point->Position(point) ;

	circle->AddRadius(circle , 50.0) ;
	area = point->Area(point) ;

	ptr = (IMethod*)circle ;
//	area = ptr->Area() ;
    ptr->GetClassName() ;
	Delete(ptr) ;

}
int main( int argc, char **argv )
{


  if ( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
    throw runtime_error(SDL_GetError());

  SDL_Window *window = SDL_CreateWindow( "Circle and line collision example",
					 SDL_WINDOWPOS_CENTERED,
					 SDL_WINDOWPOS_CENTERED,
					 WINDOW_WIDTH, 
					 WINDOW_HEIGHT, 
					 SDL_WINDOW_SHOWN
					 );
  
  if ( window == NULL )
    throw runtime_error(SDL_GetError());
  
  SDL_Renderer *renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_SOFTWARE);
  if ( renderer == NULL )
    throw runtime_error(SDL_GetError());



  bool bRunning = true;

  LineSegment line;
  line.SetStart(250,50);
  line.SetEnd(200,200); 

  Circle circle;
  circle.SetCenter( Vector2(250,150));
  circle.SetRadius(30);
  
  while ( bRunning )
  {

    SDL_Event ev;

    while ( SDL_PollEvent( & ev ))  // Check event queue.
    {
      switch( ev.type )
      {
      case SDL_QUIT: // when window is closed
	bRunning = false;
	break;
      case SDL_MOUSEBUTTONDOWN:
	switch( ev.button.button )
	{
	case SDL_BUTTON_LEFT:
	  line.SetEnd( ev.button.x, ev.button.y );
	  break;
	case SDL_BUTTON_RIGHT:
	  line.SetStart( ev.button.x, ev.button.y );
	  break;
	default:
	  break;
	}
	break;
      case SDL_MOUSEMOTION:
	if ( ev.motion.state & SDL_BUTTON( SDL_BUTTON_LEFT ))
	{
	  line.SetEnd( ev.motion.x, ev.motion.y);
	}

	break;
      }

      SDL_SetRenderDrawColor(renderer,0,0,0,0);
      SDL_RenderClear(renderer);
      
      draw_line( renderer, line, 0,255,0,255);

      if ( collides( circle, line) )
      {
	draw_circle( renderer, circle, 255,0,0,255);
      }
      else
	draw_circle( renderer, circle, 255,127,0,255);

      SDL_RenderPresent( renderer );
      SDL_Delay(1);
    }
  }
  SDL_Quit();
  return 0;
}