aboutsummaryrefslogtreecommitdiffstats
path: root/examples/shooter/main.cpp
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-12-31 18:00:01 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-12-31 18:00:01 +0000
commit34908f108ad7c2ee6cff96491a0bc40381477424 (patch)
treef58c6bdde485d07a7136f78055240bab923bd4a6 /examples/shooter/main.cpp
parent943e3a5bc98ebcc2aa1b1d576700f7c4010c143c (diff)
downloadYAGE-34908f108ad7c2ee6cff96491a0bc40381477424.tar.gz
YAGE-34908f108ad7c2ee6cff96491a0bc40381477424.zip
[Test] Benchmarking the engine and trying to optimize.
Diffstat (limited to 'examples/shooter/main.cpp')
-rw-r--r--examples/shooter/main.cpp108
1 files changed, 107 insertions, 1 deletions
diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp
index 12cf218d..d2727877 100644
--- a/examples/shooter/main.cpp
+++ b/examples/shooter/main.cpp
@@ -1,6 +1,6 @@
#include <yage/yage.h>
-#include "glad/glad.h"
+#include "player.h"
using std::cout;
@@ -12,9 +12,115 @@ int main(int argc, char **argv)
yage::Shader shader("examples/resources/textureshader.vert",
"examples/resources/textureshader.frag");
+ std::vector<yage::Texture> male_l = {
+ yage::ResourceManager::getTexture("examples/resources/fighter_ml.png",
+ 3, 4),
+ yage::ResourceManager::getTexture("examples/resources/ranger_ml.png", 3,
+ 4),
+ yage::ResourceManager::getTexture("examples/resources/mage_ml.png", 3,
+ 4),
+ yage::ResourceManager::getTexture("examples/resources/healer_ml.png", 3,
+ 4)};
+ std::vector<yage::Texture> female_l = {
+ yage::ResourceManager::getTexture("examples/resources/fighter_fl.png",
+ 3, 4),
+ yage::ResourceManager::getTexture("examples/resources/ranger_fl.png", 3,
+ 4),
+ yage::ResourceManager::getTexture("examples/resources/mage_fl.png", 3,
+ 4),
+ yage::ResourceManager::getTexture("examples/resources/healer_fl.png", 3,
+ 4)};
+ std::vector<yage::Texture> male_d = {
+ yage::ResourceManager::getTexture("examples/resources/fighter_md.png",
+ 3, 4),
+ yage::ResourceManager::getTexture("examples/resources/ranger_md.png", 3,
+ 4),
+ yage::ResourceManager::getTexture("examples/resources/mage_md.png", 3,
+ 4),
+ yage::ResourceManager::getTexture("examples/resources/healer_md.png", 3,
+ 4)};
+ std::vector<yage::Texture> female_d = {
+ yage::ResourceManager::getTexture("examples/resources/fighter_fd.png",
+ 3, 4),
+ yage::ResourceManager::getTexture("examples/resources/ranger_fd.png", 3,
+ 4),
+ yage::ResourceManager::getTexture("examples/resources/mage_fd.png", 3,
+ 4),
+ yage::ResourceManager::getTexture("examples/resources/healer_fd.png", 3,
+ 4)};
+
+ yage::SpriteBatch sp;
+ yage::Camera camera(800, 600);
+
+ int i = 0;
+ int j = 0;
+ bool space_pressed = false;
+ bool c_pressed = false;
+
+ shader.use();
+ shader.setUniform("texture_sampler", 0);
+
+ auto textures = male_l;
+
+ Player player({400, 300, 48 * 2, 64 * 2}, textures.front());
+
while (!window.shouldClose()) {
window.pollEvents();
+
+ if (window.keyPressed(yage::key::D)) {
+ player.move(Direction::RIGHT);
+ }
+ if (window.keyPressed(yage::key::S)) {
+ player.move(Direction::DOWN);
+ }
+ if (window.keyPressed(yage::key::A)) {
+ player.move(Direction::LEFT);
+ }
+ if (window.keyPressed(yage::key::W)) {
+ player.move(Direction::UP);
+ }
+ if (!window.keyPressed(yage::key::D) &&
+ !window.keyPressed(yage::key::S) &&
+ !window.keyPressed(yage::key::A) &&
+ !window.keyPressed(yage::key::W)) {
+ player.idle();
+ }
+ if (window.keyPressed(yage::key::SPACE) && !space_pressed) {
+ space_pressed = true;
+ i = (i + 1) % textures.size();
+ }
+ if (!window.keyPressed(yage::key::SPACE)) {
+ space_pressed = false;
+ }
+ if (window.keyPressed(yage::key::C) && !c_pressed) {
+ c_pressed = true;
+ j = (j + 1) % 4;
+ switch (j) {
+ case 0:
+ textures = male_l;
+ break;
+ case 1:
+ textures = male_d;
+ break;
+ case 2:
+ textures = female_l;
+ break;
+ case 3:
+ textures = female_d;
+ break;
+ }
+ }
+ if (!window.keyPressed(yage::key::C)) {
+ c_pressed = false;
+ }
+
+ player.setTexture(textures[i]);
+
+ camera.update(shader);
+
window.clearBuffer();
+ player.draw(sp);
+ sp.render();
window.swapBuffer();
}