source: trunk/examples/demo/qasteroids/view.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: 3.2 KB
Line 
1/*
2 * KAsteroids - Copyright (c) Martin R. Jones 1997
3 *
4 * Part of the KDE project
5 */
6
7#ifndef __AST_VIEW_H__
8#define __AST_VIEW_H__
9
10#include <qwidget.h>
11#include <qptrlist.h>
12#include <qintdict.h>
13#include <qtimer.h>
14#include <qcanvas.h>
15#include "sprites.h"
16
17#define MAX_POWER_LEVEL 1000
18
19class KAsteroidsView : public QWidget
20{
21 Q_OBJECT
22public:
23 KAsteroidsView( QWidget *parent = 0, const char *name = 0 );
24 virtual ~KAsteroidsView();
25
26 int refreshRate;
27
28 void reset();
29 void setRockSpeed( double rs ) { rockSpeed = rs; }
30 void addRocks( int num );
31 void newGame();
32 void endGame();
33 void newShip();
34
35 void rotateLeft( bool r ) { rotateL = r; rotateSlow = 5; }
36 void rotateRight( bool r ) { rotateR = r; rotateSlow = 5; }
37 void thrust( bool t ) { thrustShip = t && shipPower > 0; }
38 void shoot( bool s ) { shootShip = s; shootDelay = 0; }
39 void setShield( bool s );
40 void teleport( bool te) { teleportShip = te && mTeleportCount; }
41 void brake( bool b );
42 void pause( bool p);
43
44 void showText( const QString &text, const QColor &color, bool scroll=TRUE );
45 void hideText();
46
47 int shots() const { return shotsFired; }
48 int hits() const { return shotsHit; }
49 int power() const { return shipPower; }
50
51 int teleportCount() const { return mTeleportCount; }
52 int brakeCount() const { return mBrakeCount; }
53 int shieldCount() const { return mShieldCount; }
54 int shootCount() const { return mShootCount; }
55
56signals:
57 void shipKilled();
58 void rockHit( int size );
59 void rocksRemoved();
60 void updateVitals();
61
62private slots:
63 void hideShield();
64
65protected:
66 bool readSprites();
67 void wrapSprite( QCanvasItem * );
68 void rockHit( QCanvasItem * );
69 void reducePower( int val );
70 void addExhaust( double x, double y, double dx, double dy, int count );
71 void processMissiles();
72 void processShip();
73 void processPowerups();
74 void processShield();
75 double randDouble();
76 int randInt( int range );
77
78 virtual void resizeEvent( QResizeEvent *event );
79 virtual void timerEvent( QTimerEvent * );
80
81 void showEvent( QShowEvent * );
82
83private:
84 QCanvas field;
85 QCanvasView view;
86 QIntDict<QCanvasPixmapArray> animation;
87 QPtrList<QCanvasSprite> rocks;
88 QPtrList<KMissile> missiles;
89 QPtrList<KBit> bits;
90 QPtrList<KExhaust> exhaust;
91 QPtrList<KPowerup> powerups;
92 KShield *shield;
93 QCanvasSprite *ship;
94 QCanvasText *textSprite;
95
96 bool rotateL;
97 bool rotateR;
98 bool thrustShip;
99 bool shootShip;
100 bool teleportShip;
101 bool brakeShip;
102 bool pauseShip;
103 bool shieldOn;
104
105 bool vitalsChanged;
106
107 int shipAngle;
108 int rotateSlow;
109 int rotateRate;
110 int shipPower;
111
112 int shotsFired;
113 int shotsHit;
114 int shootDelay;
115
116 int mBrakeCount;
117 int mShieldCount;
118 int mTeleportCount;
119 int mShootCount;
120
121 double shipDx;
122 double shipDy;
123
124 int textDy;
125 int mFrameNum;
126 bool mPaused;
127 int mTimerId;
128
129 double rockSpeed;
130 double powerupSpeed;
131
132 bool can_destroy_powerups;
133
134 QTimer *shieldTimer;
135 bool initialized;
136};
137
138#endif
Note: See TracBrowser for help on using the repository browser.