Development/Tutorials/Games/KGLEngine2d

From KDE TechBase
Revision as of 22:12, 10 October 2008 by Packadal (talk | contribs)
{{{KGLEngine2d tutorial}}}
Tutorial Series   KGLEngine2d developement
Prerequisites   None
What's Next   Nothing at the moment
Further Reading   KGLEngine2d's code

Abstract

KGLEngine2d is a recent try to develop a 2D games engine using openGL, and powerful enough to deliver complex and beautiful games. As of now, version 1.0 is not even out, but the API is stable enough for anyone to start playing with the engine. Through this tutorial I will explain how to use a great part of the engine, included but not limited to : sprites creation, rotation and deplacement and collision detection.

The example : kglPong

Anyone who have followed the KGLEngine2d developement a bit will have seen some kglPong screenshot, as this is the way new features are shown, using this simple game to showcase them.

Starting Point : the main.cpp

Every application need one, so let's start with it, as it really is simple.

  1. include <KApplication>
  2. include <KAboutData>
  3. include <KCmdLineArgs>
  1. include "pongengine.h"

int main( int argc, char **argv) {

KAboutData aboutData( "kglpong", 0, ki18n("kglpong"), "0.1", ki18n("Classic pong game using KGLEngine2d"), KAboutData::License_GPL,

                             ki18n("Copyright (c) 2008 Developer") );

KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineOptions options; KCmdLineArgs::addCmdLineOptions(options); KApplication app;

pongEngine pong; pong.show();

return app.exec();; } So, what are we doing ? Initializing the KApplication, and creating an instance of our main class, the one that surclasses KGLEngine2d. Then we tell him to show himself, and that's all. I told you there was nothing exciting in here :)

The KGLEngine2d pong engine

TODO: finish this :p