Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - booncoder

Pages: [1]
1
Graphics / Width and height
« on: April 21, 2010, 03:21:50 pm »
How can i access the width and height of a sprite to implement collision using bounding boxes?

i know there is a getSize() sprite function but it is in the form of a vector2f does that get the width and height or just the x and y poistion.

2
General / Calling constructors from inherited classes
« on: April 19, 2010, 08:00:36 pm »
its basicly the same from previous jsut constructor changes

sinking cpp
Code: [Select]

sinkingObstacle::sinkingObstacle(const Image &Img, const Vector2f &Position, const Vector2f &Scale, float Rotation, const Color &Col, float scrollPos):Obstacle(Img,Position,Scale,Rotation,Col,scrollPos)
{

std::cout<<getScrollPos()<<std::endl;
}
sinkingObstacle::sinkingObstacle():Obstacle()
{
}

obstacle cpp
Code: [Select]

Obstacle::Obstacle(const Image &Img, const Vector2f &Position, const Vector2f &Scale, float Rotation, const Color &Col, float scrollPos):Sprite (Img ,Position, Scale, Rotation, Col)//,scrollposition(scrollPos)
{scrollposition=scrollPos;

}
Obstacle::Obstacle():Sprite()
{
}

error
Code: [Select]

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <sstream>
#include "obstacle.h"
#include "explosiveObstacle.h"
#include "sinkingObstacle.h"
#include "Scroller.h"
#include "AnimatedSprite.h"
#include "game.h"
#include "submarine.h"
#include <cmath>
#include <time.h>

int main()
{
//initialisation - lots of this code could be put into functions for
//neatness and separation of concerns. You need to declare objects here to draw them
//but the set up for those objects could be done in a function or a class

//window dimensions
unsigned int width=600;
unsigned int height=480;
Game newgame(0,0);

//we need a timer to update things - get a clock
sf::Clock clock;
static float timeAccumulator=0.0;

//load resources for the scroller - images and sounds (if you have any)
sf::Image backGround;
if(!backGround.LoadFromFile("images/underwater.jpg")) std::cout<<"File not found background.jpg"<<std::endl;

sf::Image Rock;
if(!Rock.LoadFromFile("images/rock.png")) std::cout<<"File not found SpriteRock.png"<<std::endl;
//sf::Sprite SpriteRock;
sf::Image seamine;
if(!seamine.LoadFromFile("images/seamine.png")) std::cout<<"File not found seamine.png"<<std::endl;
//sf::Sprite SpriteSeamine;
sf::Image shipreck;
if(!shipreck.LoadFromFile("images/shipreck.png")) std::cout<<"File not found shipreck.png"<<std::endl;
//sf::Sprite SpriteShipreck;

Submarine newsub(100);
newsub.Init("images/submarine.png");
newsub.getEnergy();



float random = sf::Randomizer::Random(0.f,1.f);
sf::Sprite backGndSprite(backGround);
backGndSprite.Scale(0.75f,0.8f);
//declare obstacles here
//Obstacle ObsRock(Rock);
//set up the scroller data
//sinkingObstacle Seamine(seamine);
sinkingObstacle Seamine(seamine);//error here

my main game loop

3
General / Calling constructors from inherited classes
« on: April 19, 2010, 06:12:12 pm »
yea copy and paste issue thanks.

anyway got another strange error i changed my constructor calls and they work but i did have an overloaded constructor and i deleted it but it still says it is there.
1>mainscroller.cpp(57) : error C2664: 'sinkingObstacle::sinkingObstacle(const sinkingObstacle &)' : cannot convert parameter 1 from 'sf::Image' to 'const sinkingObstacle &'
1>        Reason: cannot convert from 'sf::Image' to 'const sinkingObstacle'
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
even though it is using the copy constructor

4
General / Calling constructors from inherited classes
« on: April 15, 2010, 07:23:41 pm »
ahh didn't notice thanks yea the headers where in there. thanks for the tip nexus

5
General / Calling constructors from inherited classes
« on: April 15, 2010, 07:09:24 pm »
sinkingobstacle.cpp(5) : error C2065: 'Img' : undeclared identifier
sinkingobstacle.cpp(5) : error C2065: 'Postion' : undeclared identifier
sinkingobstacle.cpp(5) : error C3867: 'sf::Drawable::Scale': function call missing argument list; use '&sf::Drawable::Scale' to create a pointer to member
sinkingobstacle.cpp(5) : error C2065: 'Roation' : undeclared identifier
sinkingobstacle.cpp(5) : error C2065: 'Col' : undeclared identifier
sinkingobstacle.cpp(5) : error C2065: 'scrollPos' : undeclared identifier

6
General / Calling constructors from inherited classes
« on: April 15, 2010, 06:56:59 pm »
here it is

Code: [Select]

#include "obstacle.h"

Obstacle::Obstacle(const Image &Img, const Vector2f &Position, const Vector2f &Scale, float Rotation, const Color &Col, float scrollPos):Sprite (Img ,Position, Scale, Rotation, Col)
{
}
Obstacle::Obstacle(const Obstacle &Obs)
{
}
Obstacle::Obstacle():Sprite()
{
}

7
General / Calling constructors from inherited classes
« on: April 15, 2010, 06:21:39 pm »
hi my problem is that i can't draw my sprite using during the game loop because it doesn't inherit the constructors of other classes and when im trying to call the constructor of another class it doesn't like it.
Code: [Select]

class Obstacle:public Sprite
{

private:
float scrollposition;
float verticalposition;
int cost;
sf::Image img;
sf::Sprite explosion;
public:
Obstacle(const Image &Img, const Vector2f &Position=Vector2f(0, 0), const Vector2f &Scale=Vector2f(1, 1), float Rotation=0.f, const Color &Col=Color(255, 255, 255, 255),float scrollPos=0.0);
Obstacle(const Obstacle &Obs);


only a bit of the class. takes the sprite constructor and calls it in a different cpp

Code: [Select]

#include "obstacle.h"
//inherits obstacle methods but not constructors
class sinkingObstacle: public Obstacle
{
private:
int cost;
public:
sinkingObstacle();
sinkingObstacle(const Obstacle &Obs);
int getcost();
void setcost(int c);
//virtual void Render (const RenderWindow &Window) const ;
};


cpp file
Code: [Select]

#include "sinkingObstacle.h"
#include <SFML/Graphics.hpp>
using namespace sf;

sinkingObstacle::sinkingObstacle(const Obstacle &Obs):Obstacle(Img,Postion,Scale,Roation,Col,scrollPos)
{
}
sinkingObstacle::sinkingObstacle():Obstacle()
{
}

says obstacle(Img,Postion,Scale,Roation,Col,scrollpos) not defined even though i used the sprite constructor in the same way.

8
Graphics / link issues
« on: March 16, 2010, 06:45:45 pm »
ahh i see thanks

9
Graphics / link issues
« on: March 16, 2010, 06:40:20 pm »
im trying to load and image and convert it to a sprite inside a class by using some kind of image management here is the code.
Code: [Select]

class Submarine:public sf::Sprite
{
private:
short int energy;
sf::Sprite subSprite;
static sf::Image submarine;
public:
Submarine()
    {
subSprite.SetImage(submarine);
cout<<"Sprite created";
initSprite("images/submarine.png");
    }
static bool initSprite(const string& Imagefile)
{
return submarine.LoadFromFile(Imagefile);


};
};

error is LNK2001: unresolved external symbol "private: static class sf::Image Submarine::submarine" (?submarine@Submarine@@0VImage@sf@@A)
of corse the header files are there

Pages: [1]