I have no luck whatsoever.
Projectile.h
[cpp]
#pragma once
#include <SFML/Graphics.hpp>
class Projectile
{
public:
sf::Image BulletImage;
sf::Sprite Bullet;
public:
~Projectile(void);
void SetDirection(sf::Sprite);
void SetSpeed(float);
void Think(float);
};
[/cpp]
Projectile.cpp
[cpp]
#include "Projectile.h"
#include <SFML/Graphics.hpp>
Projectile::~Projectile(void)
{
}
Projectile::SetDirection(sf::Sprite Reference)
{
float TargetRotation = Reference.GetRotation();
Bullet.SetRotation(static_cast<float>(fmod(TargetRotation, 360)));
float BulletRotation = Bullet.GetRotation();
if (BulletRotation < 0)
Bullet.SetRotation(BulletRotation + 360.f);
}
Projectile::SetSpeed(float SpeedMultiplier)
{
float BulletX = Bullet.GetPosition().x;
float BulletY = Bullet.GetPosition().y;
Bullet.SetX(BulletX * SpeedMultiplier);
Bullet.SetY(BulletY * SpeedMultiplier);
}
[/cpp]
[code]
1>c:\users\darkspirit\documents\visual studio 2008\projects\zombie\zombie\projectile.cpp(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\darkspirit\documents\visual studio 2008\projects\zombie\zombie\projectile.cpp(11) : error C2556: 'int Projectile::SetDirection(sf::Sprite)' : overloaded function differs only by return type from 'void Projectile::SetDirection(sf::Sprite)'
1> c:\users\darkspirit\documents\visual studio 2008\projects\zombie\zombie\projectile.h(13) : see declaration of 'Projectile::SetDirection'
1>c:\users\darkspirit\documents\visual studio 2008\projects\zombie\zombie\projectile.cpp(11) : error C2371: 'Projectile::SetDirection' : redefinition; different basic types
1> c:\users\darkspirit\documents\visual studio 2008\projects\zombie\zombie\projectile.h(13) : see declaration of 'Projectile::SetDirection'
1>c:\users\darkspirit\documents\visual studio 2008\projects\zombie\zombie\projectile.cpp(20) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\darkspirit\documents\visual studio 2008\projects\zombie\zombie\projectile.cpp(20) : error C2556: 'int Projectile::SetSpeed(float)' : overloaded function differs only by return type from 'void Projectile::SetSpeed(float)'
1> c:\users\darkspirit\documents\visual studio 2008\projects\zombie\zombie\projectile.h(15) : see declaration of 'Projectile::SetSpeed'
1>c:\users\darkspirit\documents\visual studio 2008\projects\zombie\zombie\projectile.cpp(20) : error C2371: 'Projectile::SetSpeed' : redefinition; different basic types
1> c:\users\darkspirit\documents\visual studio 2008\projects\zombie\zombie\projectile.h(15) : see declaration of 'Projectile::SetSpeed'[/code]
You need a return type before your method definitions. Stick a [i]void[/i] there.
Oh. :v:
[editline]08:35PM[/editline]
How would I go about making the Think() function? Never did one before and I can't find any examples so I don't have any idea of what it should actually contain.
Call it just before you draw it
How do I make it drawable?
Bullet1.think();
Bullet1.draw();
I created the Think function at main.cpp.
[cpp]
void Think(Projectile Targ)
{
Targ.SetSpeed(1);
}
[/cpp]
SetSpeed:
[cpp]
void Projectile::SetSpeed(float SpeedMultiplier)
{
BulletImage.LoadFromFile("bullet.png");
Bullet.SetImage(BulletImage);
float BulletX = Bullet.GetPosition().x;
float BulletY = Bullet.GetPosition().y;
Bullet.SetX(BulletX * SpeedMultiplier);
Bullet.SetY(BulletY * SpeedMultiplier);
}
[/cpp]
Now, before all the draws I put in "Think(Bullet);", now how do I make Bullet drawable?
I did everything wrong, right?
[editline]09:24PM[/editline]
Also, I do realize the bullet won't get out of the same spot.
Yeah that's a really weird way to do it. I used to do things weird ways like that, until I relearned classes.
Sorry, you need to Log In to post a reply to this thread.