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

Pages: 1 ... 6 7 [8] 9 10
106
General discussions / How to make an sprite go to correct direction
« on: January 04, 2011, 02:12:48 am »
Hi s3rius,

Your function works like a charm.

You can see my game prototype here:
http://www.prsolucoes.com/downloads/solodefender.zip

But i have a simple problem now, my shoot with your function go correctly to X/Y position, but i need that it continue moving if not collide with target, so i need that the shoot continue moving to current direction and go out of screen.

So resuming:
How i can change your function to make my shoot go to a direction based on targetX / targetY position and dont stop move?

107
General discussions / How to make an sprite go to correct direction
« on: December 18, 2010, 04:04:26 am »
Is it that i do.

TargetX and TargetY is the position of enemy (x and y).

The problem is that i need rotate the laser to point to the enemy, and make the bullet go to targetX and targetY on the correspondent angle.

108
General discussions / How to make an sprite go to correct direction
« on: December 11, 2010, 06:39:08 am »
Hi,

On my game i want that my shoot go to correct direction (enemy direction), but it doesnt occur.

You can see here:
http://www.prsolucoes.com/downloads/solodefender.zip

The code that im using is (on update):

Code: [Select]


void Bullet::update()
{
updateSpriteDirection();
checkCollision();
updatePosition();
}

void Bullet::updateSpriteDirection()
{
sprite.SetRotation( Functions::angle(sprite.GetPosition().x, sprite.GetPosition().y, targetX, targetY) );
}

void Bullet::checkCollision()
{
if (sprite.GetPosition().x + sprite.GetSize().x < 0)
{
remove();
}
else if (sprite.GetPosition().y + sprite.GetSize().y < 0)
{
remove();
}
else if (sprite.GetPosition().x > Constants::SCREEN_WIDTH)
{
remove();
}
else if (sprite.GetPosition().y > Constants::SCREEN_HEIGHT)
{
remove();
}
}


void Bullet::updatePosition()
{
sprite.SetPosition(sprite.GetPosition().x + speedX, sprite.GetPosition().y + speedY);
}

void Bullet::updateSpeed()
{
if (sprite.GetPosition().x < targetX)
{
speedX = Constants::BULLET_SPEED;
}

if (sprite.GetPosition().x > targetX)
{
speedX = (Constants::BULLET_SPEED * -1);
}

if (sprite.GetPosition().y < targetY)
{
speedY = Constants::BULLET_SPEED;
}

if (sprite.GetPosition().y > targetY)
{
speedY = (Constants::BULLET_SPEED * -1);
}
}



What is wrong?

109
General / How to remove class/sprite
« on: December 10, 2010, 02:54:44 pm »
Hi,

With boost smartpointer, when i do the ERASE from vector it will be deleted?

Do you have a function example?

110
General / How to remove class/sprite
« on: December 09, 2010, 10:05:24 pm »
To delete the class from memory, i invoke:

Code: [Select]
delete this;

And now the destructor is called.

111
General / How to remove class/sprite
« on: December 09, 2010, 09:46:43 pm »
So nexus, what you recommend?

112
General / How to remove class/sprite
« on: December 04, 2010, 07:05:55 pm »
Hi,

What i do to prevent it, is make a loop on this vector objects without look it, an example:

Code: [Select]
for (long x = 0; x < (long)GameObjects::enemies->size(); ++x)
{
    Enemy *enemy = GameObjects::enemies->at(x);
    ...
    enemy->remove();
}


The remove method is:

Code: [Select]
GameObjects::enemies->erase(std::find(GameObjects::enemies->begin(), GameObjects::enemies->end(), this));

So, when i need loop vectors, i will use FOR without iterator, then i can remove without problems.

With this solution my problem is solved.

This is a good practice?

113
General / How to remove class/sprite
« on: December 04, 2010, 05:16:39 pm »
Hi,

The problem is that if im in the loop, and a method in this loop remove an element from the vector, the program crashes, an example:

Code: [Select]

for (std::vector<Enemy*>::iterator it = GameObjects::enemies->begin(); it!=GameObjects::enemies->end(); ++it) {
((Enemy*)*it)->update();
}


The update check the collision and call remove method:

Code: [Select]
if (Collision::PixelPerfectTest(sprite, GameObjects::planet->getSprite()))
{
GameObjects::enemies->erase(std::find(GameObjects::enemies->begin(), GameObjects::enemies->end(), this));
}



When ERASE method is called, the program crashes.

114
General / How to remove class/sprite
« on: December 04, 2010, 05:05:15 pm »
Hey laurent,

Sorry man, i dont see your posts.

Now i change my solution for yours, its simply perfect.

Thanks very much, it help a lot.

115
General / How to remove class/sprite
« on: December 04, 2010, 07:29:00 am »
Hi,

I resolve the problem with:

Code: [Select]

for (long x = 0; x < (long)GameObjects::enemies->size(); ++x)
{
Enemy *enemy = GameObjects::enemies->at(x);

if (enemy == this)
{
GameObjects::enemies->erase(GameObjects::enemies->begin() + x);
}

}



When i erase an element from vector, it is all removed from the memory?

116
General / How to remove class/sprite
« on: December 03, 2010, 10:30:26 pm »
Hi,

On my game i have a vector with all my enemies, and i want that when it collide with some other objects, be removed from vector and destroyed.

My vector:

Code: [Select]
static std::vector<Enemy*> *enemies;

What i have tested:

Code: [Select]
void Enemy::remove()
{
//GameObjects::enemies->erase(*this);
//delete this;

for (std::vector<Enemy*>::iterator it = GameObjects::enemies->begin(); it!=GameObjects::enemies->end(); ++it) {
if (((Enemy*)*it) == this)
{
GameObjects::enemies->erase(it);
}
}
}


But allways that i do it, i get a fatal error.

117
General discussions / Problem executing on different PC
« on: December 02, 2010, 03:37:45 pm »
Ok, thanks.

In release mode i dont test, only debug.

I only know where is this option for future problem.

Thanks man.

118
General discussions / Problem executing on different PC
« on: December 02, 2010, 03:05:53 pm »
Hi,

Thanks.

Where i see this option on visual studio 2008?

Other question:
You have SFML2 compiled library for VS 2008?

119
General discussions / Problem executing on different PC
« on: December 02, 2010, 06:18:10 am »
Hi,

Im making a sample app with SFML 1.6 on my PC (Windows 7 - 32bits) and it works nice.

But when i copy the files (exe + dll) to my other PC (Windows XP SP3 - 32bits), i got an error when open .EXE.

The error say that the application need be reinstalled and dont open.

What can be the problem?

120
General / Make some sfml objects as static
« on: November 28, 2010, 02:31:36 pm »
Hi,

I want make some objects static like RenderWindow,

Instaed of make on main file:
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics")

I have a classe called GameObjects, that will have a static attribute to hold the RenderWindow.

But i dont know how to do it, i get some erros, because i dont know how to do it without pointer objects, like:

GameObjects::app = new Object...

Pages: 1 ... 6 7 [8] 9 10
anything