예제 #1
0
void CVaisseau::AfficherVaisseau (sf::RenderWindow& AppVaisseau)
{
    float fVitesseVaisseau = 350.f;

    if (
        AppVaisseau.GetInput().IsKeyDown(sf::Key::Left)
        ||(AppVaisseau.GetInput().GetJoystickAxis(0, sf::Joy::AxisX) < 0)
       )
        {
            m_PositionVaisseau = GetPositionVaisseau ();

            if (m_PositionVaisseau.x <= (0.f + m_TailleVaisseau.x/2))
            {
                SpriteVaisseau.SetPosition(0.f, m_fPositionVaisseauYDepart);
            }

            else
            {
                SpriteVaisseau.Move(-fVitesseVaisseau * m_fElapsedTimeVaisseau, 0);
            }

            m_PositionVaisseau = GetPositionVaisseau ();
            m_PositionFlamme = PositionnerFlamme ();
        }

    else if (
            AppVaisseau.GetInput().IsKeyDown(sf::Key::Right)
            ||(AppVaisseau.GetInput().GetJoystickAxis(0, sf::Joy::AxisX) > 0)
            )
            {
                m_PositionVaisseau = GetPositionVaisseau ();

                if (m_PositionVaisseau.x >= (LARGEUR_FENETRE - m_TailleVaisseau.x/2))
                {
                    SpriteVaisseau.SetPosition (LARGEUR_FENETRE - m_TailleVaisseau.x, m_fPositionVaisseauYDepart);
                }

                else
                {
                    SpriteVaisseau.Move(fVitesseVaisseau * m_fElapsedTimeVaisseau, 0);
                    //std::cout<<"1 - " <<m_fElapsedTimeVaisseau <<std::endl;
                }

                m_PositionVaisseau = GetPositionVaisseau ();
                m_PositionFlamme = PositionnerFlamme ();
            }

    //std::cout <<"echo" <<std::endl;

    pParticulesVaisseau.ParticuleQuad (m_PositionFlamme);

    if (!m_bvaisseauToucheParEnnemis)
    AppVaisseau.Draw(SpriteVaisseau);
}
예제 #2
0
void Controls(sf::RenderWindow &Window, sf::Shape &player)
{
    if(Window.GetInput().IsKeyDown(sf::Key::Right))
        player.Move(MOVESPEED, 0);
    else if(Window.GetInput().IsKeyDown(sf::Key::Left))
        player.Move(-MOVESPEED, 0);
    else if(Window.GetInput().IsKeyDown(sf::Key::Down))
        player.Move(0, MOVESPEED);
    else if(Window.GetInput().IsKeyDown(sf::Key::Up))
        player.Move(0, -MOVESPEED);
}
예제 #3
0
void MouseClick(sf::RenderWindow &Window, sf::Music &introMusic)
{
    int mouseX = Window.GetInput().GetMouseX();
    int mouseY = Window.GetInput().GetMouseY();
    if(Window.GetInput().IsMouseButtonDown(sf::Mouse::Left) && mouseX >= 350 && mouseX <= 450)
    {
        if(mouseY > 100 && mouseY < 200)
            introMusic.Play();
        else if (mouseY > 200 && mouseY < 300)
            introMusic.Pause();
        else if (mouseY > 300 && mouseY < 400)
            introMusic.Stop();
    }
}
예제 #4
0
//Draws Items. Inventory when I is held.
void Items::displayItems(sf::RenderWindow& App, sf::Event& Event, sf::Sprite& ani_spr)
{
	for (unsigned int x=0; x<items.size(); x++) App.Draw(*(items[x]));
	if (App.GetInput().IsKeyDown(sf::Key::I)) 
	{
		App.Draw(inventory);
		for (int x=0; x<left_slots.size(); x++) App.Draw(*(left_slots[x]));
		for (unsigned int x=0, a=426; x<slots.size(), a<426+(32*8); x++, a+=32)
		{
			for (unsigned int y=0, b=142; y<slots[x].size(), b<142+(32*10); y++,b+=32)
			{
				App.Draw(*(slots[x][y]));
				if (Event.Type == sf::Event::MouseMoved)
				{
					//std::cout << "X: " << Event.MouseMove.X << "\nY: " << Event.MouseMove.Y << std::endl; 
					if ((Event.MouseMove.X >= a && Event.MouseMove.X <= a+32 ) && (Event.MouseMove.Y >= b && Event.MouseMove.Y <= b+32))
					{
						mouse_over.SetPosition(slots[x][y]->GetPosition());
						
					}
				}
			}
		}
	App.Draw(mouse_over);
	}
}
예제 #5
0
void InputHandler::RunIteration(sf::RenderWindow& App)
{
	const sf::Input& input = App.GetInput();

	// Replace previous states with current states.
	mPrevMouseLeftClick = mMouseLeftClick;
	mPrevMouseRightClick = mMouseRightClick;
	mPrevMouseMiddleClick = mMouseMiddleClick;

	// Replace previous key codes with current ones.
	for (int i = 0; i < 101; i++)
	{
		mPrevKeyCodes[i] = mKeyCodes[i];
	}

	// Update current states.
	mMouseLeftClick = input.IsMouseButtonDown(sf::Mouse::Button::Left);
	mMouseRightClick = input.IsMouseButtonDown(sf::Mouse::Button::Right);
	mMouseMiddleClick = input.IsMouseButtonDown(sf::Mouse::Button::Middle);

	// So let's update all the key-codes.
	for (int i = 0; i < 101; i++)
	{
		mKeyCodes[i] = input.IsKeyDown(mKeyMaps[i]);
	}
}
예제 #6
0
파일: paddle.cpp 프로젝트: d10p/pong
void Paddle::Update(sf::RenderWindow& app)
{	
	float speed = 0;
	
    // get player input
	if(app.GetInput().IsKeyDown(sf::Key::Up))
	{
		if(Y > 0)
			speed = -defaultSpeed;
	}
	if(app.GetInput().IsKeyDown(sf::Key::Down))
	{
		if(Y + H < screenHeight)
			speed = defaultSpeed;
	}
	
	Y += speed * app.GetFrameTime();
	
	SetPosition(X, Y);
}
예제 #7
0
// Actions joueur
void Player::evolue(sf::RenderWindow& app)
{
    const sf::Input& input = app.GetInput();
    m_frame = app.GetFrameTime();
    // Déplacement à la souris
    if(m_sprite.GetPosition().y > input.GetMouseY()-PLAYER_SIZE/2)
    Move(Player::TOP);
    else if(m_sprite.GetPosition().y < input.GetMouseY()-PLAYER_SIZE/2)
    Move(Player::BOTTOM);
    if(m_sprite.GetPosition().x > input.GetMouseX()-PLAYER_SIZE/2)
    Move(Player::LEFT);
    else if(m_sprite.GetPosition().x < input.GetMouseX()-PLAYER_SIZE/2)
    Move(Player::RIGHT);
}
예제 #8
0
//==============================================================================
void CRocket::DessinerRocket(sf::RenderWindow& AppRocket, sf::Vector2f PositionDuVaisseau)
{
    if (
        (
         (AppRocket.GetInput().IsKeyDown(sf::Key::Space))
         || (AppRocket.GetInput().IsJoystickButtonDown (0, 1))
        )
        && TpsCadenceTirsJoueur.GetElapsedTime () > 0.5f
       )


    {
        TpsCadenceTirsJoueur.Reset ();
        espace_appuye = true;
        CreerNouvelleRocket(PositionDuVaisseau);
    }

    else
    {
        espace_appuye = false;
        espace_gere = false;
    }
}
예제 #9
0
int Splash::Run(sf::RenderWindow &win, sf::VideoMode &vMode)
{
	Event events;
	while(win.IsOpened())
	{
		while(win.GetEvent(events))
		{
			if(events.Type == Event::Closed)
				win.Close();
			if(win.GetInput().IsKeyDown(Key::Space)) return 2;
		}
		if(m_scripter.RunScript(&m_splashBgImg, &m_splashBgSp) == 2) return 2;
		win.Clear();
		win.Draw(m_splashBgSp);
		win.Display();
	}
	return -1;
}
예제 #10
0
void Player::handleInput(sf::RenderWindow& App, float ElapsedTime, std::vector<Object*>& objects, SpatialHash& grid)
{
  if (!isAnimated)
  {
    //Shooting
    if(App.GetInput().IsKeyDown(sf::Key::Space))
      shoot(ElapsedTime);

    //Rage
    if(App.GetInput().IsKeyDown(sf::Key::S))
    {
      enableRage();

      if(rageMode)
      {
        //Kill nearby enemies
        std::vector<int> nearby = grid.getNearby(this);
        for(unsigned int i = 0; i < nearby.size(); ++i)
        {
          int position = nearby[i];

          if(objects[position]->getType() == FOE)
          {
            objects[position]->takeDamage(objects, position, getAttack());
          }
        }
      }
    }

    //Move the sprite
    if(App.GetInput().IsKeyDown(sf::Key::Left))
      move(LEFT, ElapsedTime, objects, grid.getNearby(this));
    if(App.GetInput().IsKeyDown(sf::Key::Right))
      move(RIGHT, ElapsedTime, objects, grid.getNearby(this));
    if(App.GetInput().IsKeyDown(sf::Key::Up))
      move(UP, ElapsedTime, objects, grid.getNearby(this));
    if(App.GetInput().IsKeyDown(sf::Key::Down))
      move(DOWN, ElapsedTime, objects, grid.getNearby(this));
  }
}
예제 #11
0
void MainMenu::ShowMainMenuLabels(sf::RenderWindow & App)
{	
	if(!m_Inited)
	{	
		m_Background.SetImage(gResMng.Get_Image("CONTENT//tlo-test.png"));

		m_SinglePlayerLabel = new sf::String("Single player", LoadContent::GetInstance()->m_font, 50);
		m_SinglePlayerLabel->SetColor(sf::Color::Red);
		m_SinglePlayerLabel->SetPosition(800, 220);
		m_SinglePlayerRect = m_SinglePlayerLabel->GetRect();

		m_MultiPlayerLabel = new sf::String("Multi player", LoadContent::GetInstance()->m_font, 50);
		m_MultiPlayerLabel->SetColor(sf::Color::Red);
		m_MultiPlayerLabel->SetPosition(800, 300);
		m_MultiPlayerRect = m_MultiPlayerLabel->GetRect();

		m_OptionsLabel = new sf::String("Options", LoadContent::GetInstance()->m_font, 50);
		m_OptionsLabel->SetColor(sf::Color::Red);
		m_OptionsLabel->SetPosition(800, 380);
		m_OptionsRect = m_OptionsLabel->GetRect();

		m_ExitGameLabel = new sf::String("Exit Game", LoadContent::GetInstance()->m_font, 50);
		m_ExitGameLabel->SetColor(sf::Color::Red);
		m_ExitGameLabel->SetPosition(800, 460);
		m_ExitGameRect = m_ExitGameLabel->GetRect();

		m_Inited = true;
	}

	const sf::Input& Input = App.GetInput();

	if(m_SinglePlayerRect.Contains(Input.GetMouseX(), Input.GetMouseY()) )
	{
		m_SinglePlayerLabel->SetColor(sf::Color::Green);
	}
	else
	{
		m_SinglePlayerLabel->SetColor(sf::Color::Red);
	}

	if(m_MultiPlayerRect.Contains(Input.GetMouseX(), Input.GetMouseY()) )
	{
		m_MultiPlayerLabel->SetColor(sf::Color::Green);
	}
	else
	{
		m_MultiPlayerLabel->SetColor(sf::Color::Red);
	}

	if(m_OptionsRect.Contains(Input.GetMouseX(), Input.GetMouseY()) )
	{
		m_OptionsLabel->SetColor(sf::Color::Green);
	}
	else
	{
		m_OptionsLabel->SetColor(sf::Color::Red);
	}

	if(m_ExitGameRect.Contains(Input.GetMouseX(), Input.GetMouseY()) )
	{
		m_ExitGameLabel->SetColor(sf::Color::Green);
	}
	else
	{
		m_ExitGameLabel->SetColor(sf::Color::Red);
	}




	App.Draw(*m_SinglePlayerLabel);
	App.Draw(*m_MultiPlayerLabel);
	App.Draw(*m_OptionsLabel);
	App.Draw(*m_ExitGameLabel);
}
예제 #12
0
void Player::Update(sf::RenderWindow & App, class Physic & physic)
{
	if(!m_inited)
		Init(physic);


	const sf::Input & _input = App.GetInput();

	physic.GetPlayer(0)->vel = physic.GetPlayer(0)->body->GetLinearVelocity();
	physic.GetPlayer(0)->rotation = physic.GetPlayer(0)->body->GetAngle();

		if(_input.IsKeyDown(sf::Key::A)) { physic.GetPlayer(0)->rotation += -1.0f * App.GetFrameTime(); physic.GetPlayer(0)->body->SetTransform(physic.GetPlayer(0)->body->GetPosition(), physic.GetPlayer(0)->rotation); /*m_rotationDegree -= 3; m_rotation = 3; m_player.Rotate( (float)m_rotation );*/ } // turn LEFT
		if(_input.IsKeyDown(sf::Key::D)) { physic.GetPlayer(0)->rotation += 1.0f * App.GetFrameTime(); physic.GetPlayer(0)->body->SetTransform(physic.GetPlayer(0)->body->GetPosition(), physic.GetPlayer(0)->rotation); /*m_rotationDegree += 3; m_rotation = -3; m_player.Rotate( (float)m_rotation  );*/ } // turn RIGHT

		if(_input.IsKeyDown(sf::Key::W)) { m_V += 2.00  ;    }
		if(_input.IsKeyDown(sf::Key::S)) { m_V -= 1.00  ;    }
		if(_input.IsKeyDown(sf::Key::Space)) { m_V = 0.0 ;  }

		physic.GetPlayer(0)->body->SetAngularVelocity(0.f);

/*		 
			if(m_clock2.GetElapsedTime() > 1.0f)
			{
				if(_input.IsMouseButtonDown(sf::Mouse::Left))
				{
					Shoot(App);
					m_reload = true;
					m_clock2.Reset();
				}
				m_reload = false;
			}
			else
			{
				m_reload = true;
			}
		
*/
//		UpdateBullets(App);

//		m_mousePozVec.x = _input.GetMouseX();
//		m_mousePozVec.y = _input.GetMouseY();

		m_mousePozVec = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());

		m_xH = m_cannon.GetPosition().x - m_mousePozVec.x;
		m_yH = m_cannon.GetPosition().y - m_mousePozVec.y;
		m_cannonRotation =(float)(atan2(m_yH,m_xH) * 180.f / b2_pi + 180.f);


//		if(physic.GetPlayer(0)->rotation > 359) physic.GetPlayer(0)->rotation = 0;
//		if(physic.GetPlayer(0)->rotation < 0) physic.GetPlayer(0)->rotation = 359;
		

        if( m_V > m_maxPlayerSpeed ) m_V = m_maxPlayerSpeed;
        if( m_V <  m_maxPlayerBackSpeed ) m_V = m_maxPlayerBackSpeed;

		physic.GetPlayer(0)->vel.x = m_V * cos((b2_pi*(physic.GetPlayer(0)->rotation * RADTODEG ))/180.f);
        physic.GetPlayer(0)->vel.y = m_V * sin((b2_pi*(physic.GetPlayer(0)->rotation * RADTODEG ))/180.f);

//		if( m_disVec.x >= 1 || m_disVec.x <= - 1 ) { m_playerPozVec.x += int(m_disVec.x) * App.GetFrameTime(); m_disVec.x = m_disVec.x - int( m_disVec.x ); }
//      if( m_disVec.y >= 1 || m_disVec.y <= - 1 ) { m_playerPozVec.y += int(m_disVec.y) * App.GetFrameTime(); m_disVec.y = m_disVec.y - int( m_disVec.y ); }
		
		physic.GetPlayer(0)->body->SetLinearVelocity(physic.GetPlayer(0)->vel);
		
		m_player.SetPosition( physic.GetPlayer(0)->GetPosition() );
		m_player.SetRotation( -physic.GetPlayer(0)->rotation * RADTODEG );


		m_cannon.SetPosition(m_player.GetPosition());
		m_cannon.SetRotation(-m_cannonRotation);

/*
#pragma region DEBUG INFO
std::ostringstream bufor;
sf::String tdebug;
tdebug.SetFont(LoadContent::GetInstance()->m_font2);
tdebug.SetSize(20);
bufor << "\nFPS = " << _Framerate;
tdebug.SetText(bufor.str());
App.Draw(tdebug);		
#pragma endregion	
*/

		App.Draw(m_player);
		App.Draw(m_cannon);
}
예제 #13
0
SBI gra_screen::Animate(sf::RenderWindow &App)
{
	if (Timer_c.GetElapsedTime()-osttime-korektatime>1)
	{
		korektatime=Timer_c.GetElapsedTime()-osttime;
	}
	osttime=Timer_c.GetElapsedTime()-korektatime;
	for (int i=0;i<obiekty_il;i++)
	{
		(obiekty+i)->ZasTarcie(App.GetFrameTime(),ProgTarcia);
	}
	const sf::Input& Input = App.GetInput();
	if (Input.IsKeyDown(sf::Key::B))
	{
		for (int i=0;i<obiekty_il;i++)
		{
			(obiekty+i)->SetV(0,0);
		}
	}
	for (int i=0; i<gracz_il; i++)
	{
		bool cx=false;
		bool cy=false;
		int przyspGDoc;
		bool czyuderz=(Input.IsKeyDown(gracze_ev[i][(int)Uderz].KeyCode));
		if (czyuderz)
		przyspGDoc=PrzyspGKop;
		else
		przyspGDoc=PrzyspG;
		if (Input.IsKeyDown(gracze_ev[i][(int)Lewo].KeyCode))
		{
			gracze_ob[i].SetVX(gracze_ob[i].GetVX()-App.GetFrameTime()*przyspGDoc);
			cx=true;
		}
		if (Input.IsKeyDown(gracze_ev[i][(int)Prawo].KeyCode))
		{
			gracze_ob[i].SetVX(gracze_ob[i].GetVX()+App.GetFrameTime()*przyspGDoc);
			if (cx)
				cx=false;
			else
				cx=true;
		}
		if (Input.IsKeyDown(gracze_ev[i][(int)Gora].KeyCode))
		{
			gracze_ob[i].SetVY(gracze_ob[i].GetVY()-App.GetFrameTime()*przyspGDoc);
			cy=true;
		}

		if (Input.IsKeyDown(gracze_ev[i][(int)Dol].KeyCode))
		{
			gracze_ob[i].SetVY(gracze_ob[i].GetVY()+App.GetFrameTime()*przyspGDoc);
			if (cy)
				cy=false;
			else
				cy=true;
		}
		if (Input.IsKeyDown(gracze_ev[i][(int)Uderz].KeyCode))
		{
			if (GraczPowLock[i])
			gracze_ob[i].PopV(MaxVGraczNorm);
			else
			gracze_ob[i].PopV(MaxVGraczKop);
		}
		else
		{
			gracze_ob[i].PopV(MaxVGraczNorm);
			GraczPowLock[i]=false;
		}


	}

	/*for (int i=0; i<obiekty_il; i++)
	{
		(obiekty+i)->Animate(App.GetFrameTime(),bg,bd,bl,bp,bramka);
	}
	for (int i=0; i<obiekty_il-1; i++)
		for (int j=i+1; j<obiekty_il; j++)
			if (czy&&(obiekty+i)->ZderzenieAnaliz(App.GetFrameTime(),obiekty+j,bg,bd,bl,bp,bramka))
			{
				cout << "ZDERZENIE!!!";
				czy=true;
			}*/

	double anisum=0;
	double tmp;
	double mintmp=10000000;
	double mini;
	int dodnum1,dodnum2;
    int num1,num2;
	num1=0;
	while(num1!=-1)
	{
		num1=-1;
		num2=-1;
		mini=1000000;
		for (int i=0; i<obiekty_il-1; i++)
			for (int j=i+1; j<obiekty_il; j++)
			{
				tmp=(obiekty+i)->TZderzenia(obiekty+j);
				if (tmp<mintmp)
				{
					mintmp=tmp;
					dodnum1=i;
					dodnum2=j;
				}
				if (tmp<mini&&tmp<=App.GetFrameTime()-anisum)
				{
					cout << "tmp = " << tmp << endl;
					mini=tmp;
					num1=i;
					num2=j;
				}
			}
		mini-=0.000001;
		if (mini<0)
			mini=0;
		if (num1!=-1)
		{
			anisum+=mini;
			for (int i=0; i<obiekty_il; i++)
			{
				(obiekty+i)->Animate(mini,bg,bd,bl,bp,bramka);
			}
			cout << "Przeliczanie zderzenia: " << num1 << " i " << num2 << endl;
			double mocude;
			if (num1==0&&num2>=5&&Input.IsKeyDown(gracze_ev[num2-5][(int)Uderz].KeyCode)&&!GraczPowLock[num2-5])
			{
				mocude=(obiekty+num1)->PrzeliczZderzenie(obiekty+num2,MocKop);
				GraczPowLock[num2-5]=true;
			}
			else
			mocude=(obiekty+num1)->PrzeliczZderzenie(obiekty+num2);
			if (num1==0&&num2>=5)
			{
				if (mocude>10&&(kops_p.GetStatus()==sf::Sound::Stopped||kops_p.GetPlayingOffset()>0.2))
				{
					cout << "KOPNIECIE DZWIEK";
					kops_p.SetVolume(mocude/2);
					kops_p.Play();
				}
			}
		}
	}
	for (int i=0; i<obiekty_il; i++)
	{
		(obiekty+i)->Animate(App.GetFrameTime()-anisum,bg,bd,bl,bp,bramka);
	}
	string tmpek;
	if (mintmp<100000)
	{
		tmpek+="czas do zderzenia: ";
		tmpek+=DoubleToString(mintmp);
		tmpek+=" obiektu: ";
		tmpek+=IntToString(dodnum1);
		tmpek+=" z: ";
		tmpek+=IntToString(dodnum2);
	}
	else
	{
		tmpek="brak zderzen...";
	}
	Techdata.SetText(tmpek);
	string czas;
	if ((int)(Timer_c.GetElapsedTime()-korektatime)/60<10)
		czas+="0";
	czas+=IntToString((int)(Timer_c.GetElapsedTime()-korektatime)/60);
	czas+=":";
	if ((int)(Timer_c.GetElapsedTime()-korektatime)%60<10)
		czas+="0";
	czas+=IntToString((int)(Timer_c.GetElapsedTime()-korektatime)%60);
	Timer_ob1.SetText(czas);
	//Timer_ob2.SetText(czas);
	return SBI();
}
예제 #14
0
void JoyStick(sf::RenderWindow &Window)
{
    float x = Window.GetInput().GetJoystickAxis(0, sf::Joy::AxisPOV);
    std::cout << x << std::endl;
}
예제 #15
0
SourieSfml::SourieSfml(const sf::RenderWindow& render) : inputsfml(render.GetInput())
{

}