-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.c
More file actions
34 lines (25 loc) · 760 Bytes
/
Copy pathplayer.c
File metadata and controls
34 lines (25 loc) · 760 Bytes
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
#include "game.h"
#include "player.h"
#include "bullet.h"
extern SDL_Renderer* gRenderer;
Player player;
void player_init(void) {
player.w = 50;
player.h = 20;
player.x = (SCREEN_W - player.w) / 2.0f;
player.y = SCREEN_H - player.h - 10;
}
void player_handle_input(const Uint8* keystates, float dt) {
float speed = 200.0f;
if (keystates[SDL_SCANCODE_LEFT] && player.x > 0) {
player.x -= speed * dt;
}
if (keystates[SDL_SCANCODE_RIGHT] && player.x + player.w < SCREEN_W) {
player.x += speed * dt;
}
}
void player_render(void) {
SDL_Rect rect = {(int)player.x, (int)player.y, player.w, player.h};
SDL_SetRenderDrawColor(gRenderer, 0, 255, 0, 255);
SDL_RenderFillRect(gRenderer, &rect);
}