Sign in to follow this  

making the player shoot

This topic is 2319 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having multiple problems atm.
1. player shooting animation not playing
2. arms dont appear when looking left

Here is where i set the clips
[code]

// facing right
for( int i = 0; i < 3; i++ )
{
pistolClips[i] = new SDL_Rect;
pistolClips[i]->x = 0;
pistolClips[i]->y = 16 * i;
pistolClips[i]->h = 16;
pistolClips[i]->w = 36;
}
//facing left
for( int i = 3; i < 6; i++ )
{
pistolClips[i] = new SDL_Rect;
pistolClips[i]->x = 36;
pistolClips[i]->y = 16 * i;
pistolClips[i]->h = 16;
pistolClips[i]->w = 36;
}
[/code]


Here is what should draw the arms
[code]


// loop firing animation
if( player->pistolFrame == 3 )
{
player->shoot = false;
player->pistolFrame = 1;
}

// draw
if( player->direction == RIGHT )
{
if( player->shoot )
{
graphics->ApplySurface( player->handgun.xPos, player->handgun.yPos, player->pistol, graphics->screen, player->pistolClips[player->pistolFrame] );
player->pistolFrame++;
}
else
{
graphics->ApplySurface( player->handgun.xPos, player->handgun.yPos, player->pistol, graphics->screen, player->pistolClips[0] );
}
}
else if( player->direction == LEFT )
{
if( player->shoot )
{
graphics->ApplySurface( player->handgun.xPos, player->handgun.yPos, player->pistol, graphics->screen, player->pistolClips[player->pistolFrame + 3] );
player->pistolFrame++;
}
else
{
player->handgun.xPos -= 15;
graphics->ApplySurface( player->handgun.xPos, player->handgun.yPos, player->pistol, graphics->screen, player->pistolClips[3] );
}
}
[/code]

and here is what should set player->shoot to true;
[code]

if( keystate[ SDLK_SPACE ] )
{
shoot = true;
}

[/code]

Share this post


Link to post
Share on other sites
Step One: If you haven't already, download msvc 2010 express:
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express

Step Two: Move your code into the new IDE.

Step Three: Run you code in debug mode, with a break-point set at 'shoot = true;' or some other reasonable place.


This is a problem that with a debugger you can track down very quickly, and learning to use one will help you tremendously in the future.

(if you already have msvc or a good debugger say so and we can go from there)

Share this post


Link to post
Share on other sites
I am using msvc 2010, but i cannot do step three because the program only gets to 'shoot = true;' if space is pressed. using the debuger is moves the program one frame at a time. I would have to press play, rush to the other side of the screen, click it, then press space.

Share this post


Link to post
Share on other sites
Now I could be wrong, but I'm pretty sure msvc express comes with the same debugging capabilities as the normal version.

In which case, just set the configuration to debug build and click the green arrow or w/e and it will run normally until it hits a break point.
Just add the break-point somewhere sensible.

Then you can step through the program to ensure its working properly.

Share this post


Link to post
Share on other sites
[quote name='James Leighe' timestamp='1312650012' post='4845480']
Now I could be wrong, but I'm pretty sure msvc express comes with the same debugging capabilities as the normal version.

In which case, just set the configuration to debug build and click the green arrow or w/e and it will run normally until it hits a break point.
Just add the break-point somewhere sensible.

Then you can step through the program to ensure its working properly.
[/quote]


It does.


All nano has to do is place a breakpoint after he's handeled the right keycode, aka. "Space". And then place a breakpoint on all the significant logical statements.

As someone said in one of your previous posts. "You should learn debuging because that's going to fix moste of your problems". It's really easy and it fixes your problems quickly.

Share this post


Link to post
Share on other sites

This topic is 2319 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this