aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-01-03 13:57:51 +0000
committerYann Herklotz <ymherklotz@gmail.com>2018-01-03 13:57:51 +0000
commita47649786fb94684c415b230669fbf5343cb7c5d (patch)
treeb35c5921bf90ed7b091f1bc2f08f370436abe834 /examples
parent86e4aa6265ade205aba94494a7a31a83b5686387 (diff)
downloadYAGE-a47649786fb94684c415b230669fbf5343cb7c5d.tar.gz
YAGE-a47649786fb94684c415b230669fbf5343cb7c5d.zip
[Engine] [Example] Added simple bullets that don't move
Diffstat (limited to 'examples')
-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
4 files changed, 32 insertions, 5 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_;