add missing files

This commit is contained in:
Henrique Santiago 2011-12-15 18:55:05 -02:00
parent 2643de367a
commit 9a5be9c4d8
2 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "particle.h"
#include "graphics.h"
#include <framework/core/clock.h>
Particle::Particle(const Point& pos, const Size& size, const PointF& velocity, const PointF& acceleration, float duration, const Color& color, TexturePtr texture)
{
m_rect = Rect(pos, size);
m_pos = PointF(pos.x, pos.y);
m_size = size;
m_velocity = velocity;
m_acceleration = acceleration;
m_color = color;
m_texture = texture;
m_duration = duration;
m_startTime = g_clock.time();
m_lastUpdateTime = g_clock.time();
m_finished = false;
}
void Particle::render()
{
g_painter.setColor(m_color);
if(!m_texture)
g_painter.drawFilledRect(m_rect);
else {
//g_painter.setCompositionMode(Painter::CompositionMode_AdditiveSource);
g_painter.drawTexturedRect(m_rect, m_texture);
//g_painter.setCompositionMode(Painter::CompositionMode_SourceOver);
}
}
void Particle::update()
{
float elapsedTime = g_clock.timeElapsed(m_lastUpdateTime);
m_lastUpdateTime = g_clock.time();
// check if finished
if(m_duration > 0 && g_clock.timeElapsed(m_startTime) >= m_duration) {
m_finished = true;
return;
}
// update position
PointF delta = m_velocity * elapsedTime;
delta.y *= -1; // painter orientate Y axis in the inverse direction
m_pos += delta;
// update acceleration
m_velocity += m_acceleration * elapsedTime;
m_rect.moveTo((int)m_pos.x, (int)m_pos.y);
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef PARTICLE_H
#define PARTICLE_H
#include "declarations.h"
#include <framework/global.h>
class Particle {
public:
Particle(const Point& pos, const Size& size, const PointF& velocity, const PointF& acceleration, float duration, const Color& color = Fw::white, TexturePtr texture = nullptr);
void render();
void update();
bool hasFinished() { return m_finished; }
private:
Color m_color;
TexturePtr m_texture;
PointF m_pos;
PointF m_velocity;
PointF m_acceleration;
Size m_size;
Rect m_rect;
float m_duration;
double m_startTime;
double m_lastUpdateTime;
bool m_finished;
};
#endif