-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
103 lines (84 loc) · 2.55 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <arqanore/window.h>
#include "arqanore/keyboard.h"
#include "arqanore/sprite.h"
#include "arqanore/renderer.h"
#include "arqanore/exceptions.h"
arqanore::Sprite *sprite;
arqanore::Vector2 position;
arqanore::Vector2 scale;
int frame_hor = 0;
int frame_vert = 0;
double frame_time = 0;
int direction = 2;
void on_open(arqanore::Window *window) {
try {
arqanore::Image icon("assets/icon.png");
window->set_icon(icon);
sprite = new arqanore::Sprite("assets/sprites/player.png", 16, 16);
position = arqanore::Vector2(64, 64);
scale = arqanore::Vector2(4, 4);
frame_hor = direction * 4;
} catch (arqanore::ArqanoreException &ex) {
std::cerr << ex.what() << std::endl;
window->close();
}
}
void on_close(arqanore::Window *window) {
delete sprite;
}
void on_update(arqanore::Window *window, double dt) {
auto speed = dt * 100;
if (arqanore::Keyboard::key_pressed(arqanore::Keys::ESCAPE)) {
window->close();
}
if (frame_time < 16) {
frame_time += dt * 100;
} else {
frame_time = 0;
frame_hor++;
}
if (frame_hor >= direction * 4 + 4) {
frame_hor = direction * 4;
}
if (frame_hor < direction * 4) {
frame_hor = direction * 4;
}
if (direction == 1) position.y -= speed;
if (direction == 0) position.y += speed;
if (direction == 2) position.x += speed;
if (direction == 3) position.x -= speed;
if (direction == 2 && position.x >= window->get_width() - 128) {
direction = 0;
position.x = window->get_width() - 128;
}
if (direction == 0 && position.y >= window->get_height() - 128) {
direction = 3;
position.y = window->get_height() - 128;
}
if (direction == 3 && position.x < 128) {
direction = 1;
position.x = 128;
}
if (direction == 1 && position.y < 128) {
direction = 2;
position.y = 128;
}
}
void on_render(arqanore::Window *window) {
try {
arqanore::Renderer::render_sprite(window, sprite, position, scale, arqanore::Vector2::ZERO, 0, frame_hor, frame_vert, false, false, arqanore::Color::WHITE);
} catch (arqanore::ArqanoreException &ex) {
std::cerr << ex.what() << std::endl;
window->close();
}
}
int main() {
auto window = arqanore::Window(1440, 768, "Arqanore - Sprites");
window.on_open(on_open);
window.on_close(on_close);
window.on_update(on_update);
window.on_render(on_render);
window.open(false, true, true);
return 0;
}