Save
This commit is contained in:
@@ -73,6 +73,7 @@ void ax_game::Update(){
|
|||||||
ax_TickCounter = SDL_GetTicks();
|
ax_TickCounter = SDL_GetTicks();
|
||||||
|
|
||||||
// Update Ball
|
// Update Ball
|
||||||
|
ax_ball_one.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ax_game::Output(){
|
void ax_game::Output(){
|
||||||
|
|||||||
BIN
Capter1/ball
BIN
Capter1/ball
Binary file not shown.
@@ -1,15 +1,28 @@
|
|||||||
#include "ball.hpp"
|
#include "ball.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <ranges>
|
||||||
#include <iostream>
|
#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()
|
ball::ball()
|
||||||
{
|
{
|
||||||
std::cout << "Ball erzeugt!"<< std::endl;
|
std::cout << "Ball erzeugt!"<< std::endl;
|
||||||
|
|
||||||
|
r_dir = 0;
|
||||||
|
g_dir = -1;
|
||||||
|
b_dir = 1;
|
||||||
|
|
||||||
x = 50;
|
x = 50;
|
||||||
y = 50;
|
y = 50;
|
||||||
|
|
||||||
rect = {20,20,20,20};
|
rect = {20,20,20,20};
|
||||||
color = {0,255,0,255};
|
color = {255,0,0,255};
|
||||||
}
|
}
|
||||||
|
|
||||||
ball::~ball()
|
ball::~ball()
|
||||||
@@ -28,3 +41,37 @@ void ball::Draw(SDL_Renderer* renderer){
|
|||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
|
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
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
|
class ball
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
int r_dir;
|
||||||
|
int g_dir;
|
||||||
|
int b_dir;
|
||||||
public:
|
public:
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
float x;
|
float x;
|
||||||
|
|||||||
BIN
Capter1/main
BIN
Capter1/main
Binary file not shown.
Reference in New Issue
Block a user