本文整理汇总了C++中sf::RenderWindow::GetInput方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderWindow::GetInput方法的具体用法?C++ RenderWindow::GetInput怎么用?C++ RenderWindow::GetInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::RenderWindow
的用法示例。
在下文中一共展示了RenderWindow::GetInput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AfficherVaisseau
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: Controls
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: MouseClick
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: displayItems
//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: RunIteration
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: Update
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: evolue
// 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: DessinerRocket
//==============================================================================
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: Run
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: handleInput
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: ShowMainMenuLabels
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: Update
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: Animate
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);
//.........这里部分代码省略.........
示例14: JoyStick
void JoyStick(sf::RenderWindow &Window)
{
float x = Window.GetInput().GetJoystickAxis(0, sf::Joy::AxisPOV);
std::cout << x << std::endl;
}
示例15: inputsfml
SourieSfml::SourieSfml(const sf::RenderWindow& render) : inputsfml(render.GetInput())
{
}