-
Notifications
You must be signed in to change notification settings - Fork 9
/
objects.c
65 lines (58 loc) · 1.47 KB
/
objects.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "objects.h"
#include "physic.h"
#include "constans.h"
void resolve_player_key_down(int key, struct Player* player) {
if (key == player->left_key) {
player->left = true;
}
if (key == player->right_key) {
player->right = true;
}
if (key == player->up_key) {
player->up = true;
}
if (key == player->down_key) {
player->down = true;
}
if (key == player->attack_key) {
player->shoot = player->face;
}
}
void resolve_player_key_up(int key, struct Player* player) {
if (key == player->left_key) {
player->left = false;
}
if (key == player->right_key) {
player->right = false;
}
if (key == player->up_key) {
player->up = false;
}
if (key == player->down_key) {
player->down = false;
}
if (key == player->attack_key) {
player->shoot = false;
}
}
void resolve_keyboard(SDL_Event e, struct Player* player) {
if (e.type == SDL_KEYDOWN) {
resolve_player_key_down(e.key.keysym.sym, player);
}
if (e.type == SDL_KEYUP) {
resolve_player_key_up(e.key.keysym.sym, player);
}
}
void set_player_pos(struct Player* player, float x, float y) {
player->position.x = x;
player->position.y = y;
}
struct Bullet init_bullet(int x, int y, int face) {
struct Bullet b;
b.position.x = x;
b.position.y = y;
b.position.w = BULLET_WIDTH;
b.position.h = BULLET_HEIGHT;
b.face = face;
return b;
}