1
General / Drawing lots of shapes
« on: May 25, 2011, 04:04:24 am »
Do you know of any examples I can check out?
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
class Entity{
public:
sf::Sprite mySprite;
sf::Image *myImage;
std::vector<sf::IntRect> &frames;
sf::RenderWindow &myApp;
Vector2 dir;
float speed;
public:
Entity(sf::RenderWindow &app, sf::Image &myImage, std::vector<sf::IntRect> &framesVec, float x, float y, float dirx = 0.0f, float diry = 0.0f)
: myApp(app), frames(framesVec), myImage(&myImage)
{
dir.setXY(dirx,diry);
mySprite.SetImage(myImage);
mySprite.SetPosition(x,y);
}
void update(float delta){
}
void draw(){
myApp.Draw(mySprite);
}
};
std::vector<Projectile*> entities;
void AddEntity(Projectile *ent){
entities.push_back(ent);
}
class Projectile: public Entity{
public:
Direction direction;
Animator myAnimator;
Projectile(sf::RenderWindow &app, sf::Image *myImage, std::vector<sf::IntRect> &framesVec, float x, float y, Direction DIR)
: Entity(app, *myImage, framesVec, x, y) {
speed = 10.0f;
if (DIR == RIGHT)
dir.setXY(speed,0);
else
dir.setXY(-speed,0);
myAnimator.AddNewSequence("start", 0, 0);
myAnimator.AddNewSequence("fly", 1, 3);
myAnimator.PlayAnimation("start","fly");
mySprite.SetSubRect(frames[myAnimator.UpdateAndGetFrame(.0001)]);
AddEntity(this);
}
...
class Character: public Entity{
public:
bool moving;
Direction direction;
const float speed;
const float jumpSpeed;
bool shooting;
bool falling;
bool jumping;
int jumpStartHeight;
int fallStartHeight;
int maxJumpHeight;
Animator myAnimator;
Character(sf::RenderWindow &app, sf::Image &myImage, std::vector<sf::IntRect> &framesVec, float x, float y, float dirx = 0.0f, float diry = 0.0f)
: Entity(app, myImage, framesVec, x, y, dirx, diry, maskr, maskg, maskb), speed(120.0f), jumpSpeed(370.0f), maxJumpHeight(140)
...
Character::Shoot(){
Projectile FIRE(myApp, myImage, LoadProjectileFrames(), mySprite.GetPosition().x, mySprite.GetPosition().y, direction);
}