From b6e7e454ed6242475163dcd534051897d3c9158c Mon Sep 17 00:00:00 2001 From: lamp Date: Sun, 5 Mar 2023 21:25:03 +0000 Subject: init --- src/metasprite.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/metasprite.c (limited to 'src/metasprite.c') diff --git a/src/metasprite.c b/src/metasprite.c new file mode 100644 index 0000000..262d1c4 --- /dev/null +++ b/src/metasprite.c @@ -0,0 +1,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); +} -- cgit v1.2.3