Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F125964
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/sfml_game/SpriteEntity.cpp b/src/sfml_game/SpriteEntity.cpp
index 38cb8a9..ca23b85 100644
--- a/src/sfml_game/SpriteEntity.cpp
+++ b/src/sfml_game/SpriteEntity.cpp
@@ -1,130 +1,144 @@
/** 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;
isMirroring = false;
color = sf::Color(255, 255, 255, 255);
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::setColor(sf::Color color)
{
this->color = color;
sprite.setColor(sf::Color(color.r, color.g, color.b, color.a));
}
void SpriteEntity::setShrinking(bool 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::RenderTarget* app)
{
if (isVisible)
{
int nx = frame;
int ny = 0;
if (imagesProLine > 0)
{
nx = frame % imagesProLine;
ny = frame / imagesProLine;
}
if (isMirroring)
sprite.setTextureRect(sf::IntRect((nx + 1) * width, ny * height, -width, height));
else
sprite.setTextureRect(sf::IntRect(nx * width, ny * height, width, height));
sprite.setPosition(x, y);
sprite.setRotation(angle);
if (isFading)
{
sprite.setColor(sf::Color(color.r, color.g, color.b, (sf::Uint8)(getFade() * 255)));
}
if (isShrinking)
{
sprite.setScale(initialScaleX * getFade(),
initialScaleY * getFade());
}
app->draw(sprite);
}
}
+void SpriteEntity::displayCenterAndZ(sf::RenderTarget* app)
+{
+ sf::Vertex line[] =
+ {
+ sf::Vertex(sf::Vector2f(x - 2, y), sf::Color::Green),
+ sf::Vertex(sf::Vector2f(x + 2, y), sf::Color::Green),
+ sf::Vertex(sf::Vector2f(x, y - 2), sf::Color::Green),
+ sf::Vertex(sf::Vector2f(x, y + 2), sf::Color::Green),
+ sf::Vertex(sf::Vector2f(x - 5, z), sf::Color::Green),
+ sf::Vertex(sf::Vector2f(x + 5, z), sf::Color::Green)
+ };
+ app->draw(line, 6, sf::Lines);
+}
+
void SpriteEntity::animate(float delay)
{
GameEntity::animate(delay);
}
diff --git a/src/sfml_game/SpriteEntity.h b/src/sfml_game/SpriteEntity.h
index 8ea4a1e..a7a86c4 100644
--- a/src/sfml_game/SpriteEntity.h
+++ b/src/sfml_game/SpriteEntity.h
@@ -1,65 +1,66 @@
/** This file is part of Witch Blast.
*
* Witch Blast 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.
*
* Witch Blast 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 Witch Blast. 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 setColor(sf::Color color);
void removeCenter();
virtual void render(sf::RenderTarget* app);
virtual void animate(float delay);
+ void displayCenterAndZ(sf::RenderTarget* app);
protected:
sf::Sprite sprite;
sf::Texture* image;
sf::Color color;
int width;
int height;
int frame;
int imagesProLine;
// for shrinking
float initialScaleX, initialScaleY;
bool isFading;
bool isShrinking;
bool isVisible;
bool isMirroring;
};
#endif // SPRITEENTITY_H_INCLUDED
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 10:15 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68336
Default Alt Text
(6 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline