source: trunk/examples/demo/qasteroids/sprites.h@ 168

Last change on this file since 168 was 160, checked in by dmik, 19 years ago

Imported table and iconview modules and a bunch of dependent examples from the official release 3.3.1 from Trolltech.

  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1/*
2 * KAsteroids - Copyright (c) Martin R. Jones 1997
3 *
4 * Part of the KDE project
5 */
6
7#ifndef __SPRITES_H__
8#define __SPRITES_H__
9
10#include <qcanvas.h>
11
12#define ID_ROCK_LARGE 1024
13#define ID_ROCK_MEDIUM 1025
14#define ID_ROCK_SMALL 1026
15
16#define ID_MISSILE 1030
17
18#define ID_BIT 1040
19#define ID_EXHAUST 1041
20
21#define ID_ENERGY_POWERUP 1310
22#define ID_TELEPORT_POWERUP 1311
23#define ID_BRAKE_POWERUP 1312
24#define ID_SHIELD_POWERUP 1313
25#define ID_SHOOT_POWERUP 1314
26
27#define ID_SHIP 1350
28#define ID_SHIELD 1351
29
30#define MAX_SHIELD_AGE 350
31#define MAX_POWERUP_AGE 500
32#define MAX_MISSILE_AGE 40
33
34class KMissile : public QCanvasSprite
35{
36public:
37 KMissile( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c )
38 { myAge = 0; }
39
40 virtual int rtti() const { return ID_MISSILE; }
41
42 void growOlder() { myAge++; }
43 bool expired() { return myAge > MAX_MISSILE_AGE; }
44
45private:
46 int myAge;
47};
48
49class KBit : public QCanvasSprite
50{
51public:
52 KBit( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c )
53 { death = 7; }
54
55 virtual int rtti() const { return ID_BIT; }
56
57 void setDeath( int d ) { death = d; }
58 void growOlder() { death--; }
59 bool expired() { return death <= 0; }
60
61private:
62 int death;
63};
64
65class KExhaust : public QCanvasSprite
66{
67public:
68 KExhaust( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c )
69 { death = 1; }
70
71 virtual int rtti() const { return ID_EXHAUST; }
72
73 void setDeath( int d ) { death = d; }
74 void growOlder() { death--; }
75 bool expired() { return death <= 0; }
76
77private:
78 int death;
79};
80
81class KPowerup : public QCanvasSprite
82{
83public:
84 KPowerup( QCanvasPixmapArray *s, QCanvas *c, int t ) : QCanvasSprite( s, c ),
85 myAge( 0 ), type(t) { }
86
87 virtual int rtti() const { return type; }
88
89 void growOlder() { myAge++; }
90 bool expired() const { return myAge > MAX_POWERUP_AGE; }
91
92protected:
93 int myAge;
94 int type;
95};
96
97class KRock : public QCanvasSprite
98{
99public:
100 KRock (QCanvasPixmapArray *s, QCanvas *c, int t, int sk, int st) : QCanvasSprite( s, c )
101 { type = t; skip = cskip = sk; step = st; }
102
103 void nextFrame()
104 {
105 if (cskip-- <= 0) {
106 setFrame( (frame()+step+frameCount())%frameCount() );
107 cskip = QABS(skip);
108 }
109 }
110
111 virtual int rtti() const { return type; }
112
113private:
114 int type;
115 int skip;
116 int cskip;
117 int step;
118};
119
120class KShield : public QCanvasSprite
121{
122public:
123 KShield( QCanvasPixmapArray *s, QCanvas *c )
124 : QCanvasSprite( s, c ) {}
125
126 virtual int rtti() const { return ID_SHIELD; }
127};
128
129#endif
Note: See TracBrowser for help on using the repository browser.