项目作者: mstuttgart

项目描述 :
( Unmaintained ) Oriented Object Game Library in C++
高级语言: C
项目地址: git://github.com/mstuttgart/ludic-game-library.git
创建时间: 2014-07-16T01:48:05Z
项目社区:https://github.com/mstuttgart/ludic-game-library

开源协议:MIT License

下载


Ludic-Game-Library

The Ludic Game Library, or Ludic library is a oriented object multi-platform game library,
developed on Allegro5 API and the C++ language, focused on the development of 2D games.
Its main focus is academia, providing students tools that will facilitate learning the
techniques used in creating electronic games.



Do you liked it? See the portuguese doc about: here

Ps.: Saga Game Library is the previous name of Ludic Game Library.

Features

The current version is usable. However, we intend to improve it even more,
so it is defined as an beta version.

  • Support the animated sprites
  • Support the Tiled level editor to create Levels for you
    games and animations for you Animated Sprites.
  • Support the several image formates provide by Allegro 5 API: BMP, PCX, TGA.
    Every platform also supports JPEG and PNG via external dependencies.
  • Rendering using 3D hardware acceleration.
  • Support of True Type fonts (.ttf)
  • Support of several audio formates: .wav, .flac, .ogg, .it, .mod, .s3m, .xm.
    Include support to play BGM and SFX sounds.
  • Support of mouse and keyboard inputs. Support for joystick soon.
  • Resource Manager proven methods to manage and control memory while allocating
    image resources, and audio sources.
  • Support of collision checking by rectangles and pixel-perfect methods.
  • Simple and easy to use :)

Use exemple

  1. #include "video.hpp"
  2. #include "static_sprite.hpp"
  3. #include "animated_sprite.hpp"
  4. #include "keyboard_manager.hpp"
  5. #include "mouse_manager.hpp"
  6. #include "font.hpp"
  7. #include "time_handler.hpp"
  8. #include "color.hpp"
  9. #include "config_file_stream.hpp"
  10. #include "tmx_tile_map.hpp"
  11. #include "util.hpp"
  12. #include "audio_sample.hpp"
  13. #include "audio_stream.hpp"
  14. #include "time_handler.hpp"
  15. using namespace sgl;
  16. using namespace sgl::image;
  17. using namespace sgl::font;
  18. using namespace sgl::input;
  19. using namespace sgl::core;
  20. using namespace sgl::audio;
  21. using namespace std;
  22. /* Constantes do sprite*/
  23. #define FPS 15
  24. int main()
  25. {
  26. //---------------------------
  27. Video video ( 800, 515 );
  28. video.setTitle ( "Saga Game Library" );
  29. video.setIcon ( "Resource/icone.png" );
  30. video.setBackgroundColor ( Color ( 145,184,60 ) );
  31. //-----------------------------------------------
  32. // Inicializamos os dispositivos de entrada
  33. KeyboardManager* keyboard = KeyboardManager::Instance();
  34. MouseManager* mouse = MouseManager::Instance ( &video );
  35. //-----------------------------------------------
  36. AnimatedSprite spr;
  37. spr.load ( "Resource/mapas/personagem.tmx" );
  38. // Ajustamos posicao do sprite
  39. spr.setPosition ( Vector2D ( 150.0f, 100.0f ) );
  40. // Colocamos o sprite como visible
  41. spr.setVisible ( true );
  42. AnimatedSprite enemy;
  43. enemy.load ( "Resource/mapas/death.tmx" );
  44. enemy.setPosition ( Vector2D ( 550.0f, 300.0f ) );
  45. enemy.setVisible ( true );
  46. AnimatedSprite explosion;
  47. explosion.load ( "Resource/mapas/explosion.tmx" );
  48. explosion.setVisible ( false );
  49. AudioSample splExp;
  50. splExp.load ( "Resource/mapas/spl.wav" );
  51. splExp.setGain ( 0.4 );
  52. //------------------------------------------
  53. AudioStream musica;
  54. musica.load ( "Resource/audio/Artifact.ogg", 4, 1024 );
  55. //--------------------------------------- ----
  56. Font texto;
  57. texto.load ( "Resource/ALGER.TTF", 40 );
  58. texto.setColorFont ( Color ( 255, 255, 255 ) );
  59. //-------------------------------------------
  60. TimeHandler t;
  61. t.start();
  62. TMXTileMap mapa;
  63. mapa.load ( "Resource/rpg/mapa.tmx" );
  64. t.pause();
  65. cout << t.getTicks() << endl;
  66. mapa.setScreenDimension ( video.getWidth(), video.getHeight() );
  67. //-------------------------------------------
  68. std::vector<Layer*> layerManager;
  69. layerManager.push_back ( mapa.getLayer ( "Piso" ) );
  70. layerManager.push_back ( &spr );
  71. layerManager.push_back ( &enemy );
  72. layerManager.push_back ( &explosion );
  73. layerManager.push_back ( mapa.getLayer ( "Objetos" ) );
  74. layerManager.push_back ( mapa.getLayer ( "Arvores" ) );
  75. layerManager.push_back ( mapa.getLayer ( "Colisao" ) );
  76. TiledLayer* l = mapa.getLayer ( "Colisao" );
  77. int movex = 0;
  78. int movey = 0;
  79. int x = 0, j = 0, colFlag = 0;
  80. int varCtr = 0;
  81. BoundingBox bb;
  82. //-----------------------------------------
  83. double div = 1.0 / FPS;
  84. bool sair = false;
  85. TimeHandler fpsTimer;
  86. //-----------------------------------------
  87. ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
  88. ALLEGRO_TIMER *timer = al_create_timer ( div );
  89. al_register_event_source ( event_queue, al_get_display_event_source ( video ) );
  90. al_register_event_source ( event_queue, al_get_timer_event_source ( timer ) );
  91. bool redraw = false;
  92. //double cTime;
  93. Vector2D desloc ( 0 , 0 );
  94. Vector2D desloc_enemy ( 0,0 );
  95. al_start_timer ( timer );
  96. while ( !sair )
  97. {
  98. ALLEGRO_EVENT ev;
  99. al_wait_for_event ( event_queue, &ev );
  100. if ( ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE )
  101. {
  102. sair = true;
  103. }
  104. else if ( ev.type == ALLEGRO_EVENT_TIMER )
  105. {
  106. // Realiza um tipo de snapshoot no estado das teclas
  107. keyboard->update();
  108. mouse->update();
  109. // Atualizamoa posicao do personagem de acordo com o sprite
  110. movex = 0;
  111. movey = 0;
  112. varCtr +=1;
  113. if ( keyboard->keyPressed ( KeyCode::KEY_RIGHT ) )
  114. {
  115. spr.setCurrentAnimation ( "Direita" );
  116. movex = 5;
  117. }
  118. if ( keyboard->keyPressed ( KeyCode::KEY_LEFT ) )
  119. {
  120. spr.setCurrentAnimation ( "Esquerda" );
  121. movex = -5;
  122. }
  123. if ( keyboard->keyPressed ( KeyCode::KEY_UP ) )
  124. {
  125. spr.setCurrentAnimation ( "Costas" );
  126. movey = -5;
  127. }
  128. if ( keyboard->keyPressed ( KeyCode::KEY_DOWN ) )
  129. {
  130. spr.setCurrentAnimation ( "Frente" );
  131. movey = 5;
  132. }
  133. if ( keyboard->keyRelease ( KeyCode::KEY_ESCAPE ) )
  134. {
  135. sair = true;
  136. }
  137. if ( keyboard->keyTyped ( KeyCode::KEY_SPACE ) )
  138. {
  139. musica.play();
  140. texto.setText ( "play" );
  141. }
  142. else if ( keyboard->keyTyped ( KeyCode::KEY_P ) )
  143. {
  144. musica.pause();
  145. texto.setText ( "pause" );
  146. }
  147. else if ( keyboard->keyTyped ( KeyCode::KEY_S ) )
  148. {
  149. musica.stop();
  150. texto.setText ( "stop" );
  151. }
  152. if ( keyboard->keyTyped ( KeyCode::KEY_V ) )
  153. {
  154. l->setVisible ( !l->isVisible() );
  155. }
  156. if ( varCtr < 30 )
  157. {
  158. enemy.setCurrentAnimation ( "Esquerda" );
  159. x = -5;
  160. }
  161. else
  162. {
  163. enemy.setCurrentAnimation ( "Direita" );
  164. x = +5;
  165. if ( varCtr > 60 )
  166. varCtr = 0;
  167. }
  168. desloc_enemy.setCoordinates ( x,0 );
  169. enemy.move ( desloc_enemy );
  170. enemy.nextFrame();
  171. if ( ( colFlag > 0 ) && ( colFlag < 9 ) )
  172. {
  173. explosion.nextFrame();
  174. colFlag+=1;
  175. }
  176. else if ( colFlag == 9 )
  177. {
  178. explosion.setVisible ( false );
  179. colFlag = 0;
  180. }
  181. if ( spr.collidesWith ( &enemy ) )
  182. {
  183. texto.setText ( "Game Over" );
  184. float xTexto = video.getWidth() * 0.5 - texto.getTextWidth() * 0.5;
  185. float yTexto = video.getHeight() * 0.5 - texto.getLineHeight() * 0.5;
  186. texto.setPosition ( Vector2D ( xTexto, yTexto ) );
  187. Vector2D v = spr.getPosition();
  188. v.setCoordinates ( v.getX() - 32, v.getY() - 48 );
  189. explosion.setPosition ( v );
  190. explosion.setVisible ( true );
  191. splExp.play();
  192. musica.pause();
  193. colFlag = 1;
  194. spr.setPosition ( Vector2D ( -1.0f, -1.0f ) );
  195. spr.setVisible ( false );
  196. }//if
  197. if ( mouse->buttonPressed ( 1 ) )
  198. {
  199. Vector2D v1 = mouse->getPosition();
  200. bb = enemy.getBoundingBox();
  201. BoundingBox teste ( v1,0,0 );
  202. if ( bb.checkCollision ( teste ) )
  203. {
  204. Vector2D v = enemy.getPosition();
  205. v.setCoordinates ( v.getX() - 32, v.getY() - 48 );
  206. explosion.setPosition ( v );
  207. explosion.setVisible ( true );
  208. colFlag = 1;
  209. if ( j == 0 )
  210. splExp.play();
  211. explosion.nextFrame();
  212. enemy.setPosition ( Vector2D ( -100.0f, -100.0f ) );
  213. enemy.setVisible ( false );
  214. }//if
  215. }//if
  216. // Verificamos se podemos nos movimentar no eixo X
  217. if ( l->checkCollision ( spr, movex, 0, 2 ) )
  218. {
  219. movex = 0;
  220. }
  221. if ( l->checkCollision ( spr, 0, movey, 2 ) )
  222. {
  223. movey = 0;
  224. }
  225. if ( movex || movey )
  226. {
  227. desloc.setCoordinates ( movex, movey );
  228. spr.move ( desloc );
  229. spr.nextFrame();
  230. }
  231. redraw = true;
  232. }//if timer
  233. if ( redraw && al_is_event_queue_empty ( event_queue ) )
  234. {
  235. redraw = false;
  236. // Desenhamos cada uma das camadas
  237. al_hold_bitmap_drawing ( true );
  238. for ( unsigned int i = 0; i < layerManager.size(); i++ )
  239. {
  240. layerManager.at ( i )->draw();
  241. }
  242. texto.drawText();
  243. al_hold_bitmap_drawing ( false );
  244. // Atualizamos a tela
  245. video.refresh();
  246. }
  247. }//while
  248. al_destroy_event_queue ( event_queue );
  249. al_destroy_timer ( timer );
  250. return 0;
  251. }

Contributing

If you’d like to contribute, please create a fork and issue pull requests! I am
very open to newcomers, and will need all the help we can get to make the best
Game Library available.

Dependences

Ludic Game Library makes use of other libraries to perform some of their routines:

I found a bug!

Please report any and all bugs using the project issue
tracker. Be as precise as possible so that the bug can be found easier. Thanks!

License

Ludic Game Library is released under the MIT License. This license is very simple and very permissive, go to the LICENSE file on the root of the distribution for its complete text. Just remember that Ludic Game Library uses other external libraries, and they have their own licenses that must be respected.

Credits

Copyright (C) 2013-2015 by Michell Stuttgart Faria, Paulo Vicente Gomes dos Santos and Alfredo José de Paula Barbosa.