-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.c
44 lines (38 loc) · 1.12 KB
/
player.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <SDL.h>
#include <stdio.h>
#include <stdbool.h>
#include "./constants.h"
struct player_object {
float x;
int y;
int width;
int height;
float speed;
float max_speed;
float acceleration;
float friction;
bool left;
bool right;
};
void draw_player(SDL_Renderer *renderer, struct player_object player) {
SDL_Rect player_rect = {
(int)player.x - (player.width / 2),
(int)player.y - (player.height / 2),
(int)player.width,
(int)player.height
};
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderFillRect(renderer, &player_rect);
}
void move_player_left(struct player_object* player) {
player->speed -= player->acceleration;
// if (player->x < BORDER_LEFT + (player->width / 2)) {
// player->x = BORDER_LEFT + (player->width / 2);
// }
}
void move_player_right(struct player_object* player) {
player->speed += player->acceleration;
// if (player-> x > BORDER_RIGHT - (player->width / 2)) {
// player->x = BORDER_RIGHT - (player->width / 2);
// }
}