From 022a4bdd81332ce67d799be6a06afb42ae45ac2e Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Mon, 25 Dec 2017 12:27:32 +0000 Subject: [Build] Added examples and improved build for them. --- examples/shooter/main.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/shooter/main.cpp (limited to 'examples/shooter') diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp new file mode 100644 index 00000000..d28af83e --- /dev/null +++ b/examples/shooter/main.cpp @@ -0,0 +1,22 @@ +#include + +#include + +using std::cout; + +int main(int argc, char** argv) +{ + cout << "Starting Shooter example...\n"; + + yage::Window window; + window.create("Shooter example", 1920, 1080); + + while(!window.shouldClose()) { + window.pollEvents(); + window.clearBuffer(); + + + + window.swapBuffer(); + } +} -- cgit From 354d7df4d2779ed7391701d1ef4344e959b64582 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 27 Dec 2017 19:21:12 +0000 Subject: [Broken] Texture is black. --- examples/shooter/main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'examples/shooter') diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index d28af83e..fe98f300 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -1,22 +1,60 @@ #include +#include "glad/glad.h" + #include using std::cout; -int main(int argc, char** argv) +int main(int argc, char **argv) { cout << "Starting Shooter example...\n"; yage::Window window; - window.create("Shooter example", 1920, 1080); + window.create("Shooter example", 800, 600); + + yage::Shader shader("examples/resources/colourshader.vert", + "examples/resources/colourshader.frag"); + + GLfloat vertices[] = { + 0.0f, 0.5f, 1.f, 0.f, 0.f, // Vertex 1 (X, Y, R, G, B) + 0.5f, -0.5f, 0.f, 1.f, 0.f, // Vertex 2 (X, Y, R, G, B) + -0.5f, -0.5f, 0.f, 0.f, 1.f, // Vertex 3 (X, Y, R, G, B) + }; + + // create vertex array + GLuint rect_vao, rect_vbo; + + // bind vertex array object + glGenVertexArrays(1, &rect_vao); + glBindVertexArray(rect_vao); + + // bind vertex buffer object + glGenBuffers(1, &rect_vbo); + glBindBuffer(GL_ARRAY_BUFFER, rect_vbo); - while(!window.shouldClose()) { + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + shader.use(); + + // enable vertex attribute arrays + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + + // set the vertex attribute pointers + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), + (void *)(2 * sizeof(GLfloat))); + + while (!window.shouldClose()) { window.pollEvents(); window.clearBuffer(); - + glDrawArrays(GL_TRIANGLES, 0, 3); window.swapBuffer(); } + + glDeleteBuffers(1, &rect_vbo); + + glDeleteVertexArrays(1, &rect_vao); } -- cgit From 5c1a57b3672ec1e0777d8d0878c6a7ae93ebfdca Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 30 Dec 2017 16:07:41 +0000 Subject: [Code] Fixed spritebatch and optimised it. --- examples/shooter/main.cpp | 43 ++----------------------------------------- 1 file changed, 2 insertions(+), 41 deletions(-) (limited to 'examples/shooter') diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index fe98f300..12cf218d 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -2,59 +2,20 @@ #include "glad/glad.h" -#include - using std::cout; int main(int argc, char **argv) { - cout << "Starting Shooter example...\n"; - yage::Window window; window.create("Shooter example", 800, 600); - yage::Shader shader("examples/resources/colourshader.vert", - "examples/resources/colourshader.frag"); - - GLfloat vertices[] = { - 0.0f, 0.5f, 1.f, 0.f, 0.f, // Vertex 1 (X, Y, R, G, B) - 0.5f, -0.5f, 0.f, 1.f, 0.f, // Vertex 2 (X, Y, R, G, B) - -0.5f, -0.5f, 0.f, 0.f, 1.f, // Vertex 3 (X, Y, R, G, B) - }; - - // create vertex array - GLuint rect_vao, rect_vbo; - - // bind vertex array object - glGenVertexArrays(1, &rect_vao); - glBindVertexArray(rect_vao); - - // bind vertex buffer object - glGenBuffers(1, &rect_vbo); - glBindBuffer(GL_ARRAY_BUFFER, rect_vbo); - - glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); - shader.use(); - - // enable vertex attribute arrays - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - - // set the vertex attribute pointers - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0); - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), - (void *)(2 * sizeof(GLfloat))); + yage::Shader shader("examples/resources/textureshader.vert", + "examples/resources/textureshader.frag"); while (!window.shouldClose()) { window.pollEvents(); window.clearBuffer(); - glDrawArrays(GL_TRIANGLES, 0, 3); - window.swapBuffer(); } - - glDeleteBuffers(1, &rect_vbo); - - glDeleteVertexArrays(1, &rect_vao); } -- cgit From 34908f108ad7c2ee6cff96491a0bc40381477424 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 31 Dec 2017 18:00:01 +0000 Subject: [Test] Benchmarking the engine and trying to optimize. --- examples/shooter/main.cpp | 108 +++++++++++++++++++++++++++++++++++++++++++- examples/shooter/player.cpp | 62 +++++++++++++++++++++++++ examples/shooter/player.h | 37 +++++++++++++++ 3 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 examples/shooter/player.cpp create mode 100644 examples/shooter/player.h (limited to 'examples/shooter') 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 -#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 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 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 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 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(); } diff --git a/examples/shooter/player.cpp b/examples/shooter/player.cpp new file mode 100644 index 00000000..2d0148e6 --- /dev/null +++ b/examples/shooter/player.cpp @@ -0,0 +1,62 @@ +#include "player.h" + +Player::Player(const glm::vec4 &bound, const yage::Texture &texture) + : bound_(bound), texture_(texture), direction_(Direction::DOWN), + action_(Action::IDLE), speed_(4) +{ +} + +void Player::setTexture(const yage::Texture &texture) { + texture_ = texture; +} + +void Player::draw(yage::SpriteBatch &sp) const +{ + static int time = 0; + static int iteration = 0; + float width = 1.f / static_cast(texture_.x); + float height = 1.f / static_cast(texture_.y); + + switch (action_) { + case Action::IDLE: + sp.draw(bound_, + {width, static_cast(direction_) * height, width, height}, + texture_.id, yage::Colour(255, 255, 255, 255), 0); + break; + case Action::MOVING: + if(time % 15 == 0) { + iteration = (iteration + 1) % 2; + } + sp.draw(bound_, + {iteration * 2 * width, static_cast(direction_) * height, width, height}, + texture_.id, yage::Colour(255, 255, 255, 255), 0); + time = (time + 1) % 59; + break; + } +} + +void Player::move(Direction direction) +{ + direction_ = direction; + action_ = Action::MOVING; + + switch (direction_) { + case Direction::LEFT: + bound_.x -= speed_; + break; + case Direction::DOWN: + bound_.y -= speed_; + break; + case Direction::RIGHT: + bound_.x += speed_; + break; + case Direction::UP: + bound_.y += speed_; + break; + } +} + +void Player::idle() +{ + action_ = Action::IDLE; +} diff --git a/examples/shooter/player.h b/examples/shooter/player.h new file mode 100644 index 00000000..72af7c34 --- /dev/null +++ b/examples/shooter/player.h @@ -0,0 +1,37 @@ +#ifndef EXAMPLE_SHOOTER_PLAYER_H +#define EXAMPLE_SHOOTER_PLAYER_H + +#include "yage/yage.h" + +enum class Direction { + LEFT, + DOWN, + RIGHT, + UP, +}; + +enum class Action { + IDLE, + MOVING, +}; + +class Player +{ +public: + Player(const glm::vec4 &bound, const yage::Texture &texture); + + void setTexture(const yage::Texture &texture); + + void draw(yage::SpriteBatch &sp) const; + + void move(Direction direction); + void idle(); +private: + glm::vec4 bound_; + yage::Texture texture_; + Direction direction_; + Action action_; + int speed_; +}; + +#endif -- cgit From 86e4aa6265ade205aba94494a7a31a83b5686387 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 3 Jan 2018 13:26:37 +0000 Subject: [Engine] [Example] Reenabled vsync and working on example. --- examples/shooter/bullet.cpp | 8 ++++++++ examples/shooter/bullet.h | 15 +++++++++++++++ examples/shooter/main.cpp | 3 +++ 3 files changed, 26 insertions(+) create mode 100644 examples/shooter/bullet.cpp create mode 100644 examples/shooter/bullet.h (limited to 'examples/shooter') diff --git a/examples/shooter/bullet.cpp b/examples/shooter/bullet.cpp new file mode 100644 index 00000000..55ce3f6e --- /dev/null +++ b/examples/shooter/bullet.cpp @@ -0,0 +1,8 @@ +#include "bullet.h" + +Bullet::Bullet(const glm::vec4 &bound) : bound_(bound) {} + +void Bullet::draw(yage::SpriteBatch &sp) const +{ + sp.draw(bound_, {0, 0, 1, 1}, yage::ResourceManager::getTexture("examples/resources/bullet.png").id, yage::Colour(255, 255, 255, 255), 0); +} diff --git a/examples/shooter/bullet.h b/examples/shooter/bullet.h new file mode 100644 index 00000000..37ea52ca --- /dev/null +++ b/examples/shooter/bullet.h @@ -0,0 +1,15 @@ +#ifndef EXAMPLES_SHOOTER_BULLET_H +#define EXAMPLES_SHOOTER_BULLET_H + +#include + +class Bullet { +public: + Bullet(const glm::vec4 &bound); + + void draw(yage::SpriteBatch &sp) const; +private: + glm::vec4 bound_; +}; + +#endif diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index d2727877..9a8d22d0 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -1,6 +1,7 @@ #include #include "player.h" +#include "bullet.h" using std::cout; @@ -63,6 +64,7 @@ int main(int argc, char **argv) auto textures = male_l; Player player({400, 300, 48 * 2, 64 * 2}, textures.front()); + Bullet bullet({400, 300, 25, 25}); while (!window.shouldClose()) { window.pollEvents(); @@ -120,6 +122,7 @@ int main(int argc, char **argv) window.clearBuffer(); player.draw(sp); + bullet.draw(sp); sp.render(); window.swapBuffer(); -- cgit From a47649786fb94684c415b230669fbf5343cb7c5d Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 3 Jan 2018 13:57:51 +0000 Subject: [Engine] [Example] Added simple bullets that don't move --- examples/shooter/bullet.h | 4 +++- examples/shooter/main.cpp | 23 ++++++++++++++++++++--- examples/shooter/player.cpp | 5 +++++ examples/shooter/player.h | 5 ++++- 4 files changed, 32 insertions(+), 5 deletions(-) (limited to 'examples/shooter') diff --git a/examples/shooter/bullet.h b/examples/shooter/bullet.h index 37ea52ca..1d372af1 100644 --- a/examples/shooter/bullet.h +++ b/examples/shooter/bullet.h @@ -3,11 +3,13 @@ #include -class Bullet { +class Bullet : public yage::Drawable +{ public: Bullet(const glm::vec4 &bound); void draw(yage::SpriteBatch &sp) const; + private: glm::vec4 bound_; }; diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index 9a8d22d0..c63c0cab 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -1,7 +1,10 @@ #include -#include "player.h" #include "bullet.h" +#include "player.h" + +#include +#include using std::cout; @@ -10,6 +13,8 @@ int main(int argc, char **argv) yage::Window window; window.create("Shooter example", 800, 600); + std::vector> objects; + yage::Shader shader("examples/resources/textureshader.vert", "examples/resources/textureshader.frag"); @@ -64,7 +69,7 @@ int main(int argc, char **argv) auto textures = male_l; Player player({400, 300, 48 * 2, 64 * 2}, textures.front()); - Bullet bullet({400, 300, 25, 25}); + objects.push_back(std::make_unique(glm::vec4(400, 300, 25, 25))); while (!window.shouldClose()) { window.pollEvents(); @@ -116,13 +121,25 @@ int main(int argc, char **argv) c_pressed = false; } + if (window.keyPressed(yage::key::RIGHT)) { + objects.push_back(std::make_unique(glm::vec4(player.position().x, player.position().y, 25, 25))); + } else if (window.keyPressed(yage::key::DOWN)) { + + } else if (window.keyPressed(yage::key::LEFT)) { + } else if (window.keyPressed(yage::key::UP)) { + } + player.setTexture(textures[i]); camera.update(shader); window.clearBuffer(); player.draw(sp); - bullet.draw(sp); + + for(auto &&object : objects) { + object->draw(sp); + } + sp.render(); window.swapBuffer(); diff --git a/examples/shooter/player.cpp b/examples/shooter/player.cpp index 2d0148e6..b2b85cfd 100644 --- a/examples/shooter/player.cpp +++ b/examples/shooter/player.cpp @@ -60,3 +60,8 @@ void Player::idle() { action_ = Action::IDLE; } + +glm::vec4 Player::position() const +{ + return bound_; +} diff --git a/examples/shooter/player.h b/examples/shooter/player.h index 72af7c34..b8042e71 100644 --- a/examples/shooter/player.h +++ b/examples/shooter/player.h @@ -15,7 +15,7 @@ enum class Action { MOVING, }; -class Player +class Player : public yage::Drawable { public: Player(const glm::vec4 &bound, const yage::Texture &texture); @@ -26,6 +26,9 @@ public: void move(Direction direction); void idle(); + + // simple getters + glm::vec4 position() const; private: glm::vec4 bound_; yage::Texture texture_; -- cgit From 7b95e3a9eacf296f215c73e5d8ad9090a24adb20 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 4 Jan 2018 21:36:30 +0000 Subject: [Engine] Now using stb_image to laod all kinds of textures. --- examples/shooter/bullet.cpp | 31 ++++++++++++++++++++++++++++--- examples/shooter/bullet.h | 11 +++++++++-- examples/shooter/direction.h | 11 +++++++++++ examples/shooter/main.cpp | 36 +++++++++++++++++++++++++++++------- examples/shooter/player.cpp | 11 ++++++++--- examples/shooter/player.h | 12 ++++-------- 6 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 examples/shooter/direction.h (limited to 'examples/shooter') diff --git a/examples/shooter/bullet.cpp b/examples/shooter/bullet.cpp index 55ce3f6e..c589b4db 100644 --- a/examples/shooter/bullet.cpp +++ b/examples/shooter/bullet.cpp @@ -1,8 +1,33 @@ #include "bullet.h" -Bullet::Bullet(const glm::vec4 &bound) : bound_(bound) {} +Bullet::Bullet(const glm::vec4 &bound, Direction dir, float speed, float depth) + : bound_(bound), dir_(dir), speed_(speed), depth_(depth) +{ +} + +void Bullet::draw(yage::SpriteBatch &sp) +{ + switch(dir_) { + case Direction::UP: + bound_.y += speed_; + break; + case Direction::DOWN: + bound_.y -= speed_; + break; + case Direction::LEFT: + bound_.x -= speed_; + break; + case Direction::RIGHT: + bound_.x += speed_; + break; + } + sp.draw( + bound_, {0, 0, 1, 1}, + yage::ResourceManager::getTexture("examples/resources/bullet.png").id, + yage::Colour(255, 255, 255, 255), depth_); +} -void Bullet::draw(yage::SpriteBatch &sp) const +glm::vec4 Bullet::position() const { - sp.draw(bound_, {0, 0, 1, 1}, yage::ResourceManager::getTexture("examples/resources/bullet.png").id, yage::Colour(255, 255, 255, 255), 0); + return bound_; } diff --git a/examples/shooter/bullet.h b/examples/shooter/bullet.h index 1d372af1..19430fda 100644 --- a/examples/shooter/bullet.h +++ b/examples/shooter/bullet.h @@ -3,15 +3,22 @@ #include +#include "direction.h" + class Bullet : public yage::Drawable { public: - Bullet(const glm::vec4 &bound); + Bullet(const glm::vec4 &bound, Direction dir, float speed, float depth = 0.f); - void draw(yage::SpriteBatch &sp) const; + void draw(yage::SpriteBatch &sp); + // getters + glm::vec4 position() const; private: glm::vec4 bound_; + Direction dir_; + float speed_; + float depth_; }; #endif diff --git a/examples/shooter/direction.h b/examples/shooter/direction.h new file mode 100644 index 00000000..010c6b54 --- /dev/null +++ b/examples/shooter/direction.h @@ -0,0 +1,11 @@ +#ifndef EXAMPLES_SHOOTER_DIRECTION_H +#define EXAMPLES_SHOOTER_DIRECTION_H + +enum class Direction { + LEFT, + DOWN, + RIGHT, + UP, +}; + +#endif diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index c63c0cab..e38bf53b 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -1,10 +1,11 @@ #include #include "bullet.h" +#include "direction.h" #include "player.h" -#include #include +#include using std::cout; @@ -13,7 +14,7 @@ int main(int argc, char **argv) yage::Window window; window.create("Shooter example", 800, 600); - std::vector> objects; + std::vector> bullets; yage::Shader shader("examples/resources/textureshader.vert", "examples/resources/textureshader.frag"); @@ -69,7 +70,6 @@ int main(int argc, char **argv) auto textures = male_l; Player player({400, 300, 48 * 2, 64 * 2}, textures.front()); - objects.push_back(std::make_unique(glm::vec4(400, 300, 25, 25))); while (!window.shouldClose()) { window.pollEvents(); @@ -122,11 +122,33 @@ int main(int argc, char **argv) } if (window.keyPressed(yage::key::RIGHT)) { - objects.push_back(std::make_unique(glm::vec4(player.position().x, player.position().y, 25, 25))); + bullets.push_back(std::make_unique( + glm::vec4(player.position().x + player.position().z / 2.f, + player.position().y + player.position().w / 2.f, 25, + 25), + Direction::RIGHT, 10.f)); + player.look(Direction::RIGHT); } else if (window.keyPressed(yage::key::DOWN)) { - + bullets.push_back(std::make_unique( + glm::vec4(player.position().x + player.position().z / 2.f, + player.position().y + player.position().w / 2.f, 25, + 25), + Direction::DOWN, 10.f, 2)); + player.look(Direction::DOWN); } else if (window.keyPressed(yage::key::LEFT)) { + bullets.push_back(std::make_unique( + glm::vec4(player.position().x + player.position().z / 2.f, + player.position().y + player.position().w / 2.f, 25, + 25), + Direction::LEFT, 10.f, 2)); + player.look(Direction::LEFT); } else if (window.keyPressed(yage::key::UP)) { + bullets.push_back(std::make_unique( + glm::vec4(player.position().x + player.position().z / 2.f, + player.position().y + player.position().w / 2.f, 25, + 25), + Direction::UP, 10.f)); + player.look(Direction::UP); } player.setTexture(textures[i]); @@ -136,8 +158,8 @@ int main(int argc, char **argv) window.clearBuffer(); player.draw(sp); - for(auto &&object : objects) { - object->draw(sp); + for (auto &&bullet : bullets) { + bullet->draw(sp); } sp.render(); diff --git a/examples/shooter/player.cpp b/examples/shooter/player.cpp index b2b85cfd..dab743a9 100644 --- a/examples/shooter/player.cpp +++ b/examples/shooter/player.cpp @@ -10,7 +10,7 @@ void Player::setTexture(const yage::Texture &texture) { texture_ = texture; } -void Player::draw(yage::SpriteBatch &sp) const +void Player::draw(yage::SpriteBatch &sp) { static int time = 0; static int iteration = 0; @@ -21,7 +21,7 @@ void Player::draw(yage::SpriteBatch &sp) const case Action::IDLE: sp.draw(bound_, {width, static_cast(direction_) * height, width, height}, - texture_.id, yage::Colour(255, 255, 255, 255), 0); + texture_.id, yage::Colour(255, 255, 255, 255), 1); break; case Action::MOVING: if(time % 15 == 0) { @@ -29,7 +29,7 @@ void Player::draw(yage::SpriteBatch &sp) const } sp.draw(bound_, {iteration * 2 * width, static_cast(direction_) * height, width, height}, - texture_.id, yage::Colour(255, 255, 255, 255), 0); + texture_.id, yage::Colour(255, 255, 255, 255), 1); time = (time + 1) % 59; break; } @@ -61,6 +61,11 @@ void Player::idle() action_ = Action::IDLE; } +void Player::look(Direction direction) +{ + direction_ = direction; +} + glm::vec4 Player::position() const { return bound_; diff --git a/examples/shooter/player.h b/examples/shooter/player.h index b8042e71..8b5121c5 100644 --- a/examples/shooter/player.h +++ b/examples/shooter/player.h @@ -1,14 +1,9 @@ #ifndef EXAMPLE_SHOOTER_PLAYER_H #define EXAMPLE_SHOOTER_PLAYER_H -#include "yage/yage.h" +#include -enum class Direction { - LEFT, - DOWN, - RIGHT, - UP, -}; +#include "direction.h" enum class Action { IDLE, @@ -22,10 +17,11 @@ public: void setTexture(const yage::Texture &texture); - void draw(yage::SpriteBatch &sp) const; + void draw(yage::SpriteBatch &sp); void move(Direction direction); void idle(); + void look(Direction direction); // simple getters glm::vec4 position() const; -- cgit