Save
This commit is contained in:
@@ -73,6 +73,7 @@ void ax_game::Update(){
|
||||
ax_TickCounter = SDL_GetTicks();
|
||||
|
||||
// Update Ball
|
||||
ax_ball_one.Update();
|
||||
}
|
||||
|
||||
void ax_game::Output(){
|
||||
|
||||
BIN
Capter1/ball
BIN
Capter1/ball
Binary file not shown.
@@ -1,15 +1,28 @@
|
||||
#include "ball.hpp"
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
class ball
|
||||
{
|
||||
private:
|
||||
int r_dir;
|
||||
int g_dir;
|
||||
int b_dir;
|
||||
public:
|
||||
SDL_Rect rect;
|
||||
float x;
|
||||
|
||||
BIN
Capter1/main
BIN
Capter1/main
Binary file not shown.
Reference in New Issue
Block a user