00001 /* 00002 * The Mana World 00003 * Copyright (C) 2006 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #include "imageparticle.h" 00023 00024 #include "graphics.h" 00025 00026 #include "resources/image.h" 00027 00028 ImageParticle::ImageParticle(Map *map, Image *image): 00029 Particle(map), 00030 mImage(image) 00031 { 00032 if (mImage) 00033 mImage->incRef(); 00034 } 00035 00036 ImageParticle::~ImageParticle() 00037 { 00038 if (mImage) 00039 mImage->decRef(); 00040 } 00041 00042 void ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const 00043 { 00044 if (!mAlive) 00045 return; 00046 00047 int screenX = (int) mPos.x + offsetX - mImage->getWidth() / 2; 00048 int screenY = (int) mPos.y - (int)mPos.z + offsetY - mImage->getHeight()/2; 00049 00050 // Check if on screen 00051 if (screenX + mImage->getWidth() < 0 || 00052 screenX > graphics->getWidth() || 00053 screenY + mImage->getHeight() < 0 || 00054 screenY > graphics->getHeight()) 00055 { 00056 return; 00057 } 00058 00059 float alphafactor = mAlpha; 00060 00061 if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) 00062 alphafactor *= (float) mLifetimeLeft / (float) mFadeOut; 00063 00064 if (mLifetimePast < mFadeIn) 00065 alphafactor *= (float) mLifetimePast / (float) mFadeIn; 00066 00067 mImage->setAlpha(alphafactor); 00068 graphics->drawImage(mImage, screenX, screenY); 00069 }