From c90c389a8a8d9d8661e9772ec4144c5cf2039f23 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- ksnake/level.cpp | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 ksnake/level.cpp (limited to 'ksnake/level.cpp') diff --git a/ksnake/level.cpp b/ksnake/level.cpp new file mode 100644 index 00000000..86360818 --- /dev/null +++ b/ksnake/level.cpp @@ -0,0 +1,152 @@ +/** + * Copyright Michel Filippi + * Robert Williams + * Andrew Chant + * André Luiz dos Santos + * Benjamin Meyer + * + * This file is part of the ksnake package + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include "level.h" +#include "board.h" +#include "bitmaps.h" +#include "levels.h" + +const uchar *numbers[10] = { zero_bits, one_bits, two_bits, + three_bits, four_bits, five_bits, + six_bits, seven_bits, eight_bits, nine_bits +}; + +Level::Level(Board *b) +{ + board = b; + create(Intro); +} + +void Level::nextLevel() +{ + if (level < leV->max()) + level++; +} + +void Level::create(Img img) +{ + switch(img){ + case Banner: + createBanner(); + break; + case Room: + createRoom(); + break; + case Intro: + makeImageFromData(intro_bits); + break; + case GameOver: + makeImageFromData(gameover_bits); + break; + } +} + +void Level::createRoom() +{ + QImage image = leV->getImage(level); + initBoard(image); +} + +void Level::makeImageFromData(const uchar *buf) +{ + QBitmap bitmap(BoardWidth, BoardWidth, buf, true); + QImage image = bitmap.convertToImage(); + initBoard (image); +} + +void Level::initBoard(const QImage &image) +{ + int index = 0; + uchar *b; + + for ( int y = 0;y < image.height();y++ ) { + b = image.scanLine(y); + for ( int x = 0;x < image.width();x++ ) { + + if ( image.bitOrder() == QImage::BigEndian ) { + if (((*b >> (7 - (x & 7))) & 1) == 1) + board->set(index, brick); + else board->set(index, empty); + } else { + if (((*b >> (x & 7)) & 1) == 1) + board->set(index, brick); + else board->set(index, empty); + } + + if ( (x & 7) == 7 ) + b++; + index++; + } + } +} + +void Level::createBanner() +{ + makeImageFromData(level_bits); + + QString num; + num.setNum(level); + if(level < 10) + num.insert(0,'0'); + + QString left = num.left(1); + QString right = num.right(1); + + drawNumber ( 606, numbers[left.toInt()] ); + drawNumber ( 614, numbers[right.toInt()] ); +} + +void Level::drawNumber(int beginAt, const uchar *buf) +{ + QBitmap bitmap(7, 9, buf, true); + QImage image = bitmap.convertToImage(); + + int index = beginAt; + uchar *b; + + for ( int y = 0;y < image.height();y++ ) + { + b = image.scanLine(y); + for ( int x = 0;x < image.width();x++ ) + { + if ( image.bitOrder() == QImage::BigEndian ) + { + if (((*b >> (7 - (x & 7))) & 1) == 1) + board->set(index, brick); + } else { + if (((*b >> (x & 7)) & 1) == 1) + board->set(index, brick); + } + if ( (x & 7) == 7 ) + b++; + index++; + } + index += 28; + } +} + -- cgit v1.2.1