aboutsummaryrefslogtreecommitdiffstats
path: root/examples/shooter
diff options
context:
space:
mode:
Diffstat (limited to 'examples/shooter')
-rw-r--r--examples/shooter/bullet.cpp33
-rw-r--r--examples/shooter/bullet.h24
-rw-r--r--examples/shooter/direction.h11
-rw-r--r--examples/shooter/main.cpp171
-rw-r--r--examples/shooter/player.cpp72
-rw-r--r--examples/shooter/player.h36
6 files changed, 0 insertions, 347 deletions
diff --git a/examples/shooter/bullet.cpp b/examples/shooter/bullet.cpp
deleted file mode 100644
index c589b4db..00000000
--- a/examples/shooter/bullet.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "bullet.h"
-
-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_);
-}
-
-glm::vec4 Bullet::position() const
-{
- return bound_;
-}
diff --git a/examples/shooter/bullet.h b/examples/shooter/bullet.h
deleted file mode 100644
index 19430fda..00000000
--- a/examples/shooter/bullet.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef EXAMPLES_SHOOTER_BULLET_H
-#define EXAMPLES_SHOOTER_BULLET_H
-
-#include <yage/yage.h>
-
-#include "direction.h"
-
-class Bullet : public yage::Drawable
-{
-public:
- Bullet(const glm::vec4 &bound, Direction dir, float speed, float depth = 0.f);
-
- 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
deleted file mode 100644
index 010c6b54..00000000
--- a/examples/shooter/direction.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#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
deleted file mode 100644
index 5d80c350..00000000
--- a/examples/shooter/main.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-#include <yage/yage.h>
-
-#include "bullet.h"
-#include "direction.h"
-#include "player.h"
-
-#include <memory>
-#include <vector>
-
-using std::cout;
-
-int main(int argc, char **argv)
-{
- yage::init();
- yage::Window window;
- window.create("Shooter example", 800, 600);
-
- std::vector<std::unique_ptr<Bullet>> bullets;
-
- 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;
- }
-
- if (window.keyPressed(yage::key::RIGHT)) {
- bullets.push_back(std::make_unique<Bullet>(
- 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<Bullet>(
- 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<Bullet>(
- 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<Bullet>(
- 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]);
-
- camera.update(shader);
-
- window.clearBuffer();
- player.draw(sp);
-
- for (auto &&bullet : bullets) {
- bullet->draw(sp);
- }
-
- sp.render();
-
- window.swapBuffer();
- }
- yage::quit();
-}
diff --git a/examples/shooter/player.cpp b/examples/shooter/player.cpp
deleted file mode 100644
index dab743a9..00000000
--- a/examples/shooter/player.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-#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)
-{
- static int time = 0;
- static int iteration = 0;
- float width = 1.f / static_cast<float>(texture_.x);
- float height = 1.f / static_cast<float>(texture_.y);
-
- switch (action_) {
- case Action::IDLE:
- sp.draw(bound_,
- {width, static_cast<int>(direction_) * height, width, height},
- texture_.id, yage::Colour(255, 255, 255, 255), 1);
- break;
- case Action::MOVING:
- if(time % 15 == 0) {
- iteration = (iteration + 1) % 2;
- }
- sp.draw(bound_,
- {iteration * 2 * width, static_cast<int>(direction_) * height, width, height},
- texture_.id, yage::Colour(255, 255, 255, 255), 1);
- 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;
-}
-
-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
deleted file mode 100644
index 8b5121c5..00000000
--- a/examples/shooter/player.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef EXAMPLE_SHOOTER_PLAYER_H
-#define EXAMPLE_SHOOTER_PLAYER_H
-
-#include <yage/yage.h>
-
-#include "direction.h"
-
-enum class Action {
- IDLE,
- MOVING,
-};
-
-class Player : public yage::Drawable
-{
-public:
- Player(const glm::vec4 &bound, const yage::Texture &texture);
-
- void setTexture(const yage::Texture &texture);
-
- void draw(yage::SpriteBatch &sp);
-
- void move(Direction direction);
- void idle();
- void look(Direction direction);
-
- // simple getters
- glm::vec4 position() const;
-private:
- glm::vec4 bound_;
- yage::Texture texture_;
- Direction direction_;
- Action action_;
- int speed_;
-};
-
-#endif