Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. #include <SDL.h>
  2. #include "Pane.h"
  3. #include "Ball.h"
  4. #include "Brick.h"
  5.  
  6. class Core
  7. {
  8. private:
  9. static bool Running;
  10.  
  11. public:
  12. //score, lives
  13. static SDL_Window* window; //zmienne statyczne
  14. static SDL_Renderer* renderer;
  15. static Pane* pane; // Deklaracja paletki a obiekt bedzie w void initialize (juz po stworzeniu silnika)--------------Pointer--------------------
  16. static Ball* ball;
  17. Brick* brick;
  18.  
  19. static void Initialize() //funkcja rozpoczecia!!!!
  20. {
  21. SDL_Init(SDL_INIT_VIDEO);
  22. window = SDL_CreateWindow("ARKANOID", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 600, SDL_WINDOW_SHOWN); //Okno gry
  23. renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); // tworzy to cos co jest w okienku? taka naklejka xD (jak dodajemy -1 to nie tworzy tabeli ale tlyko jedno okienko)
  24. SDL_RenderClear(renderer); //czyszczenie buffora zeby nie bylo syfu na poczatku odpalania
  25.  
  26. Running = true;
  27.  
  28. Brick* brick[500];
  29. for (int i = 0; i < 20; i++)
  30. {
  31. brick[i] = new Brick();
  32. brick[i]->x = 32 * i;
  33. brick[i]->y = 0;
  34. }
  35.  
  36. pane = new Pane();//zmienna pane = nowemu obiektowi Pane
  37. ball = new Ball(renderer);
  38. //brick = new Brick(renderer);
  39.  
  40. }
  41.  
  42. static bool OnInitialize()
  43. {
  44. return !(SDL_Init(SDL_INIT_EVERYTHING) < 0);
  45. }
  46.  
  47. static void OnEvent(SDL_Event*Event) //Eventy, na razie nie uzywamy ale powinno byc wrazie czego
  48. {
  49. if (Event->type == SDL_QUIT) //standard pisania aplikacji w SDL'u
  50. {
  51. Running = false;
  52. return;
  53. }
  54.  
  55. if (Event->type == SDL_KEYDOWN) // Jeżeli eventem jest nacisniecie klawisza to wg klawisza zrob dana akcje (trzeba to ulepszyc bo sie zacina :D)
  56. {
  57. switch (Event->key.keysym.sym)
  58. {
  59. case SDLK_LEFT: pane->x -= 5; break;
  60. case SDLK_RIGHT: pane->x += 5; break;
  61. }
  62. }
  63. }
  64.  
  65. static void OnUpdate() //zmiana zmiennych, obiektow, mechanika, think, tick (sprawdza czy jest kolizja miedzy obiektami itp / myslenie obiektow)
  66. {
  67. //-------------------------------------------------------------------------------------------------
  68.  
  69. }
  70.  
  71. static void OnRender()//wyswietlanie bajerkow
  72. {
  73. SDL_SetRenderDrawColor(renderer, 69, 90, 100, 255);
  74. SDL_RenderClear(renderer);
  75.  
  76. // rzeczy ktore wyswietlam -------------------------------------------------------------------------
  77.  
  78. pane->Draw(renderer);//<---wywoluje funkcje calego wysweitlania z Pane.h
  79. ball->Draw(renderer);
  80. //brick->Draw(renderer);
  81. for(int i = 0; i < 20; i++)
  82. {
  83. brick[i]->Draw(renderer);
  84. }
  85.  
  86. SDL_RenderPresent(renderer);
  87. }
  88.  
  89. static void OnCleanup()//funkcja do zwolnienia pamieci po zamknieciu petli - gry (dodaje sie bo na starych kompach nie czyscilo pamieci ale teraz jest to tylko jesli chcesz)
  90. {
  91. SDL_Quit();
  92. }
  93.  
  94. static int OnExecute()
  95. {
  96. if (!OnInitialize())//jezeli aplikacja sie zle wczytala wywal error!!
  97. {
  98. return -1;
  99. }
  100.  
  101. SDL_Event Event;// to tak kolejka z linijki nizej
  102.  
  103. while (Running)
  104. {
  105. while (SDL_PollEvent(&Event))//jezeli kolejka eventow dziala to odpalamy event kolejki
  106. {
  107. OnEvent(&Event);
  108. }
  109.  
  110. OnUpdate();//kolejnosc jest wazna bo to wczytrawanie "silnika"
  111. OnRender();// wczytywanie obiektow z tej funkcji OnRender
  112. }
  113. OnCleanup();
  114.  
  115. return 0;
  116. }
  117.  
  118. };
  119.  
  120. //Definitions (OGAR) - definicja zmiennych statycznych (w razie czego)
  121. bool Core::Running;
  122. Pane* Core::pane;
  123. Ball* Core::ball;
  124. //Brick* Core::brick;
  125. SDL_Window* Core::window;
  126. SDL_Renderer* Core::renderer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement