#include <iostream>
#include <smk/Color.hpp>
#include <smk/Sprite.hpp>
#include <smk/Texture.hpp>
#include <smk/Window.hpp>
#include "asset.hpp"
struct Player {
public:
Player(int x, int y) : x(x), y(y) {}
void Step() {
x += dx;
if (x >= 640 - texture.
width() / 2)
dx = -dx;
if (x <= texture.
width() / 2)
dx = -dx;
}
sprite.
SetScale(dx > 0 ? 1.0 : -1.0, 1.0);
}
private:
int x;
int y;
int dx = 1.0;
};
int main() {
auto window =
smk::Window(640, 32 * 3,
"smk/example/sprite");
std::vector<Player> players = {Player(320, 0), Player(32, 32),
Player(624, 64)};
window.ExecuteMainLoop([&] {
window.PoolEvents();
for (auto& player : players)
player.Step();
for (auto& player : players)
player.Draw(window);
window.Display();
});
return EXIT_SUCCESS;
}
virtual void Draw(const Drawable &drawable)
Draw on the surface.
A window. You can draw objects on the window.
const glm::vec4 Black
Black.
int width() const
Access the width of the texture.