File indexing completed on 2024-04-28 07:54:25
0001 /* 0002 SPDX-FileCopyrightText: 1998-2001 Andreas Zehender <az@azweb.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __SPRITE_BASE_H 0008 #define __SPRITE_BASE_H 0009 0010 #include <QGraphicsSvgItem> 0011 0012 //#include "defines.h" 0013 #include "structs.h" 0014 0015 class SimpleSprite: public QGraphicsSvgItem 0016 { 0017 public: 0018 int width(); 0019 int height(); 0020 QPointF center(); 0021 protected: 0022 void init(); 0023 0024 private: 0025 int m_width; 0026 int m_height; 0027 QPointF m_center; 0028 protected: 0029 SimpleSprite(QSvgRenderer* svg, const QString& element); 0030 }; 0031 0032 class MobileSprite:public SimpleSprite 0033 { 0034 public: 0035 MobileSprite(QSvgRenderer* svg, const QString&, int pn); 0036 0037 virtual void forward(double mult,int frame); 0038 virtual void forward(double mult); 0039 virtual void calculateGravity(double gravity,double mult); 0040 int spriteFieldWidth(); 0041 int spriteFieldHeight(); 0042 double xVelocity(){return xvel;} 0043 double yVelocity(){return yvel;} 0044 void setVelocity(double vx, double vy); 0045 AiSprite toAiSprite(); 0046 0047 bool isStopped() {return stopped;} 0048 void stop(bool s=true) {stopped=s;} 0049 int getPlayerNumber() {return playerNumber;} 0050 protected: 0051 void checkBounds(); 0052 bool stopped; 0053 int playerNumber; 0054 double xvel; 0055 double yvel; 0056 }; 0057 0058 class AnimatedSprite:public MobileSprite 0059 { 0060 public: 0061 explicit AnimatedSprite(QSvgRenderer* svg, const QList<QString> &animation, int pn=0); 0062 0063 void setFrame(int frame); 0064 inline int frame() const 0065 { return currentFrame; } 0066 inline int frameCount() const 0067 { return frames.size(); } 0068 inline QString element(int frame) const 0069 { return frames.isEmpty() ? QString() : frames.at(frame % frames.size()); } 0070 QPainterPath shape() const override; 0071 void setAnimation(const QList<QString> &animation); 0072 0073 void advance(int phase) override; 0074 0075 private: 0076 int currentFrame; 0077 QList<QString> frames; 0078 }; 0079 0080 #endif