diff --git a/Capter1/ax_game.cpp b/Capter1/ax_game.cpp index b05a81e..4e79bb6 100644 --- a/Capter1/ax_game.cpp +++ b/Capter1/ax_game.cpp @@ -73,6 +73,7 @@ void ax_game::Update(){ ax_TickCounter = SDL_GetTicks(); // Update Ball + ax_ball_one.Update(); } void ax_game::Output(){ diff --git a/Capter1/ball b/Capter1/ball index 412eeb1..f8c98ce 100755 Binary files a/Capter1/ball and b/Capter1/ball differ diff --git a/Capter1/ball.cpp b/Capter1/ball.cpp index dd5ff75..c6ff98f 100644 --- a/Capter1/ball.cpp +++ b/Capter1/ball.cpp @@ -1,15 +1,28 @@ #include "ball.hpp" +#include +#include #include +inline int clamp_int(int v, int lo, int hi) { + if (v < lo) return lo; + if (v > hi) return hi; + return v; +} + + ball::ball() { std::cout << "Ball erzeugt!"<< std::endl; + r_dir = 0; + g_dir = -1; + b_dir = 1; + x = 50; y = 50; rect = {20,20,20,20}; - color = {0,255,0,255}; + color = {255,0,0,255}; } ball::~ball() @@ -28,3 +41,37 @@ void ball::Draw(SDL_Renderer* renderer){ SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a); SDL_RenderFillRect(renderer, &rect); } + +void ball::Update(){ + color.r += r_dir; + color.g += g_dir; + color.b += b_dir; + + //=================ColorCycle====================== + // Clamp values between 1 and 254 + color.g = clamp_int(color.g, 1, 254); + color.b = clamp_int(color.b, 1, 254); + color.r = clamp_int(color.r, 1, 254); + + // Transition logic + if (r_dir != 0 && (color.r == 254 || color.r == 1)) { + r_dir = 0; + g_dir = (color.r == 254) ? 1 : -1; + b_dir = 0; + } + else if (g_dir != 0 && (color.g == 254 || color.g == 1)) { + g_dir = 0; + b_dir = (color.g == 254) ? 1 : -1; + r_dir = (color.g == 254) ? -1 : 1; + } + else if (b_dir != 0 && (color.b == 254 || color.b == 1)) { + b_dir = 0; + r_dir = 0; + g_dir = (color.b == 254) ? -1 : 1; + } + + //=================Movement====================== + x+=10.0; + y+=10.0; + +} diff --git a/Capter1/ball.hpp b/Capter1/ball.hpp index 29787ba..34cbda2 100644 --- a/Capter1/ball.hpp +++ b/Capter1/ball.hpp @@ -2,6 +2,10 @@ class ball { +private: + int r_dir; + int g_dir; + int b_dir; public: SDL_Rect rect; float x; diff --git a/Capter1/main b/Capter1/main index bbc9180..2390930 100755 Binary files a/Capter1/main and b/Capter1/main differ