Showing posts with label final fantasy. Show all posts
Showing posts with label final fantasy. Show all posts

Sunday, October 31, 2010

C++ Project - Final Fantasy Battle System pt.3 - Game Loop

So this past week was spent mostly learning the ClanLib GUI system and starting development on a Scene management system that is a basic implementation of a scene graph.

But more on that later. Today I just wanted to follow up on a loose end from last week. Namely the addition of a proper timed game loop to the project.

At some point I will be looking at animations or character movement and I will need the delta time for each frame in order to have proper frame dependent movement.

So the math for this is very simple. I have setup a constant which is my targeted time for each frame:

 static const unsigned int TIME_PER_FRAME = 16; // time per frame in milliseconds  


Since I would like to target 60 fps, I have set the value to 16 milliseconds per frame.

Now in order to calculate the frame time it will look something like this:

- Get system time before game loop
- while (gameLoop)
- Get time before executing game code.
- Calculate deltaTime = (time_before_loop - time_before_executing_game_code)
- GAME CODE
- Get time after game loop.
- Calculate timeToSleep = (TARGET_FRAME_TIME) - (time_before_executing_game_code - time_after_game_loop
- Sleep(timeToSleep)
- loop


Not too bad. And now the actual implementation in our Game class:

      unsigned int lasttime = CL_System::get_time();  
while (m_currentGameState == Running)
{
unsigned int startFrameTime = CL_System::get_time();
int deltaTime = startFrameTime - lasttime;
lasttime = startFrameTime;
DO GAME STUFF HERE
startFrameTime = CL_System::get_time();
int timeToSleep = TIME_PER_FRAME - (startFrameTime - lasttime);
if (timeToSleep > 0)
{
CL_System::sleep(timeToSleep);
}
}


Now I can pass my delta time per frame to my update functions in my IGameComponent class.

 virtual void Update(unsigned int) = 0;  


On other fronts, my Game class is starting to become a little unwieldy especially with all of the GUI stuff making its way in, so I think my next entry will be a bit of a lesson in refactoring.

Sunday, October 17, 2010

C++ Project - Final Fantasy Battle System pt.1

So in order to keep my programming skills in shape, I like to take a new engine and begin to develop some game systems utilizing it. Most of these are usually stalled due to lack of time or my curiosity about something new that is more interesting.


In order to rectify this, I've decided to start a small project that is not necessarily about writing a complete game for release, but rather something I can use to practice building game systems and further my use of design patterns within these systems.


So, I've chosen to go with a 2D C++ engine called ClanLib and what I will be working to build is essentially this:


That's right, I will be working on developing the battle system from Final Fantasy I. I'm a major fan of RPG games and this was probably my second or third RPG ever, so it holds sentimental value. Also, I've limited the scope slightly so I'm not overwhelmed with large complicated AI or physics systems, as it truly is the gameplay systems that really light my game developer fire. I've also picked something that can done with simple sprites as I am not an artist either.

So, within this project, I will be implementing the following:
  • General game loop
  • Input handling
  • GUI
  • Scene Management
  • RPG system (PC/NPC stats, item handling, spell casting abilities, etc.)
  • Battle system
I will be blogging each step of the way with my goals being:
  • Improve my design capabilities
  • Improve my coding standards to develop code that is highly readable and maintainable.
  • Expand my knowledge of 3rd-party game engines.
  • Expand my knowledge of game systems.
Anyhow, it should be a blast!