ManaPlus
Public Member Functions | Static Public Attributes
ImageParticle Class Reference

#include <imageparticle.h>

Inheritance diagram for ImageParticle:
Particle Actor AnimationParticle RotationalParticle

Public Member Functions

 ImageParticle (Image *const image)
 
void draw (Graphics *const graphics, const int offsetX, const int offsetY) const
 
void setAlpha (const float alpha)
 
- Public Member Functions inherited from Particle
 Particle ()
 
 ~Particle ()
 
void clear ()
 
bool update ()
 
void draw (Graphics *const graphics, const int offsetX, const int offsetY) const
 
int getPixelY () const
 
int getSortPixelY () const
 
ParticleaddEffect (const std::string &particleEffectFile, const int pixelX, const int pixelY, const int rotation)
 
void addEmitter (ParticleEmitter *const emitter)
 
void moveTo (const Vector &pos)
 
void moveTo (const float x, const float y)
 
void moveBy (const Vector &change)
 
void setLifetime (const int lifetime)
 
void setFadeOut (const int fadeOut)
 
void setFadeIn (const int fadeIn)
 
void setVelocity (const float x, const float y, const float z)
 
void setGravity (const float gravity)
 
void setRandomness (const int r)
 
void setBounce (const float bouncieness)
 
void setFollow (const bool follow)
 
bool doesFollow () const
 
void setDestination (Particle *const target, const float accel, const float moment)
 
void setDieDistance (const float dist)
 
void adjustEmitterSize (const int w, const int h)
 
void setAllowSizeAdjust (const bool adjust)
 
bool isAlive () const
 
void prepareToDie ()
 
bool isExtinct () const
 
void kill ()
 
void disableAutoDelete ()
 
int getNumberOfLayers () const
 
float getAlpha () const
 
void setAlpha (const float alpha)
 
virtual void setDeathEffect (const std::string &effectFile, const signed char conditions)
 
void setActor (const BeingId actor)
 
- Public Member Functions inherited from Actor
virtual ~Actor ()
 
virtual int getWidth () const
 
virtual int getHeight () const
 
const VectorgetPixelPositionF () const
 
virtual void setPixelPositionF (const Vector &pos)
 
int getPixelX () const
 
virtual int getTileX () const
 
virtual int getTileY () const
 
virtual void setMap (Map *const map)
 
const MapgetMap () const
 

Static Public Attributes

static StringIntMap imageParticleCountByName
 

Additional Inherited Members

- Data Fields inherited from Actor
int mPixelX
 
int mPixelY
 
- Protected Member Functions inherited from Particle
void updateSelf ()
 
- Protected Member Functions inherited from Actor
 Actor ()
 
- Protected Attributes inherited from Particle
float mAlpha
 
int mLifetimeLeft
 
int mLifetimePast
 
int mFadeOut
 
int mFadeIn
 
Vector mVelocity
 
AliveStatusT mAlive
 
ParticleTypeT mType
 
SimpleAnimationmAnimation
 
ImagemImage
 
BeingId mActor
 
- Protected Attributes inherited from Actor
MapmMap
 
Vector mPos
 
int mYDiff
 

Detailed Description

A particle that uses an image for its visualization.

Definition at line 36 of file imageparticle.h.

Constructor & Destructor Documentation

◆ ImageParticle()

ImageParticle::ImageParticle ( Image *const  image)
explicit

Constructor. The image is reference counted by this particle.

Parameters
imagean Image instance, may not be NULL

Definition at line 34 of file imageparticle.cpp.

34  :
35  Particle()
36 {
38  mImage = image;
39  if (mImage != nullptr)
40  {
41  mImage->incRef();
42 
43  const std::string &restrict name = mImage->mIdPath;
48  else
49  (*it).second ++;
50  }
51 }
static StringIntMap imageParticleCountByName
Definition: imageparticle.h:59
Image * mImage
Definition: particle.h:277
Particle()
Definition: particle.cpp:59
ParticleTypeT mType
Definition: particle.h:271
#define restrict
Definition: localconsts.h:165
StringIntMap::iterator StringIntMapIter
Definition: stringmap.h:29

References ParticleType::Image, imageParticleCountByName, Particle::mImage, Particle::mType, and restrict.

Member Function Documentation

◆ draw()

void ImageParticle::draw ( Graphics *const  graphics,
const int  offsetX,
const int  offsetY 
) const
virtual

Draws the particle image

Implements Actor.

Definition at line 53 of file imageparticle.cpp.

56 {
57  FUNC_BLOCK("ImageParticle::draw", 1)
58  if (mAlive != AliveStatus::ALIVE || (mImage == nullptr))
59  return;
60 
61  const int w = mImage->mBounds.w;
62  const int h = mImage->mBounds.h;
63  const int screenX = CAST_S32(mPos.x)
64  + offsetX - w / 2;
65  const int screenY = CAST_S32(mPos.y) - CAST_S32(mPos.z)
66  + offsetY - h / 2;
67 
68  // Check if on screen
69  if (screenX + w < 0 ||
70  screenX > graphics->mWidth ||
71  screenY + h < 0 ||
72  screenY > graphics->mHeight)
73  {
74  return;
75  }
76 
77  float alphafactor = mAlpha;
78 
79  if ((mFadeOut != 0) && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
80  {
81  alphafactor *= static_cast<float>(mLifetimeLeft)
82  / static_cast<float>(mFadeOut);
83  }
84 
85  if ((mFadeIn != 0) && mLifetimePast < mFadeIn)
86  {
87  alphafactor *= static_cast<float>(mLifetimePast)
88  / static_cast<float>(mFadeIn);
89  }
90 
91  mImage->setAlpha(alphafactor);
92  graphics->drawImage(mImage, screenX, screenY);
93 }
#define CAST_S32
Definition: cast.h:30
Vector mPos
Definition: actor.h:140
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
int mFadeIn
Definition: particle.h:263
int mLifetimePast
Definition: particle.h:257
float mAlpha
Definition: particle.h:251
int mLifetimeLeft
Definition: particle.h:254
AliveStatusT mAlive
Definition: particle.h:269
int mFadeOut
Definition: particle.h:260
if(!vert) return
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:81

References AliveStatus::ALIVE, CAST_S32, FUNC_BLOCK, and anonymous_namespace{mrand.cpp}::mPos.

◆ setAlpha()

void ImageParticle::setAlpha ( const float  alpha)
inlinevirtual

Sets the alpha value used to draw the actor.

Implements Actor.

Definition at line 56 of file imageparticle.h.

57  { mAlpha = alpha; }

References Particle::mAlpha.

Field Documentation

◆ imageParticleCountByName

StringIntMap ImageParticle::imageParticleCountByName
static

The documentation for this class was generated from the following files: