[QUOTE=BlkDucky;33954649]But whatever, I really can't see how what I posted is any more effort at all, honestly.[/QUOTE]
Not for someone copy-pasting it, no - but it was development time for you to work it out - and all it creates is easily written rect-shaped string literals with * borders.
Now I know why you're arguing it, the "data-driven" programming method - don't hardcode anything in. But the obvious answer then is to have external map files, easily edited. Then programming the save/load routines are indeed worth the development time. The maps become arbitrary in both size and shape, it's easily extended for new features, etc.
If sticking with the current method however, the point at which writing that function becomes worth the effort is the point which external data files would be a better solution i.e. where there is so much repetition a better method is needed.
[editline]29th December 2011[/editline]
[QUOTE=Meatpuppet;33954674]Still no more info, I'll look into what you said
[editline]29th December 2011[/editline]
argh
[editline]29th December 2011[/editline]
The only thing in my include files that uses SFML is a function that I already know works, which is the function to get the filename of the sprite I'm using for the ship. Hmm.[/QUOTE]
Best suggestion I could give in that case at the moment is to use breakpoints, and find where it'll run to.
[url]http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks[/url]
Can't figure out why this isn't staying open. The if statement for App.Close is never being met.
ship1.GetLifeSupportTime() is 86400, by the way.
[url]http://pastebin.com/t3ctrpLF[/url]
[QUOTE=Meatpuppet;33956031]Can't figure out why this isn't staying open. The if statement for App.Close is never being met.
ship1.GetLifeSupportTime() is 86400, by the way.
[url]http://pastebin.com/t3ctrpLF[/url][/QUOTE]
[code]if (seconds = ship1.GetLifeSupportTime())
App.Close();
[/code]
Should be
[code]if (seconds == ship1.GetLifeSupportTime())
App.Close();[/code]
Note the double equals sign instead of the single.
Thanks. Gotta stop making these stupid mistakes.
[editline]30th December 2011[/editline]
Ok.
[cpp] std::cout << ship1.GetX() << " " << ship1.GetY() << " " << ship1.GetShipImage().GetRotation() << "\n";[/cpp]
Keeps giving me error: no match for 'operator<<' in 'std::operator<<
Even though I included the header #include <iostream>
The functions are correct; they return floats.
ship1.GetY() is missing the parentheses?
They were already in there. Still nothing?
[editline]30th December 2011[/editline]
Got it. It wasn't in the right part of the main loop.
[QUOTE=BlkDucky;33954649]You mean two maps, assuming:
But whatever, I really can't see how what I posted is any more effort at all, honestly.[/QUOTE]
It is actually useful for something like I'm doing at the moment where the program is fed the map file which can be varied in size.
Serious question time. How do I save the rotation of the ship between images? e.g. when I change the image it just goes back to no rotation at all.
[url]http://pastebin.com/WNDLNtf9[/url]
[editline]30th December 2011[/editline]
Basically, I want it to keep the rotation of the ship when the user presses/releases the thrust key.
[QUOTE=Meatpuppet;33957819]Serious question time. How do I save the rotation of the ship between images? e.g. when I change the image it just goes back to no rotation at all.
[url]http://pastebin.com/WNDLNtf9[/url]
[editline]30th December 2011[/editline]
Basically, I want it to keep the rotation of the ship when the user presses/releases the thrust key.[/QUOTE]
Try saving the rotation value in the ship object itself, rather than in the image object, and then applying the rotation when a new image is used.
[QUOTE=Octave;33957855]Try saving the rotation value in the ship object itself, rather than in the image object, and then applying the rotation when a new image is used.[/QUOTE]
How do I call the object of a class within a class's function? *this?
[QUOTE=Meatpuppet;33957895]How do I call the object of a class within a class's function? *this?[/QUOTE]
'this' is a pointer, so you can go like:
[cpp]
SomeClass* me = this;
[/cpp]
The * part of '*this' dereferences the pointer, which is a fancy way of saying that the computer will go grab whatever this points to. You want to be careful when using *this, because you could accidentally make another copy of the object.
[cpp]
SomeClass me = *this; // woops, this will make another copy of 'this' that's separate from the actual 'this' object
[/cpp]
The way we solve this in C++ is by using a [i]reference[/i]:
[cpp]
SomeClass& me = *this; // this is ok!
[/cpp]
Here, 'me' feels like a regular old variable, but it's actually the same thing as *this, just under a different name.
Got it. Thanks.
How to get a simple 2D box collision?
This is what I have now. The bug in this is it stops moving completely, even it should stop only X or Z to cause sliding.
[code]
public void Tick()
{
if(bforward)
MoveForward(0.5f);
if(bbackward)
MoveForward(-0.5f);
}
public void MoveForward( float Distance )
{
MoveForwardX(Distance);
MoveForwardZ(Distance);
}
public void MoveForwardX( float Distance )
{
if(CollideX(Distance)) return;
Positionx += ViewDirx*Distance; // Viewdir = direction.
}
boolean CollideX( float Distance )
{
if(((Positionx + (ViewDirx*Distance)) <= 1.8f*2f) && ((Positionx + (ViewDirx*Distance)) >= 0.2f*2f) && ((Positionz + (ViewDirz*Distance)) <= 1.8f*2f) && ((Positionz + (ViewDirz*Distance)) >= 0.2f*2f))
return true;
}
public void MoveForwardZ( float Distance )
{
if(CollideZ(Distance)) return;
Positionz += ViewDirz*Distance;
}
boolean CollideZ( float Distance )
{
if(((Positionz + (ViewDirz*Distance)) <= 1.8f*2f) && ((Positionz + (ViewDirz*Distance)) >= 0.2f*2f) && ((Positionx + (ViewDirx*Distance)) <= 1.8f*2f) && ((Positionx + (ViewDirx*Distance)) >= 0.2f*2f))
return true;
}
[/code]
[QUOTE=swift and shift;33961616]'this' is a pointer, so you can go like:
SomeClass* me = this;
The * part of '*this' dereferences the pointer, which is a fancy way of saying that the computer will go grab whatever this points to. You want to be careful when using *this, because you could accidentally make another copy of the object.
SomeClass me = *this; // woops, this will make another copy of 'this' that's separate from the actual 'this' object
The way we solve this in C++ is by using a [I]reference[/I]:
SomeClass& me = *this; // this is ok!
Here, 'me' feels like a regular old variable, but it's actually the same thing as *this, just under a different name.[/QUOTE]
This seems to work: [cpp] float GetShipRotation()
{
Spaceship& ship = *this;
return ship.GetShipImage().GetRotation();
}[/cpp]
but how do I implement it into the main function? This:
[cpp] if(!ship1.Thrusting)
{
ship1.Thrusting = 1;
ship1.ShipLoadImage("spaceship1_thrusting.png");
ship1.SetShipAccel(ship1.GetShipImage().GetRotation(), ship1.GetThrust(), ship1.GetMass());
ship1.SetShipVelocity();
ship1.SetShipPosition(int(Clock.GetElapsedTime()));
ship1.GetShipImage().SetPosition(ship1.GetX(), ship1.GetY());
ship1.GetShipImage().SetRotation(ship1.GetShipRotation());
ship1.GetShipImage().SetCenter(ship1.GetShipImage().GetSize()/2.f);
std::cout << "Thrusting is on...\n";
}[/cpp]
Doesn't work.
Why not just
[code]
float GetShipRotation()
{
return rotation;
}
[/code]
?
EDIT: I should ask, how is rotation stored?
Yes, you should make your own variables for position/rotation etc instead of relying on SFML's (purely visual) sprite settings.
[QUOTE=Parad0x0217;33966423]Why not just
[code]
float GetShipRotation()
{
return rotation;
}
[/code]
?
EDIT: I should ask, how is rotation stored?[/QUOTE]
As an unused variable now. How do I use class functions within the definition of a class variable, e.g. setting rotation equal to (object).GetShipImage().GetRotation()?
Use it.
You shouldn't make a pointer to the ship.
Just directly assign variables within a class. No need to call the member functions inside the class itself.
[QUOTE=Parad0x0217;33966663]Use it.
You shouldn't make a pointer to the ship.
Just directly assign variables within a class. No need to call the member functions inside the class itself.[/QUOTE]
I already declared rotation, should I define it within the class as
[cpp]
rotation = GetShipImage().GetRotation()
[/cpp]
Or will that not work?
[editline]30th December 2011[/editline]
I'm probably overthinking this and there's an obvious answer.
Yes, it will work.
How do you define GetShipImage() in your ship class?
[QUOTE=Parad0x0217;33966733]Yes, it will work.
How do you define GetShipImage() in your ship class?[/QUOTE]It just returns the ship's sprite, based off of ShipLoadImage, which has a parameter that is the images filename.
Then instead of
[code]
rotation = GetShipImage().GetRotation();
[/code]
use
[code]
rotation = ShipSprite.GetRotation();
[/code]
I just defined it and declared it in the same line (it's private, does that matter?) with what I typed earlier, but now it's giving me loadsa errors.
[editline]30th December 2011[/editline]
[QUOTE=Parad0x0217;33966794]Then instead of
[code]
rotation = GetShipImage().GetRotation();
[/code]
use
[code]
rotation = ShipSprite.GetRotation();
[/code][/QUOTE]
How would that change matter? It's exactly the same.
In your header
[code]
private:
float rotation;
[/code]
in your source file
[code]
rotation = ShipSprite.GetRotation();
[/code]
EDIT: Yes it is the same, but there is no need for unneeded function calls when you can access the object directly.
Oooh.
[editline]30th December 2011[/editline]
Not working. Tried Spaceship.Rotation =, and Spaceship::Rotation =, but those didn't work either.
Are you trying to change the rotation from outside the class?
Then you'll need to create a function like so:
[code]
void Spaceship::setRotation(float Rot)
{
rotation = Rot;
}
[/code]
Ok. Do I still need to define rotation?
Yes.
I'm thinking now that you should use this:
[code]
void Spaceship::setRotation(float Rot)
{
ShipSprite.SetRotation(Rot);
}
[/code]
because you set rotation equal to ShipSprite's rotation.
Make sure you update rotation every frame.
Like this?
[cpp]void Spaceship::SetShipRotation(float rot)
{
GetShipImage().SetRotation(rot);
}
[/cpp]
Oh and it is. I have the ships rotation in the console at all times via std::cout.
How do I make it work in main?
Yes, but I don't understand why you insist on calling GetShipImage() when you can just use ShipSprite or whatever your ship's sprite is.
Sorry, you need to Log In to post a reply to this thread.