• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kgoldrunner

kgrplayfield.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                        kgrplayfield.cpp  -  description
00003                              -------------------
00004     begin                : Fri Aug 04 2006
00005     Copyright 2006 Mauricio Piacentini <mauricio@tabuleiro.com>
00006     Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
00007 
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #include "kgrplayfield.h"
00020 #include <KDebug>
00021 
00022 KGrPlayField::KGrPlayField( KGameCanvasAbstract* canvas )
00023     : KGameCanvasGroup(canvas)
00024 {
00025     m_background = 0;
00026     show();
00027 }
00028 
00029 KGrPlayField::~KGrPlayField()
00030 {
00031     // Clear all stored data.
00032     while (!m_tilesprites.isEmpty())
00033             delete m_tilesprites.takeFirst();
00034     delete m_background;
00035 }
00036 
00037 void KGrPlayField::setTile (int x, int y, int tilenum)
00038 {
00039     Q_ASSERT(m_tileset);
00040     // Update the sprite pixmap using our tileset cache.
00041     if ((m_background != 0) && (tilenum == 0)) {
00042     m_tilesprites.at(y*m_numTilesH + x)->hide();
00043     }
00044     else {
00045     m_tilesprites.at(y*m_numTilesH + x)->setPixmap(m_tileset->at(tilenum));
00046     m_tilesprites.at(y*m_numTilesH + x)->show();
00047     m_tilesprites.at(y*m_numTilesH + x)->raise();
00048     }
00049 }
00050 
00051 void KGrPlayField::setBackground (const bool create, const QImage * background,
00052                     const QPoint & tl)
00053 {
00054     if (create) {
00055     delete m_background;                // Create a background
00056     m_background = 0;               // from tile zero
00057     if (background != 0) {              // or a QImage.
00058         m_background = new KGameCanvasPixmap (this);
00059         m_background->moveTo (tl.x(), tl.y());
00060         m_background->setPixmap (QPixmap::fromImage (* background));
00061         m_background->show();
00062     }
00063     }
00064     else {
00065     m_background->moveTo (tl.x(), tl.y());      // Move an existing bg.
00066     }
00067 }
00068 
00069 void KGrPlayField::setTiles (QList<QPixmap> * tileset, const QPoint & topLeft,
00070     const int h, const int v, const int tilewidth, const int tileheight)
00071 {
00072     QPixmap   pm;
00073     m_tilew = tilewidth;
00074     m_tileh = tileheight;
00075     m_numTilesH = h;
00076     m_numTilesV = v;
00077 
00078     Q_ASSERT(tileset);
00079     // Clear previously cached tile data.
00080     while (!m_tilesprites.isEmpty())
00081             delete m_tilesprites.takeFirst();
00082 
00083     // Now store our tileset as a list of Pixmaps, one for each tile.
00084     m_tileset = tileset;
00085 
00086     // Create the list of tile sprites in the playfield, arranged as a grid.
00087     int totaltiles = m_numTilesH * m_numTilesV;
00088     for (int i=0; i < totaltiles; ++i)
00089     {
00090     KGameCanvasPixmap * thissprite = new KGameCanvasPixmap(this);
00091     thissprite->moveTo((i % m_numTilesH) * m_tilew + topLeft.x(),
00092                (i / m_numTilesH) * m_tileh + topLeft.y());
00093     if (m_background == 0) {
00094         // If no background pixmap, fill the cell with tile zero.
00095         thissprite->setPixmap(m_tileset->at(0));
00096         thissprite->show();
00097     }
00098 
00099     //Finally, store the item in our tilesprite list
00100     m_tilesprites.append(thissprite);
00101     }
00102 }

kgoldrunner

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

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal