diff --git a/Capter1/ax_game b/Capter1/ax_game new file mode 100755 index 0000000..2d8d9d9 Binary files /dev/null and b/Capter1/ax_game differ diff --git a/Capter1/ax_game.cpp b/Capter1/ax_game.cpp index 6400952..b05a81e 100644 --- a/Capter1/ax_game.cpp +++ b/Capter1/ax_game.cpp @@ -1,5 +1,4 @@ #include "ax_game.hpp" -#include "ball.hpp" ax_game::ax_game() { @@ -17,25 +16,70 @@ ax_game::~ax_game() } bool ax_game::Init(){ + int sdlResult = SDL_Init(SDL_INIT_VIDEO); + if(sdlResult != 0){ + SDL_Log("Fehler bei SDL_INIT: %s", SDL_GetError()); + return false; + } + + ax_Window = SDL_CreateWindow("Ersted Fenster", 100,100,1024,768,0); + + ax_Renderer = SDL_CreateRenderer(ax_Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + + if(!ax_Renderer){ + SDL_Log("Fehler bei SDL_CreateRenderer: %s", SDL_GetError()); + return false; + } + + + + return true; } void ax_game::RunLoop(){ - + while(ax_IsRunning){ + Input(); + Update(); + Output(); + } } void ax_game::Shutdown(){ - + SDL_DestroyRenderer(ax_Renderer); + SDL_DestroyWindow(ax_Window); + SDL_Quit(); } void ax_game::Input(){ - + SDL_Event event; + while(SDL_PollEvent(&event)){ + switch (event.type) + { + case SDL_QUIT: + ax_IsRunning = false; + break; + } + } } void ax_game::Update(){ - + while(!SDL_TICKS_PASSED(SDL_GetTicks(), ax_TickCounter + 16)); + float DeltaTime = (SDL_GetTicks() - ax_TickCounter) / 1000.0f; + if (DeltaTime > 0.05f) + { + DeltaTime = 0.05f; + } + ax_TickCounter = SDL_GetTicks(); + + // Update Ball } void ax_game::Output(){ - + SDL_SetRenderDrawColor(ax_Renderer,0,0,255,255); + SDL_RenderClear(ax_Renderer); + + ax_ball_one.Draw(ax_Renderer); + + SDL_RenderPresent(ax_Renderer); } \ No newline at end of file diff --git a/Capter1/ball b/Capter1/ball new file mode 100755 index 0000000..412eeb1 Binary files /dev/null and b/Capter1/ball differ diff --git a/Capter1/ball.cpp b/Capter1/ball.cpp index f432d22..dd5ff75 100644 --- a/Capter1/ball.cpp +++ b/Capter1/ball.cpp @@ -1,11 +1,30 @@ #include "ball.hpp" +#include ball::ball() { - x = 0; - y = 0; + std::cout << "Ball erzeugt!"<< std::endl; + + x = 50; + y = 50; + + rect = {20,20,20,20}; + color = {0,255,0,255}; } ball::~ball() { } + +int ball::GetXPos(){ + return x; +} + +int ball::GetYPos(){ + return y; +} + +void ball::Draw(SDL_Renderer* renderer){ + SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a); + SDL_RenderFillRect(renderer, &rect); +} diff --git a/Capter1/ball.hpp b/Capter1/ball.hpp index e70a5f8..29787ba 100644 --- a/Capter1/ball.hpp +++ b/Capter1/ball.hpp @@ -1,9 +1,20 @@ +#include "SDL2/SDL.h" + class ball { -private: +public: + SDL_Rect rect; float x; float y; + float velx; + float vely; + SDL_Color color; + public: ball(); ~ball(); + int GetXPos(); + int GetYPos(); + void Update(); + void Draw(SDL_Renderer* renderer); }; diff --git a/Capter1/main b/Capter1/main index 276af1e..bbc9180 100755 Binary files a/Capter1/main and b/Capter1/main differ diff --git a/Capter1/main.cpp b/Capter1/main.cpp index 19c6024..d64788e 100644 --- a/Capter1/main.cpp +++ b/Capter1/main.cpp @@ -1,5 +1,6 @@ //#include "Game.h" #include "ax_game.hpp" +#include int main(int argc, char** argv) { @@ -11,8 +12,16 @@ int main(int argc, char** argv) } game.Shutdown(); */ + int i = 0; - + ax_game AXGAME; + bool success = AXGAME.Init(); + if(success){ + AXGAME.RunLoop(); + std::cout<< i++ << std::endl; + } + + AXGAME.Shutdown(); return 0; } \ No newline at end of file