diff --git a/src/Audio.cpp b/src/Audio.cpp index 9749022..25fb7b6 100644 --- a/src/Audio.cpp +++ b/src/Audio.cpp @@ -5,6 +5,7 @@ void Audio::update() { auto cmd = pop(); + std::cout << "Playing sound: " + std::to_string(cmd->soundId) << std::endl; // use volume, soundId to play sound delete cmd; diff --git a/src/Audio.h b/src/Audio.h index 4686053..9291375 100644 --- a/src/Audio.h +++ b/src/Audio.h @@ -2,6 +2,8 @@ #include "Queue.h" +#define SOUND_JUMP 0 + struct AudioCommand { double volume; unsigned soundId; diff --git a/src/Game.cpp b/src/Game.cpp index eb25d1a..b8c2889 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -4,8 +4,6 @@ void Game::draw(QPixmap &output) { QPainter p(&output); - double w = output.size().width(); - double h = output.size().height(); player.draw(p); } @@ -15,6 +13,7 @@ void Game::update(float dTime) { } Game::Game() { + InputWindow::inputQueue->registerListener(&player); } diff --git a/src/Game.h b/src/Game.h index d825e8e..937e406 100644 --- a/src/Game.h +++ b/src/Game.h @@ -4,6 +4,9 @@ #include "Player.h" #include "Spectator.h" +#define WIDTH 1000 +#define HEIGHT 500 + class Game { Player player; std::vector spectators; diff --git a/src/Player.cpp b/src/Player.cpp index 91b7fd0..1e71451 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -1,9 +1,11 @@ #include "Player.h" +#include "Audio.h" #include void Player::mousePressed(MouseEvent *event) { - if (pos.y() == ground) - vel += {0, -300}; + if (pos.y() == ground && event->button == Qt::MouseButton::LeftButton){ + jump(); + } } void Player::draw(QPainter &painter) { @@ -24,3 +26,8 @@ void Player::update(float dTime) { vel = {}; } } + +void Player::jump() { + vel += {0, -300}; + Audio::playSound(1, SOUND_JUMP); +} diff --git a/src/Player.h b/src/Player.h index bedeea1..6d6be5b 100644 --- a/src/Player.h +++ b/src/Player.h @@ -5,12 +5,13 @@ #include "Entity.h" #include -class Player : public Entity, public GameListener, public InputListener { +class Player : public Entity, public InputListener { QVector2D pos {50, 50}; QVector2D vel {}; QVector2D acc {0, 9.81 * 30}; float ground = 400; + void jump(); public: void draw(QPainter &painter); void update(float dTime); diff --git a/src/Window.cpp b/src/Window.cpp index 015b0a9..93a9da3 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -14,7 +14,7 @@ Window::Window() { } void Window::paintEvent(QPaintEvent *event) { - QPixmap output(1000, 500); + QPixmap output(WIDTH, HEIGHT); output.fill(Qt::white); game.draw(output); label->setPixmap(output.scaled(label->size()));