summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-11 02:24:48 +0200
committermanuel <manuel@mausz.at>2011-04-11 02:24:48 +0200
commit43061892c7c9d341bacb7c679444f2885bd56907 (patch)
treefaae1880915c23f85901fa4f0ef7f2e5465681ec
parent57e3e48eb558b73077c2b5b4e531ee1cd75b0fbf (diff)
downloadfoop-43061892c7c9d341bacb7c679444f2885bd56907.tar.gz
foop-43061892c7c9d341bacb7c679444f2885bd56907.tar.bz2
foop-43061892c7c9d341bacb7c679444f2885bd56907.zip
- make use of my_color (still TODO: pre-game dialog (with intro music) + display own color first in scoreboard)
- remove some audio debugging noice
-rw-r--r--pacman-c++/audio.cpp7
-rw-r--r--pacman-c++/mainwidget.cpp14
-rw-r--r--pacman-c++/mainwidget.h8
-rw-r--r--pacman-c++/sceneholder.cpp9
-rw-r--r--pacman-c++/sceneholder.h3
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;
13AudioManager::AudioManager() 13AudioManager::AudioManager()
14 : m_muted(true) 14 : m_muted(true)
15{ 15{
16#ifndef SERVER 16#ifdef SERVER
17 qDebug() << "Server has no sound"
18#else
17 preload(); 19 preload();
18 20
19 AudioPlayer *firstplayer = new AudioPlayer(this); 21 AudioPlayer *firstplayer = new AudioPlayer(this);
@@ -22,8 +24,6 @@ AudioManager::AudioManager()
22 m_players.append(firstplayer); 24 m_players.append(firstplayer);
23 25
24 m_muted = false; 26 m_muted = false;
25#else
26 qDebug() << "Server has no sound"
27#endif // SERVER 27#endif // SERVER
28} 28}
29 29
@@ -47,7 +47,6 @@ void AudioManager::setMuted(bool mute)
47 if (mute == m_muted) 47 if (mute == m_muted)
48 return; 48 return;
49 49
50 qDebug() << "mute";
51 for(int i = 0; i < m_players.count(); ++i) 50 for(int i = 0; i < m_players.count(); ++i)
52 m_players.at(i)->setMuted(mute); 51 m_players.at(i)->setMuted(mute);
53 m_muted = mute; 52 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)
10: SceneHolder(parent), m_currentKey(0), m_running(false) 10: SceneHolder(parent), m_currentKey(0), m_running(false)
11{ 11{
12 createGui(); 12 createGui();
13 updateMap(Util::createDemoMap());
14 13
15 Color::Color myColor = connectToServer(); 14 m_color = connectToServer();
16 if (myColor == Color::none) 15 if (m_color == Color::none)
17 { 16 {
18 QMessageBox::critical(this, "Error", "Failed to connect to server, falling back to local test mode"); 17 QMessageBox::critical(this, "Error", "Failed to connect to server, falling back to local test mode");
19 // TODO: quit application here or sth 18 // TODO: quit application here or sth
20 m_socket = NULL; 19 m_socket = NULL;
20 m_color = Color::red;
21 QTimer *timer = new QTimer(this); 21 QTimer *timer = new QTimer(this);
22 connect(timer, SIGNAL(timeout()), this, SLOT(tick())); 22 connect(timer, SIGNAL(timeout()), this, SLOT(tick()));
23 timer->start(Constants::tick); 23 timer->start(Constants::tick);
24 } 24 }
25 else 25
26 /* call updateMap after m_color ist set! */
27 updateMap(Util::createDemoMap());
28
29 if (m_socket != NULL)
26 connect(m_socket, SIGNAL(readyRead()), this, SLOT(tick())); 30 connect(m_socket, SIGNAL(readyRead()), this, SLOT(tick()));
27 31
28 // TODO: use mycolor 32 // TODO: use mycolor
29 qDebug() << "mycolor=" << myColor; 33 qDebug() << "mycolor=" << m_color;
30 34
31 //TODO: play intro as soon as there are enough players 35 //TODO: play intro as soon as there are enough players
32 //connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(startGame())); 36 //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:
36 bool isRunning(); 36 bool isRunning();
37 Color::Color connectToServer(); 37 Color::Color connectToServer();
38 38
39 // GUI elements needed in the progress of the game 39 /* GUI elements needed in the progress of the game */
40 QList<QGridLayout*> m_playerScoreLayouts; 40 QList<QGridLayout*> m_playerScoreLayouts;
41 41
42 // key currently pressed by user 42 /* key currently pressed by user */
43 Transmission::field_t m_currentKey; 43 Transmission::field_t m_currentKey;
44 44
45 // translate Qt::Key to our key format 45 /* translate Qt::Key to our key format */
46 Transmission::field_t translateKey(int key); 46 Transmission::field_t translateKey(int key);
47 47
48 // game running 48 /* game running */
49 bool m_running; 49 bool m_running;
50 50
51 QTcpSocket *m_socket; 51 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 @@
8#include "point.h" 8#include "point.h"
9#include "util.h" 9#include "util.h"
10 10
11SceneHolder::SceneHolder(QWidget* parent): QWidget(parent) 11SceneHolder::SceneHolder(QWidget* parent)
12 : QWidget(parent), m_color(Color::none)
12{ 13{
13 m_scene = new QGraphicsScene(0, 0, Constants::map_size_pixel.width, Constants::map_size_pixel.height, this); 14 m_scene = new QGraphicsScene(0, 0, Constants::map_size_pixel.width, Constants::map_size_pixel.height, this);
14 m_scene->setBackgroundBrush(Qt::black); 15 m_scene->setBackgroundBrush(Qt::black);
@@ -27,11 +28,8 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
27 const Transmission::field_t &cur = map[x][y]; 28 const Transmission::field_t &cur = map[x][y];
28 if (cur == Transmission::none) 29 if (cur == Transmission::none)
29 continue; 30 continue;
30 //qDebug() << "not 0 at x=" << x << ", y=" << y << ", val=" << cur;
31 31
32 Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); 32 Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask);
33 //qDebug() << "col=" << color;
34
35 PixmapItem* item = NULL; 33 PixmapItem* item = NULL;
36 if (cur == Transmission::none) 34 if (cur == Transmission::none)
37 { 35 {
@@ -74,8 +72,7 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
74 Actor *actor = m_actors.value(color, NULL); 72 Actor *actor = m_actors.value(color, NULL);
75 if (actor == NULL) 73 if (actor == NULL)
76 { 74 {
77 //qDebug() << "new actor of col" << color; 75 actor = new Actor(color, (color == m_color));
78 actor = new Actor(color, (color == Color::red)); //TODO: red = local for testing
79 m_actors[color] = actor; 76 m_actors[color] = actor;
80 m_scene->addItem(actor); 77 m_scene->addItem(actor);
81 actor->setPos(mapPositionToCoord(x, y)); 78 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:
33 // map of actors in order to keep track of those instances 33 // map of actors in order to keep track of those instances
34 QMap<Color::Color, Actor*> m_actors; 34 QMap<Color::Color, Actor*> m_actors;
35 35
36 /* my color */
37 Color::Color m_color;
38
36 QGraphicsScene *m_scene; 39 QGraphicsScene *m_scene;
37}; 40};
38 41