• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kgoldrunner

  • sources
  • kde-4.14
  • kdegames
  • kgoldrunner
  • src
kgrscene.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright 2012 Roney Gomes <roney477@gmail.com> *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16  ****************************************************************************/
17 
47 #ifndef KGRSCENE_H
48 #define KGRSCENE_H
49 
50 #include <QGraphicsScene>
51 
52 #include "kgrglobals.h"
53 
54 class KGrView;
55 class KGrSprite;
56 class KGrRenderer;
57 class KGameRenderer;
58 class KGameRenderedItem;
59 class QTimeLine;
60 
61 enum StartFrame {RIGHTWALK1 = 1, RIGHTWALK2, RIGHTWALK3, RIGHTWALK4,
62  RIGHTWALK5, RIGHTWALK6, RIGHTWALK7, RIGHTWALK8,
63  LEFTWALK1, LEFTWALK2, LEFTWALK3, LEFTWALK4,
64  LEFTWALK5, LEFTWALK6, LEFTWALK7, LEFTWALK8,
65  RIGHTCLIMB1, RIGHTCLIMB2, RIGHTCLIMB3, RIGHTCLIMB4,
66  RIGHTCLIMB5, RIGHTCLIMB6, RIGHTCLIMB7, RIGHTCLIMB8,
67  LEFTCLIMB1, LEFTCLIMB2, LEFTCLIMB3, LEFTCLIMB4,
68  LEFTCLIMB5, LEFTCLIMB6, LEFTCLIMB7, LEFTCLIMB8,
69  CLIMB1, CLIMB2,
70  FALL1, FALL2,
71  DIGBRICK1 = 1, DIGBRICK2, DIGBRICK3, DIGBRICK4,
72  DIGBRICK5,
73  DIGBRICK6, DIGBRICK7, DIGBRICK8, DIGBRICK9};
74 
75 class KGrScene : public QGraphicsScene
76 {
77  Q_OBJECT
78 public:
79  KGrScene (KGrView * view);
80  ~KGrScene ();
81 
85  void changeTheme ();
86 
90  void changeSize ();
91 
97  void setLevel (unsigned int level);
98 
104  void setTitle (const QString & newTitle);
105 
106  void setReplayMessage (const QString & msg);
107 
108  void showReplayMessage (bool onOff);
109 
110  void setHasHintText (const QString & msg);
111 
112  void setPauseResumeText (const QString & msg);
113 
114  void goToBlack();
115  void fadeIn (bool inOut);
116 
121  QSize tileSize () const { return QSize (m_tileSize, m_tileSize); }
122 
126  KGrRenderer * renderer () const { return m_renderer; }
127 
128  inline void setGoldEnemiesRule (bool showIt) { enemiesShowGold = showIt; }
129 
130 public slots:
131  void showLives (long lives);
132 
133  void showScore (long score);
134 
135  int makeSprite (const char type, int i, int j);
136 
137  void animate (bool missed);
138  void gotGold (const int spriteId, const int i, const int j,
139  const bool spriteHasGold, const bool lost = false);
140  void showHiddenLadders (const QList<int> & ladders, const int width);
141  void deleteSprite (const int id);
142  void deleteAllSprites ();
143 
155  void paintCell (const int i, const int j, const char type);
156 
169  void startAnimation (const int id, const bool repeating,
170  const int i, const int j, const int time,
171  const Direction dirn, const AnimationType type);
172 
178  void preRenderSprites();
179 
180  void setMousePos (const int i, const int j);
181  void getMousePos (int & i, int & j);
182 
183 signals:
184  void fadeFinished();
185  void redrawEditToolbar();
186 
187 private:
188  /*
189  * Actions performed whenever the viewport is resized or a different theme
190  * is loaded.
191  */
192  void redrawScene ();
193 
194  /*
195  * Load and set the size and position of the KGameRenderedItem's which make
196  * up the border layout.
197  */
198  void drawBorder ();
199 
200  /*
201  * Draw a frame around the playing area when there are no border tiles.
202  */
203  void drawFrame ();
204 
205  /*
206  * Load and set the size and position of the background image for the
207  * current level.
208  *
209  * @param level The current level.
210  */
211  void loadBackground (const int level);
212 
213  /*
214  * Add a new element, with coordinates x and y, to the border-layout.
215  *
216  * @param spriteKey The sprite key of the requested item.
217  * @param x The item's x coordinate.
218  * @param y The item's y coordinate.
219  */
220  void setBorderTile (const QString spriteKey, const int x, const int y);
221 
222  /*
223  * Resize a game's visual element.
224  *
225  * @param tile The element to be resized.
226  * @param tileSize The new size.
227  */
228  void setTile (KGameRenderedItem * tile, const int tileSize,
229  const int i, const int j);
230 
231  KGrView * m_view;
232  KGrRenderer * m_renderer;
233  KGameRenderedItem * m_background;
234  int m_level;
235 
236  QGraphicsRectItem * m_frame;
237 
238  // Text items.
239  QGraphicsSimpleTextItem * m_title;
240  QGraphicsSimpleTextItem * m_replayMessage;
241  QGraphicsSimpleTextItem * m_livesText;
242  QGraphicsSimpleTextItem * m_scoreText;
243  QGraphicsSimpleTextItem * m_hasHintText;
244  QGraphicsSimpleTextItem * m_pauseResumeText;
245 
246  int m_heroId;
247  int m_tilesWide;
248  int m_tilesHigh;
249  int m_tileSize;
250  int m_toolbarTileSize;
251 
252  bool m_sizeChanged;
253  bool m_themeChanged;
254 
255  // The animated sprites for dug bricks, hero and enemies.
256  QList <KGrSprite *> m_sprites;
257 
258  // The visible elements of the scenario (tiles and borders), excluding the
259  // background picture and the animated sprites.
260  QVector <KGameRenderedItem *> m_tiles;
261 
262  // The type of each tile stored in m_tiles.
263  QByteArray m_tileTypes;
264 
265  bool enemiesShowGold; // Show or conceal if enemies have gold.
266 
267  int m_topLeftX;
268  int m_topLeftY;
269 
270  QCursor * m_mouse;
271 
272  void setTextFont (QGraphicsSimpleTextItem * t, double fontFraction);
273  void placeTextItems();
274 
275  QGraphicsRectItem * m_spotlight; // Fade-out/fade-in item.
276  QTimeLine * m_fadingTimeLine; // Timing for fade-out/fade-in.
277  QRadialGradient m_gradient; // Black with circular hole.
278  qreal m_maxRadius;
279 
280 private slots:
281  void drawSpotlight (qreal ratio); // Animate m_spotlight.
282 };
283 
284 #endif // KGRSCENE_H
LEFTWALK1
Definition: kgrscene.h:63
LEFTCLIMB4
Definition: kgrscene.h:67
RIGHTCLIMB6
Definition: kgrscene.h:66
RIGHTWALK5
Definition: kgrscene.h:62
QGraphicsScene
KGrScene::getMousePos
void getMousePos(int &i, int &j)
Definition: kgrscene.cpp:620
KGrScene::redrawEditToolbar
void redrawEditToolbar()
RIGHTCLIMB5
Definition: kgrscene.h:66
KGrScene::showReplayMessage
void showReplayMessage(bool onOff)
Definition: kgrscene.cpp:242
KGrScene::setReplayMessage
void setReplayMessage(const QString &msg)
Definition: kgrscene.cpp:237
DIGBRICK6
Definition: kgrscene.h:73
DIGBRICK7
Definition: kgrscene.h:73
RIGHTWALK2
Definition: kgrscene.h:61
KGrScene::fadeIn
void fadeIn(bool inOut)
Definition: kgrscene.cpp:320
QByteArray
LEFTWALK4
Definition: kgrscene.h:63
RIGHTWALK6
Definition: kgrscene.h:62
LEFTWALK7
Definition: kgrscene.h:64
KGrScene::tileSize
QSize tileSize() const
Get the current size of the squared region occupied by a single visual element (characters, ladders, bricks etc.).
Definition: kgrscene.h:121
LEFTWALK6
Definition: kgrscene.h:64
LEFTWALK8
Definition: kgrscene.h:64
FALL1
Definition: kgrscene.h:70
DIGBRICK1
Definition: kgrscene.h:71
DIGBRICK9
Definition: kgrscene.h:73
KGrScene::animate
void animate(bool missed)
Definition: kgrscene.cpp:488
DIGBRICK5
Definition: kgrscene.h:72
KGrScene::setTitle
void setTitle(const QString &newTitle)
Set the text for the title of the current level.
Definition: kgrscene.cpp:227
KGrScene::fadeFinished
void fadeFinished()
RIGHTCLIMB3
Definition: kgrscene.h:65
KGrScene::gotGold
void gotGold(const int spriteId, const int i, const int j, const bool spriteHasGold, const bool lost=false)
Definition: kgrscene.cpp:551
KGrScene::setGoldEnemiesRule
void setGoldEnemiesRule(bool showIt)
Definition: kgrscene.h:128
QGraphicsSimpleTextItem
LEFTWALK5
Definition: kgrscene.h:64
KGrScene::deleteAllSprites
void deleteAllSprites()
Definition: kgrscene.cpp:589
Direction
Direction
Definition: kgrglobals.h:174
RIGHTCLIMB7
Definition: kgrscene.h:66
KGrScene::setPauseResumeText
void setPauseResumeText(const QString &msg)
Definition: kgrscene.cpp:309
DIGBRICK3
Definition: kgrscene.h:71
LEFTCLIMB2
Definition: kgrscene.h:67
KGrScene::changeTheme
void changeTheme()
Redraw the scene whenever the current theme has changed.
Definition: kgrscene.cpp:215
KGrScene::~KGrScene
~KGrScene()
Definition: kgrscene.cpp:103
RIGHTWALK4
Definition: kgrscene.h:61
RIGHTWALK8
Definition: kgrscene.h:62
CLIMB2
Definition: kgrscene.h:69
KGrScene::setHasHintText
void setHasHintText(const QString &msg)
Definition: kgrscene.cpp:303
StartFrame
StartFrame
Definition: kgrscene.h:61
KGrScene::changeSize
void changeSize()
Redraw the scene whenever the view widget is resized.
Definition: kgrscene.cpp:221
DIGBRICK4
Definition: kgrscene.h:71
KGrScene::goToBlack
void goToBlack()
Definition: kgrscene.cpp:315
QString
QList< int >
RIGHTCLIMB8
Definition: kgrscene.h:66
KGrScene::showScore
void showScore(long score)
Definition: kgrscene.cpp:296
KGrScene::renderer
KGrRenderer * renderer() const
Get a pointer to the scene's renderer.
Definition: kgrscene.h:126
KGrRenderer
Definition: kgrrenderer.h:61
LEFTCLIMB3
Definition: kgrscene.h:67
RIGHTWALK1
Definition: kgrscene.h:61
QSize
LEFTCLIMB7
Definition: kgrscene.h:68
LEFTCLIMB6
Definition: kgrscene.h:68
RIGHTCLIMB4
Definition: kgrscene.h:65
RIGHTWALK7
Definition: kgrscene.h:62
LEFTWALK3
Definition: kgrscene.h:63
KGrScene::deleteSprite
void deleteSprite(const int id)
Definition: kgrscene.cpp:575
QVector< KGameRenderedItem * >
LEFTCLIMB1
Definition: kgrscene.h:67
DIGBRICK8
Definition: kgrscene.h:73
kgrglobals.h
QGraphicsRectItem
RIGHTCLIMB1
Definition: kgrscene.h:65
QRadialGradient
KGrView
Definition: kgrview.h:27
KGrSprite
Definition: kgrsprite.h:29
FALL2
Definition: kgrscene.h:70
LEFTCLIMB8
Definition: kgrscene.h:68
KGameRenderedItem
KGrScene::setMousePos
void setMousePos(const int i, const int j)
Definition: kgrscene.cpp:613
QTimeLine
KGrScene::showLives
void showLives(long lives)
Definition: kgrscene.cpp:289
LEFTWALK2
Definition: kgrscene.h:63
DIGBRICK2
Definition: kgrscene.h:71
KGrScene::setLevel
void setLevel(unsigned int level)
Set the current level number.
Definition: kgrscene.cpp:346
KGrScene::preRenderSprites
void preRenderSprites()
Just as the game starts, ensure that all frames of the "hero" and "enemy" sprites have been rendered...
Definition: kgrscene.cpp:595
KGrScene
The QGraphicsScene that represents KGoldrunner on the screen.
Definition: kgrscene.h:75
RIGHTCLIMB2
Definition: kgrscene.h:65
LEFTCLIMB5
Definition: kgrscene.h:68
CLIMB1
Definition: kgrscene.h:69
QCursor
RIGHTWALK3
Definition: kgrscene.h:61
KGrScene::startAnimation
void startAnimation(const int id, const bool repeating, const int i, const int j, const int time, const Direction dirn, const AnimationType type)
Requests the view to display an animation of a runner or dug brick at a particular cell...
Definition: kgrscene.cpp:497
AnimationType
AnimationType
Definition: kgrglobals.h:203
KGrScene::makeSprite
int makeSprite(const char type, int i, int j)
Definition: kgrscene.cpp:442
KGrScene::showHiddenLadders
void showHiddenLadders(const QList< int > &ladders, const int width)
Definition: kgrscene.cpp:566
KGrScene::paintCell
void paintCell(const int i, const int j, const char type)
Requests the view to display a particular type of tile at a particular cell, or make it empty and sho...
Definition: kgrscene.cpp:430
KGrScene::KGrScene
KGrScene(KGrView *view)
Definition: kgrscene.cpp:37
QGraphicsScene::width
qreal width() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:24 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgoldrunner

Skip menu "kgoldrunner"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal