diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2018-05-19 15:15:20 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2018-05-19 15:15:20 +0100 |
commit | a8de6cb5593e3d6347393eb4c144c9cc22a470d8 (patch) | |
tree | c92063014bb76356acd09a2231e81aa084c49266 | |
parent | 6985227db75f6adfeba880926e6629bf17b00ee8 (diff) | |
download | YAGE-a8de6cb5593e3d6347393eb4c144c9cc22a470d8.tar.gz YAGE-a8de6cb5593e3d6347393eb4c144c9cc22a470d8.zip |
Moving resources and generalising examples
-rw-r--r-- | examples/CMakeLists.txt | 22 | ||||
-rw-r--r-- | examples/shooter/bullet.cpp | 33 | ||||
-rw-r--r-- | examples/shooter/bullet.h | 24 | ||||
-rw-r--r-- | examples/shooter/direction.h | 11 | ||||
-rw-r--r-- | examples/shooter/main.cpp | 171 | ||||
-rw-r--r-- | examples/shooter/player.cpp | 72 | ||||
-rw-r--r-- | examples/shooter/player.h | 36 | ||||
-rw-r--r-- | examples/simple/main.cpp | 6 | ||||
-rw-r--r-- | examples/simple/resources/breast_black.png (renamed from examples/resources/breast_black.png) | bin | 225 -> 225 bytes | |||
-rw-r--r-- | examples/simple/resources/bullet.png (renamed from examples/resources/bullet.png) | bin | 1383 -> 1383 bytes | |||
-rw-r--r-- | examples/simple/resources/colourshader.frag (renamed from examples/resources/colourshader.frag) | 0 | ||||
-rw-r--r-- | examples/simple/resources/colourshader.vert (renamed from examples/resources/colourshader.vert) | 0 | ||||
-rw-r--r-- | examples/simple/resources/container.jpg (renamed from examples/resources/container.jpg) | bin | 184939 -> 184939 bytes | |||
-rw-r--r-- | examples/simple/resources/dngn_blood_fountain.png (renamed from examples/resources/dngn_blood_fountain.png) | bin | 955 -> 955 bytes | |||
-rw-r--r-- | examples/simple/resources/fighter_fd.png (renamed from examples/resources/fighter_fd.png) | bin | 6467 -> 6467 bytes | |||
-rw-r--r-- | examples/simple/resources/fighter_fl.png (renamed from examples/resources/fighter_fl.png) | bin | 2916 -> 2916 bytes | |||
-rw-r--r-- | examples/simple/resources/fighter_md.png (renamed from examples/resources/fighter_md.png) | bin | 6464 -> 6464 bytes | |||
-rw-r--r-- | examples/simple/resources/fighter_ml.png (renamed from examples/resources/fighter_ml.png) | bin | 2843 -> 2843 bytes | |||
-rw-r--r-- | examples/simple/resources/healer_fd.png (renamed from examples/resources/healer_fd.png) | bin | 7862 -> 7862 bytes | |||
-rw-r--r-- | examples/simple/resources/healer_fl.png (renamed from examples/resources/healer_fl.png) | bin | 3256 -> 3256 bytes | |||
-rw-r--r-- | examples/simple/resources/healer_md.png (renamed from examples/resources/healer_md.png) | bin | 6756 -> 6756 bytes | |||
-rw-r--r-- | examples/simple/resources/healer_ml.png (renamed from examples/resources/healer_ml.png) | bin | 2940 -> 2940 bytes | |||
-rw-r--r-- | examples/simple/resources/learnopenglshader.frag (renamed from examples/resources/learnopenglshader.frag) | 0 | ||||
-rw-r--r-- | examples/simple/resources/learnopenglshader.vert (renamed from examples/resources/learnopenglshader.vert) | 0 | ||||
-rw-r--r-- | examples/simple/resources/mage_fd.png (renamed from examples/resources/mage_fd.png) | bin | 7026 -> 7026 bytes | |||
-rw-r--r-- | examples/simple/resources/mage_fl.png (renamed from examples/resources/mage_fl.png) | bin | 3283 -> 3283 bytes | |||
-rw-r--r-- | examples/simple/resources/mage_md.png (renamed from examples/resources/mage_md.png) | bin | 6794 -> 6794 bytes | |||
-rw-r--r-- | examples/simple/resources/mage_ml.png (renamed from examples/resources/mage_ml.png) | bin | 3139 -> 3139 bytes | |||
-rw-r--r-- | examples/simple/resources/ranger_fd.png (renamed from examples/resources/ranger_fd.png) | bin | 6798 -> 6798 bytes | |||
-rw-r--r-- | examples/simple/resources/ranger_fl.png (renamed from examples/resources/ranger_fl.png) | bin | 2884 -> 2884 bytes | |||
-rw-r--r-- | examples/simple/resources/ranger_md.png (renamed from examples/resources/ranger_md.png) | bin | 6182 -> 6182 bytes | |||
-rw-r--r-- | examples/simple/resources/ranger_ml.png (renamed from examples/resources/ranger_ml.png) | bin | 2803 -> 2803 bytes | |||
-rw-r--r-- | examples/simple/resources/textureshader.frag (renamed from examples/resources/textureshader.frag) | 0 | ||||
-rw-r--r-- | examples/simple/resources/textureshader.vert (renamed from examples/resources/textureshader.vert) | 0 | ||||
-rw-r--r-- | examples/simple/resources/wall.jpg (renamed from examples/resources/wall.jpg) | bin | 256989 -> 256989 bytes | |||
-rw-r--r-- | examples/simple/resources/wall.png (renamed from examples/resources/wall.png) | bin | 607366 -> 607366 bytes | |||
-rw-r--r-- | examples/simplegame/main.cpp | 113 | ||||
-rwxr-xr-x | scripts/travis_build | 2 |
38 files changed, 24 insertions, 466 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 156b6a34..ec4c71e2 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,10 +1,22 @@ -function(make_example name) - +macro(make_example name) file(GLOB SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${name}/*.cpp) add_executable(${name} ${SOURCES}) target_link_libraries(${name} yage) +endmacro(make_example) + +macro(subdirlist result curdir) + file(GLOB children RELATIVE ${curdir} ${curdir}/*) + set(dirlist "") + foreach(child ${children}) + if(IS_DIRECTORY ${curdir}/${child}) + list(APPEND dirlist ${child}) + endif() + endforeach() + set(${result} ${dirlist}) +endmacro() -endfunction(make_example) +subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}) -make_example(simplegame) -make_example(shooter) +foreach(subdir ${SUBDIRS}) + make_example(${subdir}) +endforeach() 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 diff --git a/examples/simple/main.cpp b/examples/simple/main.cpp new file mode 100644 index 00000000..0869f9b1 --- /dev/null +++ b/examples/simple/main.cpp @@ -0,0 +1,6 @@ +#include <iostream> + +int main() +{ + std::cout << "Hello world"; +} diff --git a/examples/resources/breast_black.png b/examples/simple/resources/breast_black.png Binary files differindex 180b292f..180b292f 100644 --- a/examples/resources/breast_black.png +++ b/examples/simple/resources/breast_black.png diff --git a/examples/resources/bullet.png b/examples/simple/resources/bullet.png Binary files differindex 89e6289b..89e6289b 100644 --- a/examples/resources/bullet.png +++ b/examples/simple/resources/bullet.png diff --git a/examples/resources/colourshader.frag b/examples/simple/resources/colourshader.frag index e49d1ebb..e49d1ebb 100644 --- a/examples/resources/colourshader.frag +++ b/examples/simple/resources/colourshader.frag diff --git a/examples/resources/colourshader.vert b/examples/simple/resources/colourshader.vert index e5c10d77..e5c10d77 100644 --- a/examples/resources/colourshader.vert +++ b/examples/simple/resources/colourshader.vert diff --git a/examples/resources/container.jpg b/examples/simple/resources/container.jpg Binary files differindex d07bee4e..d07bee4e 100644 --- a/examples/resources/container.jpg +++ b/examples/simple/resources/container.jpg diff --git a/examples/resources/dngn_blood_fountain.png b/examples/simple/resources/dngn_blood_fountain.png Binary files differindex 7214fd47..7214fd47 100644 --- a/examples/resources/dngn_blood_fountain.png +++ b/examples/simple/resources/dngn_blood_fountain.png diff --git a/examples/resources/fighter_fd.png b/examples/simple/resources/fighter_fd.png Binary files differindex ea576b4d..ea576b4d 100644 --- a/examples/resources/fighter_fd.png +++ b/examples/simple/resources/fighter_fd.png diff --git a/examples/resources/fighter_fl.png b/examples/simple/resources/fighter_fl.png Binary files differindex 69b677ca..69b677ca 100644 --- a/examples/resources/fighter_fl.png +++ b/examples/simple/resources/fighter_fl.png diff --git a/examples/resources/fighter_md.png b/examples/simple/resources/fighter_md.png Binary files differindex 1b333abb..1b333abb 100644 --- a/examples/resources/fighter_md.png +++ b/examples/simple/resources/fighter_md.png diff --git a/examples/resources/fighter_ml.png b/examples/simple/resources/fighter_ml.png Binary files differindex 74dca840..74dca840 100644 --- a/examples/resources/fighter_ml.png +++ b/examples/simple/resources/fighter_ml.png diff --git a/examples/resources/healer_fd.png b/examples/simple/resources/healer_fd.png Binary files differindex 138e7c48..138e7c48 100644 --- a/examples/resources/healer_fd.png +++ b/examples/simple/resources/healer_fd.png diff --git a/examples/resources/healer_fl.png b/examples/simple/resources/healer_fl.png Binary files differindex 8360cfb9..8360cfb9 100644 --- a/examples/resources/healer_fl.png +++ b/examples/simple/resources/healer_fl.png diff --git a/examples/resources/healer_md.png b/examples/simple/resources/healer_md.png Binary files differindex 20ce4d2f..20ce4d2f 100644 --- a/examples/resources/healer_md.png +++ b/examples/simple/resources/healer_md.png diff --git a/examples/resources/healer_ml.png b/examples/simple/resources/healer_ml.png Binary files differindex 28377d6b..28377d6b 100644 --- a/examples/resources/healer_ml.png +++ b/examples/simple/resources/healer_ml.png diff --git a/examples/resources/learnopenglshader.frag b/examples/simple/resources/learnopenglshader.frag index 30919459..30919459 100644 --- a/examples/resources/learnopenglshader.frag +++ b/examples/simple/resources/learnopenglshader.frag diff --git a/examples/resources/learnopenglshader.vert b/examples/simple/resources/learnopenglshader.vert index 7b24b5d7..7b24b5d7 100644 --- a/examples/resources/learnopenglshader.vert +++ b/examples/simple/resources/learnopenglshader.vert diff --git a/examples/resources/mage_fd.png b/examples/simple/resources/mage_fd.png Binary files differindex b6a692f7..b6a692f7 100644 --- a/examples/resources/mage_fd.png +++ b/examples/simple/resources/mage_fd.png diff --git a/examples/resources/mage_fl.png b/examples/simple/resources/mage_fl.png Binary files differindex 66f5d2e5..66f5d2e5 100644 --- a/examples/resources/mage_fl.png +++ b/examples/simple/resources/mage_fl.png diff --git a/examples/resources/mage_md.png b/examples/simple/resources/mage_md.png Binary files differindex 40838087..40838087 100644 --- a/examples/resources/mage_md.png +++ b/examples/simple/resources/mage_md.png diff --git a/examples/resources/mage_ml.png b/examples/simple/resources/mage_ml.png Binary files differindex d559fb56..d559fb56 100644 --- a/examples/resources/mage_ml.png +++ b/examples/simple/resources/mage_ml.png diff --git a/examples/resources/ranger_fd.png b/examples/simple/resources/ranger_fd.png Binary files differindex e574cb1f..e574cb1f 100644 --- a/examples/resources/ranger_fd.png +++ b/examples/simple/resources/ranger_fd.png diff --git a/examples/resources/ranger_fl.png b/examples/simple/resources/ranger_fl.png Binary files differindex 9bc31719..9bc31719 100644 --- a/examples/resources/ranger_fl.png +++ b/examples/simple/resources/ranger_fl.png diff --git a/examples/resources/ranger_md.png b/examples/simple/resources/ranger_md.png Binary files differindex 5803cbe6..5803cbe6 100644 --- a/examples/resources/ranger_md.png +++ b/examples/simple/resources/ranger_md.png diff --git a/examples/resources/ranger_ml.png b/examples/simple/resources/ranger_ml.png Binary files differindex e2e528b4..e2e528b4 100644 --- a/examples/resources/ranger_ml.png +++ b/examples/simple/resources/ranger_ml.png diff --git a/examples/resources/textureshader.frag b/examples/simple/resources/textureshader.frag index ae12f4b0..ae12f4b0 100644 --- a/examples/resources/textureshader.frag +++ b/examples/simple/resources/textureshader.frag diff --git a/examples/resources/textureshader.vert b/examples/simple/resources/textureshader.vert index 447c68d4..447c68d4 100644 --- a/examples/resources/textureshader.vert +++ b/examples/simple/resources/textureshader.vert diff --git a/examples/resources/wall.jpg b/examples/simple/resources/wall.jpg Binary files differindex 49631987..49631987 100644 --- a/examples/resources/wall.jpg +++ b/examples/simple/resources/wall.jpg diff --git a/examples/resources/wall.png b/examples/simple/resources/wall.png Binary files differindex 3eb2cd6e..3eb2cd6e 100644 --- a/examples/resources/wall.png +++ b/examples/simple/resources/wall.png diff --git a/examples/simplegame/main.cpp b/examples/simplegame/main.cpp deleted file mode 100644 index bea3bc8d..00000000 --- a/examples/simplegame/main.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: simplegame.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#include <yage.cpp> - -#include <cstdlib> -#include <ctime> -#include <iostream> - -using std::cout; - -using namespace yage; - -int main() -{ - yage::init(); - Logger logger; - srand(time(nullptr)); - Window window; - window.create("Simple Game", 1920, 1080); - - Shader textureProgram("examples/resources/textureshader.vert", - "examples/resources/textureshader.frag"); - SpriteBatch sp; - - Texture fountain = ResourceManager::getTexture( - "examples/resources/dngn_blood_fountain.png"); - Texture breast_plate = - ResourceManager::getTexture("examples/resources/breast_black.png"); - - Texture brick = ResourceManager::getTexture("examples/resources/wall.png"); - - yLogDebug << "texture: " << brick.width << ", " << brick.height; - - Camera camera(1920, 1080); - textureProgram.use(); - textureProgram.setUniform("texture_sampler", 0); - - double prev_time = glfwGetTime(); - double final_time = 0; - double diff = 0; - double fps = 0; - int i = 0; - double time; - - while (!window.shouldClose()) { - window.clearBuffer(); - Texture texture = fountain; - - window.pollEvents(); - if (window.keyPressed(yage::key::SPACE)) { - cout << "Pressed A" << '\n'; - } - if (window.keyPressed(yage::key::E)) { - texture = breast_plate; - } - if (window.keyPressed(yage::key::EQUAL)) { - camera.zoom(0.1f); - } - if (window.keyPressed(yage::key::MINUS)) { - camera.zoom(-0.1f); - } - if (window.keyPressed(yage::key::LEFT)) { - camera.move({-5.f, 0.f}); - } - if (window.keyPressed(yage::key::RIGHT)) { - camera.move({5.f, 0.f}); - } - if (window.keyPressed(yage::key::UP)) { - camera.move({0.f, 5.f}); - } - if (window.keyPressed(yage::key::DOWN)) { - camera.move({0.f, -5.f}); - } - - camera.update(textureProgram); - - int amount = 10; - time = glfwGetTime(); - for (int i = 0; i < 1920 / amount; i++) { - for (int j = 0; j < 1080 / amount; j++) - sp.draw({(float)(amount * i), (float)(amount * j), - (float)amount, (float)amount}, - {0.f, 0.f, 1.f, 1.f}, texture.id, - Colour(rand() % 256, rand() % 256, rand() % 256, 255), - 0); - } - - sp.draw({50, 50, 100, 100}, {0, 0, 1, 1}, brick.id, - Colour(255, 255, 255, 255), 1); - yLogDebug << "draw: " << glfwGetTime() - time; - - time = glfwGetTime(); - sp.render(); - yLogDebug << "render: " << glfwGetTime() - time; - window.swapBuffer(); - - if (i == 0) { - final_time = glfwGetTime(); - diff = final_time - prev_time; - prev_time = final_time; - fps = 1 / diff * 30; - yLogInfo << "fps: " << fps; - } - i = (i + 1) % 30; - } - yage::quit(); -} diff --git a/scripts/travis_build b/scripts/travis_build index e60088c8..7da8a258 100755 --- a/scripts/travis_build +++ b/scripts/travis_build @@ -12,7 +12,7 @@ cd $TRAVIS_BUILD_DIR # start building mkdir -p build cd build -cmake -DYAGE_BUILD_TESTS=ON -DYAGE_BUILD_DOCS=ON .. +cmake -DYAGE_BUILD_TESTS=ON -DYAGE_BUILD_DOCS=ON -DYAGE_BUILD_EXAMPLES=ON .. make cd tests ctest -j 2 --schedule-random --repeat-until-fail 3 |