aboutsummaryrefslogtreecommitdiff
path: root/src/metasprite.c
blob: 262d1c43e2f08362cff309f473a3b84722bb4d47 (plain)
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
#include "metasprite.h"

inline void metasprite_init(Metasprite *metasprite) {
  metasprite_update_tiles(metasprite);
  metasprite_move_to(metasprite, metasprite->x, metasprite->y);
}

inline void metasprite_move_offset(Metasprite *metasprite,
                                   ScreenCoordinate offset_x,
                                   ScreenCoordinate offset_y) {
  metasprite_move_to(metasprite, metasprite->x + offset_x,
                     metasprite->y + offset_y);
}

// TODO: consider height and width
inline void metasprite_move_to(Metasprite *metasprite, ScreenCoordinate new_x,
                               ScreenCoordinate new_y) {
  metasprite->x = new_x;
  metasprite->y = new_y;
  move_sprite(metasprite->sprite_ids[0], new_x, new_y);
  move_sprite(metasprite->sprite_ids[1], new_x, new_y + TILE_SIZE);
  move_sprite(metasprite->sprite_ids[2], new_x + TILE_SIZE, new_y);
  move_sprite(metasprite->sprite_ids[3], new_x + TILE_SIZE, new_y + TILE_SIZE);
}

inline void metasprite_apply_gravity(Metasprite *metasprite) {
  metasprite->velocity_y += GRAVITY_ACCELERATION;
}

inline void metasprite_update_position_using_velocity(Metasprite *metasprite) {
  metasprite->x += metasprite->velocity_x;
  metasprite->y += metasprite->velocity_y;
  metasprite_move_to(metasprite, metasprite->x, metasprite->y);
}

inline void metasprite_jump(Metasprite *metasprite) {
  metasprite->velocity_y = JUMP_VELOCITY;
}

inline void metasprite_update_tiles(Metasprite *metasprite) {
  set_sprite_tile(metasprite->sprite_ids[0], metasprite->tile_ids[0]);
  set_sprite_tile(metasprite->sprite_ids[1], metasprite->tile_ids[1]);
  set_sprite_tile(metasprite->sprite_ids[2], metasprite->tile_ids[2]);
  set_sprite_tile(metasprite->sprite_ids[3], metasprite->tile_ids[3]);
}

inline void metasprite_hide(Metasprite *metasprite) {
  move_sprite(metasprite->sprite_ids[0], 0, 0);
  move_sprite(metasprite->sprite_ids[1], 0, 0);
  move_sprite(metasprite->sprite_ids[2], 0, 0);
  move_sprite(metasprite->sprite_ids[3], 0, 0);
}