Sge2d
Encyclopedia
Sge2d is a open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

 platform independent MIT license
MIT License
The MIT License is a free software license originating at the Massachusetts Institute of Technology . It is a permissive license, meaning that it permits reuse within proprietary software provided all copies of the licensed software include a copy of the MIT License terms...

d framework for programming 2d games in C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

/C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

. It aims for low dependencies and easy portability. Its main focus is providing an easy API and providing features useful for commercial game development.

Since release 20110122 it is possible to use the library from C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...


Example

The following example opens a window in the dimension 320×240, reads a bitmap font from an encrypted file and prints hello world limited to 30 frames per second.

  1. include


// struct to hold font data
typedef struct {
SGEFONT *font;
} MainStateData;

// redraw function of current state
void on_redraw(SGEGAMESTATE *state) {
// get state data
SGEEVENTSTATE es = state->manager->event_state;
MainStateData *data = (MainStateData*)state->data;

// quit if return (or start on gp2x) is pressed
if (es.start.released) {
sgeGameStateManagerQuit(state->manager);
return;
}

// clear screen and print hello world at 50/50
sgeClearScreen;
sgeFontPrintBitmap(data->font, screen, 50, 50, "Hello world");

// finally display the screen
sgeFlip;
}

// game entry point
int run(int argc, char *argv[]) {
SGEGAMESTATEMANAGER *manager;
SGEGAMESTATE *mainstate;
MainStateData data;
SGEFILE *f;

// initialize engine and set up resolution and depth
sgeInit(NOAUDIO,NOJOYSTICK);
sgeOpenScreen("Wikipedia example",320,240,32,NOFULLSCREEN);
sgeHideMouse;

// load the font from our encrypted data file with secret password asdf
f=sgeOpenFile("data.d","asdf");
data.font=sgeFontNewFile(f, SGEFONT_BITMAP, "font.png");
sgeCloseFile(f);

// add a new game state with redraw function and data struct
mainstate = sgeGameStateNew;
mainstate->onRedraw = on_redraw;
mainstate->data = &data;

// initialize state manager with default state
manager = sgeGameStateManagerNew;
sgeGameStateManagerChange(manager, mainstate);

// start the game running with 30 frames per seconds
sgeGameStateManagerRun(manager, 30);

// close the screen and quit
sgeCloseScreen;
return 0;
}

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK