C++ CGL


SUBMITTED BY: Guest

DATE: Nov. 20, 2013, 1:08 p.m.

FORMAT: C++

SIZE: 2.3 kB

HITS: 829

  1. // =============================================================================
  2. #include <cgl/cgl.h>
  3. #include <core/corefile.h>
  4. #include <cgl/core.h>
  5. #include <coresound/coresound.h>
  6. #include <stdlib.h>
  7. #include "c_player.h"
  8. #include "c_enemy.h"
  9. #define MAXENEMIES 250
  10. // ======================== variables ===============================
  11. // objects
  12. c_player player;
  13. c_enemy enemy[MAXENEMIES];
  14. int currentframe;
  15. int gameactive;
  16. // graphics
  17. s_bitmap bmp_background;
  18. s_sprite spr_player;
  19. s_sprite spr_enemy;
  20. s_font gamefont;
  21. // ======================== functions ===============================
  22. void InitEnemies()
  23. {
  24. for (int i=0;i<MAXENEMIES;i++) {
  25. enemy[i].Init(rand()%1024,rand()%768);
  26. }
  27. }
  28. void DrawEnemies()
  29. {
  30. for (int i=0;i<MAXENEMIES;i++) {
  31. enemy[i].Draw();
  32. }
  33. }
  34. void HandleEnemies()
  35. {
  36. for (int i=0;i<MAXENEMIES;i++) {
  37. enemy[i].Handle(&player);
  38. }
  39. }
  40. void LoadGraphics()
  41. {
  42. int numtiles,x,y;
  43. // Load background image, sprites and font
  44. CGL_LoadBitmap("background.tga",&bmp_background);
  45. CGL_LoadSprite("player.tga",&spr_player);
  46. CGL_LoadSprite("ball.tga",&spr_enemy);
  47. CGL_InitFont("font_heat.tga",&gamefont);
  48. }
  49. void DrawBackground()
  50. {
  51. CGL_DrawBitmap(0,0,bmp_background);
  52. }
  53. void DrawHUD()
  54. {
  55. CGL_DrawText(10,30,gamefont,"SCORE: %d",player.score);
  56. }
  57. // ===================== Main - Program entry =================
  58. void coremain()
  59. {
  60. // Init Video & Resources
  61. corefile_mountimage("res",MOUNT_DIR);
  62. CGL_InitVideo(1024,768,CGL_VIDEO_NONE);
  63. CGL_SetTitle("CGL - Minimal zombie game");
  64. LoadGraphics();
  65. InitEnemies();
  66. player.Init();
  67. // update loop
  68. gameactive=1;
  69. do {
  70. CGL_WaitRefresh();
  71. // Draw stuff
  72. DrawBackground();
  73. DrawEnemies();
  74. player.Draw();
  75. DrawHUD();
  76. // Handle stuff
  77. HandleEnemies();
  78. player.HandleInput();

comments powered by Disqus