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 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'examples/shooter/bullet.cpp') 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_; } -- cgit