本文整理汇总了C++中Paddle::update方法的典型用法代码示例。如果您正苦于以下问题:C++ Paddle::update方法的具体用法?C++ Paddle::update怎么用?C++ Paddle::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Paddle
的用法示例。
在下文中一共展示了Paddle::update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
// Il metodo `run` farà partire il game loop.
void run()
{
while(true)
{
window.clear(sf::Color::Black);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) break;
// Il tasto `P` gestirà la pausa.
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::P))
{
// Prima di mettere/togliere la pausa, controlliamo
// se il tasto era già stato pressato.
if(!pausePressedLastFrame)
{
if(state == State::Paused)
state = State::InProgress;
else if(state == State::InProgress)
state = State::Paused;
}
pausePressedLastFrame = true;
}
else
pausePressedLastFrame = false;
// Il tasto `R` farà ricominciare il gioco.
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::R)) restart();
// Se il gioco è in pausa, non aggiorneremo i game
// object.
if(state != State::Paused)
{
ball.update();
paddle.update();
for(auto& brick : bricks)
{
brick.update();
solveBrickBallCollision(brick, ball);
}
bricks.erase(
std::remove_if(std::begin(bricks), std::end(bricks),
[](const auto& mBrick)
{
return mBrick.destroyed;
}),
std::end(bricks));
solvePaddleBallCollision(paddle, ball);
}
ball.draw(window);
paddle.draw(window);
for(auto& brick : bricks) brick.draw(window);
window.display();
}
}
示例2: main
int main () {
Ball ball{windowWidth / 2, windowHeight /2 };
Paddle paddle {windowWidth / 2, windowHeight - 50};
std::vector<Brick> bricks;
for(int iX{0}; iX < countBlocksX; ++iX)
for(int iY{0}; iY < countBlocksY; ++iY)
bricks.emplace_back((iX + 1) * (blockWidth + 3) +22,
(iY + 2) * (blockHeight +3));
// { // Equivalente a emplace_back : C++11
// Brick umBrick{(iX + 1) * (blockWidth + 3) +22,
// (iY + 2) * (blockHeight +3)};
// bricks.push_back(umBrick);
// }
sf::RenderWindow window({windowWidth,windowHeight}, "Arkanoid - 5");
window.setFramerateLimit(60);
// Loop do jogo
while (window.isOpen()) {
// Monitora os eventos e reage de acordo
sf::Event event;
while(window.pollEvent(event)) {
if(event.type == sf::Event::Closed || (event.type == sf::Event::KeyPressed
&& event.key.code == sf::Keyboard::Key::Escape)) {
window.close();
}
}
// Limpa a tela
window.clear(sf::Color::Black);
// Renderiza os objetos na tela
ball.update();
paddle.update();
// testa colisão a cada ciclo
testCollision(paddle, ball);
// remove blocos colididos
bricks.erase(
remove_if(
begin(bricks),
end(bricks),
[](const Brick& mBrick){ return mBrick.destroyed; }),
end(bricks)
);
// testa colisões entre bola e blocos
for(auto& brick : bricks) testCollision(brick,ball);
window.draw(ball.shape);
window.draw(paddle.shape);
// for(int i{0}; i < bricks.size(); ++i) // Equivalente
for(auto& brick : bricks) // C++11
window.draw(brick.shape);
// Exibe os conteúdos da tela
window.display();
}
return EXIT_SUCCESS;
}
示例3: main
int main( void )
{
Setup setup;
setup.init();
window = setup.get_window();
draw_paddle(paddle.get_x()-paddle_size_x/2,
paddle.get_y()+paddle_size_y/2,
paddle_size_x,
paddle_size_y);
draw_ball();
vector<Brick> bricks = get_bricks();
draw_bricks(bricks);
init_hexagon();
draw_hexagon();
// Ensure we can capture the escape key being pressed below
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
// Dark blue background
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
glfwSetKeyCallback(window, keyCalback);
GLuint VertexArrayID;
glGenVertexArrays(1, &VertexArrayID);
glBindVertexArray(VertexArrayID);
// Create and compile our GLSL program from the shaders
GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" );
OpenGl opengl(programID);
GLuint vertexbuffer;
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*g_vertex_buffer_data.size(), &g_vertex_buffer_data[0], GL_DYNAMIC_DRAW);
do{
glClear(GL_COLOR_BUFFER_BIT);
if(ball.get_y() < -1.0){
ball.set_y(0.0);
}
// Use our shader
glUseProgram(programID);
// Draw nothing, see you in tutorial 2 !
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
opengl.draw_hexagon(g_hexagonOffset);
ball.update();
paddle.update(666);
collision.test_collision(paddle, ball, ball_velocity);
for(auto& brick : bricks) test_collision(brick, ball);
// Ball
opengl.draw_ball(ball.get_x(), ball.get_y());
// Paddle
opengl.draw_paddle(paddle.get_x());
opengl.draw_bricks(bricks);
// Swap buffers
glDisableVertexAttribArray(0);
glfwSwapBuffers(window);
glfwPollEvents();
} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0 );
// Close OpenGL window and terminate GLFW
glfwTerminate();
//.........这里部分代码省略.........