Skip to content

Commit

Permalink
Merge pull request #82
Browse files Browse the repository at this point in the history
Добавлена фоновая музыка и звук взрыва. Также есть возможность отключить музыку в настройках.
  • Loading branch information
Lessyless authored May 15, 2019
1 parent 48da8d6 commit 4e594f0
Show file tree
Hide file tree
Showing 23 changed files with 171 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ before_install:
- sudo apt-get update

install:
- sudo apt-get install qt510base cppcheck
- sudo apt-get install qt510base qt510multimedia cppcheck
- source /opt/qt5*/bin/qt5*-env.sh
- /opt/qt5*/bin/qmake PREFIX=/usr

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Tanks - 2D-игра, написанная на C++ с использование
* Неверо Андрей ([@anevero](https://github.com/anevero))
* Тарайкович Алеся ([@Lessyless](https://github.com/Lessyless))

В программе используется музыка [David Fesliyan](https://www.fesliyanstudios.com/) и [spinningmerkaba](http://dig.ccmixter.org/people/jlbrock44).

## Статус разработки

Разработка завершена в мае 2019 года. Последняя версия программы - [0.7](https://github.com/anevero/tanks/tree/0.7).
Expand Down
12 changes: 7 additions & 5 deletions android-sources/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0"?>
<manifest package="org.qtproject.tanks" xmlns:android="http://schemas.android.com/apk/res/android"
android:versionName="0.7.0" android:versionCode="4"
android:versionName="0.8.0" android:versionCode="5"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="24" />
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<supports-screens android:xlargeScreens="true" />
<application android:name="org.qtproject.qt5.android.bindings.QtApplication"
android:label="Tanks" android:icon="@drawable/icon"
Expand Down Expand Up @@ -36,11 +38,11 @@
<meta-data android:name="android.app.libs_prefix"
android:value="/data/local/tmp/qt/" />
<meta-data android:name="android.app.load_local_libs"
android:value="plugins/platforms/android/libqtforandroid.so" />
android:value="plugins/bearer/libqandroidbearer.so:plugins/platforms/android/libqtforandroid.so:plugins/mediaservice/libqtmedia_android.so" />
<meta-data android:name="android.app.load_local_jars"
android:value="jar/QtAndroid.jar" />
android:value="jar/QtAndroidBearer.jar:jar/QtAndroid.jar:jar/QtMultimedia.jar" />
<meta-data android:name="android.app.static_init_classes"
android:value="" />
android:value="org.qtproject.qt5.android.multimedia.QtMultimediaUtils" />
<meta-data android:value="@string/ministro_not_found_msg"
android:name="android.app.ministro_not_found_msg" />
<meta-data android:value="@string/ministro_needed_msg"
Expand Down
3 changes: 3 additions & 0 deletions boom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Boom::Boom(const std::shared_ptr<Map>& map,
speed) {
LoadImage();
opacity_ = 0.85;

boom_sound_.setMedia(QUrl("qrc:/sounds/boom.mp3"));
boom_sound_.play();
}

void Boom::LoadImage() {
Expand Down
4 changes: 4 additions & 0 deletions boom.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define BOOM_H

#include <QDebug>
#include <QMediaPlayer>
#include <QPainter>
#include <memory>
#include <vector>
Expand All @@ -19,6 +20,9 @@ class Boom : public Movable {
const int number_of_cells, const QList<std::shared_ptr<Movable>>&,
QList<QPair<std::shared_ptr<Movable>, Coordinates>>*,
std::vector<std::vector<std::shared_ptr<ObjectOnMap>>>*) override;

private:
QMediaPlayer boom_sound_;
};

#endif // BOOM_H
Binary file added data/backgroundmusic.mp3
Binary file not shown.
3 changes: 3 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ int main(int argc, char *argv[]) {

QString language{};
bool charge_line = true;
bool music_enabled = true;
int fps_option;

#ifdef Q_OS_ANDROID
Expand All @@ -30,6 +31,7 @@ int main(int argc, char *argv[]) {
QJsonObject json = json_document.object();
language = json["language"].toString();
charge_line = json["charge_line"].toBool();
music_enabled = json["music_enabled"].toBool();
fps_option = json["fps"].toInt();
}

Expand All @@ -48,6 +50,7 @@ int main(int argc, char *argv[]) {
QJsonObject new_json_obj;
new_json_obj["language"] = language;
new_json_obj["charge_line"] = charge_line;
new_json_obj["music_enabled"] = music_enabled;
new_json_obj["fps"] = fps_option;
QJsonDocument new_json_document(new_json_obj);
QString new_json_string = new_json_document.toJson();
Expand Down
39 changes: 38 additions & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ MainWindow::MainWindow(QWidget *parent)

setMinimumSize(600, 450);
resize(600, 450);

music_playlist_.addMedia(QUrl("qrc:/sounds/backgroundmusic1.mp3"));
music_playlist_.addMedia(QUrl("qrc:/sounds/backgroundmusic2.mp3"));
music_playlist_.addMedia(QUrl("qrc:/sounds/backgroundmusic3.mp3"));
music_playlist_.addMedia(QUrl("qrc:/sounds/backgroundmusic4.mp3"));
music_player_.setPlaylist(&music_playlist_);
music_player_.setVolume(50);
}

void MainWindow::mouseReleaseEvent(QMouseEvent *event) {
Expand Down Expand Up @@ -503,6 +510,8 @@ void MainWindow::RedrawContent() {
killTimer(timer_id_);
timer_id_ = 0;

music_player_.stop();

screen_timer_ms_ = 0;
screen_timer_sec_ = 0;
screen_timer_min_ = 0;
Expand Down Expand Up @@ -606,6 +615,13 @@ void MainWindow::RedrawContent() {
}

timer_id_ = startTimer(timer_duration_);

music_playlist_.setCurrentIndex(current_game_options_.map_number);
music_playlist_.setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
if (music_enabled_) {
music_player_.play();
}

RedrawChargeButtons();
repaint();
}
Expand Down Expand Up @@ -703,7 +719,7 @@ void MainWindow::CheckDeadObjects() {
}

void MainWindow::MakeBoom(const std::shared_ptr<Movable> &object) {
std::shared_ptr<Boom> boom(new Boom(map_, object, 500));
std::shared_ptr<Boom> boom(new Boom(map_, object, 1000));
rockets_.append(boom);
boom->StartMovement(1, tanks_, &objects_copies_, &obstacles_and_bonuses_);
}
Expand Down Expand Up @@ -786,6 +802,15 @@ void MainWindow::SwitchVirtualButtonsLayout() {
RedrawButtons();
}

void MainWindow::ToggleMusic() {
music_enabled_ = !music_enabled_;
if (!music_enabled_) {
music_player_.stop();
} else if (music_enabled_ && timer_id_ == 0 && paused_) {
music_player_.play();
}
}

void MainWindow::ChangeFPSOption(const int new_option, bool start_timer) {
fps_option_ = new_option;
timer_duration_ = available_fps_options_[new_option].second;
Expand All @@ -799,6 +824,8 @@ void MainWindow::ChangeFPSOption(const int new_option, bool start_timer) {
}

void MainWindow::GameOver(bool win) {
music_player_.stop();

killTimer(timer_id_);
timer_id_ = 0;

Expand Down Expand Up @@ -907,6 +934,8 @@ void MainWindow::InitializeSettingsDialog() {
charge_line_checkbox_ =
new QCheckBox(tr("Activate charge line"), settings_dialog_);

music_checkbox_ = new QCheckBox(tr("Music"), settings_dialog_);

fps_menu_label_ =
new QLabel(QString(tr("Performance")) + QString(":"), settings_dialog_);

Expand Down Expand Up @@ -934,6 +963,7 @@ void MainWindow::InitializeSettingsDialog() {
settings_dialog_layout_->addWidget(virtual_keys_checkbox_);
settings_dialog_layout_->addWidget(new_virtual_keys_checkbox_);
settings_dialog_layout_->addWidget(charge_line_checkbox_);
settings_dialog_layout_->addWidget(music_checkbox_);
settings_dialog_layout_->addWidget(fps_menu_label_);
settings_dialog_layout_->addWidget(fps_menu_);
settings_dialog_layout_->addWidget(language_menu_label_);
Expand Down Expand Up @@ -1011,6 +1041,9 @@ void MainWindow::DetermineCurrentSettings() {
charge_line_shown_ = json["charge_line"].toBool();
charge_line_checkbox_->setChecked(charge_line_shown_);

music_enabled_ = json["music_enabled"].toBool();
music_checkbox_->setChecked(music_enabled_);

fps_option_ = json["fps"].toInt();
fps_menu_->setCurrentIndex(fps_option_);
}
Expand All @@ -1022,6 +1055,9 @@ void MainWindow::ChangeCurrentSettings() {
if (new_virtual_keys_enabled_ != new_virtual_keys_checkbox_->isChecked()) {
SwitchVirtualButtonsLayout();
}
if (music_enabled_ != music_checkbox_->isChecked()) {
ToggleMusic();
}

charge_line_shown_ = charge_line_checkbox_->isChecked();
ChangeFPSOption(fps_menu_->currentIndex());
Expand All @@ -1044,6 +1080,7 @@ void MainWindow::ChangeCurrentSettings() {

new_json_obj["language"] = language;
new_json_obj["charge_line"] = charge_line_shown_;
new_json_obj["music_enabled"] = music_enabled_;
new_json_obj["fps"] = fps_option_;

QJsonDocument new_json_document(new_json_obj);
Expand Down
8 changes: 8 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <QLabel>
#include <QList>
#include <QMainWindow>
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QMessageBox>
#include <QPainter>
#include <QPalette>
Expand Down Expand Up @@ -98,6 +100,7 @@ class MainWindow : public QMainWindow {
int GetTimerDuration() const;
void ToggleVirtualKeys();
void SwitchVirtualButtonsLayout();
void ToggleMusic();
void ChangeFPSOption(const int new_option, bool start_timer = false);
void InitializeNewGameDialog();
void InitializeSettingsDialog();
Expand All @@ -112,6 +115,7 @@ class MainWindow : public QMainWindow {
bool virtual_keys_shown_ = true;
bool new_virtual_keys_enabled_ = true;
bool charge_line_shown_;
bool music_enabled_;
int fps_option_;
int timer_duration_;

Expand Down Expand Up @@ -142,6 +146,7 @@ class MainWindow : public QMainWindow {
QCheckBox *virtual_keys_checkbox_;
QCheckBox *new_virtual_keys_checkbox_;
QCheckBox *charge_line_checkbox_;
QCheckBox *music_checkbox_;
QComboBox *fps_menu_;
QComboBox *language_menu_;
QLabel *fps_menu_label_;
Expand Down Expand Up @@ -175,6 +180,9 @@ class MainWindow : public QMainWindow {
QVBoxLayout *new_virtual_buttons_layout_left_;
QHBoxLayout *new_virtual_buttons_layout_right_;

QMediaPlayer music_player_;
QMediaPlaylist music_playlist_;

std::shared_ptr<Map> map_;
QList<std::shared_ptr<Movable>> tanks_;
QList<std::shared_ptr<Movable>> rockets_;
Expand Down
5 changes: 5 additions & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@
<file>rules/settings.png</file>
<file>rules/about.png</file>
<file>rules/timer.png</file>
<file>sounds/backgroundmusic1.mp3</file>
<file>sounds/backgroundmusic2.mp3</file>
<file>sounds/backgroundmusic3.mp3</file>
<file>sounds/backgroundmusic4.mp3</file>
<file>sounds/boom.mp3</file>
</qresource>
</RCC>
6 changes: 3 additions & 3 deletions rules/rules.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h3>
game, learn about management features and clarify information
about objects on the map.
</h3>
<h4>Version 0.7.0.0</h4>
<h4>Version 0.8.0.0</h4>
<h3>
This project was developed by <a href="https://github.com/Lessyless">
Alesia Taraikovich </a>, <a href="https://github.com/sashhrmz">
Expand Down Expand Up @@ -133,7 +133,7 @@ <h3>1</h3>
<h3>low</h3>
</td>
<td>
<h3>hight</h3>
<h3>high</h3>
</td>
<td>
<h3>yes</h3>
Expand All @@ -158,7 +158,7 @@ <h3>yes</h3>
<h3>3</h3>
</td>
<td>
<h3>hight</h3>
<h3>high</h3>
</td>
<td>
<h3>low</h3>
Expand Down
Binary file added sounds/backgroundmusic1.mp3
Binary file not shown.
Binary file added sounds/backgroundmusic2.mp3
Binary file not shown.
Binary file added sounds/backgroundmusic3.mp3
Binary file not shown.
Binary file added sounds/backgroundmusic4.mp3
Binary file not shown.
Binary file added sounds/boom.mp3
Binary file not shown.
9 changes: 4 additions & 5 deletions tanks.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 4):
QT += widgets core gui multimedia

TARGET = Tanks
TEMPLATE = app
Expand All @@ -9,7 +8,7 @@ DEFINES += QT_DEPRECATED_WARNINGS

ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
DISTFILES += \
android-sources/AndroidManifest.xml
android-sources/AndroidManifest.xml

SOURCES += \
main.cpp \
Expand Down Expand Up @@ -48,4 +47,4 @@ TRANSLATIONS += \

RC_ICONS = app_icon.ico

VERSION = 0.7.0.0
VERSION = 0.8.0.0
Binary file modified translations/tanks_be_BY.qm
Binary file not shown.
Loading

0 comments on commit 4e594f0

Please sign in to comment.