diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
commit | bd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch) | |
tree | 7a520322212d48ebcb9fbe1087e7fca28b76185c /examples/demo/qasteroids | |
download | qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip |
Add Qt3 development HEAD version
Diffstat (limited to 'examples/demo/qasteroids')
178 files changed, 2200 insertions, 0 deletions
diff --git a/examples/demo/qasteroids/bg.png b/examples/demo/qasteroids/bg.png Binary files differnew file mode 100644 index 0000000..33cdc48 --- /dev/null +++ b/examples/demo/qasteroids/bg.png diff --git a/examples/demo/qasteroids/ledmeter.cpp b/examples/demo/qasteroids/ledmeter.cpp new file mode 100644 index 0000000..d2113a8 --- /dev/null +++ b/examples/demo/qasteroids/ledmeter.cpp @@ -0,0 +1,117 @@ +/* + * KAsteroids - Copyright (c) Martin R. Jones 1997 + * + * Part of the KDE project + */ + +#include <qpainter.h> +#include "ledmeter.h" + +KALedMeter::KALedMeter( QWidget *parent ) : QFrame( parent ) +{ + mCRanges.setAutoDelete( TRUE ); + mRange = 100; + mCount = 20; + mCurrentCount = 0; + mValue = 0; + setMinimumWidth( mCount * 2 + frameWidth() ); +} + +void KALedMeter::setRange( int r ) +{ + mRange = r; + if ( mRange < 1 ) + mRange = 1; + setValue( mValue ); + update(); +} + +void KALedMeter::setCount( int c ) +{ + mCount = c; + if ( mCount < 1 ) + mCount = 1; + setMinimumWidth( mCount * 2 + frameWidth() ); + calcColorRanges(); + setValue( mValue ); + update(); +} + +void KALedMeter::setValue( int v ) +{ + mValue = v; + if ( mValue > mRange ) + mValue = mRange; + else if ( mValue < 0 ) + mValue = 0; + int c = ( mValue + mRange / mCount - 1 ) * mCount / mRange; + if ( c != mCurrentCount ) + { + mCurrentCount = c; + update(); + } +} + +void KALedMeter::addColorRange( int pc, const QColor &c ) +{ + ColorRange *cr = new ColorRange; + cr->mPc = pc; + cr->mColor = c; + mCRanges.append( cr ); + calcColorRanges(); +} + +void KALedMeter::resizeEvent( QResizeEvent *e ) +{ + QFrame::resizeEvent( e ); + int w = ( width() - frameWidth() - 2 ) / mCount * mCount; + w += frameWidth() + 2; + setFrameRect( QRect( 0, 0, w, height() ) ); +} + +void KALedMeter::drawContents( QPainter *p ) +{ + QRect b = contentsRect(); + + unsigned cidx = 0; + int ncol = mCount; + QColor col = colorGroup().foreground(); + + if ( !mCRanges.isEmpty() ) + { + col = mCRanges.at( cidx )->mColor; + ncol = mCRanges.at( cidx )->mValue; + } + p->setBrush( col ); + p->setPen( col ); + + int lw = b.width() / mCount; + int lx = b.left() + 1; + for ( int i = 0; i < mCurrentCount; i++, lx += lw ) + { + if ( i > ncol ) + { + if ( ++cidx < mCRanges.count() ) + { + col = mCRanges.at( cidx )->mColor; + ncol = mCRanges.at( cidx )->mValue; + p->setBrush( col ); + p->setPen( col ); + } + } + + p->drawRect( lx, b.top() + 1, lw - 1, b.height() - 2 ); + } +} + +void KALedMeter::calcColorRanges() +{ + int prev = 0; + ColorRange *cr; + for ( cr = mCRanges.first(); cr; cr = mCRanges.next() ) + { + cr->mValue = prev + cr->mPc * mCount / 100; + prev = cr->mValue; + } +} + diff --git a/examples/demo/qasteroids/ledmeter.h b/examples/demo/qasteroids/ledmeter.h new file mode 100644 index 0000000..d0f2091 --- /dev/null +++ b/examples/demo/qasteroids/ledmeter.h @@ -0,0 +1,53 @@ +/* + * KAsteroids - Copyright (c) Martin R. Jones 1997 + * + * Part of the KDE project + */ + +#ifndef __LEDMETER_H__ +#define __LEDMETER_H__ + +#include <qframe.h> +#include <qptrlist.h> + + +class KALedMeter : public QFrame +{ + Q_OBJECT +public: + KALedMeter( QWidget *parent ); + + int range() const { return mRange; } + void setRange( int r ); + + int count() const { return mCount; } + void setCount( int c ); + + int value () const { return mValue; } + + void addColorRange( int pc, const QColor &c ); + +public slots: + void setValue( int v ); + +protected: + virtual void resizeEvent( QResizeEvent * ); + virtual void drawContents( QPainter * ); + void calcColorRanges(); + +protected: + struct ColorRange + { + int mPc; + int mValue; + QColor mColor; + }; + + int mRange; + int mCount; + int mCurrentCount; + int mValue; + QPtrList<ColorRange> mCRanges; +}; + +#endif diff --git a/examples/demo/qasteroids/sounds/Explosion.wav b/examples/demo/qasteroids/sounds/Explosion.wav Binary files differnew file mode 100644 index 0000000..7b140b1 --- /dev/null +++ b/examples/demo/qasteroids/sounds/Explosion.wav diff --git a/examples/demo/qasteroids/sprites.h b/examples/demo/qasteroids/sprites.h new file mode 100644 index 0000000..0b0a718 --- /dev/null +++ b/examples/demo/qasteroids/sprites.h @@ -0,0 +1,129 @@ +/* + * KAsteroids - Copyright (c) Martin R. Jones 1997 + * + * Part of the KDE project + */ + +#ifndef __SPRITES_H__ +#define __SPRITES_H__ + +#include <qcanvas.h> + +#define ID_ROCK_LARGE 1024 +#define ID_ROCK_MEDIUM 1025 +#define ID_ROCK_SMALL 1026 + +#define ID_MISSILE 1030 + +#define ID_BIT 1040 +#define ID_EXHAUST 1041 + +#define ID_ENERGY_POWERUP 1310 +#define ID_TELEPORT_POWERUP 1311 +#define ID_BRAKE_POWERUP 1312 +#define ID_SHIELD_POWERUP 1313 +#define ID_SHOOT_POWERUP 1314 + +#define ID_SHIP 1350 +#define ID_SHIELD 1351 + +#define MAX_SHIELD_AGE 350 +#define MAX_POWERUP_AGE 500 +#define MAX_MISSILE_AGE 40 + +class KMissile : public QCanvasSprite +{ +public: + KMissile( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c ) + { myAge = 0; } + + virtual int rtti() const { return ID_MISSILE; } + + void growOlder() { myAge++; } + bool expired() { return myAge > MAX_MISSILE_AGE; } + +private: + int myAge; +}; + +class KBit : public QCanvasSprite +{ +public: + KBit( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c ) + { death = 7; } + + virtual int rtti() const { return ID_BIT; } + + void setDeath( int d ) { death = d; } + void growOlder() { death--; } + bool expired() { return death <= 0; } + +private: + int death; +}; + +class KExhaust : public QCanvasSprite +{ +public: + KExhaust( QCanvasPixmapArray *s, QCanvas *c ) : QCanvasSprite( s, c ) + { death = 1; } + + virtual int rtti() const { return ID_EXHAUST; } + + void setDeath( int d ) { death = d; } + void growOlder() { death--; } + bool expired() { return death <= 0; } + +private: + int death; +}; + +class KPowerup : public QCanvasSprite +{ +public: + KPowerup( QCanvasPixmapArray *s, QCanvas *c, int t ) : QCanvasSprite( s, c ), + myAge( 0 ), type(t) { } + + virtual int rtti() const { return type; } + + void growOlder() { myAge++; } + bool expired() const { return myAge > MAX_POWERUP_AGE; } + +protected: + int myAge; + int type; +}; + +class KRock : public QCanvasSprite +{ +public: + KRock (QCanvasPixmapArray *s, QCanvas *c, int t, int sk, int st) : QCanvasSprite( s, c ) + { type = t; skip = cskip = sk; step = st; } + + void nextFrame() + { + if (cskip-- <= 0) { + setFrame( (frame()+step+frameCount())%frameCount() ); + cskip = QABS(skip); + } + } + + virtual int rtti() const { return type; } + +private: + int type; + int skip; + int cskip; + int step; +}; + +class KShield : public QCanvasSprite +{ +public: + KShield( QCanvasPixmapArray *s, QCanvas *c ) + : QCanvasSprite( s, c ) {} + + virtual int rtti() const { return ID_SHIELD; } +}; + +#endif diff --git a/examples/demo/qasteroids/sprites/.pbm b/examples/demo/qasteroids/sprites/.pbm new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/examples/demo/qasteroids/sprites/.pbm diff --git a/examples/demo/qasteroids/sprites/bits/bits.ini b/examples/demo/qasteroids/sprites/bits/bits.ini new file mode 100644 index 0000000..cb2976f --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits.ini @@ -0,0 +1,9 @@ +Cyclic_Animation=On +Width=12 +Height=12 +Final_frame=16 ;; NR_ROTS +Antialias=On +Output_Alpha=On +Output_to_File=On +Output_File_Type=n +Input_File_Name=bits.pov diff --git a/examples/demo/qasteroids/sprites/bits/bits.pov b/examples/demo/qasteroids/sprites/bits/bits.pov new file mode 100644 index 0000000..9be7ccb --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits.pov @@ -0,0 +1,31 @@ + +#version 3.0 +global_settings { assumed_gamma 2.0 } + +#include "colors.inc" +#include "textures.inc" +#include "metals.inc" + +camera { + location <15, -15, -100> + look_at <0, 0, 0> +} + +light_source { <50, 50, -50> colour White } +light_source { <0, 0, -50> colour White } + +prism { + linear_sweep + linear_spline + 0, + 0.2, + 5, + <2, 0>, <0, 2>, <-1, 1>, <0, -3>, <2, 0> + texture { T_Silver_2A } + + rotate <360*clock, 50, 30> + scale <20, 20, 20> +} + + + diff --git a/examples/demo/qasteroids/sprites/bits/bits0000.png b/examples/demo/qasteroids/sprites/bits/bits0000.png Binary files differnew file mode 100644 index 0000000..5ec9d02 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0000.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0001.png b/examples/demo/qasteroids/sprites/bits/bits0001.png Binary files differnew file mode 100644 index 0000000..07b4012 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0001.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0002.png b/examples/demo/qasteroids/sprites/bits/bits0002.png Binary files differnew file mode 100644 index 0000000..8333792 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0002.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0003.png b/examples/demo/qasteroids/sprites/bits/bits0003.png Binary files differnew file mode 100644 index 0000000..9f1fc02 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0003.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0004.png b/examples/demo/qasteroids/sprites/bits/bits0004.png Binary files differnew file mode 100644 index 0000000..eb1cc09 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0004.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0005.png b/examples/demo/qasteroids/sprites/bits/bits0005.png Binary files differnew file mode 100644 index 0000000..149be63 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0005.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0006.png b/examples/demo/qasteroids/sprites/bits/bits0006.png Binary files differnew file mode 100644 index 0000000..4ac75c8 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0006.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0007.png b/examples/demo/qasteroids/sprites/bits/bits0007.png Binary files differnew file mode 100644 index 0000000..907241d --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0007.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0008.png b/examples/demo/qasteroids/sprites/bits/bits0008.png Binary files differnew file mode 100644 index 0000000..1533268 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0008.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0009.png b/examples/demo/qasteroids/sprites/bits/bits0009.png Binary files differnew file mode 100644 index 0000000..05402ba --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0009.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0010.png b/examples/demo/qasteroids/sprites/bits/bits0010.png Binary files differnew file mode 100644 index 0000000..ca4f229 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0010.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0011.png b/examples/demo/qasteroids/sprites/bits/bits0011.png Binary files differnew file mode 100644 index 0000000..91913c0 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0011.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0012.png b/examples/demo/qasteroids/sprites/bits/bits0012.png Binary files differnew file mode 100644 index 0000000..e55d439 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0012.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0013.png b/examples/demo/qasteroids/sprites/bits/bits0013.png Binary files differnew file mode 100644 index 0000000..9c73436 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0013.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0014.png b/examples/demo/qasteroids/sprites/bits/bits0014.png Binary files differnew file mode 100644 index 0000000..f0463a2 --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0014.png diff --git a/examples/demo/qasteroids/sprites/bits/bits0015.png b/examples/demo/qasteroids/sprites/bits/bits0015.png Binary files differnew file mode 100644 index 0000000..bce35aa --- /dev/null +++ b/examples/demo/qasteroids/sprites/bits/bits0015.png diff --git a/examples/demo/qasteroids/sprites/exhaust/exhaust.png b/examples/demo/qasteroids/sprites/exhaust/exhaust.png Binary files differnew file mode 100644 index 0000000..a17ee71 --- /dev/null +++ b/examples/demo/qasteroids/sprites/exhaust/exhaust.png diff --git a/examples/demo/qasteroids/sprites/missile/missile.png b/examples/demo/qasteroids/sprites/missile/missile.png Binary files differnew file mode 100644 index 0000000..4283c67 --- /dev/null +++ b/examples/demo/qasteroids/sprites/missile/missile.png diff --git a/examples/demo/qasteroids/sprites/powerups/brake.png b/examples/demo/qasteroids/sprites/powerups/brake.png Binary files differnew file mode 100644 index 0000000..75cd649 --- /dev/null +++ b/examples/demo/qasteroids/sprites/powerups/brake.png diff --git a/examples/demo/qasteroids/sprites/powerups/energy.png b/examples/demo/qasteroids/sprites/powerups/energy.png Binary files differnew file mode 100644 index 0000000..2d97ac1 --- /dev/null +++ b/examples/demo/qasteroids/sprites/powerups/energy.png diff --git a/examples/demo/qasteroids/sprites/powerups/shield.png b/examples/demo/qasteroids/sprites/powerups/shield.png Binary files differnew file mode 100644 index 0000000..bd60555 --- /dev/null +++ b/examples/demo/qasteroids/sprites/powerups/shield.png diff --git a/examples/demo/qasteroids/sprites/powerups/shoot.png b/examples/demo/qasteroids/sprites/powerups/shoot.png Binary files differnew file mode 100644 index 0000000..4b2b3e3 --- /dev/null +++ b/examples/demo/qasteroids/sprites/powerups/shoot.png diff --git a/examples/demo/qasteroids/sprites/powerups/teleport.png b/examples/demo/qasteroids/sprites/powerups/teleport.png Binary files differnew file mode 100644 index 0000000..121ec9c --- /dev/null +++ b/examples/demo/qasteroids/sprites/powerups/teleport.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock1.ini b/examples/demo/qasteroids/sprites/rock1/rock1.ini new file mode 100644 index 0000000..e42fc76 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock1.ini @@ -0,0 +1,9 @@ +Cyclic_Animation=On +Width=48 +Height=48 +Final_frame=32 ;; NR_ROTS +Antialias=On +Output_Alpha=On +Output_to_File=On +Output_File_Type=n +Input_File_Name=rock1.pov diff --git a/examples/demo/qasteroids/sprites/rock1/rock1.pov b/examples/demo/qasteroids/sprites/rock1/rock1.pov new file mode 100644 index 0000000..58298c0 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock1.pov @@ -0,0 +1,26 @@ +#include "colors.inc" +#include "shapes.inc" +#include "textures.inc" +// #include "stones.inc" + +camera { + location <2,2,-6> + up <0, 1, 0> +// right <4/3, 0, 0> + look_at <0,0,0> +} + +object { light_source { <10, 5, -5> color red 1.1 green 1.1 blue 1.0 } } + +#declare Rock = +mesh { + #include "rock.inc" /* collection of triangle or smooth_triangle data */ +} + +object { + Rock + texture { pigment {White} } + scale 1.9 + rotate <60, 45, 360*clock> +} + diff --git a/examples/demo/qasteroids/sprites/rock1/rock10000.png b/examples/demo/qasteroids/sprites/rock1/rock10000.png Binary files differnew file mode 100644 index 0000000..2e3ff93 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10000.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10001.png b/examples/demo/qasteroids/sprites/rock1/rock10001.png Binary files differnew file mode 100644 index 0000000..ba70d24 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10001.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10002.png b/examples/demo/qasteroids/sprites/rock1/rock10002.png Binary files differnew file mode 100644 index 0000000..88d776e --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10002.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10003.png b/examples/demo/qasteroids/sprites/rock1/rock10003.png Binary files differnew file mode 100644 index 0000000..9db197d --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10003.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10004.png b/examples/demo/qasteroids/sprites/rock1/rock10004.png Binary files differnew file mode 100644 index 0000000..9b92d55 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10004.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10005.png b/examples/demo/qasteroids/sprites/rock1/rock10005.png Binary files differnew file mode 100644 index 0000000..9cdddf5 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10005.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10006.png b/examples/demo/qasteroids/sprites/rock1/rock10006.png Binary files differnew file mode 100644 index 0000000..0c421a0 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10006.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10007.png b/examples/demo/qasteroids/sprites/rock1/rock10007.png Binary files differnew file mode 100644 index 0000000..2339c83 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10007.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10008.png b/examples/demo/qasteroids/sprites/rock1/rock10008.png Binary files differnew file mode 100644 index 0000000..d1eb8aa --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10008.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10009.png b/examples/demo/qasteroids/sprites/rock1/rock10009.png Binary files differnew file mode 100644 index 0000000..47ada42 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10009.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10010.png b/examples/demo/qasteroids/sprites/rock1/rock10010.png Binary files differnew file mode 100644 index 0000000..1a2eba0 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10010.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10011.png b/examples/demo/qasteroids/sprites/rock1/rock10011.png Binary files differnew file mode 100644 index 0000000..ec213e1 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10011.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10012.png b/examples/demo/qasteroids/sprites/rock1/rock10012.png Binary files differnew file mode 100644 index 0000000..3bdb39b --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10012.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10013.png b/examples/demo/qasteroids/sprites/rock1/rock10013.png Binary files differnew file mode 100644 index 0000000..08de9a0 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10013.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10014.png b/examples/demo/qasteroids/sprites/rock1/rock10014.png Binary files differnew file mode 100644 index 0000000..3b6ce60 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10014.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10015.png b/examples/demo/qasteroids/sprites/rock1/rock10015.png Binary files differnew file mode 100644 index 0000000..01216dc --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10015.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10016.png b/examples/demo/qasteroids/sprites/rock1/rock10016.png Binary files differnew file mode 100644 index 0000000..efb612d --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10016.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10017.png b/examples/demo/qasteroids/sprites/rock1/rock10017.png Binary files differnew file mode 100644 index 0000000..97bbfce --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10017.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10018.png b/examples/demo/qasteroids/sprites/rock1/rock10018.png Binary files differnew file mode 100644 index 0000000..2986267 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10018.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10019.png b/examples/demo/qasteroids/sprites/rock1/rock10019.png Binary files differnew file mode 100644 index 0000000..80eab6d --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10019.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10020.png b/examples/demo/qasteroids/sprites/rock1/rock10020.png Binary files differnew file mode 100644 index 0000000..78023e0 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10020.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10021.png b/examples/demo/qasteroids/sprites/rock1/rock10021.png Binary files differnew file mode 100644 index 0000000..076a338 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10021.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10022.png b/examples/demo/qasteroids/sprites/rock1/rock10022.png Binary files differnew file mode 100644 index 0000000..4f8f5ed --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10022.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10023.png b/examples/demo/qasteroids/sprites/rock1/rock10023.png Binary files differnew file mode 100644 index 0000000..4e6ba04 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10023.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10024.png b/examples/demo/qasteroids/sprites/rock1/rock10024.png Binary files differnew file mode 100644 index 0000000..1a15fc3 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10024.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10025.png b/examples/demo/qasteroids/sprites/rock1/rock10025.png Binary files differnew file mode 100644 index 0000000..b627d53 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10025.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10026.png b/examples/demo/qasteroids/sprites/rock1/rock10026.png Binary files differnew file mode 100644 index 0000000..7df23b1 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10026.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10027.png b/examples/demo/qasteroids/sprites/rock1/rock10027.png Binary files differnew file mode 100644 index 0000000..d2cb5d3 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10027.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10028.png b/examples/demo/qasteroids/sprites/rock1/rock10028.png Binary files differnew file mode 100644 index 0000000..68611a6 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10028.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10029.png b/examples/demo/qasteroids/sprites/rock1/rock10029.png Binary files differnew file mode 100644 index 0000000..44d6a30 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10029.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10030.png b/examples/demo/qasteroids/sprites/rock1/rock10030.png Binary files differnew file mode 100644 index 0000000..9dca7db --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10030.png diff --git a/examples/demo/qasteroids/sprites/rock1/rock10031.png b/examples/demo/qasteroids/sprites/rock1/rock10031.png Binary files differnew file mode 100644 index 0000000..10beae6 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock1/rock10031.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock2.ini b/examples/demo/qasteroids/sprites/rock2/rock2.ini new file mode 100644 index 0000000..d50e6fa --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock2.ini @@ -0,0 +1,9 @@ +Cyclic_Animation=On +Width=32 +Height=32 +Final_frame=32 ;; NR_ROTS +Antialias=On +Output_Alpha=On +Output_to_File=On +Output_File_Type=n +Input_File_Name=rock2.pov diff --git a/examples/demo/qasteroids/sprites/rock2/rock2.pov b/examples/demo/qasteroids/sprites/rock2/rock2.pov new file mode 100644 index 0000000..2f37a20 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock2.pov @@ -0,0 +1,26 @@ +#include "colors.inc" +#include "shapes.inc" +#include "textures.inc" +// #include "stones.inc" + +camera { + location <2,2,-6> + up <0, 1, 0> +// right <4/3, 0, 0> + look_at <0,0,0> +} + +object { light_source { <10, 5, -5> color red 1.1 green 1.1 blue 1.0 } } + +#declare Rock = +mesh { + #include "rock.inc" /* collection of triangle or smooth_triangle data */ +} + +object { + Rock + texture { pigment {White} } + scale 1.9 + rotate <60, 30, 360*clock> +} + diff --git a/examples/demo/qasteroids/sprites/rock2/rock20000.png b/examples/demo/qasteroids/sprites/rock2/rock20000.png Binary files differnew file mode 100644 index 0000000..5cb52bb --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20000.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20001.png b/examples/demo/qasteroids/sprites/rock2/rock20001.png Binary files differnew file mode 100644 index 0000000..c4c85eb --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20001.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20002.png b/examples/demo/qasteroids/sprites/rock2/rock20002.png Binary files differnew file mode 100644 index 0000000..dea49d7 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20002.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20003.png b/examples/demo/qasteroids/sprites/rock2/rock20003.png Binary files differnew file mode 100644 index 0000000..39772b8 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20003.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20004.png b/examples/demo/qasteroids/sprites/rock2/rock20004.png Binary files differnew file mode 100644 index 0000000..fb02ee4 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20004.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20005.png b/examples/demo/qasteroids/sprites/rock2/rock20005.png Binary files differnew file mode 100644 index 0000000..a81c5ac --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20005.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20006.png b/examples/demo/qasteroids/sprites/rock2/rock20006.png Binary files differnew file mode 100644 index 0000000..cf5c2f4 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20006.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20007.png b/examples/demo/qasteroids/sprites/rock2/rock20007.png Binary files differnew file mode 100644 index 0000000..479c21d --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20007.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20008.png b/examples/demo/qasteroids/sprites/rock2/rock20008.png Binary files differnew file mode 100644 index 0000000..871abca --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20008.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20009.png b/examples/demo/qasteroids/sprites/rock2/rock20009.png Binary files differnew file mode 100644 index 0000000..d5d7860 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20009.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20010.png b/examples/demo/qasteroids/sprites/rock2/rock20010.png Binary files differnew file mode 100644 index 0000000..1da9953 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20010.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20011.png b/examples/demo/qasteroids/sprites/rock2/rock20011.png Binary files differnew file mode 100644 index 0000000..2988658 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20011.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20012.png b/examples/demo/qasteroids/sprites/rock2/rock20012.png Binary files differnew file mode 100644 index 0000000..d104ff9 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20012.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20013.png b/examples/demo/qasteroids/sprites/rock2/rock20013.png Binary files differnew file mode 100644 index 0000000..e12943d --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20013.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20014.png b/examples/demo/qasteroids/sprites/rock2/rock20014.png Binary files differnew file mode 100644 index 0000000..dc7529c --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20014.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20015.png b/examples/demo/qasteroids/sprites/rock2/rock20015.png Binary files differnew file mode 100644 index 0000000..3d9d318 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20015.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20016.png b/examples/demo/qasteroids/sprites/rock2/rock20016.png Binary files differnew file mode 100644 index 0000000..6314f03 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20016.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20017.png b/examples/demo/qasteroids/sprites/rock2/rock20017.png Binary files differnew file mode 100644 index 0000000..5a8aeef --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20017.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20018.png b/examples/demo/qasteroids/sprites/rock2/rock20018.png Binary files differnew file mode 100644 index 0000000..f0e5b08 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20018.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20019.png b/examples/demo/qasteroids/sprites/rock2/rock20019.png Binary files differnew file mode 100644 index 0000000..d731950 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20019.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20020.png b/examples/demo/qasteroids/sprites/rock2/rock20020.png Binary files differnew file mode 100644 index 0000000..8bc7e20 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20020.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20021.png b/examples/demo/qasteroids/sprites/rock2/rock20021.png Binary files differnew file mode 100644 index 0000000..b2854b2 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20021.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20022.png b/examples/demo/qasteroids/sprites/rock2/rock20022.png Binary files differnew file mode 100644 index 0000000..781d620 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20022.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20023.png b/examples/demo/qasteroids/sprites/rock2/rock20023.png Binary files differnew file mode 100644 index 0000000..1f64b02 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20023.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20024.png b/examples/demo/qasteroids/sprites/rock2/rock20024.png Binary files differnew file mode 100644 index 0000000..bd19e74 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20024.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20025.png b/examples/demo/qasteroids/sprites/rock2/rock20025.png Binary files differnew file mode 100644 index 0000000..180f5b6 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20025.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20026.png b/examples/demo/qasteroids/sprites/rock2/rock20026.png Binary files differnew file mode 100644 index 0000000..f2681d4 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20026.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20027.png b/examples/demo/qasteroids/sprites/rock2/rock20027.png Binary files differnew file mode 100644 index 0000000..5bc1add --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20027.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20028.png b/examples/demo/qasteroids/sprites/rock2/rock20028.png Binary files differnew file mode 100644 index 0000000..5621b4d --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20028.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20029.png b/examples/demo/qasteroids/sprites/rock2/rock20029.png Binary files differnew file mode 100644 index 0000000..aec4a34 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20029.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20030.png b/examples/demo/qasteroids/sprites/rock2/rock20030.png Binary files differnew file mode 100644 index 0000000..121b70e --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20030.png diff --git a/examples/demo/qasteroids/sprites/rock2/rock20031.png b/examples/demo/qasteroids/sprites/rock2/rock20031.png Binary files differnew file mode 100644 index 0000000..661b18e --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock2/rock20031.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock3.ini b/examples/demo/qasteroids/sprites/rock3/rock3.ini new file mode 100644 index 0000000..26a3cf9 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock3.ini @@ -0,0 +1,9 @@ +Cyclic_Animation=On +Width=20 +Height=20 +Final_frame=32 ;; NR_ROTS +Antialias=On +Output_Alpha=On +Output_to_File=On +Output_File_Type=n +Input_File_Name=rock3.pov diff --git a/examples/demo/qasteroids/sprites/rock3/rock3.pov b/examples/demo/qasteroids/sprites/rock3/rock3.pov new file mode 100644 index 0000000..2f37a20 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock3.pov @@ -0,0 +1,26 @@ +#include "colors.inc" +#include "shapes.inc" +#include "textures.inc" +// #include "stones.inc" + +camera { + location <2,2,-6> + up <0, 1, 0> +// right <4/3, 0, 0> + look_at <0,0,0> +} + +object { light_source { <10, 5, -5> color red 1.1 green 1.1 blue 1.0 } } + +#declare Rock = +mesh { + #include "rock.inc" /* collection of triangle or smooth_triangle data */ +} + +object { + Rock + texture { pigment {White} } + scale 1.9 + rotate <60, 30, 360*clock> +} + diff --git a/examples/demo/qasteroids/sprites/rock3/rock30000.png b/examples/demo/qasteroids/sprites/rock3/rock30000.png Binary files differnew file mode 100644 index 0000000..de1205a --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30000.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30001.png b/examples/demo/qasteroids/sprites/rock3/rock30001.png Binary files differnew file mode 100644 index 0000000..12ebc00 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30001.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30002.png b/examples/demo/qasteroids/sprites/rock3/rock30002.png Binary files differnew file mode 100644 index 0000000..265c381 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30002.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30003.png b/examples/demo/qasteroids/sprites/rock3/rock30003.png Binary files differnew file mode 100644 index 0000000..1ff7a06 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30003.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30004.png b/examples/demo/qasteroids/sprites/rock3/rock30004.png Binary files differnew file mode 100644 index 0000000..5b505bf --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30004.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30005.png b/examples/demo/qasteroids/sprites/rock3/rock30005.png Binary files differnew file mode 100644 index 0000000..204c969 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30005.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30006.png b/examples/demo/qasteroids/sprites/rock3/rock30006.png Binary files differnew file mode 100644 index 0000000..32140cf --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30006.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30007.png b/examples/demo/qasteroids/sprites/rock3/rock30007.png Binary files differnew file mode 100644 index 0000000..f01baa6 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30007.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30008.png b/examples/demo/qasteroids/sprites/rock3/rock30008.png Binary files differnew file mode 100644 index 0000000..eee458e --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30008.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30009.png b/examples/demo/qasteroids/sprites/rock3/rock30009.png Binary files differnew file mode 100644 index 0000000..14412d4 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30009.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30010.png b/examples/demo/qasteroids/sprites/rock3/rock30010.png Binary files differnew file mode 100644 index 0000000..bb61d54 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30010.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30011.png b/examples/demo/qasteroids/sprites/rock3/rock30011.png Binary files differnew file mode 100644 index 0000000..8486e5a --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30011.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30012.png b/examples/demo/qasteroids/sprites/rock3/rock30012.png Binary files differnew file mode 100644 index 0000000..d9ae419 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30012.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30013.png b/examples/demo/qasteroids/sprites/rock3/rock30013.png Binary files differnew file mode 100644 index 0000000..ce69400 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30013.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30014.png b/examples/demo/qasteroids/sprites/rock3/rock30014.png Binary files differnew file mode 100644 index 0000000..981e92c --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30014.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30015.png b/examples/demo/qasteroids/sprites/rock3/rock30015.png Binary files differnew file mode 100644 index 0000000..63f0a69 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30015.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30016.png b/examples/demo/qasteroids/sprites/rock3/rock30016.png Binary files differnew file mode 100644 index 0000000..72bc42f --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30016.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30017.png b/examples/demo/qasteroids/sprites/rock3/rock30017.png Binary files differnew file mode 100644 index 0000000..c89f358 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30017.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30018.png b/examples/demo/qasteroids/sprites/rock3/rock30018.png Binary files differnew file mode 100644 index 0000000..e1ba724 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30018.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30019.png b/examples/demo/qasteroids/sprites/rock3/rock30019.png Binary files differnew file mode 100644 index 0000000..5f004a7 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30019.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30020.png b/examples/demo/qasteroids/sprites/rock3/rock30020.png Binary files differnew file mode 100644 index 0000000..58009bf --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30020.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30021.png b/examples/demo/qasteroids/sprites/rock3/rock30021.png Binary files differnew file mode 100644 index 0000000..8d9549c --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30021.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30022.png b/examples/demo/qasteroids/sprites/rock3/rock30022.png Binary files differnew file mode 100644 index 0000000..1e8a1c2 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30022.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30023.png b/examples/demo/qasteroids/sprites/rock3/rock30023.png Binary files differnew file mode 100644 index 0000000..9b960d6 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30023.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30024.png b/examples/demo/qasteroids/sprites/rock3/rock30024.png Binary files differnew file mode 100644 index 0000000..6c15f2b --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30024.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30025.png b/examples/demo/qasteroids/sprites/rock3/rock30025.png Binary files differnew file mode 100644 index 0000000..12b05da --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30025.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30026.png b/examples/demo/qasteroids/sprites/rock3/rock30026.png Binary files differnew file mode 100644 index 0000000..16190e9 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30026.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30027.png b/examples/demo/qasteroids/sprites/rock3/rock30027.png Binary files differnew file mode 100644 index 0000000..a862501 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30027.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30028.png b/examples/demo/qasteroids/sprites/rock3/rock30028.png Binary files differnew file mode 100644 index 0000000..e3e0c18 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30028.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30029.png b/examples/demo/qasteroids/sprites/rock3/rock30029.png Binary files differnew file mode 100644 index 0000000..ec70b84 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30029.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30030.png b/examples/demo/qasteroids/sprites/rock3/rock30030.png Binary files differnew file mode 100644 index 0000000..0b060d0 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30030.png diff --git a/examples/demo/qasteroids/sprites/rock3/rock30031.png b/examples/demo/qasteroids/sprites/rock3/rock30031.png Binary files differnew file mode 100644 index 0000000..c1dc1b9 --- /dev/null +++ b/examples/demo/qasteroids/sprites/rock3/rock30031.png diff --git a/examples/demo/qasteroids/sprites/shield/shield0000.png b/examples/demo/qasteroids/sprites/shield/shield0000.png Binary files differnew file mode 100644 index 0000000..e3434e6 --- /dev/null +++ b/examples/demo/qasteroids/sprites/shield/shield0000.png diff --git a/examples/demo/qasteroids/sprites/shield/shield0001.png b/examples/demo/qasteroids/sprites/shield/shield0001.png Binary files differnew file mode 100644 index 0000000..038cf5d --- /dev/null +++ b/examples/demo/qasteroids/sprites/shield/shield0001.png diff --git a/examples/demo/qasteroids/sprites/shield/shield0002.png b/examples/demo/qasteroids/sprites/shield/shield0002.png Binary files differnew file mode 100644 index 0000000..1cf0da0 --- /dev/null +++ b/examples/demo/qasteroids/sprites/shield/shield0002.png diff --git a/examples/demo/qasteroids/sprites/shield/shield0003.png b/examples/demo/qasteroids/sprites/shield/shield0003.png Binary files differnew file mode 100644 index 0000000..40c7256 --- /dev/null +++ b/examples/demo/qasteroids/sprites/shield/shield0003.png diff --git a/examples/demo/qasteroids/sprites/shield/shield0004.png b/examples/demo/qasteroids/sprites/shield/shield0004.png Binary files differnew file mode 100644 index 0000000..4ee43ba --- /dev/null +++ b/examples/demo/qasteroids/sprites/shield/shield0004.png diff --git a/examples/demo/qasteroids/sprites/shield/shield0005.png b/examples/demo/qasteroids/sprites/shield/shield0005.png Binary files differnew file mode 100644 index 0000000..0122e14 --- /dev/null +++ b/examples/demo/qasteroids/sprites/shield/shield0005.png diff --git a/examples/demo/qasteroids/sprites/shield/shield0006.png b/examples/demo/qasteroids/sprites/shield/shield0006.png Binary files differnew file mode 100644 index 0000000..dc5bea3 --- /dev/null +++ b/examples/demo/qasteroids/sprites/shield/shield0006.png diff --git a/examples/demo/qasteroids/sprites/ship/ship.ini b/examples/demo/qasteroids/sprites/ship/ship.ini new file mode 100644 index 0000000..479cc20 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship.ini @@ -0,0 +1,9 @@ +Cyclic_Animation=On +Width=42 +Height=42 +Final_frame=32 ;; NR_ROTS +Antialias=On +Output_Alpha=On +Output_to_File=On +Output_File_Type=n +Input_File_Name=ship.pov diff --git a/examples/demo/qasteroids/sprites/ship/ship.pov b/examples/demo/qasteroids/sprites/ship/ship.pov new file mode 100644 index 0000000..8f185cd --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship.pov @@ -0,0 +1,128 @@ + +#version 3.0 +global_settings { assumed_gamma 2.0 } + +#include "colors.inc" +#include "textures.inc" +#include "metals.inc" + +camera { + orthographic + up <0, 130, 0> + right <130, 0, 0> + location <0, 0, -130> + look_at <0, 0, 0> +} + +light_source { <50, 25, -25> colour White } +light_source { <0, 0, -100> colour Gray80 } + +#declare ShipColor = color red 1.0 green 1.0 blue 0.9 + +#declare BaseTexture = +texture { + pigment { ShipColor } +} + +#declare Grubby = +texture { + pigment { + bozo + color_map { + [0.0 color rgbt <1, 1, 1, 1>] + [0.8 color rgbt <0.9, 0.9, 0.9, 0.5>] + [1.0 color rgbt <0.8, 0.8, 0.8, 0.5>] + } + turbulence 2.0 + scale 3 + } +} + +#declare ShipTexture = +texture { BaseTexture } +texture { Grubby } + +union { + cone { + <12, 0, 0>, 0.5 + <11, 0, 0>, 1.0 + texture { ShipTexture } + } + cone { + <11, 0, 0>, 1.0 + <8, 0, 0>, 2.0 + texture { ShipTexture } + } + cone { + <8, 0, 0>, 2.0 + <3.5, 0, 0>, 3.8 + texture { ShipTexture } + } + difference { + cone { + <8, 0, -0.01>, 2.0 + <3.5, 0, -0.01>, 3.8 + pigment { color Gray20 } + } + box { + <9, -4.0, -3.7>, + <2, 4.0, 10> + rotate <0, -18, 0> + } + box { + <6.5, -4.0, -8>, + <10, 4.0, 8> + } + box { + <2, -4.0, -8>, + <4.5, 4.0, 8> + } + } + cone { + <3.5, 0, 0>, 3.8 + <2, 0, 0>, 4.0 + texture { ShipTexture } + } + cylinder { + <2, 0, 0>, + <-9, 0, 0>, + 4.0 + texture { ShipTexture } + } + cone { + <-9, 0, 0>, 4.0 + <-10, 0, 0>, 3.5 + texture { ShipTexture } + } + prism { + linear_sweep + linear_spline + 0, + 0.5, + 4, + <7.5, 0>, <-7.5, 10>, <-7.5, -10>, <7.5, 0> + rotate <90, 0, 0> + texture { T_Silver_2A } + texture { ShipTexture } + } + prism { + linear_sweep + linear_spline + -0.5, + 0.5, + 4, + <4, 0>, <-7.5, 5>, <-7.5, -5>, <4, 0> + pigment { color White } + } + cone { + <-12, 0, 0>, 3.0 + <-10, 0, 0>, 2.0 + texture { T_Silver_2A } + pigment { color Gray60 } + } + + rotate <0, 0,-360*clock> + scale <5, 5, 5> +} + + diff --git a/examples/demo/qasteroids/sprites/ship/ship0000.png b/examples/demo/qasteroids/sprites/ship/ship0000.png Binary files differnew file mode 100644 index 0000000..1d73a6e --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0000.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0001.png b/examples/demo/qasteroids/sprites/ship/ship0001.png Binary files differnew file mode 100644 index 0000000..d3f4b3f --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0001.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0002.png b/examples/demo/qasteroids/sprites/ship/ship0002.png Binary files differnew file mode 100644 index 0000000..c5f40fa --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0002.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0003.png b/examples/demo/qasteroids/sprites/ship/ship0003.png Binary files differnew file mode 100644 index 0000000..a1c8c25 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0003.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0004.png b/examples/demo/qasteroids/sprites/ship/ship0004.png Binary files differnew file mode 100644 index 0000000..8d3b6d9 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0004.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0005.png b/examples/demo/qasteroids/sprites/ship/ship0005.png Binary files differnew file mode 100644 index 0000000..15843dd --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0005.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0006.png b/examples/demo/qasteroids/sprites/ship/ship0006.png Binary files differnew file mode 100644 index 0000000..380509a --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0006.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0007.png b/examples/demo/qasteroids/sprites/ship/ship0007.png Binary files differnew file mode 100644 index 0000000..633f562 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0007.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0008.png b/examples/demo/qasteroids/sprites/ship/ship0008.png Binary files differnew file mode 100644 index 0000000..e40ad04 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0008.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0009.png b/examples/demo/qasteroids/sprites/ship/ship0009.png Binary files differnew file mode 100644 index 0000000..19f3436 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0009.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0010.png b/examples/demo/qasteroids/sprites/ship/ship0010.png Binary files differnew file mode 100644 index 0000000..b1142f4 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0010.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0011.png b/examples/demo/qasteroids/sprites/ship/ship0011.png Binary files differnew file mode 100644 index 0000000..b8acd62 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0011.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0012.png b/examples/demo/qasteroids/sprites/ship/ship0012.png Binary files differnew file mode 100644 index 0000000..06ac9eb --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0012.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0013.png b/examples/demo/qasteroids/sprites/ship/ship0013.png Binary files differnew file mode 100644 index 0000000..71cf38c --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0013.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0014.png b/examples/demo/qasteroids/sprites/ship/ship0014.png Binary files differnew file mode 100644 index 0000000..988a77f --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0014.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0015.png b/examples/demo/qasteroids/sprites/ship/ship0015.png Binary files differnew file mode 100644 index 0000000..1ad2193 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0015.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0016.png b/examples/demo/qasteroids/sprites/ship/ship0016.png Binary files differnew file mode 100644 index 0000000..c4f7125 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0016.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0017.png b/examples/demo/qasteroids/sprites/ship/ship0017.png Binary files differnew file mode 100644 index 0000000..09e226e --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0017.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0018.png b/examples/demo/qasteroids/sprites/ship/ship0018.png Binary files differnew file mode 100644 index 0000000..56b6190 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0018.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0019.png b/examples/demo/qasteroids/sprites/ship/ship0019.png Binary files differnew file mode 100644 index 0000000..473340a --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0019.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0020.png b/examples/demo/qasteroids/sprites/ship/ship0020.png Binary files differnew file mode 100644 index 0000000..dcfaa98 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0020.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0021.png b/examples/demo/qasteroids/sprites/ship/ship0021.png Binary files differnew file mode 100644 index 0000000..f5718a2 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0021.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0022.png b/examples/demo/qasteroids/sprites/ship/ship0022.png Binary files differnew file mode 100644 index 0000000..d59ca32 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0022.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0023.png b/examples/demo/qasteroids/sprites/ship/ship0023.png Binary files differnew file mode 100644 index 0000000..8f24927 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0023.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0024.png b/examples/demo/qasteroids/sprites/ship/ship0024.png Binary files differnew file mode 100644 index 0000000..0cae497 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0024.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0025.png b/examples/demo/qasteroids/sprites/ship/ship0025.png Binary files differnew file mode 100644 index 0000000..bc7c5db --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0025.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0026.png b/examples/demo/qasteroids/sprites/ship/ship0026.png Binary files differnew file mode 100644 index 0000000..386a9c7 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0026.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0027.png b/examples/demo/qasteroids/sprites/ship/ship0027.png Binary files differnew file mode 100644 index 0000000..ad96779 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0027.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0028.png b/examples/demo/qasteroids/sprites/ship/ship0028.png Binary files differnew file mode 100644 index 0000000..117420f --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0028.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0029.png b/examples/demo/qasteroids/sprites/ship/ship0029.png Binary files differnew file mode 100644 index 0000000..0677ce1 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0029.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0030.png b/examples/demo/qasteroids/sprites/ship/ship0030.png Binary files differnew file mode 100644 index 0000000..576625c --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0030.png diff --git a/examples/demo/qasteroids/sprites/ship/ship0031.png b/examples/demo/qasteroids/sprites/ship/ship0031.png Binary files differnew file mode 100644 index 0000000..ba87690 --- /dev/null +++ b/examples/demo/qasteroids/sprites/ship/ship0031.png diff --git a/examples/demo/qasteroids/toplevel.cpp b/examples/demo/qasteroids/toplevel.cpp new file mode 100644 index 0000000..aafc841 --- /dev/null +++ b/examples/demo/qasteroids/toplevel.cpp @@ -0,0 +1,494 @@ +/* + * KAsteroids - Copyright (c) Martin R. Jones 1997 + * + * Part of the KDE project + */ +// --- toplevel.cpp --- +#include <qaccel.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlcdnumber.h> +#include <qpushbutton.h> + +#include <qapplication.h> + +#include "toplevel.h" +#include "ledmeter.h" + + +#define SB_SCORE 1 +#define SB_LEVEL 2 +#define SB_SHIPS 3 + +struct SLevel +{ + int nrocks; + double rockSpeed; +}; + +#define MAX_LEVELS 16 + +SLevel levels[MAX_LEVELS] = +{ + { 1, 0.4 }, + { 1, 0.6 }, + { 2, 0.5 }, + { 2, 0.7 }, + { 2, 0.8 }, + { 3, 0.6 }, + { 3, 0.7 }, + { 3, 0.8 }, + { 4, 0.6 }, + { 4, 0.7 }, + { 4, 0.8 }, + { 5, 0.7 }, + { 5, 0.8 }, + { 5, 0.9 }, + { 5, 1.0 } +}; + +const char *soundEvents[] = +{ + "ShipDestroyed", + "RockDestroyed", + 0 +}; + +const char *soundDefaults[] = +{ + "Explosion.wav", + "ploop.wav", + 0 +}; + + +KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) + : QMainWindow( parent, name, 0 ) +{ + QWidget *border = new QWidget( this ); + border->setBackgroundColor( black ); + setCentralWidget( border ); + + QVBoxLayout *borderLayout = new QVBoxLayout( border ); + borderLayout->addStretch( 1 ); + + QWidget *mainWin = new QWidget( border ); + mainWin->setFixedSize(640, 480); + borderLayout->addWidget( mainWin, 0, AlignHCenter ); + + borderLayout->addStretch( 1 ); + + view = new KAsteroidsView( mainWin ); + view->setFocusPolicy( StrongFocus ); + connect( view, SIGNAL( shipKilled() ), SLOT( slotShipKilled() ) ); + connect( view, SIGNAL( rockHit(int) ), SLOT( slotRockHit(int) ) ); + connect( view, SIGNAL( rocksRemoved() ), SLOT( slotRocksRemoved() ) ); + connect( view, SIGNAL( updateVitals() ), SLOT( slotUpdateVitals() ) ); + + QVBoxLayout *vb = new QVBoxLayout( mainWin ); + QHBoxLayout *hb = new QHBoxLayout; + QHBoxLayout *hbd = new QHBoxLayout; + vb->addLayout( hb ); + + QFont labelFont( "helvetica", 24 ); + QColorGroup grp( darkGreen, black, QColor( 128, 128, 128 ), + QColor( 64, 64, 64 ), black, darkGreen, black ); + QPalette pal( grp, grp, grp ); + + mainWin->setPalette( pal ); + + hb->addSpacing( 10 ); + + QLabel *label; + label = new QLabel( tr("Score"), mainWin ); + label->setFont( labelFont ); + label->setPalette( pal ); + label->setFixedWidth( label->sizeHint().width() ); + hb->addWidget( label ); + + scoreLCD = new QLCDNumber( 6, mainWin ); + scoreLCD->setFrameStyle( QFrame::NoFrame ); + scoreLCD->setSegmentStyle( QLCDNumber::Flat ); + scoreLCD->setFixedWidth( 150 ); + scoreLCD->setPalette( pal ); + hb->addWidget( scoreLCD ); + hb->addStretch( 10 ); + + label = new QLabel( tr("Level"), mainWin ); + label->setFont( labelFont ); + label->setPalette( pal ); + label->setFixedWidth( label->sizeHint().width() ); + hb->addWidget( label ); + + levelLCD = new QLCDNumber( 2, mainWin ); + levelLCD->setFrameStyle( QFrame::NoFrame ); + levelLCD->setSegmentStyle( QLCDNumber::Flat ); + levelLCD->setFixedWidth( 70 ); + levelLCD->setPalette( pal ); + hb->addWidget( levelLCD ); + hb->addStretch( 10 ); + + label = new QLabel( tr("Ships"), mainWin ); + label->setFont( labelFont ); + label->setFixedWidth( label->sizeHint().width() ); + label->setPalette( pal ); + hb->addWidget( label ); + + shipsLCD = new QLCDNumber( 1, mainWin ); + shipsLCD->setFrameStyle( QFrame::NoFrame ); + shipsLCD->setSegmentStyle( QLCDNumber::Flat ); + shipsLCD->setFixedWidth( 40 ); + shipsLCD->setPalette( pal ); + hb->addWidget( shipsLCD ); + + hb->addStrut( 30 ); + + vb->addWidget( view, 10 ); + +// -- bottom layout: + vb->addLayout( hbd ); + + QFont smallFont( "helvetica", 14 ); + hbd->addSpacing( 10 ); + + QString sprites_prefix = "qasteroids/sprites/"; +/* + label = new QLabel( tr( "T" ), mainWin ); + label->setFont( smallFont ); + label->setFixedWidth( label->sizeHint().width() ); + label->setPalette( pal ); + hbd->addWidget( label ); + + teleportsLCD = new QLCDNumber( 1, mainWin ); + teleportsLCD->setFrameStyle( QFrame::NoFrame ); + teleportsLCD->setSegmentStyle( QLCDNumber::Flat ); + teleportsLCD->setPalette( pal ); + teleportsLCD->setFixedHeight( 20 ); + hbd->addWidget( teleportsLCD ); + + hbd->addSpacing( 10 ); +*/ + QPixmap pm( sprites_prefix + "powerups/brake.png" ); + label = new QLabel( mainWin ); + label->setPixmap( pm ); + label->setFixedWidth( label->sizeHint().width() ); + label->setPalette( pal ); + hbd->addWidget( label ); + + brakesLCD = new QLCDNumber( 1, mainWin ); + brakesLCD->setFrameStyle( QFrame::NoFrame ); + brakesLCD->setSegmentStyle( QLCDNumber::Flat ); + brakesLCD->setPalette( pal ); + brakesLCD->setFixedHeight( 20 ); + hbd->addWidget( brakesLCD ); + + hbd->addSpacing( 10 ); + + pm.load( sprites_prefix + "powerups/shield.png" ); + label = new QLabel( mainWin ); + label->setPixmap( pm ); + label->setFixedWidth( label->sizeHint().width() ); + label->setPalette( pal ); + hbd->addWidget( label ); + + shieldLCD = new QLCDNumber( 1, mainWin ); + shieldLCD->setFrameStyle( QFrame::NoFrame ); + shieldLCD->setSegmentStyle( QLCDNumber::Flat ); + shieldLCD->setPalette( pal ); + shieldLCD->setFixedHeight( 20 ); + hbd->addWidget( shieldLCD ); + + hbd->addSpacing( 10 ); + + pm.load( sprites_prefix + "powerups/shoot.png" ); + label = new QLabel( mainWin ); + label->setPixmap( pm ); + label->setFixedWidth( label->sizeHint().width() ); + label->setPalette( pal ); + hbd->addWidget( label ); + + shootLCD = new QLCDNumber( 1, mainWin ); + shootLCD->setFrameStyle( QFrame::NoFrame ); + shootLCD->setSegmentStyle( QLCDNumber::Flat ); + shootLCD->setPalette( pal ); + shootLCD->setFixedHeight( 20 ); + hbd->addWidget( shootLCD ); + + hbd->addStretch( 1 ); + + label = new QLabel( tr( "Fuel" ), mainWin ); + label->setFont( smallFont ); + label->setFixedWidth( label->sizeHint().width() + 10 ); + label->setPalette( pal ); + hbd->addWidget( label ); + + powerMeter = new KALedMeter( mainWin ); + powerMeter->setFrameStyle( QFrame::Box | QFrame::Plain ); + powerMeter->setRange( MAX_POWER_LEVEL ); + powerMeter->addColorRange( 10, darkRed ); + powerMeter->addColorRange( 20, QColor(160, 96, 0) ); + powerMeter->addColorRange( 70, darkGreen ); + powerMeter->setCount( 40 ); + powerMeter->setPalette( pal ); + powerMeter->setFixedSize( 200, 12 ); + hbd->addWidget( powerMeter ); + + shipsRemain = 3; + showHiscores = FALSE; + + actions.insert( Qt::Key_Up, Thrust ); + actions.insert( Qt::Key_Left, RotateLeft ); + actions.insert( Qt::Key_Right, RotateRight ); + actions.insert( Qt::Key_Space, Shoot ); + actions.insert( Qt::Key_Z, Teleport ); + actions.insert( Qt::Key_X, Brake ); + actions.insert( Qt::Key_S, Shield ); + actions.insert( Qt::Key_P, Pause ); + actions.insert( Qt::Key_L, Launch ); + actions.insert( Qt::Key_N, NewGame ); + + view->showText( tr( "Press N to start playing" ), yellow ); +} + +KAstTopLevel::~KAstTopLevel() +{ +} + +void KAstTopLevel::playSound( const char * ) +{ +} + +void KAstTopLevel::keyPressEvent( QKeyEvent *event ) +{ + if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) + { + event->ignore(); + return; + } + + Action a = actions[ event->key() ]; + + switch ( a ) + { + case RotateLeft: + view->rotateLeft( TRUE ); + break; + + case RotateRight: + view->rotateRight( TRUE ); + break; + + case Thrust: + view->thrust( TRUE ); + break; + + case Shoot: + view->shoot( TRUE ); + break; + + case Shield: + view->setShield( TRUE ); + break; + + case Teleport: + view->teleport( TRUE ); + break; + + case Brake: + view->brake( TRUE ); + break; + + default: + event->ignore(); + return; + } + event->accept(); +} + +void KAstTopLevel::keyReleaseEvent( QKeyEvent *event ) +{ + if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) + { + event->ignore(); + return; + } + + Action a = actions[ event->key() ]; + + switch ( a ) + { + case RotateLeft: + view->rotateLeft( FALSE ); + break; + + case RotateRight: + view->rotateRight( FALSE ); + break; + + case Thrust: + view->thrust( FALSE ); + break; + + case Shoot: + view->shoot( FALSE ); + break; + + case Brake: + view->brake( FALSE ); + break; + + case Shield: + view->setShield( FALSE ); + break; + + case Teleport: + view->teleport( FALSE ); + break; + + case Launch: + if ( waitShip ) + { + view->newShip(); + waitShip = FALSE; + view->hideText(); + } + else + { + event->ignore(); + return; + } + break; + + case NewGame: + slotNewGame(); + break; +/* + case Pause: + { + view->pause( TRUE ); + QMessageBox::information( this, + tr("KAsteroids is paused"), + tr("Paused") ); + view->pause( FALSE ); + } + break; +*/ + default: + event->ignore(); + return; + } + + event->accept(); +} + +void KAstTopLevel::showEvent( QShowEvent *e ) +{ + QMainWindow::showEvent( e ); + view->pause( FALSE ); + view->setFocus(); +} + +void KAstTopLevel::hideEvent( QHideEvent *e ) +{ + QMainWindow::hideEvent( e ); + view->pause( TRUE ); +} + +void KAstTopLevel::slotNewGame() +{ + score = 0; + shipsRemain = SB_SHIPS; + scoreLCD->display( 0 ); + level = 0; + levelLCD->display( level+1 ); + shipsLCD->display( shipsRemain-1 ); + view->newGame(); + view->setRockSpeed( levels[0].rockSpeed ); + view->addRocks( levels[0].nrocks ); +// view->showText( tr( "Press L to launch." ), yellow ); + view->newShip(); + waitShip = FALSE; + view->hideText(); + isPaused = FALSE; +} + +void KAstTopLevel::slotShipKilled() +{ + shipsRemain--; + shipsLCD->display( shipsRemain-1 ); + + playSound( "ShipDestroyed" ); + + if ( shipsRemain ) + { + waitShip = TRUE; + view->showText( tr( "Ship Destroyed. Press L to launch."), yellow ); + } + else + { + view->showText( tr("Game Over!"), red ); + view->endGame(); + doStats(); +// highscore->addEntry( score, level, showHiscores ); + } +} + +void KAstTopLevel::slotRockHit( int size ) +{ + switch ( size ) + { + case 0: + score += 10; + break; + + case 1: + score += 20; + break; + + default: + score += 40; + } + + playSound( "RockDestroyed" ); + + scoreLCD->display( score ); +} + +void KAstTopLevel::slotRocksRemoved() +{ + level++; + + if ( level >= MAX_LEVELS ) + level = MAX_LEVELS - 1; + + view->setRockSpeed( levels[level-1].rockSpeed ); + view->addRocks( levels[level-1].nrocks ); + + levelLCD->display( level+1 ); +} + +void KAstTopLevel::doStats() +{ + QString r( "0.00" ); + if ( view->shots() ) + r = QString::number( (double)view->hits() / view->shots() * 100.0, + 'g', 2 ); + +/* multi-line text broken in Qt 3 + QString s = tr( "Game Over\n\nShots fired:\t%1\n Hit:\t%2\n Missed:\t%3\nHit ratio:\t%4 %\n\nPress N for a new game" ) + .arg(view->shots()).arg(view->hits()) + .arg(view->shots() - view->hits()) + .arg(r); +*/ + + view->showText( "Game Over. Press N for a new game.", yellow, FALSE ); +} + +void KAstTopLevel::slotUpdateVitals() +{ + brakesLCD->display( view->brakeCount() ); + shieldLCD->display( view->shieldCount() ); + shootLCD->display( view->shootCount() ); +// teleportsLCD->display( view->teleportCount() ); + powerMeter->setValue( view->power() ); +} diff --git a/examples/demo/qasteroids/toplevel.h b/examples/demo/qasteroids/toplevel.h new file mode 100644 index 0000000..6f1b581 --- /dev/null +++ b/examples/demo/qasteroids/toplevel.h @@ -0,0 +1,79 @@ +/* + * KAsteroids - Copyright (c) Martin R. Jones 1997 + * + * Part of the KDE project + */ + +#ifndef __KAST_TOPLEVEL_H__ +#define __KAST_TOPLEVEL_H__ + +#include <qmainwindow.h> +#include <qdict.h> +#include <qmap.h> + +#include "view.h" + + +class KALedMeter; +class QLCDNumber; + +class KAstTopLevel : public QMainWindow +{ + Q_OBJECT +public: + KAstTopLevel( QWidget *parent=0, const char *name=0 ); + virtual ~KAstTopLevel(); + +private: + void playSound( const char *snd ); + void readSoundMapping(); + void doStats(); + +protected: + virtual void showEvent( QShowEvent * ); + virtual void hideEvent( QHideEvent * ); + virtual void keyPressEvent( QKeyEvent *event ); + virtual void keyReleaseEvent( QKeyEvent *event ); + +private slots: + void slotNewGame(); + + void slotShipKilled(); + void slotRockHit( int size ); + void slotRocksRemoved(); + + void slotUpdateVitals(); + +private: + KAsteroidsView *view; + QLCDNumber *scoreLCD; + QLCDNumber *levelLCD; + QLCDNumber *shipsLCD; + + QLCDNumber *teleportsLCD; +// QLCDNumber *bombsLCD; + QLCDNumber *brakesLCD; + QLCDNumber *shieldLCD; + QLCDNumber *shootLCD; + KALedMeter *powerMeter; + + bool sound; + QDict<QString> soundDict; + + // waiting for user to press Enter to launch a ship + bool waitShip; + bool isPaused; + + int shipsRemain; + int score; + int level; + bool showHiscores; + + enum Action { Launch, Thrust, RotateLeft, RotateRight, Shoot, Teleport, + Brake, Shield, Pause, NewGame }; + + QMap<int,Action> actions; +}; + +#endif + diff --git a/examples/demo/qasteroids/view.cpp b/examples/demo/qasteroids/view.cpp new file mode 100644 index 0000000..d6ccd5d --- /dev/null +++ b/examples/demo/qasteroids/view.cpp @@ -0,0 +1,908 @@ +/* + * KAsteroids - Copyright (c) Martin R. Jones 1997 + * + * Part of the KDE project + */ + +#include <stdlib.h> +#include <math.h> +#include <qapplication.h> +#include <qkeycode.h> +#include <qaccel.h> +#include <qmessagebox.h> + +#include "view.h" + +#define IMG_BACKGROUND "qasteroids/bg.png" + +#define REFRESH_DELAY 33 +#define SHIP_SPEED 0.3 +#define MISSILE_SPEED 10.0 +#define SHIP_STEPS 64 +#define ROTATE_RATE 2 +#define SHIELD_ON_COST 1 +#define SHIELD_HIT_COST 30 +#define BRAKE_ON_COST 4 + +#define MAX_ROCK_SPEED 2.5 +#define MAX_POWERUP_SPEED 1.5 +#define MAX_SHIP_SPEED 12 +#define MAX_BRAKES 5 +#define MAX_SHIELDS 5 +#define MAX_FIREPOWER 5 + +#define TEXT_SPEED 4 + +#define PI_X_2 6.283185307 +#ifndef M_PI +#define M_PI 3.141592654 +#endif + +static struct +{ + int id; + const char *path; + int frames; +} +kas_animations [] = +{ + { ID_ROCK_LARGE, "rock1/rock1%1.png", 32 }, + { ID_ROCK_MEDIUM, "rock2/rock2%1.png", 32 }, + { ID_ROCK_SMALL, "rock3/rock3%1.png", 32 }, + { ID_SHIP, "ship/ship%1.png", 32 }, + { ID_MISSILE, "missile/missile.png", 1 }, + { ID_BIT, "bits/bits%1.png", 16 }, + { ID_EXHAUST, "exhaust/exhaust.png", 1 }, + { ID_ENERGY_POWERUP, "powerups/energy.png", 1 }, +// { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 }, + { ID_BRAKE_POWERUP, "powerups/brake.png", 1 }, + { ID_SHIELD_POWERUP, "powerups/shield.png", 1 }, + { ID_SHOOT_POWERUP, "powerups/shoot.png", 1 }, + { ID_SHIELD, "shield/shield%1.png", 6 }, + { 0, 0, 0 } +}; + + + +KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name ) + : QWidget( parent, name ), + field(640, 440), + view(&field,this) +{ + view.setVScrollBarMode( QScrollView::AlwaysOff ); + view.setHScrollBarMode( QScrollView::AlwaysOff ); + view.viewport()->setFocusProxy( this ); + rocks.setAutoDelete( TRUE ); + missiles.setAutoDelete( TRUE ); + bits.setAutoDelete( TRUE ); + powerups.setAutoDelete( TRUE ); + exhaust.setAutoDelete( TRUE ); + + field.setBackgroundColor( black ); + QPixmap pm( IMG_BACKGROUND ); + field.setBackgroundPixmap( pm ); + + textSprite = new QCanvasText( &field ); + QFont font( "helvetica", 18 ); + textSprite->setFont( font ); + + shield = 0; + shieldOn = FALSE; + refreshRate = REFRESH_DELAY; + + initialized = readSprites(); + + shieldTimer = new QTimer( this ); + connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) ); + mTimerId = -1; + + shipPower = MAX_POWER_LEVEL; + vitalsChanged = TRUE; + can_destroy_powerups = FALSE; + + mPaused = TRUE; + + if ( !initialized ) { + textSprite->setText( tr("Error: Cannot read sprite images") ); + textSprite->setColor( red ); + textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2, + (field.height()-textSprite->boundingRect().height()) / 2 ); + textSprite->show(); + } +} + +// - - - + +KAsteroidsView::~KAsteroidsView() +{ +} + +// - - - + +void KAsteroidsView::reset() +{ + if ( !initialized ) + return; + rocks.clear(); + missiles.clear(); + bits.clear(); + powerups.clear(); + exhaust.clear(); + + shotsFired = 0; + shotsHit = 0; + + rockSpeed = 1.0; + powerupSpeed = 1.0; + mFrameNum = 0; + mPaused = FALSE; + + ship->hide(); + shield->hide(); +/* + if ( mTimerId >= 0 ) { + killTimer( mTimerId ); + mTimerId = -1; + } +*/ +} + +// - -- + +void KAsteroidsView::newGame() +{ + if ( !initialized ) + return; + if ( shieldOn ) + { + shield->hide(); + shieldOn = FALSE; + } + reset(); + if ( mTimerId < 0 ) + mTimerId = startTimer( REFRESH_DELAY ); + emit updateVitals(); +} + +// - - - + +void KAsteroidsView::endGame() +{ +} + +void KAsteroidsView::pause( bool p ) +{ + if ( !initialized ) + return; + if ( !mPaused && p ) { + if ( mTimerId >= 0 ) { + killTimer( mTimerId ); + mTimerId = -1; + } + } else if ( mPaused && !p ) + mTimerId = startTimer( REFRESH_DELAY ); + mPaused = p; +} + +// - - - + +void KAsteroidsView::newShip() +{ + if ( !initialized ) + return; + ship->move( width()/2, height()/2, 0 ); + shield->move( width()/2, height()/2, 0 ); + ship->setVelocity( 0.0, 0.0 ); + shipDx = 0; + shipDy = 0; + shipAngle = 0; + rotateL = FALSE; + rotateR = FALSE; + thrustShip = FALSE; + shootShip = FALSE; + brakeShip = FALSE; + teleportShip = FALSE; + shieldOn = TRUE; + shootDelay = 0; + shipPower = MAX_POWER_LEVEL; + rotateRate = ROTATE_RATE; + rotateSlow = 0; + + mBrakeCount = 0; + mTeleportCount = 0; + mShootCount = 0; + + ship->show(); + shield->show(); + mShieldCount = 1; // just in case the ship appears on a rock. + shieldTimer->start( 1000, TRUE ); +} + +void KAsteroidsView::setShield( bool s ) +{ + if ( !initialized ) + return; + if ( shieldTimer->isActive() && !s ) { + shieldTimer->stop(); + hideShield(); + } else { + shieldOn = s && mShieldCount; + } +} + +void KAsteroidsView::brake( bool b ) +{ + if ( !initialized ) + return; + if ( mBrakeCount ) + { + if ( brakeShip && !b ) + { + rotateL = FALSE; + rotateR = FALSE; + thrustShip = FALSE; + rotateRate = ROTATE_RATE; + } + + brakeShip = b; + } +} + +// - - - + +bool KAsteroidsView::readSprites() +{ + QString sprites_prefix = "qasteroids/sprites/"; + + int i = 0; + while ( kas_animations[i].id ) + { + QCanvasPixmapArray *anim = + new QCanvasPixmapArray( sprites_prefix + kas_animations[i].path, + kas_animations[i].frames ); + if ( !anim->isValid() ) + return FALSE; + animation.insert( kas_animations[i].id, anim ); + i++; + } + + ship = new QCanvasSprite( animation[ID_SHIP], &field ); + ship->hide(); + + shield = new KShield( animation[ID_SHIELD], &field ); + shield->hide(); + + return (ship->image(0) && shield->image(0)); +} + +// - - - + +void KAsteroidsView::addRocks( int num ) +{ + if ( !initialized ) + return; + for ( int i = 0; i < num; i++ ) + { + KRock *rock = new KRock( animation[ID_ROCK_LARGE], &field, + ID_ROCK_LARGE, randInt(2), randInt(2) ? -1 : 1 ); + double dx = (2.0 - randDouble()*4.0) * rockSpeed; + double dy = (2.0 - randDouble()*4.0) * rockSpeed; + rock->setVelocity( dx, dy ); + rock->setFrame( randInt( rock->frameCount() ) ); + if ( dx > 0 ) + { + if ( dy > 0 ) + rock->move( 5, 5, 0 ); + else + rock->move( 5, field.height() - 25, 0 ); + } + else + { + if ( dy > 0 ) + rock->move( field.width() - 25, 5, 0 ); + else + rock->move( field.width() - 25, field.height() - 25, 0 ); + } + rock->show( ); + rocks.append( rock ); + } +} + +// - - - + +void KAsteroidsView::showText( const QString &text, const QColor &color, bool scroll ) +{ + if ( !initialized ) + return; + textSprite->setText( text ); + textSprite->setColor( color ); + + if ( scroll ) { + textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2, + -textSprite->boundingRect().height() ); + textDy = TEXT_SPEED; + } else { + textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2, + (field.height()-textSprite->boundingRect().height()) / 2 ); + textDy = 0; + } + textSprite->show(); +} + +// - - - + +void KAsteroidsView::hideText() +{ + textDy = -TEXT_SPEED; +} + +// - - - + +void KAsteroidsView::resizeEvent(QResizeEvent* event) +{ + QWidget::resizeEvent(event); + field.resize(width()-4, height()-4); + view.resize(width(),height()); +} + +// - - - + +void KAsteroidsView::timerEvent( QTimerEvent * ) +{ + field.advance(); + + QCanvasSprite *rock; + + // move rocks forward + for ( rock = rocks.first(); rock; rock = rocks.next() ) { + ((KRock *)rock)->nextFrame(); + wrapSprite( rock ); + } + + wrapSprite( ship ); + + // check for missile collision with rocks. + processMissiles(); + + // these are generated when a ship explodes + for ( KBit *bit = bits.first(); bit; bit = bits.next() ) + { + if ( bit->expired() ) + { + bits.removeRef( bit ); + } + else + { + bit->growOlder(); + bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() ); + } + } + + for ( KExhaust *e = exhaust.first(); e; e = exhaust.next() ) + exhaust.removeRef( e ); + + // move / rotate ship. + // check for collision with a rock. + processShip(); + + // move powerups and check for collision with player and missiles + processPowerups(); + + if ( textSprite->isVisible() ) + { + if ( textDy < 0 && + textSprite->boundingRect().y() <= -textSprite->boundingRect().height() ) { + textSprite->hide(); + } else { + textSprite->moveBy( 0, textDy ); + } + if ( textSprite->boundingRect().y() > (field.height()-textSprite->boundingRect().height())/2 ) + textDy = 0; + } + + if ( vitalsChanged && !(mFrameNum % 10) ) { + emit updateVitals(); + vitalsChanged = FALSE; + } + + mFrameNum++; +} + +void KAsteroidsView::wrapSprite( QCanvasItem *s ) +{ + int x = int(s->x() + s->boundingRect().width() / 2); + int y = int(s->y() + s->boundingRect().height() / 2); + + if ( x > field.width() ) + s->move( s->x() - field.width(), s->y() ); + else if ( x < 0 ) + s->move( field.width() + s->x(), s->y() ); + + if ( y > field.height() ) + s->move( s->x(), s->y() - field.height() ); + else if ( y < 0 ) + s->move( s->x(), field.height() + s->y() ); +} + +// - - - + +void KAsteroidsView::rockHit( QCanvasItem *hit ) +{ + KPowerup *nPup = 0; + int rnd = int(randDouble()*30.0) % 30; + switch( rnd ) + { + case 4: + case 5: + nPup = new KPowerup( animation[ID_ENERGY_POWERUP], &field, + ID_ENERGY_POWERUP ); + break; + case 10: +// nPup = new KPowerup( animation[ID_TELEPORT_POWERUP], &field, +// ID_TELEPORT_POWERUP ); + break; + case 15: + nPup = new KPowerup( animation[ID_BRAKE_POWERUP], &field, + ID_BRAKE_POWERUP ); + break; + case 20: + nPup = new KPowerup( animation[ID_SHIELD_POWERUP], &field, + ID_SHIELD_POWERUP ); + break; + case 24: + case 25: + nPup = new KPowerup( animation[ID_SHOOT_POWERUP], &field, + ID_SHOOT_POWERUP ); + break; + } + if ( nPup ) + { + double r = 0.5 - randDouble(); + nPup->move( hit->x(), hit->y(), 0 ); + nPup->setVelocity( hit->xVelocity() + r, hit->yVelocity() + r ); + nPup->show( ); + powerups.append( nPup ); + } + + if ( hit->rtti() == ID_ROCK_LARGE || hit->rtti() == ID_ROCK_MEDIUM ) + { + // break into smaller rocks + double addx[4] = { 1.0, 1.0, -1.0, -1.0 }; + double addy[4] = { -1.0, 1.0, -1.0, 1.0 }; + + double dx = hit->xVelocity(); + double dy = hit->yVelocity(); + + double maxRockSpeed = MAX_ROCK_SPEED * rockSpeed; + if ( dx > maxRockSpeed ) + dx = maxRockSpeed; + else if ( dx < -maxRockSpeed ) + dx = -maxRockSpeed; + if ( dy > maxRockSpeed ) + dy = maxRockSpeed; + else if ( dy < -maxRockSpeed ) + dy = -maxRockSpeed; + + QCanvasSprite *nrock; + + for ( int i = 0; i < 4; i++ ) + { + double r = rockSpeed/2 - randDouble()*rockSpeed; + if ( hit->rtti() == ID_ROCK_LARGE ) + { + nrock = new KRock( animation[ID_ROCK_MEDIUM], &field, + ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 ); + emit rockHit( 0 ); + } + else + { + nrock = new KRock( animation[ID_ROCK_SMALL], &field, + ID_ROCK_SMALL, randInt(2), randInt(2) ? -1 : 1 ); + emit rockHit( 1 ); + } + + nrock->move( hit->x(), hit->y(), 0 ); + nrock->setVelocity( dx+addx[i]*rockSpeed+r, dy+addy[i]*rockSpeed+r ); + nrock->setFrame( randInt( nrock->frameCount() ) ); + nrock->show( ); + rocks.append( nrock ); + } + } + else if ( hit->rtti() == ID_ROCK_SMALL ) + emit rockHit( 2 ); + rocks.removeRef( (QCanvasSprite *)hit ); + if ( rocks.count() == 0 ) + emit rocksRemoved(); +} + +void KAsteroidsView::reducePower( int val ) +{ + shipPower -= val; + if ( shipPower <= 0 ) + { + shipPower = 0; + thrustShip = FALSE; + if ( shieldOn ) + { + shieldOn = FALSE; + shield->hide(); + } + } + vitalsChanged = TRUE; +} + +void KAsteroidsView::addExhaust( double x, double y, double dx, + double dy, int count ) +{ + for ( int i = 0; i < count; i++ ) + { + KExhaust *e = new KExhaust( animation[ID_EXHAUST], &field ); + e->move( x + 2 - randDouble()*4, y + 2 - randDouble()*4 ); + e->setVelocity( dx, dy ); + e->show( ); + exhaust.append( e ); + } +} + +void KAsteroidsView::processMissiles() +{ + KMissile *missile; + + // if a missile has hit a rock, remove missile and break rock into smaller + // rocks or remove completely. + QPtrListIterator<KMissile> it(missiles); + + for ( ; it.current(); ++it ) + { + missile = it.current(); + missile->growOlder(); + + if ( missile->expired() ) + { + missiles.removeRef( missile ); + continue; + } + + wrapSprite( missile ); + + QCanvasItemList hits = missile->collisions( TRUE ); + QCanvasItemList::Iterator hit; + for ( hit = hits.begin(); hit != hits.end(); ++hit ) + { + if ( (*hit)->rtti() >= ID_ROCK_LARGE && + (*hit)->rtti() <= ID_ROCK_SMALL ) + { + shotsHit++; + rockHit( *hit ); + missiles.removeRef( missile ); + break; + } + } + } +} + +// - - - + +void KAsteroidsView::processShip() +{ + if ( ship->isVisible() ) + { + if ( shieldOn ) + { + shield->show(); + reducePower( SHIELD_ON_COST ); + static int sf = 0; + sf++; + + if ( sf % 2 ) + shield->setFrame( (shield->frame()+1) % shield->frameCount() ); + shield->move( ship->x() - 9, ship->y() - 9 ); + + QCanvasItemList hits = shield->collisions( TRUE ); + QCanvasItemList::Iterator it; + for ( it = hits.begin(); it != hits.end(); ++it ) + { + if ( (*it)->rtti() >= ID_ROCK_LARGE && + (*it)->rtti() <= ID_ROCK_SMALL ) + { + int factor; + switch ( (*it)->rtti() ) + { + case ID_ROCK_LARGE: + factor = 3; + break; + + case ID_ROCK_MEDIUM: + factor = 2; + break; + + default: + factor = 1; + } + + if ( factor > mShieldCount ) + { + // shield not strong enough + shieldOn = FALSE; + break; + } + rockHit( *it ); + // the more shields we have the less costly + reducePower( factor * (SHIELD_HIT_COST - mShieldCount*2) ); + } + } + } + + if ( !shieldOn ) + { + shield->hide(); + QCanvasItemList hits = ship->collisions( TRUE ); + QCanvasItemList::Iterator it; + for ( it = hits.begin(); it != hits.end(); ++it ) + { + if ( (*it)->rtti() >= ID_ROCK_LARGE && + (*it)->rtti() <= ID_ROCK_SMALL ) + { + KBit *bit; + for ( int i = 0; i < 12; i++ ) + { + bit = new KBit( animation[ID_BIT], &field ); + bit->move( ship->x() + 5 - randDouble() * 10, + ship->y() + 5 - randDouble() * 10, + randInt(bit->frameCount()) ); + bit->setVelocity( 1-randDouble()*2, + 1-randDouble()*2 ); + bit->setDeath( 60 + randInt(60) ); + bit->show( ); + bits.append( bit ); + } + ship->hide(); + shield->hide(); + emit shipKilled(); + break; + } + } + } + + + if ( rotateSlow ) + rotateSlow--; + + if ( rotateL ) + { + shipAngle -= rotateSlow ? 1 : rotateRate; + if ( shipAngle < 0 ) + shipAngle += SHIP_STEPS; + } + + if ( rotateR ) + { + shipAngle += rotateSlow ? 1 : rotateRate; + if ( shipAngle >= SHIP_STEPS ) + shipAngle -= SHIP_STEPS; + } + + double angle = shipAngle * PI_X_2 / SHIP_STEPS; + double cosangle = cos( angle ); + double sinangle = sin( angle ); + + if ( brakeShip ) + { + thrustShip = FALSE; + rotateL = FALSE; + rotateR = FALSE; + rotateRate = ROTATE_RATE; + if ( fabs(shipDx) < 2.5 && fabs(shipDy) < 2.5 ) + { + shipDx = 0.0; + shipDy = 0.0; + ship->setVelocity( shipDx, shipDy ); + brakeShip = FALSE; + } + else + { + double motionAngle = atan2( -shipDy, -shipDx ); + if ( angle > M_PI ) + angle -= PI_X_2; + double angleDiff = angle - motionAngle; + if ( angleDiff > M_PI ) + angleDiff = PI_X_2 - angleDiff; + else if ( angleDiff < -M_PI ) + angleDiff = PI_X_2 + angleDiff; + double fdiff = fabs( angleDiff ); + if ( fdiff > 0.08 ) + { + if ( angleDiff > 0 ) + rotateL = TRUE; + else if ( angleDiff < 0 ) + rotateR = TRUE; + if ( fdiff > 0.6 ) + rotateRate = mBrakeCount + 1; + else if ( fdiff > 0.4 ) + rotateRate = 2; + else + rotateRate = 1; + + if ( rotateRate > 5 ) + rotateRate = 5; + } + else if ( fabs(shipDx) > 1 || fabs(shipDy) > 1 ) + { + thrustShip = TRUE; + // we'll make braking a bit faster + shipDx += cosangle/6 * (mBrakeCount - 1); + shipDy += sinangle/6 * (mBrakeCount - 1); + reducePower( BRAKE_ON_COST ); + addExhaust( ship->x() + 20 - cosangle*22, + ship->y() + 20 - sinangle*22, + shipDx-cosangle, shipDy-sinangle, + mBrakeCount+1 ); + } + } + } + + if ( thrustShip ) + { + // The ship has a terminal velocity, but trying to go faster + // still uses fuel (can go faster diagonally - don't care). + double thrustx = cosangle/4; + double thrusty = sinangle/4; + if ( fabs(shipDx + thrustx) < MAX_SHIP_SPEED ) + shipDx += thrustx; + if ( fabs(shipDy + thrusty) < MAX_SHIP_SPEED ) + shipDy += thrusty; + ship->setVelocity( shipDx, shipDy ); + reducePower( 1 ); + addExhaust( ship->x() + 20 - cosangle*20, + ship->y() + 20 - sinangle*20, + shipDx-cosangle, shipDy-sinangle, 3 ); + } + + ship->setFrame( shipAngle >> 1 ); + + if ( shootShip ) + { + if ( !shootDelay && (int)missiles.count() < mShootCount + 2 ) + { + KMissile *missile = new KMissile( animation[ID_MISSILE], &field ); + missile->move( 21+ship->x()+cosangle*21, + 21+ship->y()+sinangle*21, 0 ); + missile->setVelocity( shipDx + cosangle*MISSILE_SPEED, + shipDy + sinangle*MISSILE_SPEED ); + missile->show( ); + missiles.append( missile ); + shotsFired++; + reducePower( 1 ); + + shootDelay = 5; + } + + if ( shootDelay ) + shootDelay--; + } + + if ( teleportShip ) + { + int ra = rand() % 10; + if( ra == 0 ) + ra += rand() % 20; + int xra = ra * 60 + ( (rand() % 20) * (rand() % 20) ); + int yra = ra * 50 - ( (rand() % 20) * (rand() % 20) ); + ship->move( xra, yra ); + } + + vitalsChanged = TRUE; + } +} + +// - - - + +void KAsteroidsView::processPowerups() +{ + if ( !powerups.isEmpty() ) + { + // if player gets the powerup remove it from the screen, if option + // "Can destroy powerups" is enabled and a missile hits the powerup + // destroy it + + KPowerup *pup; + QPtrListIterator<KPowerup> it( powerups ); + + for( ; it.current(); ++it ) + { + pup = it.current(); + pup->growOlder(); + + if( pup->expired() ) + { + powerups.removeRef( pup ); + continue; + } + + wrapSprite( pup ); + + QCanvasItemList hits = pup->collisions( TRUE ); + QCanvasItemList::Iterator it; + for ( it = hits.begin(); it != hits.end(); ++it ) + { + if ( (*it) == ship ) + { + switch( pup->rtti() ) + { + case ID_ENERGY_POWERUP: + shipPower += 150; + if ( shipPower > MAX_POWER_LEVEL ) + shipPower = MAX_POWER_LEVEL; + break; + case ID_TELEPORT_POWERUP: + mTeleportCount++; + break; + case ID_BRAKE_POWERUP: + if ( mBrakeCount < MAX_BRAKES ) + mBrakeCount++; + break; + case ID_SHIELD_POWERUP: + if ( mShieldCount < MAX_SHIELDS ) + mShieldCount++; + break; + case ID_SHOOT_POWERUP: + if ( mShootCount < MAX_FIREPOWER ) + mShootCount++; + break; + } + + powerups.removeRef( pup ); + vitalsChanged = TRUE; + } + else if ( (*it) == shield ) + { + powerups.removeRef( pup ); + } + else if ( (*it)->rtti() == ID_MISSILE ) + { + if ( can_destroy_powerups ) + { + powerups.removeRef( pup ); + } + } + } + } + } // -- if( powerups.isEmpty() ) +} + +// - - - + +void KAsteroidsView::hideShield() +{ + shield->hide(); + mShieldCount = 0; + shieldOn = FALSE; +} + +double KAsteroidsView::randDouble() +{ + int v = rand(); + return (double)v / (double)RAND_MAX; +} + +int KAsteroidsView::randInt( int range ) +{ + return rand() % range; +} + +void KAsteroidsView::showEvent( QShowEvent *e ) +{ +#if defined( QT_LICENSE_PROFESSIONAL ) + static bool wasThere = FALSE; + + if ( !wasThere ) { + wasThere = TRUE; + QMessageBox::information( this, tr("QCanvas demo"), + tr("This game has been implemented using the QCanvas class.\n" + "The QCanvas class is not part of the Professional Edition. Please \n" + "contact Trolltech if you want to upgrade to the Enterprise Edition.") ); + } +#endif + + QWidget::showEvent( e ); +} diff --git a/examples/demo/qasteroids/view.h b/examples/demo/qasteroids/view.h new file mode 100644 index 0000000..f09d1c3 --- /dev/null +++ b/examples/demo/qasteroids/view.h @@ -0,0 +1,138 @@ +/* + * KAsteroids - Copyright (c) Martin R. Jones 1997 + * + * Part of the KDE project + */ + +#ifndef __AST_VIEW_H__ +#define __AST_VIEW_H__ + +#include <qwidget.h> +#include <qptrlist.h> +#include <qintdict.h> +#include <qtimer.h> +#include <qcanvas.h> +#include "sprites.h" + +#define MAX_POWER_LEVEL 1000 + +class KAsteroidsView : public QWidget +{ + Q_OBJECT +public: + KAsteroidsView( QWidget *parent = 0, const char *name = 0 ); + virtual ~KAsteroidsView(); + + int refreshRate; + + void reset(); + void setRockSpeed( double rs ) { rockSpeed = rs; } + void addRocks( int num ); + void newGame(); + void endGame(); + void newShip(); + + void rotateLeft( bool r ) { rotateL = r; rotateSlow = 5; } + void rotateRight( bool r ) { rotateR = r; rotateSlow = 5; } + void thrust( bool t ) { thrustShip = t && shipPower > 0; } + void shoot( bool s ) { shootShip = s; shootDelay = 0; } + void setShield( bool s ); + void teleport( bool te) { teleportShip = te && mTeleportCount; } + void brake( bool b ); + void pause( bool p); + + void showText( const QString &text, const QColor &color, bool scroll=TRUE ); + void hideText(); + + int shots() const { return shotsFired; } + int hits() const { return shotsHit; } + int power() const { return shipPower; } + + int teleportCount() const { return mTeleportCount; } + int brakeCount() const { return mBrakeCount; } + int shieldCount() const { return mShieldCount; } + int shootCount() const { return mShootCount; } + +signals: + void shipKilled(); + void rockHit( int size ); + void rocksRemoved(); + void updateVitals(); + +private slots: + void hideShield(); + +protected: + bool readSprites(); + void wrapSprite( QCanvasItem * ); + void rockHit( QCanvasItem * ); + void reducePower( int val ); + void addExhaust( double x, double y, double dx, double dy, int count ); + void processMissiles(); + void processShip(); + void processPowerups(); + void processShield(); + double randDouble(); + int randInt( int range ); + + virtual void resizeEvent( QResizeEvent *event ); + virtual void timerEvent( QTimerEvent * ); + + void showEvent( QShowEvent * ); + +private: + QCanvas field; + QCanvasView view; + QIntDict<QCanvasPixmapArray> animation; + QPtrList<QCanvasSprite> rocks; + QPtrList<KMissile> missiles; + QPtrList<KBit> bits; + QPtrList<KExhaust> exhaust; + QPtrList<KPowerup> powerups; + KShield *shield; + QCanvasSprite *ship; + QCanvasText *textSprite; + + bool rotateL; + bool rotateR; + bool thrustShip; + bool shootShip; + bool teleportShip; + bool brakeShip; + bool pauseShip; + bool shieldOn; + + bool vitalsChanged; + + int shipAngle; + int rotateSlow; + int rotateRate; + int shipPower; + + int shotsFired; + int shotsHit; + int shootDelay; + + int mBrakeCount; + int mShieldCount; + int mTeleportCount; + int mShootCount; + + double shipDx; + double shipDy; + + int textDy; + int mFrameNum; + bool mPaused; + int mTimerId; + + double rockSpeed; + double powerupSpeed; + + bool can_destroy_powerups; + + QTimer *shieldTimer; + bool initialized; +}; + +#endif |