Ejemplo n.º 1
0
static void person(double x, double y , double z, double r, double height)
{
    ball(z, y, z, r);
    height += 1; // no unused variable warning
    // int h,ph;
    // float yellow[] = {1.0,1.0,0.0,1.0};
    // float Emission[]  = {0.0,0.0,0.01*emission,1.0};
    // //  Save transformation
    // glPushMatrix();
    // //  Offset, scale and rotate
    // glTranslated(x,y,z);
    // glScaled(r,r,r);
    // //  White ball
    // glMaterialfv(GL_FRONT,GL_SHININESS,shinyvec);
    // glMaterialfv(GL_FRONT,GL_SPECULAR,yellow);
    // glMaterialfv(GL_FRONT,GL_EMISSION,Emission);
    // //  Bands of latitude
    // for (ph=-90;ph<90;ph+=inc)
    // {
    //    glBegin(GL_QUAD_STRIP);
    //    for (h = -height/2; h < height/2; h+=inc)
    //    {
    //       glNormal3d(Cos(ph),Sin(ph),h);
    //       glVertex3d(Cos(ph),Sin(ph),h);
    //       glNormal3d(Cos(ph+inc),Sin(ph+inc),h+inc);
    //       glVertex3d(Cos(ph+inc),Sin(ph+inc),h+inc);
    //       // Vertex(th,ph);
    //       // Vertex(th,ph+inc);
    //    }
    //    glEnd();
    // }
    // //  Undo transofrmations
    // glPopMatrix();
    
}
Ejemplo n.º 2
0
    /**
     * Compute the histogram of euclidean distances from a query point to sample points on the shape. The histogram bins
     * uniformly subdivide the range of distances from zero to \a max_distance. If \a max_distance is negative, the shape scale
     * specified in the constructor will be used.
     *
     * @param position The position of the query point.
     * @param histogram The histogram to be computed.
     * @param max_distance The distance to the furthest point to consider for the histogram. A negative value indicates the
     *   entire shape is to be considered (in which case \a max_distance is set to the shape scale specified in the
     *   constructor). The histogram range is set appropriately.
     * @param sample_reduction_ratio The fraction of the available set of samples -- expressed as a number between 0 and 1 --
     *   that will be randomly selected and used to actually build the histogram. This may be useful for getting a more evenly
     *   sampled set of pairwise distances when calling this function with multiple query points (and an extra-large initial set
     *   of points). A negative value, or a value of 1, indicates all sample points will be used.
     */
    void computeEuclidean(Vector3 const & position, Histogram & histogram, Real max_distance, Real sample_reduction_ratio) const
    {
        if (sample_reduction_ratio < 0)
            sample_reduction_ratio = 1.1;  // play safe

        bool process_all = (max_distance < 0);
        if (process_all)
            max_distance = this->getNormalizationScale();

        histogram.setRange(0, std::max((double)max_distance, 1.0e-30));
        histogram.setZero();

        EuclideanCallback callback(position, histogram, sample_reduction_ratio);

        if (process_all)
        {
            long num_samples = this->numSamples();
            for (long i = 0; i < num_samples; ++i)
                callback(i, this->getSamplePosition(i));
        }
        else
        {
            Ball3 ball(position, max_distance);

            if (this->hasExternalKDTree())
                this->getMutableExternalKDTree()->template processRangeUntil<IntersectionTester>(ball, &callback);
            else
                this->getMutableInternalKDTree()->template processRangeUntil<IntersectionTester>(ball, &callback);
        }
    }
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	Setup();

	bool done = false;

	SDL_Event event;

	PreProcesses();

	const Uint8* keys = SDL_GetKeyboardState(NULL);

	Paddle p1(-0.9);
	Paddle p2(0.9);
	float angle[] = { 45, 135, 225, 315 };
	int choice = floor(rand() % 4);
	Ball ball(0.0005, angle[choice]);

	GLuint wins = LoadTexture("wins.png", GL_RGBA);

	while (!done) {
		while (SDL_PollEvent(&event)) {
			if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE) {
				done = true;
			}
			else if (event.type == SDL_KEYDOWN){
				if (event.key.keysym.scancode == SDL_SCANCODE_SPACE){
					p1.Reset(-0.9);
					p2.Reset(0.9);
					choice = floor(rand() % 4);
					ball.Reset(angle[choice]);
				}
			}

		}

		if (CollisionX(ball)){
			ball.d_y = -ball.d_y;
		}

		if (CollisionY(ball, p1, p2)){
			if (ball.x > 0){
				ball.d_x = -abs(ball.d_x);
			}
			else {
				ball.d_x = abs(ball.d_x);
			}
		}

		PaddleMovement(keys, p1.y, p2.y);

		Update(ball);
		Render(p1, p2, ball, wins);

		SDL_GL_SwapWindow(displayWindow);
	}

	SDL_Quit();
	return 0;
}
void FireHydrant(double x, double y, double z, double dx, double dy, double dz, double th)
{

	glPushMatrix();

	glTranslated(x,y,z);
	glRotated(th,0,1,0);
	glScaled(dx,dy,dz);

	glColor3f(.2,.2,.2);
	Cylinder(0,0,0,.7,.7,.1,90,0);
	glColor3f(1,0,0);
	Cylinder(0,.8,0,.4,.4,.8,90,0);
	Cylinder(0,1.6,0,.65,.65,.1,90,0);

	ball(0,1.7,0,.4);
	Cylinder(-.4,1,0,.3,.3,.1,0,90);
	Cylinder(0,1.1,-.5,.2,.2,.1,0,0);
	Cylinder(0,1.1,.5,.2,.2,.1,0,0);
	Cylinder(0,1.1,0,.05,.05,.68,0,0);
	Cylinder(-.5,1,0,.05,.05,.05,0,90);
	Cylinder(0,2.1,0,.05,.05,.05,90,0);
	glPopMatrix();
	glColor3f(1,1,1);

}
Ejemplo n.º 5
0
GameEngine::GameEngine()
{
    MyML ball("Pos.x=4;Pos.y=6;Gui.OldPos.x=4;Gui.OldPos.y=6"); //! das hier soll mal so aussehen: MyML ball("Pos[x=4;y=6];Gui[OldPos[x=4;y=6]")
    ball.AddA("color",IntToString(0xffffff));
    ball.AddA("owner","");
    data.AddE("Ball",ball);

    rnd.seed(seed_val);
    invert_positions=false;


    data.Do("Config.Actions");
    MyML& actions=data.E("Config.Actions");

    actions.E("None",MyML("action=none;prio=10"));
    actions.E("Move",MyML("action=move;prio=20"));
    //actions.E("Tackle",MyML("action=tackle;prio=80"));
    //actions.E("Dive",MyML("action=dive;prio=0")); //schwalbe
    //actions.E("Pass",MyML("action=pass;prio=30"));
    //actions.E("Cross",MyML("action=cross;prio=40"));//flanke
    //actions.E("Shot",MyML("action=shot;prio=30")); //torschuss
    //actions.E("Foul",MyML("action=foul;prio=90"));

    //! hier noch hinzufügen:
    //Kopfball -> Ball muss in der Luft sein, aber sehr hohe prio
    //Raumdeckung -> wie Tackle, aber nicht so extrem... behindert den gegenspieler nur und führt selten zu ner ballübernahme

    // die mussen mal raus:
    //actions.E("Kick",MyML("action=kick;prio=30")); // is das gleich wie shot...
    //actions.E("Takeball",MyML("action=takeball;prio=90")); // is das gleich wie tackle...


}
Ejemplo n.º 6
0
vec make_ball(const Points & points,
	      const vec & center,
	      const double radius){
  uint N = points.n_rows;
  vec ball = zeros<vec>(N);
  vec dist = lp_norm(points.each_row() - center.t(),2,1);
  ball(find(dist <= radius)).fill(1);
  return ball;
}
Ejemplo n.º 7
0
void selectType(char *type, Particle **p) {
	if (!strcmp(type, "bouble"))		bouble(&(*p));
	if (!strcmp(type, "smoke"))		smoke(&(*p));
	if (!strcmp(type, "water"))		water(&(*p));
	if (!strcmp(type, "ball"))			ball(&(*p));
	if (!strcmp(type, "wind"))			wind(&(*p));
	if (!strcmp(type, "siva"))			siva(&(*p));
	if (!strcmp(type, "sun"))			sun(&(*p));
}
void SimpleBallGameWidget::initializeGL()
{
	GLWidget::initializeGL();
	QImage background(":/SimpleBallGame/background.png");
	m_backgroundTexture = bindTexture(background);

	QImage ball(":/SimpleBallGame/ball.png");
	m_ballTexture = bindTexture(ball);
}
Ejemplo n.º 9
0
void Model::add_ball(float x, float y)
{
	// Get logical coordinates
	float logical_x = get_logical_x(x);
	float logical_y = get_logical_y(y);

	// set radius w.r.t nearby walls
	float max_radius = std::min(BASE_RADIUS,
								std::min(std::min(std::abs(1 - logical_x), std::abs(1 + logical_x)),
										 std::min(std::abs(1 - logical_y), std::abs(1 + logical_y))));

	// Randomize dominant color and color mix
	int strong_color = rand() % 3;
	float red = get_random(0.0, 0.3);
	float green = get_random(0.0, 0.3);
	float blue = get_random(0.0, 0.3);

	switch(strong_color % 3)
	{
	case 0:
		red = 0.8;
		break;
	case 1:
		green = 0.8;
		break;
	case 2:
		blue = 0.8;
		break;
	}

	// Prevent new balls inside existing ones
	for (std::vector<Ball>::iterator ball = _balls.begin(); ball != _balls.end(); ++ball)
	{
		glm::vec4 new_center(logical_x, logical_y, 0, 1);
		if (glm::distance(new_center, ball->_position) < ball->_cur_radius)
		{
			return;
		}
	}

	// Create new ball object
	Ball ball(_balls.size(),
			  logical_x,
		      logical_y,
		      get_random(0, 2*M_PI),
		      max_radius,
		      red,
		      green,
		      blue);

	// Set size according to surrounding balls. No need to skip existing balls
	std::set<size_t> skip;
	ball._max_radius = get_new_radius(ball, skip);

	_balls.push_back(ball);
}
Ejemplo n.º 10
0
//
//  Draw the window
//
void Ex04opengl::paintGL()
{
   //  Wall time (seconds)
   float t = 0.001*time.elapsed();
   if (move) zh = fmod(90*t,360);

   //  Clear screen and Z-buffer
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glEnable(GL_DEPTH_TEST);

   //  Set view
   glLoadIdentity();
   if (fov) glTranslated(0,0,-2*dim);
   glRotated(ph,1,0,0);
   glRotated(th,0,1,0);

   //  Translate intensity to color vectors
   float Ambient[]  = {0.3,0.3,0.3,1.0};
   float Diffuse[]  = {0.8,0.8,0.8,1.0};
   float Specular[] = {1.0,1.0,1.0,1.0};
   float Position[] = {(float)(3*Cos(zh)),z0,(float)(3*Sin(zh)),1.0};

   //  Draw light position (no lighting yet)
   glColor3f(1,1,1);
   ball(Position[0],Position[1],Position[2] , 0.1);
   //  OpenGL should normalize normal vectors
   glEnable(GL_NORMALIZE);
   //  Enable lighting
   glEnable(GL_LIGHTING);
   //  Enable light 0
   glEnable(GL_LIGHT0);
   //  Set ambient, diffuse, specular components and position of light 0
   glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
   glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
   glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
   glLightfv(GL_LIGHT0,GL_POSITION,Position);

   //  Apply shader
   if (mode) shader[mode].bind();

   //  Draw scene
   glPushMatrix();
   if (obj) obj->display();
   glPopMatrix();

   //  Release shader
   if (mode) shader[mode].release();
   glDisable(GL_LIGHTING);
   glDisable(GL_DEPTH_TEST);
   
   //  Emit angles to display
   emit angles(QString::number(th)+","+QString::number(ph));
   //  Emit light angle
   emit light((int)zh);
}
Ejemplo n.º 11
0
void Palet::tick( float dTime )
{
    if (m_Ai)
    {
        Ball* ball(m_Game->getBall());
        if (he::dot(ball->getVelocity(), m_MoveTo) > 0.0)
        {
            float z(ball->getPosition().z);
            if (fabs(m_MoveTo.z - z) > m_PaletDim.y/2)
            {
                if (m_MoveTo.z < z - m_Speed * dTime)
                {
                    m_MoveTo.z += m_Speed * dTime;
                }
                else if (m_MoveTo.z > z + m_Speed * dTime)
                {
                    m_MoveTo.z -= m_Speed * dTime;
                }
            }
        }
        else
        {   // return to center
            if (m_MoveTo.z < -m_Speed * dTime)
            {
                m_MoveTo.z += m_Speed * dTime;
            }
            else if (m_MoveTo.z > m_Speed * dTime)
            {
                m_MoveTo.z -= m_Speed * dTime;
            }
        }
    }
    else
    {
        if (m_GoUp)
        {
            m_MoveTo.z += m_Speed * dTime;
            if (m_MoveTo.z + m_PaletDim.y / 2 > m_Game->getBoardDimension().y / 2)
                m_MoveTo.z = m_Game->getBoardDimension().y / 2 - m_PaletDim.y / 2;
        }
        if (m_GoDown)
        {
            m_MoveTo.z -= m_Speed * dTime;
            if (m_MoveTo.z - m_PaletDim.y / 2 <  -m_Game->getBoardDimension().y / 2)
                m_MoveTo.z = -m_Game->getBoardDimension().y / 2 + m_PaletDim.y / 2;
        }
    }

    float len(he::length(m_MoveTo - m_Position));
    if (len > m_Speed * dTime)
        m_Position += (m_MoveTo - m_Position) / len * m_Speed * dTime;
    else
        m_Position = m_MoveTo;
}
void loop(){
  int buttonState = digitalRead(2);
  if(buttonState == HIGH){
    for(int i=1;i<=3;i++){
      //verse1(0);
      verse(1);
      bridge();
      ball();
    }
  }
}
Ejemplo n.º 13
0
void minball(int n, point pt[]) {
	ball();
	if (outCnt < 4) for (int i = 0; i < n; ++i)
		if ((res - pt[i]).norm() > +radius + EPS) {
			out[outCnt] = pt[i]; ++outCnt; minball(i, pt); --outCnt;
			if (i > 0) {
				point Tt = pt[i];
				memmove(&pt[1], &pt[0], sizeof(point) * i);
				pt[0] = Tt;
			}
		}
}
Ejemplo n.º 14
0
Archivo: main.c Proyecto: ryanlamo/pong
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;

    ball_t pongball = ball(50,50,50,30,5);

	while (1)
	{
		pongball = move_ball(pongball);
	}
	
	return 0;
}
Ejemplo n.º 15
0
/*  update_frame
 *  Draw interface for a given frame
 */
void update_frame() {
  if (game_menu == 1) { draw_menu(); }
  else {
    // Regular game
    if ((game_mode == 0) && (game_paused == 0)) {
      paddle(PADDLE_1_XOFF,p1_h,p1_c);
      paddle(PADDLE_2_XOFF,p2_h,p2_c);
	  	ball(ball_x, ball_y, C_WHITE);

		  char* hw = "Score: ";
		  int x = 10;
		  while (*hw) {
				write_char(x, 2, *hw);
				x++;
				hw++;
		  }
	  	write_char(x, 2, '0' + p1_score);
		  hw = "Score: ";
		  x = 60;
		  while (*hw) {
				write_char(x, 2, *hw);
				x++;
				hw++;
		  }
	  	write_char(x, 2, '0' + p2_score);
    }
    // Paused game
    if (game_paused == 1) {
			unsigned char txt3[] = {'P','A','U','S','E','D','\n','\0'};
			console_out(txt3);
      fill_screen(C_RED);
		  char* hw = "GAME PAUSED";
	  	int x = 10;
		  while (*hw) {
				write_char(x, 2, *hw);
				x++;
				hw++;
		   }
    }
    // Different mode, not implemented
    if (game_mode != 0) {
			unsigned char txt4[] = {'U','N','K','N','O','W','N','\n','\0'};
			console_out(txt4);
      fill_screen(C_DBLUE);
    }
  }
}
Ejemplo n.º 16
0
bool Kick::findShot(const Geometry2d::Segment& segment, Geometry2d::Segment& result, bool chip, float min_segment_length) const {
	// calculate available target segments
	WindowEvaluator evaluator(state());
	evaluator.enable_chip = chip;
	evaluator.chip_min_range = minChipRange;
	evaluator.chip_max_range = maxChipRange;
	evaluator.run(ball().pos, segment);
	Window *window = evaluator.best();

	// check for output
	if(window && window->segment.length() > min_segment_length)	{
		result = window->segment;
		return true;
	} else {
		return false;
	}
}
Ejemplo n.º 17
0
/* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
    struct pong pong;
    int game = 1;

    /* init the struct with some silly values to start with */

    pong.ballx = 20*RES;
    pong.bally = 20*RES;

    pong.e_pad[0] = 0;
    pong.w_pad[0] = 7;
    pong.e_pad[1] = 0;
    pong.w_pad[1] = 40;

    pong.ballspeedx = SPEEDX;
    pong.ballspeedy = SPEEDY;

    pong.score[0] = pong.score[1] = 0; /* lets start at 0 - 0 ;-) */

    /* if you don't use the parameter, you can do like
       this to avoid the compiler warning about it */
    (void)parameter;

    TEST_PLUGIN_API(api);
    
    rb = api; /* use the "standard" rb pointer */

    /* Clear screen */
    rb->lcd_clear_display();

    /* go go go */
    while(game > 0) {
        showscore(&pong);
        pad(&pong, 0); /* draw left pad */
        pad(&pong, 1); /* draw right pad */
        ball(&pong); /* move and draw ball */

        rb->lcd_update();

        game = keys(&pong); /* deal with keys */
    }

    return (game == 0) ? PLUGIN_OK : PLUGIN_USB_CONNECTED;
}
Ejemplo n.º 18
0
void Lyrics::HandlePaint_BouncingBall(wxDC &dc)
{
   int ctr = mWidth / 2;
   int x;
   double y;
   GetKaraokePosition(mT, &x, &y);

   dc.SetTextForeground(wxColour(238, 0, 102));
   bool changedColor = false;

   SetDrawnFont(&dc);
   unsigned int i;
   wxCoord yTextTop = mKaraokeHeight - mTextHeight - 4;
   for(i=0; i<mSyllables.GetCount(); i++) {
      if (mSyllables[i].x + mSyllables[i].width < (x - ctr))
         continue;
      if (mSyllables[i].x > x + ctr)
         continue;

      if (!changedColor && mSyllables[i].x >= x) {
         dc.SetTextForeground(*wxBLACK);
         changedColor = true;
      }

      wxString text = mSyllables[i].text;
      if (text.Length() > 0 && text.Right(1) == wxT("_")) {
         text = text.Left(text.Length() - 1);
      }

      dc.DrawText(text,
                  mSyllables[i].leftX + ctr - x,
                  yTextTop);
   }

   int ballRadius = (int)(mTextHeight / 8.0);
   int bounceTop = ballRadius * 2;
   int bounceHeight = yTextTop - bounceTop;
   int yi = (int)(yTextTop - 4 - (y * bounceHeight));

   if (mT >= 0.0) {
      wxRect ball(ctr - ballRadius, yi - ballRadius, 2 * ballRadius, 2 * ballRadius);
      dc.SetBrush(wxBrush(wxColour(238, 0, 102), wxSOLID));
      dc.DrawEllipse(ball);
   }
}
Ejemplo n.º 19
0
void minball(int n)
{
    ball();
    if( nouter<4 )
        for(int i=0; i<n; ++i)
            if( dist(res, point[i])-radius>eps ) 
            {
                outer[nouter]=point[i]; 
                ++nouter;
                minball(i);             
                --nouter;
                if( i>0 ) 
                {
                    point_type Tt = point[i];
                    memmove(&point[1], &point[0], sizeof(point_type)*i);
                    point[0]=Tt;
                }
            }
}
Ejemplo n.º 20
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) // HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow
{
	config = _CONFIG(1024, 768, {0.0f,1.2f,10.f}, {}, 60.f, 0.01f, 40.f);
	_WINDOW wnd = _WINDOW(hInstance, "Main Window");

	if (wnd.isInitialized())
	{
		//load file
		Model teapot(getFilenameFromCurrentDirectory("teapot.obj"), {0,3,1}, {}, {.5f, .5f, .5f});
		Model ball(getFilenameFromCurrentDirectory("sphere.obj"), {}, {}, {.8f,.8f,.8f});

		float rotOfTeapot[3] = {0.0f, 0.0f, 0.0f};
		while (true)
		{
			while (PeekMessage(&wnd.msg, nullptr, 0, 0, PM_REMOVE) > 0)
			{
				TranslateMessage(&wnd.msg);
				DispatchMessage(&wnd.msg);
			}

			//Background
			DrawWindowElements::ClearZBuffer();
			DrawWindowElements::FillRectangle(MyColor::LIGHTBLUE);
			//DrawWindowElements::DrawGrid(32, MyColor::BLACK);

			//Setting visual and camera
			DrawCommon::SetProjection();
			DrawCommon::SetViewMatrix();

			//Drawing models
			drawTeapot(teapot, rotOfTeapot);
			drawBalls(ball);

			DrawMyWindow(wnd.hwndMain);
			Controller::OverlayHUD(wnd.hwndMain);

			Sleep(20);
			if (wnd.msg.message == WM_QUIT) return EXIT_SUCCESS;
		}
	}
	return EXIT_FAILURE;
}
Ejemplo n.º 21
0
//--------------------------------------------------------------
void testApp::updateSpotFromMovers(){
  float interval = ofGetWidth()/nbLedProjector;
  //for (int i = 0; i < (int) spots.size(); i++){
  //  spots[i].set(0);
  //}
  for (int i = 0; i < (int) movers.size(); i++){
    float diameter = movers[i].get()->getDiameter();
    float radius = diameter/2.;
    int start = floor((movers[i].get()->getLocation().x-radius)/interval);
    int end = ceil((movers[i].get()->getLocation().x+radius)/interval);
    start = ofClamp(start, 0, spots.size()-1);
    end = ofClamp(end, 0, spots.size()-1);
    ofRectangle ball(movers[i].get()->getLocation().x-radius, movers[i].get()->getLocation().y-radius, diameter, diameter);
    for (int j = start; j < end; j++){
      ofRectangle intervalRect(j*interval, 0, interval, ofGetHeight());
      ofRectangle intersect = intervalRect.getIntersection(ball);
      spots[j]+=1/movers[i].get()->getMass()*intersect.getArea()/400.;
    }
  }
}
Ejemplo n.º 22
0
int main(int argc, char ** argv) {
    sf::VideoMode mode(WIDTH, HEIGHT);
    sf::RenderWindow window;
    Bat bat1(10, HEIGHT / 2 - 50);
    Bat bat2(WIDTH - 20, HEIGHT / 2 - 50);
    Ball ball(WIDTH / 2, HEIGHT / 2);
    std::vector<Entity*> entities;
    entities = {&bat1, &bat2, &ball};
    int bat1score = 0, bat2score = 0;

    window.create(mode, "Pong");
    window.setVerticalSyncEnabled(true);

    while (window.isOpen()) {
        draw(window, entities);
        update(window, entities, bat1score, bat2score);
    }

    return 0;
}
Ejemplo n.º 23
0
	virtual int Run(int argc, char* argv[])
	{
		dWorld world;
		world.setGravity(0, 0, -1.0);

		dMass m;
		m.setSphereTotal(1.0, 0.2);

		dBody ball(world);
		ball.setMass(m);
		ball.setPosition(0, 0, 1.0);

		while(true) {
			const dReal stepsize = 0.1;
			world.step(stepsize);
			dump_position(ball.getPosition());

			if(get_cin_key() == 'q')
				break;
		}

		return 0;
	}
Ejemplo n.º 24
0
task usercontrol()
{
	while (true)
	{
		ball();
		if (time1[T1]>100)
		{
			Speed();
			resetTimer();
			SensorValue[LeftSpeed] = 0;
			SensorValue[RightSpeed] = 0;
		}

		Drive();
		Fire();
		Pnumatics();
		Pid();
		Drive2();
		Fire2();
		Pnumatics2();
		Pid2();
	}
}
Ejemplo n.º 25
0
int Field::isTouched(const touchPosition& touch) {
    if( mode == POKEBALLMODE ) {
        const std::string BALLTEXTURE = ExtDataManager::getBasePath() + "/textures/ball.png";
        const int XLABELPOS = posx + 5;
        const int XBALLPOS = XLABELPOS;
        const int YBALLPOS = posy + 2;

        Drawable ball(TextureManager::getTexture(BALLTEXTURE), XBALLPOS, YBALLPOS, active, id);
        return ball.isTouched(touch);
    }

    if( mode == ARROWMODE) {
        const int XDOWNPOS = posx + 5;
        const int YDOWNPOS = posy + 2;
        const std::string DOWNARROW = ExtDataManager::getBasePath() + "/textures/downarrow.png";

        const std::string FONTPATH = ExtDataManager::getBasePath() + "/fonts/roboto_bold.ttf";
        const int XLABELARROWPOS = posx + 5 + TextureManager::getTexture(DOWNARROW)->width + 5;
        const int XUPPOS = XLABELARROWPOS + getTextWidth(FontManager::getFont(FONTPATH), 9, label+" "+textfield) + 5;
        const int YUPPOS = YDOWNPOS;
        const std::string UPARROW = ExtDataManager::getBasePath() + "/textures/uparrow.png";

        Drawable downarrow(TextureManager::getTexture(DOWNARROW), XDOWNPOS, YDOWNPOS, active, id);
        Drawable uparrow(TextureManager::getTexture(UPARROW), XUPPOS, YUPPOS, active, id+1);

        if( downarrow.isTouched(touch) )
            return id;

        if( uparrow.isTouched(touch) )
            return id+1;

        return 0;
    }

    return 0;
}
Ejemplo n.º 26
0
int main() {


    time_t secs;
    time(&secs);
    srand( (unsigned int)secs);

    dir = rand() % 4 + 1;
    BITMAP *buffer, *sball, *player1,*player2;
    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT_WINDOWED, 440, 280, 0, 0);
    buffer = create_bitmap( 440, 280);
    sball=create_bitmap(50,50);
    player1 = create_bitmap( 10, 60);
    player2 = create_bitmap( 10, 60);
    clear_to_color( sball, makecol( 255, 0, 0 ) );
    clear_to_color( player1, makecol( 0, 255, 0 ) );
    clear_to_color( player2, makecol( 0, 255, 0 ) );
    while( !key[KEY_ESC]) {
        clear_to_color( buffer, makecol( 0, 0, 255 ) );
        ball();
        play1();
        play2();
//rest(1);
        blit(sball,buffer,0,0,x,y,sball->w,sball->h);
        blit(player1,buffer,0,0,xx,yy,player1->w,player1->h);
        blit(player2,buffer,0,0,xxx,yyy,player2->w,player2->h);
        blit(buffer,screen,0,0,0,0,440,280);
        std::cout<<"dir"<<dir<<std::endl;
    }

    return 0;

}
Ejemplo n.º 27
0
int main()
{

	//Création de la fenêtre 
	sf::RenderWindow window;
	window.create(sf::VideoMode(640, 480), "Pong");
	//Modification de la position de la fenêtre ( x=L , y=H)
	window.setPosition(sf::Vector2i(150, 50));
	//Définition des images par secondes maximal 
	window.setFramerateLimit(60);

	//Création du Paddle de gauche 
	Paddle lPaddle(10,60,40,210);
	sf::RectangleShape leftPaddle(sf::Vector2f(lPaddle.getm_width(),lPaddle.getm_height()));
	leftPaddle.setPosition(sf::Vector2f(lPaddle.getm_x(), lPaddle.getm_y()));
	
	//Création du Paddle de droite
	Paddle rPaddle(10, 60, 590, 210);
	sf::RectangleShape rightPaddle(sf::Vector2f(rPaddle.getm_width(), rPaddle.getm_height()));
	rightPaddle.setPosition(sf::Vector2f(rPaddle.getm_x(), rPaddle.getm_y()));
		
	//Création de la balle 
	Ball cball;
	sf::CircleShape ball(cball.getm_radius());
	ball.setPosition(sf::Vector2f(cball.getm_x(), cball.getm_y()));
	sf::Vector2f ballSpeed(cball.getm_speed(),cball.getm_speed());
	
	
	//Tant que la fenêtre est ouverte...
	while (window.isOpen()) {

		sf::Event event;
		//Test des évènements 
		while (window.pollEvent(event))	{ 

			//Si on clique sur fermer
			if (event.type == sf::Event::Closed)
				//On ferme la fenêtre
				window.close();
		}

			/* Gestion des déplacements clavier du paddle de gauche */
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) {
			leftPaddle.move(0, -lPaddle.getm_speed());
			}
			else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
			leftPaddle.move(0, lPaddle.getm_speed());
			}

		    /* Gestion des déplacements clavier du paddle de droite */
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) ) {
				rightPaddle.move(0, -rPaddle.getm_speed());
			}
			else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
				rightPaddle.move(0, rPaddle.getm_speed());
			}

			/*Initialisation de la direction de la balle au départ*/
			ball.move(-ballSpeed.x, ballSpeed.y*2);

			/*Gestion de collision avec un mur*/
			if (ball.getPosition().y <= 0) {
				std::cout << "Balle collision Haut" << std::endl;
				ballSpeed.y = -ballSpeed.y;
				
			}
			else if (ball.getPosition().y >= 463) {
				std::cout << "Balle collision Bas" << std::endl;
				ballSpeed.y = -ballSpeed.y;
			}
			else if (ball.getPosition().x <= 20) {
				std::cout << "Joueur 2 a marqué" << std::endl;
				ball.setPosition(sf::Vector2f(cball.getm_x(), cball.getm_y()));
				
			}
			else if (ball.getPosition().x >= 620) {
				std::cout << "Joueur 1 a marqué" << std::endl;
				ball.setPosition(sf::Vector2f(cball.getm_x(), cball.getm_y()));
				
			}

			/*Gestion de collision avec un paddle*/
			sf::FloatRect ballBox = ball.getGlobalBounds();
			sf::FloatRect leftBox = leftPaddle.getGlobalBounds();
			sf::FloatRect rightBox = rightPaddle.getGlobalBounds();

			if (leftBox.intersects(ballBox)) {
				ballSpeed.x = -ballSpeed.x;
			}
			else if (rightBox.intersects(ballBox)) {
				ballSpeed.x = -ballSpeed.x;
			}
			
			/*Gestion de collision paddle gauche & mur*/
			if (leftPaddle.getPosition().y <= 0) {
				std::cout << "Padlle gauche collision Haut " << std::endl;
				leftPaddle.setPosition (40,0);
			}
			else if (leftPaddle.getPosition().y >= 420) {
				std::cout << "Padlle gauche collision Bas " << std::endl;
				leftPaddle.setPosition(40, 420);
			}

			/*Gestion de collision paddle droite & mur*/
			if (rightPaddle.getPosition().y <= 0) {
				std::cout << "Padlle droite collision Haut " << std::endl;
				rightPaddle.setPosition(590, 0);
			}
			else if (rightPaddle.getPosition().y >= 420) {
				std::cout << "Padlle droite collision Bas " << std::endl;
				rightPaddle.setPosition(590, 420);
			}

		window.clear();
		window.draw(leftPaddle);
		window.draw(rightPaddle);
		window.draw(ball);
		window.display();
		
	}

	return 0;
}
Ejemplo n.º 28
0
void fball(int fx, int fy, int tx, int ty, int dmg)
{
    ball(fx,fy,tx,ty,dmg,FLAME);
}
Ejemplo n.º 29
0
void snowball(int fx, int fy, int tx, int ty, int dmg)
{
    ball(fx,fy,tx,ty,dmg,COLD);
}
Ejemplo n.º 30
0
void manastorm(int x, int y, int dmg)
{
    ball(x,y,x,y,dmg,UNSTOPPABLE);
}