1/*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
3 Copyright (c) 2010 Brian Croom <brian.s.croom@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9*/
10
11#ifndef MAINAREA_H
12#define MAINAREA_H
13
14#include <QTimer>
15#include <QTime>
16#include <QList>
17#include <QGraphicsScene>
18#include <KGameRenderer>
19#include <KgSound>
20#include "animator.h"
21#include "message.h"
22
23class Renderer;
24class Ball;
25class Animation;
26class QGraphicsSceneMouseEvent;
27class KAction;
28
29struct Collision;
30
31class MainArea : public QGraphicsScene
32{
33Q_OBJECT
34 QTimer m_timer;
35 int m_last_time;
36 int m_last_game_time;
37 QTime m_time;
38
39 /// time interval between two balls being added
40 int m_ball_timeout;
41
42 int m_size;
43 KGameRenderer m_renderer;
44 Animator m_animator;
45 QFont m_msg_font;
46
47 QList<Ball*> m_balls;
48 QList<Ball*> m_fading;
49 Ball* m_man;
50
51 /// the blue ball is dead
52 bool m_death;
53
54 /// the falling animation is over, we're waiting for a new game to start
55 bool m_game_over;
56
57 bool m_paused;
58 int m_pause_time;
59 int m_penalty;
60
61 QList<MessagePtr> m_welcome_msg;
62 QList<MessagePtr> m_pause_msg;
63
64 // Flag if sound is enabled.
65 bool m_soundEnabled;
66
67 KgSound m_soundHitWall;
68 KgSound m_soundYouLose;
69 KgSound m_soundBallLeaving;
70 KgSound m_soundStart;
71
72 KAction* m_pause_action;
73
74 double radius() const;
75 QPointF randomPoint() const;
76 QPointF randomDirection(double val) const;
77
78 Ball* addBall(const QString& id);
79 bool collide(const QPointF& a, const QPointF& b,
80 double diam, Collision& collision);
81
82 Animation* writeMessage(const QString& text);
83 Animation* writeText(const QString& lines, bool fade = true);
84 void displayMessages(const QList<KSharedPtr<Message> >& msgs);
85 void playSound(int sound);
86 void onDeath();
87 void setManPosition(const QPointF& p);
88protected:
89 virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
90 virtual void focusOutEvent(QFocusEvent*);
91public:
92 MainArea();
93 void start();
94 void setPauseAction(KAction* action);
95public slots:
96 void tick();
97 void enableSounds(bool enable);
98 void abort();
99 void togglePause();
100signals:
101 void starting();
102 void gameOver(int);
103 void changeBallNumber(int);
104 void changeGameTime(int);
105 void changeState(bool);
106 void pause(bool);
107};
108
109#endif // MAINAREA_H
110
111