aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/shooter/bullet.h4
-rw-r--r--examples/shooter/main.cpp23
-rw-r--r--examples/shooter/player.cpp5
-rw-r--r--examples/shooter/player.h5
-rw-r--r--yage/render/drawable.h4
-rw-r--r--yage/yage.h1
6 files changed, 36 insertions, 6 deletions
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 <yage/yage.h>
-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 <yage/yage.h>
-#include "player.h"
#include "bullet.h"
+#include "player.h"
+
+#include <vector>
+#include <memory>
using std::cout;
@@ -10,6 +13,8 @@ int main(int argc, char **argv)
yage::Window window;
window.create("Shooter example", 800, 600);
+ std::vector<std::unique_ptr<yage::Drawable>> 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<Bullet>(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<Bullet>(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_;
diff --git a/yage/render/drawable.h b/yage/render/drawable.h
index 0e4b6843..8ef48f2d 100644
--- a/yage/render/drawable.h
+++ b/yage/render/drawable.h
@@ -1,13 +1,15 @@
#ifndef YAGE_CORE_DRAWABLE_H
#define YAGE_CORE_DRAWABLE_H
+#include "spritebatch.h"
+
namespace yage
{
class Drawable
{
public:
- virtual void render() const;
+ virtual void draw(SpriteBatch &sp) const = 0;
};
} // namespace yage
diff --git a/yage/yage.h b/yage/yage.h
index 43f1f61b..97665c5c 100644
--- a/yage/yage.h
+++ b/yage/yage.h
@@ -29,6 +29,7 @@
#include "physics/rigidbody.h"
#include "render/shader.h"
#include "render/spritebatch.h"
+#include "render/drawable.h"
#include "util/active.h"
#include "util/syncqueue.h"