Renderproblem behoben, Input verarbeitung, Positionsupdate

This commit is contained in:
2025-10-22 19:57:08 +02:00
parent 0335a726c9
commit dd3d405ce6
8 changed files with 98 additions and 26 deletions

View File

@@ -1,13 +1,6 @@
#include "ball.hpp"
#include <algorithm>
#include <ranges>
#include <iostream>
#include "ax_funktions.hpp"
inline int clamp_int(int v, int lo, int hi) {
if (v < lo) return lo;
if (v > hi) return hi;
return v;
}
ball::ball()
@@ -18,8 +11,8 @@ ball::ball()
g_dir = -1;
b_dir = 1;
x = 50;
y = 50;
velx = 200;
vely = 200;
rect = {20,20,20,20};
color = {255,0,0,255};
@@ -30,28 +23,30 @@ ball::~ball()
}
int ball::GetXPos(){
return x;
return rect.x;
}
int ball::GetYPos(){
return y;
return rect.y;
}
void ball::Draw(SDL_Renderer* renderer){
rect.x;
rect.y;
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
SDL_RenderFillRect(renderer, &rect);
}
void ball::Update(){
void ball::Update(float f_DeltaTime){
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);
color.g = ax::clamp_int(color.g, 1, 254);
color.b = ax::clamp_int(color.b, 1, 254);
color.r = ax::clamp_int(color.r, 1, 254);
// Transition logic
if (r_dir != 0 && (color.r == 254 || color.r == 1)) {
@@ -71,7 +66,12 @@ void ball::Update(){
}
//=================Movement======================
x+=10.0;
y+=10.0;
//Update Position
rect.x +=velx * f_DeltaTime;
rect.y +=vely * f_DeltaTime;
//Kollisioinstest Fenster 1024x768
if(rect.x > (1024 -20) || rect.x < 0) velx *= -0.5;
if(rect.y > (768 - 20) || rect.y < 0) vely *= -0.5;
//std::cout << velx <<"|"<< vely <<std::endl;
}