blob: e5a08539af64e2b9f0b1ec849548f127e5360199 (
plain) (
blame)
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
|
#include "components.h"
#include "input.h"
#include "player.h"
#include "standard.h"
#include "world.h"
void init_player(Player* player, World* world) {
CSprite* sprite;
CPosition* pos;
Entity e;
e = new_entity(world);
player->entity = e;
add_components(world, e, ctype_sprite | ctype_position);
sprite = &world->sprites[e];
pos = &world->positions[e];
pos->x = 32;
pos->y = 70;
sprite->id = asset_id_char;
sprite->rect = make_rect(0, 16, 16, 16);
}
void update_player(Player* player, World* world) {
int dx, dy;
Entity e;
CPosition* pos;
e = player->entity;
pos = &world->positions[e];
dx = dy = 0;
if (button_pressed(btn_dpad_left)) {
dx -= 1 << fbits;
}
if (button_pressed(btn_dpad_right)) {
dx += 1 << fbits;
}
if (button_pressed(btn_dpad_up)) {
dy -= 1 << fbits;
}
if (button_pressed(btn_dpad_down)) {
dy += 1 << fbits;
}
if (dx != 0 || dy != 0) {
vec_nrmise(&dx, &dy);
pos->x += dx;
pos->y += dy;
}
}
|