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 - e_barroga

Pages: 1 2 3 [4] 5 6
46
Graphics / Drawable.GetPosition()
« on: April 17, 2009, 05:37:39 am »
I've moved the initialization to the constructor, but now I'm not quite sure how to write this:
Code: [Select]

float GetX() {
    return ( self.GetPosition().x );
}


...considering it isn't returning a float type. I checked the source and it seems I should be using const Vector2f but it doesn't work.

47
Graphics / Drawable.GetPosition()
« on: April 17, 2009, 01:08:41 am »
Now, I'm getting the following error after trying to write the shape as a class:
Code: [Select]

C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|6|error: `sf::Shape::Rectangle' cannot appear in a constant-expression|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|6|error: a call to a constructor cannot appear in a constant-expression|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|6|error: a function call cannot appear in a constant-expression|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|6|error: invalid in-class initialization of static data member of non-integral type `const sf::Shape'|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h||In constructor `Paddle::Paddle(float, float)':|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|11|error: `self' was not declared in this scope|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|11|warning: unused variable 'self'|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h||In member function `void Paddle::Move(float, float)':|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|15|error: `self' was not declared in this scope|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|15|warning: unused variable 'self'|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h||In member function `void Paddle::SetX(float)':|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|19|error: `self' was not declared in this scope|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|19|warning: unused variable 'self'|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h||In member function `void Paddle::SetY(float)':|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|23|error: `self' was not declared in this scope|
C:\Users\BarrogaTravels\Desktop\Pong\Engine.h|23|warning: unused variable 'self'|
C:\Users\BarrogaTravels\Desktop\Pong\main.cpp||In function `int main()':|
C:\Users\BarrogaTravels\Desktop\Pong\main.cpp|45|error: 'class Paddle' has no member named 'GetPosition'|
C:\Users\BarrogaTravels\Desktop\Pong\main.cpp|46|error: 'class Paddle' has no member named 'GetPosition'|
C:\Users\BarrogaTravels\Desktop\Pong\main.cpp|48|error: 'class Paddle' has no member named 'GetPosition'|
C:\Users\BarrogaTravels\Desktop\Pong\main.cpp|49|error: 'class Paddle' has no member named 'GetPosition'|
C:\Users\BarrogaTravels\Desktop\Pong\main.cpp|66|error: expected `)' before "App"|
C:\Users\BarrogaTravels\Desktop\Pong\main.cpp|67|error: no matching function for call to `sf::RenderWindow::Draw(Paddle&)'|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\SFML\Graphics\RenderTarget.hpp|67|note: candidates are: virtual void sf::RenderTarget::Draw(const sf::Drawable&)|
C:\Users\BarrogaTravels\Desktop\Pong\main.cpp|68|error: no matching function for call to `sf::RenderWindow::Draw(Paddle&)'|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\SFML\Graphics\RenderTarget.hpp|67|note: candidates are: virtual void sf::RenderTarget::Draw(const sf::Drawable&)|
C:\Users\BarrogaTravels\Desktop\Pong\main.cpp|52|warning: unused variable 'Factor'|
||=== Build finished: 15 errors, 5 warnings ===|


Disregard the "GetPosition" error.

Code: [Select]

class Paddle {
    private:
        sf::Shape self = sf::Shape::Rectangle( 0, 10, 100, sf::Color( 255, 255, 255 ) );

    public:
        Paddle();
        Paddle( float X, float Y ) {
            self.Move( X, Y );
        }

        void Move( float X, float Y ) {
            self.Move( X, Y );
        }

        void SetX( float X ) {
            self.SetX( X );
        }

        void SetY( float Y ) {
            self.SetY( Y );
        }
};

48
Graphics / Drawable.GetPosition()
« on: April 17, 2009, 12:53:09 am »
Quote from: "Laurent"
It should be zero. The fact that you put the points of your shape around (300, 400) doesn't move its origin from (0, 0). It's just not a good idea because you'll always have this offset.


Oh, okay. I think I get it. This makes perfect sense, thank you. The actual reason it is -7 is because I move the shape -7.

Thanks for the explanation.

49
Graphics / Drawable.GetPosition()
« on: April 16, 2009, 11:16:10 pm »
I've created a shape as follows:
Code: [Select]

sf::Shape Ball = sf::Shape::Circle( 400, 300, BallRadius, sf::Color( 255, 255, 255 ) ); //Ball


When I check the Y coordinate (writing to console) I get: -7

Shouldn't it be 300?

50
Window / Removing the console
« on: April 16, 2009, 04:34:32 pm »
P.S.
I wouldn't say that you would need to look in a "Basic C++ Tutorial" to learn how to link libraries.

For a beginner those tutorials are probably complex.

I learned because I needed 3 libraries to get a WinSock Network Library (39DLL) to work.

51
Window / Removing the console
« on: April 16, 2009, 02:42:01 am »
Quote from: "Laurent"
Quote
What do you mean by "link to sfml-main.lib".

I mean "link to sfml-main.lib". If you really don't know what this means, then I suggest you read some basic C++ tutorial first.

Quote
Also, what do you mean by "keep main as my entry point".

I mean that your entrey point is still the portable "main" and not an OS-specific one like "WinMain".


Okay, I get it.... but yeah, I know how to link.

52
Window / Removing the console
« on: April 15, 2009, 08:41:15 pm »
Quote from: "Laurent"
And to keep main as your entry point (instead of WinMain), you must link to sfml-main.lib.


What do you mean by "link to sfml-main.lib".

Also, what do you mean by "keep main as my entry point".

53
General / Flexible Object Manager
« on: January 14, 2009, 02:45:10 am »
Quote from: "Tank"
e_barroga:
Please read the posts more carefully. :)

Using an object manager class, your code could look like as follows:
Code: [Select]

int main() {
  ObjectManager mgr;

  mgr.addObject( new MyObject ); // MyObject derived from BaseObject
  mgr.addObject( new MyOtherObject ); // MyOtherObject derived from BaseObject

  while( true ) { // Some kind of main loop.
    mgr.processObjects(); // Calls step() for every object.
  }
}


BaseObject has the virtual functions create() and step(). create() can be called in several ways: Either by the constructor or by ObjectManager::addObject(). ObjectManager::processObjects() iterates through all added objects and calls step() on each. I hope it's more clear this time.

Edit:
klusark:
You're implementing some kind of factory pattern. I would either prefer to implement functions like: createPlayer(), create...() instead of comparing type strings (we're using OOP ;) ), or directly pass a pointer to the proper object by using the new statement.
For example something like:
Code: [Select]

objectmanager.register( ObjectFactory::createPlayer(), "an_unique_id" );


Yes, I already know about writing an object manager, but I am having issues writing the method to create instances through arguments.

Code: [Select]

void ObjectManager::addObject ( argument0 ) {
  new argument0;
}


How do I make it create an instance of whatever is defined in argument0?

54
General / Flexible Object Manager
« on: January 13, 2009, 03:35:14 am »
How would I properly execute this:
Code: [Select]


void instance_create ( name_of_object ) {
  name_of_object newInstance;
  instances.push_back( newInstance );
}


int main () {
  instance_create( o_ball );

  for ( int i=0; i<instances.size(); i++ ) {
    instances[i].Step();
  }
}

55
General / Flexible Object Manager
« on: January 11, 2009, 11:42:47 pm »
So you're saying that instead of writing virtual functions in the base class.... write the functions in a "manager class"?

How would I make that work, I don't completely understand.

The main reason I wish to make a base object class that has virtual functions:

Code: [Select]

virtual Create();
virtual Step();
virtual Destroy();


is so that I can add new object classes very simple. How would I get that to work if I made the Create, Step, Destroy methods for every derived objects in an "object manager" class?

56
General / Flexible Object Manager
« on: January 11, 2009, 04:32:33 am »
One thing that stumps is how to properly call the specific object when I want to create it:

Code: [Select]

instance_create( <name of object> ) {
  <name of object> newObj;
  instances.push_back( newObj );
}


I want to use it in the main loop like so:
Code: [Select]

instance_create( test );



Also.... when initializing the instance list, it doesn't seem to recognize the child objects. I did the following:

Code: [Select]

std::vector <base> instances;


I've created a child object:
Code: [Select]

class test: public base {
  public:
    void step() {
      std::cout << "Testing\n";
    }
};


Then I have the following in my main loop:
Code: [Select]

for (i=0; i<instances.size(); i++) {
  instances[i].step();
}


But it doesn't seem to work, so I changed the vector type for testing:
Code: [Select]

std::vector <test> instances;


And it outputs the text repeatedly, as I wanted.

57
General / Flexible Object Manager
« on: January 10, 2009, 03:04:08 am »
I need help writing an object manager.

I'm trying to make it extremely flexible so that content can be added easily.

Basically, I want to make an instance list so that SFML can loop through it and draw the instances at their coordinated places. I want to make a base object class, which is what SFML will be using for reference. This base object will have three virtual functions:

Code: [Select]

Create()

Step()

Destroy()


This way, I can easily write new object classes without messing with the engine in its entirety.


Code: [Select]

class baseObject {//The base Game Object

virtual Create();
virtual Step();
virtual Destroy();
};


class objBall: public baseObject {

void Create();
void Step();
void Destroy();
};



Then, I would just loop through the baseObject and it'll perform the Create, Step, and Destroy methods the way they're stated in the childs.

I'm having difficulty getting this to work, could I get some assistance?

Thanks.[/code]

58
General / Best Way to Handle Instances
« on: November 18, 2008, 09:48:54 pm »
I've gone through: www.cplusplus.com

I know stuff like pointers, classes, polymorphism, etc.

However, I think that the only way to truely know the language is by experience.... which you can't really get unless you dive into programming.

Also.... I understand the concepts of "scope" and the "scope operator> ::

59
General / Best Way to Handle Instances
« on: November 18, 2008, 04:48:58 pm »
I did something like this:

main.cpp
Code: [Select]

#include "Includes.h"

int main()
{
    GetInput();
}


Includes.h
Code: [Select]

#include "Get Input.h"


It says that "GetInput()" is not in this scope.

60
General / Best Way to Handle Instances
« on: November 18, 2008, 12:13:49 am »
So something like this:

Get Input.h
Code: [Select]

//Prevent Multiple Inclusions
#ifndef GET_INPUT_H
#define GET_INPUT_H

extern void GetInput();

#endif GET_INPUT_H


Get Input.cpp
Code: [Select]

void GetInput()
{
}


main.cpp
Code: [Select]

#include "Get Input.h"

int main()
{
GetInput();
}


Would that work, or am I supposed to include the "Get Input.cpp" file as well? If so, I do not understand how it would know to compile the ".cpp" file.

Pages: 1 2 3 [4] 5 6