From 43061892c7c9d341bacb7c679444f2885bd56907 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 11 Apr 2011 02:24:48 +0200 Subject: - make use of my_color (still TODO: pre-game dialog (with intro music) + display own color first in scoreboard) - remove some audio debugging noice --- pacman-c++/audio.cpp | 7 +++---- pacman-c++/mainwidget.cpp | 14 +++++++++----- pacman-c++/mainwidget.h | 8 ++++---- pacman-c++/sceneholder.cpp | 9 +++------ pacman-c++/sceneholder.h | 3 +++ 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/pacman-c++/audio.cpp b/pacman-c++/audio.cpp index ebeda2b..d74445a 100644 --- a/pacman-c++/audio.cpp +++ b/pacman-c++/audio.cpp @@ -13,7 +13,9 @@ bool AudioManager::m_working = false; AudioManager::AudioManager() : m_muted(true) { -#ifndef SERVER +#ifdef SERVER + qDebug() << "Server has no sound" +#else preload(); AudioPlayer *firstplayer = new AudioPlayer(this); @@ -22,8 +24,6 @@ AudioManager::AudioManager() m_players.append(firstplayer); m_muted = false; -#else - qDebug() << "Server has no sound" #endif // SERVER } @@ -47,7 +47,6 @@ void AudioManager::setMuted(bool mute) if (mute == m_muted) return; - qDebug() << "mute"; for(int i = 0; i < m_players.count(); ++i) m_players.at(i)->setMuted(mute); m_muted = mute; diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index 9c53513..bdc2da1 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp @@ -10,23 +10,27 @@ MainWidget::MainWidget(QWidget *parent) : SceneHolder(parent), m_currentKey(0), m_running(false) { createGui(); - updateMap(Util::createDemoMap()); - Color::Color myColor = connectToServer(); - if (myColor == Color::none) + m_color = connectToServer(); + if (m_color == Color::none) { QMessageBox::critical(this, "Error", "Failed to connect to server, falling back to local test mode"); // TODO: quit application here or sth m_socket = NULL; + m_color = Color::red; QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(tick())); timer->start(Constants::tick); } - else + + /* call updateMap after m_color ist set! */ + updateMap(Util::createDemoMap()); + + if (m_socket != NULL) connect(m_socket, SIGNAL(readyRead()), this, SLOT(tick())); // TODO: use mycolor - qDebug() << "mycolor=" << myColor; + qDebug() << "mycolor=" << m_color; //TODO: play intro as soon as there are enough players //connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(startGame())); diff --git a/pacman-c++/mainwidget.h b/pacman-c++/mainwidget.h index ede3ecf..46de6fb 100644 --- a/pacman-c++/mainwidget.h +++ b/pacman-c++/mainwidget.h @@ -36,16 +36,16 @@ private: bool isRunning(); Color::Color connectToServer(); - // GUI elements needed in the progress of the game + /* GUI elements needed in the progress of the game */ QList m_playerScoreLayouts; - // key currently pressed by user + /* key currently pressed by user */ Transmission::field_t m_currentKey; - // translate Qt::Key to our key format + /* translate Qt::Key to our key format */ Transmission::field_t translateKey(int key); - // game running + /* game running */ bool m_running; QTcpSocket *m_socket; diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index 0236470..0a65d19 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp @@ -8,7 +8,8 @@ #include "point.h" #include "util.h" -SceneHolder::SceneHolder(QWidget* parent): QWidget(parent) +SceneHolder::SceneHolder(QWidget* parent) + : QWidget(parent), m_color(Color::none) { m_scene = new QGraphicsScene(0, 0, Constants::map_size_pixel.width, Constants::map_size_pixel.height, this); m_scene->setBackgroundBrush(Qt::black); @@ -27,11 +28,8 @@ void SceneHolder::updateMap(const Transmission::map_t& map) const Transmission::field_t &cur = map[x][y]; if (cur == Transmission::none) continue; - //qDebug() << "not 0 at x=" << x << ", y=" << y << ", val=" << cur; Color::Color color = static_cast(cur & Transmission::color_mask); - //qDebug() << "col=" << color; - PixmapItem* item = NULL; if (cur == Transmission::none) { @@ -74,8 +72,7 @@ void SceneHolder::updateMap(const Transmission::map_t& map) Actor *actor = m_actors.value(color, NULL); if (actor == NULL) { - //qDebug() << "new actor of col" << color; - actor = new Actor(color, (color == Color::red)); //TODO: red = local for testing + actor = new Actor(color, (color == m_color)); m_actors[color] = actor; m_scene->addItem(actor); actor->setPos(mapPositionToCoord(x, y)); diff --git a/pacman-c++/sceneholder.h b/pacman-c++/sceneholder.h index 7494c3f..1ca991e 100644 --- a/pacman-c++/sceneholder.h +++ b/pacman-c++/sceneholder.h @@ -33,6 +33,9 @@ protected: // map of actors in order to keep track of those instances QMap m_actors; + /* my color */ + Color::Color m_color; + QGraphicsScene *m_scene; }; -- cgit v1.2.3