本文整理汇总了C++中Snake::get_raw_img_size方法的典型用法代码示例。如果您正苦于以下问题:C++ Snake::get_raw_img_size方法的具体用法?C++ Snake::get_raw_img_size怎么用?C++ Snake::get_raw_img_size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Snake
的用法示例。
在下文中一共展示了Snake::get_raw_img_size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sfml_loop
void sfml_loop(Snake &snake) {
sf::Texture texture;
texture.loadFromMemory(snake.get_raw_img(), snake.get_raw_img_size());
sf::RenderWindow window({ texture.getSize().x, texture.getSize().y },
"Snakes & Flies",
sf::Style::Titlebar | sf::Style::Close);
window.setVerticalSyncEnabled(true);
sf::Sprite sprite;
sprite.setTexture(texture);
unsigned long snake_size = 0;
std::vector<double> xs(snake_size), ys(snake_size);
bool inited = false, play = false;
std::vector<sf::Vertex> snake_scheme;
snake_scheme.push_back(sf::Vertex({ 0, 0 }, sf::Color::Red));
while (window.isOpen()) {
// check all the window's events that were triggered since the last
// iteration of the loop
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
if (event.type == sf::Event::MouseMoved) {
if (!inited) {
snake_scheme.back().position =
sf::Vector2f(sf::Mouse::getPosition(window));
}
}
if (event.type == sf::Event::MouseButtonPressed) {
if (!inited) {
snake_scheme.insert(
snake_scheme.end() - 1,
sf::Vertex(sf::Vector2f(sf::Mouse::getPosition(window)),
sf::Color::Red));
}
}
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Escape) {
window.close();
}
if (event.key.code == sf::Keyboard::Space) {
play = !play;
}
if (event.key.code == sf::Keyboard::Left ||
event.key.code == sf::Keyboard::Right) {
bool direction = event.key.code == sf::Keyboard::Right;
if (!snake.shift_frame(direction)) {
window.close();
}
texture.loadFromMemory(snake.get_raw_img(), snake.get_raw_img_size());
}
}
if (event.type == sf::Event::KeyPressed && snake_scheme.size() > 2) {
if (!inited) {
if (snake.is_closed()) {
snake_scheme.back() = snake_scheme.front();
} else {
snake_scheme.pop_back();
}
int implicit_joints = snake.get_implicit();
if (implicit_joints > 0) {
snake_size = implicit_joints * (snake_scheme.size() - 1) + 1;
} else {
snake_size = snake_scheme.size();
}
xs.resize(snake_size);
ys.resize(snake_size);
if (implicit_joints > 0) {
for (int k = 0; k < snake_scheme.size() - 1; ++k) {
auto x_diff = (snake_scheme[k + 1].position.x -
snake_scheme[k].position.x) /
implicit_joints;
auto y_diff = (snake_scheme[k + 1].position.y -
snake_scheme[k].position.y) /
implicit_joints;
for (int j = 0; j < implicit_joints; ++j) {
xs[k * snake.get_implicit() + j] =
snake_scheme[k].position.x + j * x_diff;
ys[k * snake.get_implicit() + j] =
snake_scheme[k].position.y + j * y_diff;
}
}
}
xs.back() = snake_scheme[snake_scheme.size() - 1].position.x;
ys.back() = snake_scheme[snake_scheme.size() - 1].position.y;
snake_scheme.resize(snake_size, { { 0, 0 }, sf::Color::Red });
snake.set_xs(xs);
snake.set_ys(ys);
snake.set_pentamat();
//.........这里部分代码省略.........