Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
9 KB
Referenced Files
None
Subscribers
None
diff --git a/src/BoltEntity.cpp b/src/BoltEntity.cpp
index 545b49b..954d706 100644
--- a/src/BoltEntity.cpp
+++ b/src/BoltEntity.cpp
@@ -1,126 +1,137 @@
#include "BoltEntity.h"
#include "Constants.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SoundManager.h"
BoltEntity::BoltEntity(sf::Texture* image, float x, float y, float boltLifeTime) : CollidingSpriteEntity (image, x, y, BOLT_WIDTH, BOLT_HEIGHT)
{
lifetime = boltLifeTime;
- damages = INITIAL_BOLT_DAMAGES;
+ setDamages(INITIAL_BOLT_DAMAGES);
type = ENTITY_BOLT;
viscosity = 0.97f;
frame = 0;
}
int BoltEntity::getDamages()
{
return damages;
}
void BoltEntity::setDamages(int damages)
{
this->damages = damages;
+
+ if (damages <= 4) renderScale = 0.8f;
+ else if (damages <= 8) renderScale = 0.85f;
+ else if (damages <= 12) renderScale = 0.9f;
+ else if (damages <= 16) renderScale = 1.0f;
+ else if (damages <= 20) renderScale = 1.1f;
+ else if (damages <= 24) renderScale = 1.2f;
+ else if (damages <= 30) renderScale = 1.3f;
+ else renderScale = 1.4f;
+
+ sprite.scale(renderScale, renderScale);
}
void BoltEntity::animate(float delay)
{
SpriteEntity* trace = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_BOLT), x, y, BOLT_WIDTH, BOLT_HEIGHT);
trace->setFading(true);
trace->setZ(y);
trace->setLifetime(0.2f);
- trace->setShrinking(true);
+ trace->setShrinking(true, renderScale, renderScale);
trace->setType(16);
z = y + height;
//if (viscosity < 1.0f && ((velocity.x)*(velocity.x) + (velocity.y)*(velocity.y)) < 900.0f) viscosity = 1.0f;
CollidingSpriteEntity::animate(delay);
if ( (lifetime - age) < 0.2f)
{
if (age >= lifetime)
sprite.setColor(sf::Color(255, 255, 255, 0));
else
sprite.setColor(sf::Color(255, 255, 255, (sf::Uint8)((lifetime - age) / 0.2f * 255)));
}
if (((velocity.x)*(velocity.x) + (velocity.y)*(velocity.y)) < 1500.0f) isDying = true;
}
void BoltEntity::collide()
{
isDying = true;
for (int i=0; i<5; i++)
{
Vector2D vel(40.0f + rand() % 50);
generateParticule(vel);
}
}
void BoltEntity::generateParticule(Vector2D vel)
{
SpriteEntity* trace = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_BOLT), x, y, BOLT_WIDTH, BOLT_HEIGHT);
trace->setFading(true);
trace->setZ(y);
trace->setLifetime(0.5f);
trace->setScale(0.3f, 0.3f);
trace->setVelocity(vel);
trace->setViscosity(0.97f);
trace->setType(16);
}
void BoltEntity::collideMapRight()
{
velocity.x = 0.0f;
isDying = true;
SoundManager::getSoundManager()->playSound(SOUND_WALL_IMPACT);
for (int i=0; i<5; i++)
{
Vector2D vel(100.0f + rand() % 150);
if (vel.x > 0.0f) vel.x = - vel.x;
generateParticule(vel);
}
}
void BoltEntity::collideMapLeft()
{
velocity.x = 0.0f;
isDying = true;
SoundManager::getSoundManager()->playSound(SOUND_WALL_IMPACT);
for (int i=0; i<5; i++)
{
Vector2D vel(100.0f + rand() % 150);
if (vel.x < 0.0f) vel.x = - vel.x;
generateParticule(vel);
}
}
void BoltEntity::collideMapTop()
{
velocity.y = 0.0f;
isDying = true;
SoundManager::getSoundManager()->playSound(SOUND_WALL_IMPACT);
for (int i=0; i<5; i++)
{
Vector2D vel(100.0f + rand() % 150);
if (vel.y < 0.0f) vel.y = - vel.y;
generateParticule(vel);
}
}
void BoltEntity::collideMapBottom()
{
velocity.y = 0.0f;
isDying = true;
SoundManager::getSoundManager()->playSound(SOUND_WALL_IMPACT);
for (int i=0; i<5; i++)
{
Vector2D vel(100.0f + rand() % 150);
if (vel.y > 0.0f) vel.y = - vel.y;
generateParticule(vel);
}
}
diff --git a/src/BoltEntity.h b/src/BoltEntity.h
index 3d5c704..8dce4ae 100644
--- a/src/BoltEntity.h
+++ b/src/BoltEntity.h
@@ -1,27 +1,28 @@
#ifndef BOLTENTITY_H
#define BOLTENTITY_H
#include "sfml_game/CollidingSpriteEntity.h"
class BoltEntity : public CollidingSpriteEntity
{
public:
BoltEntity(sf::Texture* image, float x, float y, float boltLifeTime);
virtual void animate(float delay);
void collide();
void generateParticule(Vector2D vel);
int getDamages();
void setDamages(int damages);
protected:
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
int damages;
+ float renderScale;
private:
};
#endif // BOLTENTITY_H
diff --git a/src/sfml_game/SpriteEntity.cpp b/src/sfml_game/SpriteEntity.cpp
index afa5fb8..80f8207 100644
--- a/src/sfml_game/SpriteEntity.cpp
+++ b/src/sfml_game/SpriteEntity.cpp
@@ -1,110 +1,119 @@
/** This file is part of sfmlGame.
*
* FreeTumble is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTumble is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FreeTumble. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SpriteEntity.h"
SpriteEntity::SpriteEntity(sf::Texture* image, float x, float y, int width, int height, int imagesProLine) : GameEntity(x, y)
{
frame = 0;
isFading = false;
isShrinking = false;
isVisible = true;
this->image = image;
sprite.setTexture(*image);
this->width = width <= 0 ? image->getSize().x : width;
this->height = height <= 0 ? image->getSize().y : height;
//sprite.SetSubRect(sf::IntRect(0, 0, this->width, this->height));
sprite.setOrigin((float)(this->width / 2), (float)(this->height / 2));
this->imagesProLine = imagesProLine;
}
int SpriteEntity::getFrame() { return frame; }
int SpriteEntity::getWidth() { return width; }
float SpriteEntity::getScaleX()
{
return sprite.getScale().x;
}
void SpriteEntity::setFading(bool isFading)
{
this->isFading = isFading;
}
void SpriteEntity::setShrinking(bool isShrinking)
{
- this->isShrinking = isShrinking;
+ //this->isShrinking = isShrinking;
+ setShrinking(isShrinking, 1.0f, 1.0f);
+}
+
+void SpriteEntity::setShrinking(bool isShrinking, float initialScaleX, float initialScaleY)
+{
+ this->isShrinking = isShrinking;
+ this->initialScaleX = initialScaleX;
+ this->initialScaleY = initialScaleY;
}
void SpriteEntity::setVisible(bool isVisible)
{
this->isVisible = isVisible;
}
void SpriteEntity::setFrame(int frame) { this->frame = frame; }
void SpriteEntity::setScale(float scx, float scy)
{
sprite.setScale(scx, scy);
}
void SpriteEntity::setImagesProLine(int n)
{
imagesProLine = n;
}
void SpriteEntity::removeCenter()
{
sprite.setOrigin(0.0f, 0.0f);
}
void SpriteEntity::render(sf::RenderWindow* app)
{
if (isVisible)
{
int nx = frame;
int ny = 0;
if (imagesProLine > 0)
{
nx = frame % imagesProLine;
ny = frame / imagesProLine;
}
sprite.setTextureRect(sf::IntRect(nx * width, ny * height, /*(nx + 1) **/ width, /*(ny + 1) */ height));
sprite.setPosition(x, y);
sprite.setRotation(angle);
if (isFading)
{
sprite.setColor(sf::Color(255, 255, 255, (sf::Uint8)(getFade() * 255)));
}
if (isShrinking)
{
- sprite.setScale(getFade(), getFade());
+ sprite.setScale(initialScaleX * getFade(),
+ initialScaleY * getFade());
}
app->draw(sprite);
}
}
void SpriteEntity::animate(float delay)
{
GameEntity::animate(delay);
}
diff --git a/src/sfml_game/SpriteEntity.h b/src/sfml_game/SpriteEntity.h
index 6ff6250..f11b9f5 100644
--- a/src/sfml_game/SpriteEntity.h
+++ b/src/sfml_game/SpriteEntity.h
@@ -1,58 +1,62 @@
/** This file is part of sfmlGame.
*
* FreeTumble is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTumble is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FreeTumble. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SPRITEENTITY_H_INCLUDED
#define SPRITEENTITY_H_INCLUDED
#include "GameEntity.h"
// Basis class for sprite
class SpriteEntity : public GameEntity
{
public:
// create a sprite with the entire image
SpriteEntity(sf::Texture* image, float x = 0.0f, float y = 0.0f, int width = -1, int height = -1, int imagesProLine = 0);
int getFrame();
float getScaleX();
int getWidth();
void setFading(bool isFading);
void setShrinking(bool isShrinking);
+ void setShrinking(bool isShrinking, float initialScaleX, float initialScaleY);
void setVisible(bool isVisible);
void setFrame(int frame);
void setImagesProLine(int n);
void setScale(float scx, float scy);
void removeCenter();
virtual void render(sf::RenderWindow* app);
virtual void animate(float delay);
protected:
sf::Sprite sprite;
sf::Texture* image;
int width;
int height;
int frame;
int imagesProLine;
+ // for shrinking
+ float initialScaleX, initialScaleY;
+
bool isFading;
bool isShrinking;
bool isVisible;
};
#endif // SPRITEENTITY_H_INCLUDED

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:48 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68872
Default Alt Text
(9 KB)

Event Timeline