1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the examples of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:BSD$ 9 ** You may use this file under the terms of the BSD license as follows: 10 ** 11 ** "Redistribution and use in source and binary forms, with or without 12 ** modification, are permitted provided that the following conditions are 13 ** met: 14 ** * Redistributions of source code must retain the above copyright 15 ** notice, this list of conditions and the following disclaimer. 16 ** * Redistributions in binary form must reproduce the above copyright 17 ** notice, this list of conditions and the following disclaimer in 18 ** the documentation and/or other materials provided with the 19 ** distribution. 20 ** * Neither the name of The Qt Company Ltd nor the names of its 21 ** contributors may be used to endorse or promote products derived 22 ** from this software without specific prior written permission. 23 ** 24 ** 25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 ** 37 ** $QT_END_LICENSE$ 38 ** 39 ****************************************************************************/ 40 41 /* 42 * KAsteroids - Copyright (c) Martin R. Jones 1997 43 * 44 * Part of the KDE project 45 */ 46 47 #ifndef __SPRITES_H__ 48 #define __SPRITES_H__ 49 50 #include "animateditem.h" 51 52 #define ID_ROCK_LARGE 1024 53 #define ID_ROCK_MEDIUM 1025 54 #define ID_ROCK_SMALL 1026 55 56 #define ID_MISSILE 1030 57 58 #define ID_BIT 1040 59 #define ID_EXHAUST 1041 60 61 #define ID_ENERGY_POWERUP 1310 62 #define ID_TELEPORT_POWERUP 1311 63 #define ID_BRAKE_POWERUP 1312 64 #define ID_SHIELD_POWERUP 1313 65 #define ID_SHOOT_POWERUP 1314 66 67 #define ID_SHIP 1350 68 #define ID_SHIELD 1351 69 70 #define MAX_SHIELD_AGE 350 71 #define MAX_POWERUP_AGE 500 72 #define MAX_MISSILE_AGE 40 73 74 class KMissile : public AnimatedPixmapItem 75 { 76 public: KMissile(const QList<QPixmap> & s,QGraphicsScene * c)77 KMissile( const QList<QPixmap> &s, QGraphicsScene *c ) : AnimatedPixmapItem( s, c ) 78 { myAge = 0; } 79 type()80 virtual int type() const { return ID_MISSILE; } 81 growOlder()82 void growOlder() { myAge++; } expired()83 bool expired() { return myAge > MAX_MISSILE_AGE; } 84 85 private: 86 int myAge; 87 }; 88 89 class KBit : public AnimatedPixmapItem 90 { 91 public: KBit(const QList<QPixmap> & s,QGraphicsScene * c)92 KBit( const QList<QPixmap> &s, QGraphicsScene *c ) : AnimatedPixmapItem( s, c ) 93 { death = 7; } 94 type()95 virtual int type() const { return ID_BIT; } 96 setDeath(int d)97 void setDeath( int d ) { death = d; } growOlder()98 void growOlder() { death--; } expired()99 bool expired() { return death <= 0; } 100 101 private: 102 int death; 103 }; 104 105 class KExhaust : public AnimatedPixmapItem 106 { 107 public: KExhaust(const QList<QPixmap> & s,QGraphicsScene * c)108 KExhaust( const QList<QPixmap> &s, QGraphicsScene *c ) : AnimatedPixmapItem( s, c ) 109 { death = 1; } 110 type()111 virtual int type() const { return ID_EXHAUST; } 112 setDeath(int d)113 void setDeath( int d ) { death = d; } growOlder()114 void growOlder() { death--; } expired()115 bool expired() { return death <= 0; } 116 117 private: 118 int death; 119 }; 120 121 class KPowerup : public AnimatedPixmapItem 122 { 123 public: KPowerup(const QList<QPixmap> & s,QGraphicsScene * c,int t)124 KPowerup( const QList<QPixmap> &s, QGraphicsScene *c, int t ) : AnimatedPixmapItem( s, c ), 125 myAge( 0 ), _type(t) { } 126 type()127 virtual int type() const { return _type; } 128 growOlder()129 void growOlder() { myAge++; } expired()130 bool expired() const { return myAge > MAX_POWERUP_AGE; } 131 132 protected: 133 int myAge; 134 int _type; 135 }; 136 137 class KRock : public AnimatedPixmapItem 138 { 139 public: KRock(const QList<QPixmap> & s,QGraphicsScene * c,int t,int sk,int st)140 KRock (const QList<QPixmap> &s, QGraphicsScene *c, int t, int sk, int st) : AnimatedPixmapItem( s, c ) 141 { _type = t; skip = cskip = sk; step = st; } 142 nextFrame()143 void nextFrame() 144 { 145 if (cskip-- <= 0) { 146 setFrame( (frame()+step+frameCount())%frameCount() ); 147 cskip = qAbs(skip); 148 } 149 } 150 type()151 virtual int type() const { return _type; } 152 153 private: 154 int _type; 155 int skip; 156 int cskip; 157 int step; 158 }; 159 160 class KShield : public AnimatedPixmapItem 161 { 162 public: KShield(QList<QPixmap> & s,QGraphicsScene * c)163 KShield( QList<QPixmap> &s, QGraphicsScene *c ) 164 : AnimatedPixmapItem( s, c ) {} 165 type()166 virtual int type() const { return ID_SHIELD; } 167 }; 168 169 #endif 170