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

Pages: [1]
1
Graphics / Tank doesn't Shoot Multiple Bullets
« on: February 05, 2012, 09:11:25 am »
I tried your suggestion but it doesn't fix it. I still get the Same Error. Thnx for all the help though guys, I really appreciate it. I'll be putting this project on hold for now though, work requires me to focus on php and mysql instead =(

2
Graphics / Tank doesn't Shoot Multiple Bullets
« on: February 02, 2012, 04:04:08 pm »
So after correcting the mistake pointed out by TheCake, thanks :), I get a new error when the bullet hits the side of the screen. This Pops up:

http://imageshack.us/photo/my-images/821/errorgl.png/


the debugger shows an exception thrown as below:

Code: [Select]

// throw -- terminate on thrown exception REPLACEABLE
#define _HAS_EXCEPTIONS 0
#include <cstdio>
#include <cstdlib>
#include <exception>
#include <crtdbg.h>

_STD_BEGIN

#ifdef _DEBUG
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Debug_message(const wchar_t *message, const wchar_t *file, unsigned int line)
{ // report error and die
        if(::_CrtDbgReportW(_CRT_ASSERT, file, line, NULL, message)==1)
        {
            ::_CrtDbgBreak();
        }
}
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Debug_message(const unsigned short *message, const unsigned short *file, unsigned int line)
{ // report error and die
        _Debug_message((wchar_t *) message, (wchar_t *) file, line);
}

#endif

_STD_END

3
Graphics / Tank doesn't Shoot Multiple Bullets
« on: February 02, 2012, 01:38:07 pm »
hi, yes because the gamobject manager stores the items in a std::map, which stores an item with an associated unique label. the label for the bullet is "SmallBulleti". The GameObjectManager::Remove() is as shown below.


Code: [Select]

void GameObjectManager::Remove(std::string name)
{
std::map<std::string, VisibleGameObject*>::iterator results = _gameObjects.find(name);
if (results != _gameObjects.end())
{
delete results->second;
_gameObjects.erase(results);
}
}


Edit:: _gameObjects is the name of my variable, of type GameObjectManager

2ndEdit: Sorry TheCake, I saw what you meant by "SmallBulleti". That I corrected it, but a new problem arises.

4
Graphics / Tank doesn't Shoot Multiple Bullets
« on: February 02, 2012, 07:29:30 am »
Hey guys, I'm creating a little game using C++ and SFML. Ran into a little problem trying to make my tank shoot more than one bullet. Hope you guys can give me some help. I've attached a small snippet of code that recreates the problem.


Loop to shoot

Code: [Select]

if(Game::GetInput().IsKeyDown(sf::Key::Space))
{
PrimaryWeapon PW1;
sf::Vector2f pos = PlayerTank::GetPosition();
if(!Game::GetGameObjectManager().Get("SmallBullet"))
{
PW1.Fire(pos);
}

}


Code: [Select]

void PrimaryWeapon::Fire(sf::Vector2f pos)
{


SmallBullet* i = new SmallBullet;
i->SetPosition(pos.x, pos.y);
Game::GetGameObjectManager().Add( "SmallBullet", i);

}


Code: [Select]

void SmallBullet::Update(float elapsedTime)
{

GetSprite().Move(Velocity * elapsedTime, 0);
sf::Vector2f pos = GetPosition();
if (pos.x >= Game::SCREEN_WIDTH)
{
Game::GetGameObjectManager().Remove( "SmallBullet");
}
}


the GameObjectManager in the code is a std::map that automatically draws and updates all items added to it, in the game loop. Remove() deletes the pointer to the object and then entry in the map.

Edit:: the code is supposed to cause the bullet to be deleted if it hits the side of the screen. Once it is deleted, a new bullet can be created and "shot" again. In my program however, once it hits the side of the screen, it disappears and no new bullets are created when spacebar is pressed.

Pages: [1]