Sign in to follow this  
nsto119

I'm trying to implement slow-mo...

Recommended Posts

nsto119    103
So, I've got an vertically scrolling shooter in SDL (original, I know), and I'm looking to add a slo-mo bullet time type of effect. So, when the player enters bullet time, the screen goes black and white (not greyscale), a motion-blur is added, and (obviously) time slows down. The first two were easy to implement, but I'm having trouble with the slow motion. In the Engine class, I have a timer object, and any object that requires time-based movement or animation is passed a pointer to the timer when they get constructed - this way our objects can be in-sync and don't get messed up when the game is paused. I've added this code to the Timer class's GetTicks() function to attempt to implement slow-mo:
else if( m_bSloMo )
{
	int t = ( SDL_GetTicks() - m_iStartTicks - m_iSloMoTicks ) / 4;


	return m_iSloMoTicks + t;
}

where m_iSloMoTicks is initialized to this->GetTicks() when slomo is activated. The logic all works out in my head but it just doesn't do anything when I activate it in game... anybody see any flas in my code?

Share this post


Link to post
Share on other sites
Zahlman    1682
What does it return normally?

I would set it up like this:


// As a member variable
int m_previousSDLTicks; // the value returned by the last SDL_GetTicks() call
int m_myTicks; // time since the beginning of the game. This timer will run
// at 4 times the SDL tick rate.

// In the getTicks()

// First, see how much time has elapsed
int elapsedRealTimeTicks = SDL_GetTicks() - m_previousSDLTicks;
m_previousSDLTicks += elapsedRealTimeTicks; // set up for next call.

if (m_sloMo) {
// don't use those prefixes for type; they don't tell you anything your
// declarations/IDE can't. Hungarian notation is supposed to be about "type"
// of the sort that isn't checked by the language, which often isn't really
// a useful concept at all.
// Anyway. If we're in slow motion, we add 1*elapsed time to our timer
m_myTicks += elapsedRealTimeTicks;
} else {
// normally, we add 4*elapsed time.
m_myTicks += 4*elapsedRealTimeTicks;
}


Later, this can be generalized by replacing the sloMo member with a 'clock multiplier' member (int; 1 for what is currently considered slo-mo, 4 for normal speed, say 12 for hyper speed in some other part of the game...)

Share this post


Link to post
Share on other sites
nsto119    103
Thanks, I got it working. Turns out I had my SlomoToggle() function messed up.

Anyway, I use Hungarian notation because

1) I'm terrible with naming conventions
2) It narrows the search down when using Intellisense to type m_b rather than just m_

It's kind of hard to think of good prefixes for classes I wrote myself, though.

Share this post


Link to post
Share on other sites
AAAP    137
why not just slow all the physics to 50% or something? if its _bullet time_, shouldn't the player's craft operate as normal anyway? I think you could have more control and less hastle if you did it this way. just a thought, cheers!

[Edited by - AAAP on November 27, 2005 8:38:22 PM]

Share this post


Link to post
Share on other sites
T1Oracle    100
I love Hungarian notation, it makes perfect sense to me. Using the "m_" prefix in a class for data members makes it easy to identify what is a data member and what is an outside variable. Although the only notation I really use is:

"m_" prefix: for data members
"p" prefix: for pointers (of course I use references for most cases)
Capitolized first letter (no underscores) of every word in the name (ie "PrintCopy"): for function names, I do the same with variable names except the very first letter is lower case
All caps with underscores: for macros and constants (mostly enums)
"_t" postfix: for typenames

By employing that I can quickly scan through blocks of code and know exactly what I am looking at without having to look up definitions or rely on the the IDE.

Share this post


Link to post
Share on other sites
nsto119    103
^you're right. After I got the whole time-based thing worked out, I realized that it made all the movements look really choppy... I switched to a physics-based system and it looks a ton better. It makes it easy to do a fast slow-down type thing a la FEAR.

Thanks for the help :)

Share this post


Link to post
Share on other sites
oscinis    209
Quote:
Original post by nsto119
[...] a fast slow-down type thing [...]



Aside, will you be releasing a demo any time soon? I love vertical scrolling shooters.

Share this post


Link to post
Share on other sites
nsto119    103
MAYBE a demo soon... I have a friend who's an absolutely INCREDIBLE artist, but he's stationed at an Army base in Hawaii right now and he hasn't emailed me. With him on board, the game could be done really soon, if not, I'll have to draw all the sprites myself, and I suck.

As far as the programming goes, that's all completed, though. It's got some cool features, like locational damage (and therefore a repair system), the whole bullet time thing (which happens to look really cool), and even a neat looking menu!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
cool i can't wait to see it, i love vert shooters.

I'm guessing it was influenced by ESPgaluda?

Share this post


Link to post
Share on other sites
AAAP    137
dahhh ^--- was me, always forget to login. just PM me if you get a demo out soon, I got a domain recently so I could even host it for you if you want

[Edited by - AAAP on November 27, 2005 8:42:05 PM]

Share this post


Link to post
Share on other sites
Iftah    413
i think the problem you experienced with the chopiness results from the integer rounding down the result.

say time diff is 7 it rounds down to 7/4 = 1
and if the time diff is 3 it rounds down to 0

you can change it to float, or if you want to keep everything int, you can keep the reminder of the result in another var, and add it to the calculation in the next time its called. (so 7/4 will return 1, but next time it will be (7+3)/4=2, next time it will be (7+1)/4)

if you call your method more than once per frame you can have very small time diff. even at only once per frame the error is too big to my likings.


Iftah.

Share this post


Link to post
Share on other sites

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