summaryrefslogtreecommitdiff
path: root/noncore/games/zlines/ballpainter.cpp
blob: 622ec296d33cae47076fcbdd60834bca2dcc79bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
                          ballpainter.cpp  -  description
                             -------------------
    begin                : Fri May 19 2000
    copyright            : (C) 2000 by Roman Merzlyakov
    email                : roman@sbrf.barrt.ru
    copyright            : (C) 2000 by Roman Razilov
    email                : Roman.Razilov@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <qpe/resource.h>

#include "ballpainter.h"
//#include "shotcounter.h"
#include <qpainter.h>
//#include <qcolor.h>


#define PIXSIZE 21

int colorLinesArr[NCOLORS] =
{0x0000ff, 0x00ff00, 0xff0000, 0x00ffff, 0xff00ff, 0xffff00, 0x005080};
// 0x00bbggrr
// red   ,  green  ,  blue   , yellow  , violet  ,   cyan  , brown



BallPainter::BallPainter()
	: QObject()
{
	createPixmap();
}

BallPainter::~BallPainter()
{
}

QPixmap* BallPainter::pixmap( enum Pixmaps pix )
{
    QString name;
    switch(pix) {
    case Field:
        name = QString::fromLatin1("zlines/field");
        break;
    case Balls:
        name = QString::fromLatin1("zlines/balls");
        break;
    case Fire:
        name = QString::fromLatin1("zlines/fire");
        break;
    }

    return new QPixmap(Resource::loadPixmap(name) );
}

void BallPainter::createPixmap()
{
	//  warning( kapp->kde_datadir() +"/klines/data/balls.bmp");
        backgroundPix = pixmap(Field);
	QPixmap *balls = pixmap(Balls);
	QPixmap *fire = pixmap(Fire);
	if (balls->isNull() ||backgroundPix->isNull() || fire->isNull() )
		fatal("Cannot open data files.\nHave you correctly installed klines?");

	warning("Pixsize %i", PIXSIZE);
	for(int c=0; c<NCOLORS; c++)
	{
		for(int t=0; t<PIXTIME + FIREBALLS + BOOMBALLS + 1 ; t++)
		{
			imgCash[c][t] = new QPixmap(CELLSIZE, CELLSIZE);
			QPainter p(imgCash[c][t]);
			p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE);
			p.drawPixmap(1,1,(*balls),t*PIXSIZE,c*PIXSIZE,PIXSIZE,PIXSIZE);
		}
		for(int t=0; t < FIREPIX ; t++)
		{
			firePix[t] = new QPixmap(CELLSIZE, CELLSIZE);
			QPainter p(firePix[t]);
			p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE);
			p.drawPixmap(1,1,(*fire),t*PIXSIZE,0,PIXSIZE,PIXSIZE);
		}
	}
	delete balls;
	delete fire;
}


QPixmap* BallPainter::GetBall(int color, int animstep, int panim)
{
	//    return backgroundPix;

	if( (color<0) || (color>=NCOLORS) || (animstep<0) || color == NOBALL )
	{
		// warning("BallPainter::Background");
		return backgroundPix;
	}
	if ( panim == ANIM_JUMP )
	{
		if ( ( animstep < 0 ) || ( animstep >= PIXTIME ) )
			return backgroundPix;
		else
			return imgCash[color][animstep];
	}
	else if ( panim == ANIM_BURN )
	{
		if ( animstep < FIREBALLS )
			return imgCash[color][animstep + PIXTIME + BOOMBALLS + 1];
		else if ( animstep < FIREBALLS + FIREPIX )
			return firePix[animstep - FIREBALLS];
	}
	else if ( panim == ANIM_BORN )
	{
		if ( animstep < BOOMBALLS )
			return imgCash[color][animstep + PIXTIME];
		else
			return imgCash[color][NORMALBALL];
	}
	// rest is not imlemented yet
	return imgCash[color][NORMALBALL];

}