Skip to content

Commit

Permalink
Use SpaceBeforeParens: ControlStatements
Browse files Browse the repository at this point in the history
ryukinix committed Dec 20, 2024
1 parent 0195bdc commit 8269ca3
Showing 18 changed files with 394 additions and 394 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -368,7 +368,7 @@ SpaceBeforeAssignmentOperators: true
# SBPO_Never (in configuration: Never) Never put a space before opening parentheses.
# SBPO_ControlStatements (in configuration: ControlStatements) Put a space before opening parentheses only after control statement keywords (for/if/while...).
# SBPO_Always (in configuration: Always) Always put a space before opening parentheses, except when it’s prohibited by the syntax rules (in function-like macro definitions) or when determined by other style rules (after unary operators, opening parentheses, etc.)
SpaceBeforeParens: Always
SpaceBeforeParens: ControlStatements

# SpaceInEmptyParentheses (bool)
# If true, spaces may be inserted into ().
82 changes: 41 additions & 41 deletions examples/basics/square-moving.cpp
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ struct KeyboardState {
bool velocity_up;
bool velocity_down;

bool valid_move () {
bool valid_move() {
return (up || down || left || right) && !((up && down) || (left && right));
}
};
@@ -48,59 +48,59 @@ struct Player {
SDL_Rect rect = { 0, 0, size, size };
float velocity = 300;

void set_direction (struct KeyboardState* k) {
void set_direction(struct KeyboardState* k) {
direction.x = k->right ? 1 : k->left ? -1 : 0;
direction.y = k->up ? 1 : k->down ? -1 : 0;
}

float cos_direction () {
Vector2 unit_vector (1, 0);
return direction.cos (unit_vector);
float cos_direction() {
Vector2 unit_vector(1, 0);
return direction.cos(unit_vector);
}

float sin_direction () {
float cos = cos_direction ();
float sin = sqrt (1 - cos * cos);
float sin_direction() {
float cos = cos_direction();
float sin = sqrt(1 - cos * cos);
return -direction.y * sin;
}

void move (float dt) {
position.x += cos_direction () * velocity * dt;
position.y += sin_direction () * velocity * dt;
void move(float dt) {
position.x += cos_direction() * velocity * dt;
position.y += sin_direction() * velocity * dt;
}
};

struct Player player = {};
struct KeyboardState keyboard = {};
InputHandler input_handler = InputHandler (input_config);
InputHandler input_handler = InputHandler(input_config);

void Game::event () {
void Game::event() {
static SDL_Event e;
input_handler.process (e);
keyboard.up = input_handler.read ("up");
keyboard.down = input_handler.read ("down");
keyboard.left = input_handler.read ("left");
keyboard.right = input_handler.read ("right");
keyboard.velocity_up = input_handler.read ("velocity_up");
keyboard.velocity_down = input_handler.read ("velocity_down");
this->running = !(input_handler.read (SDL_QUIT) || input_handler.read ("quit"));
input_handler.process(e);
keyboard.up = input_handler.read("up");
keyboard.down = input_handler.read("down");
keyboard.left = input_handler.read("left");
keyboard.right = input_handler.read("right");
keyboard.velocity_up = input_handler.read("velocity_up");
keyboard.velocity_down = input_handler.read("velocity_down");
this->running = !(input_handler.read(SDL_QUIT) || input_handler.read("quit"));
}

void Game::update (float dt) {
void Game::update(float dt) {
if (keyboard.velocity_up) {
player.velocity += 50;
input_handler.write ("velocity_up", false);
input_handler.write("velocity_up", false);
}
if (keyboard.velocity_down) {
player.velocity -= 50;
if (player.velocity <= 50)
player.velocity = 50;
input_handler.write ("velocity_down", false);
input_handler.write("velocity_down", false);
}

if (keyboard.valid_move ()) {
player.set_direction (&keyboard);
player.move (dt);
if (keyboard.valid_move()) {
player.set_direction(&keyboard);
player.move(dt);
}

if (player.position.x < 0) {
@@ -114,33 +114,33 @@ void Game::update (float dt) {
player.position.y = SCREEN_HEIGHT - player.size;
}

player.rect.x = round (player.position.x);
player.rect.y = round (player.position.y);
player.rect.x = round(player.position.x);
player.rect.y = round(player.position.y);
}

void Game::draw () {
void Game::draw() {
// background
SDL_SetRenderDrawColor (this->renderer, 255, 255, 255, 255);
SDL_RenderClear (this->renderer);
SDL_SetRenderDrawColor(this->renderer, 255, 255, 255, 255);
SDL_RenderClear(this->renderer);

// player
SDL_SetRenderDrawColor (this->renderer, 0, 255, 255, 255);
SDL_RenderFillRect (this->renderer, &player.rect);
SDL_SetRenderDrawColor(this->renderer, 0, 255, 255, 255);
SDL_RenderFillRect(this->renderer, &player.rect);

// render everything
SDL_RenderPresent (this->renderer);
SDL_RenderPresent(this->renderer);
}

void start () {
void start() {
cout << ":: Game initialization!" << endl;
player.position.x = SCREEN_WIDTH / 2;
player.position.y = SCREEN_HEIGHT / 2;
}

int main (void) {
start ();
Game game ("Square Moving", SCREEN_WIDTH, SCREEN_HEIGHT);
game.set_max_frame_rate (60);
int main(void) {
start();
Game game("Square Moving", SCREEN_WIDTH, SCREEN_HEIGHT);
game.set_max_frame_rate(60);

return game.run ();
return game.run();
}
Loading

0 comments on commit 8269ca3

Please sign in to comment.