diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-11-05 11:22:55 +0000 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-11-05 11:31:28 +0000 |
commit | 2fbdf974338bde8576efdae40a819a76b2391033 (patch) | |
tree | 64d41a37470143f142344f9a439d96de3e7918c2 /src/et_pickups.c | |
download | kitsunes-curse-2fbdf974338bde8576efdae40a819a76b2391033.tar.gz kitsunes-curse-2fbdf974338bde8576efdae40a819a76b2391033.zip |
Initial import of the open source release
Diffstat (limited to 'src/et_pickups.c')
-rw-r--r-- | src/et_pickups.c | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/src/et_pickups.c b/src/et_pickups.c new file mode 100644 index 0000000..58e3b25 --- /dev/null +++ b/src/et_pickups.c @@ -0,0 +1,191 @@ +/* + Kitsune's Curse + Copyright (C) 2020-2023 Juan J. Martinez <jjm@usebox.net> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + */ +#include "splib.h" +#include "plw.h" +#include "sound.h" +#include "main.h" +#include "int.h" + +#include "maps.h" + +// generated +#include "items.h" +#include "tiles.h" + +#include "entities.h" +#include "et_player.h" +#include "et_pickups.h" + +void draw_pickup() +{ + if (!is_invalid_tile2(get_tile_xy(*it_x >> 3, *it_y >> 3))) + return; + + put_sprite4(items[sp_it->type - ET_GEM], *it_x, *it_y, 2, 0); +} + +void draw_gtail() +{ + put_sprite4(items[0], *it_x, *it_y, 2, 0); + erase_sprite(*it_ox, *it_oy, 2); +} + +static const int8_t gtail_y[9] = { + 0, 0, -1, -1, -2, -3, -2, -1, -1 +}; + +static const int8_t gtails[16] = { + -1, 0, + -1, -1, + 0, -1, + 1, -1, + 1, 0, + 1, 1, + 0, 1, + -1, 1, + }; + +void _gtail_effect() +{ + uint8_t i; + int8_t x, y; + + for (i = 0; i < 5; ++i) + { + for (it_k = 0; it_k < 16; it_k += 2) + { + x = (gtails[it_k] << i); + y = (gtails[it_k + 1] << i); + + put_sprite4(items[0], *it_x + x, *it_y + y, 2, 0); + + if (i) + { + x >>= 1; + y >>= 1; + erase_sprite(*it_x + x, *it_y + y, 2); + } + } + + if (i == 2) + set_hw_ink(0, 0x4b); + + update_screen(); + wait(); + } + + wait_for(8); + set_hw_ink(0, 0x54); + draw_map(); +} + +void update_gtail() +{ + if ((*it_delay)++ == 2) + { + *it_delay = 0; + if (++(*it_frame) == 9) + { + *it_param ^= 128; + if (*it_param) + *it_frame = 2; + else + *it_frame = 0; + } + + if (*it_param) + *it_y -= gtail_y[*it_frame]; + else + *it_y += gtail_y[*it_frame]; + } + + if (!check_for_player(16)) + return; + + PLW_PlaySoundEffectP(EFX_MAGIC); + PLW_Init(songs, SONG_SPLIT); + + fill_screen(bgtiles[9]); + + // extra live + ++lives; + life = MAX_LIFE; + + gems = 30; + gtail = 1; + draw_hud_bg(); + draw_hud(); + wait(); + + *it_oy = *it_y; + + for (it_k = 0; it_k < 60; ++it_k) + { + if (it_k & 1) + { + --gems; + draw_hud(); + } + + *it_ox = *it_x; + *it_x ^= 2; + put_sprite4(items[0], *it_x, *it_y, 2, 0); + erase_sprite(*it_ox, *it_oy, 2); + + update_screen(); + wait(); + } + + + destroy_entity(); + update_persistence(sp_it->id); + + _gtail_effect(); + + PLW_Init(songs, SONG_INGAME); +} + +void update_pickup() +{ + if (!check_for_player(16)) + return; + + switch (sp_it->type) + { + case ET_POTION: + if (life == MAX_LIFE) + return; + life = MAX_LIFE; + break; + case ET_KEY: + ++keys; + break; + case ET_GEM: + ++gems; + break; + } + + erase_sprite(*it_x, *it_y, 2); + destroy_entity(); + + update_persistence(sp_it->id); + + PLW_PlaySoundEffectP(EFX_PICKUP); + + draw_hud(); +} |