From: parking_turkeys Date: Sun, 26 Jul 2026 20:48:59 +0000 (-0400) Subject: bit more animation, fix some bugs (UNTESTED) X-Git-Tag: v1.0~6 X-Git-Url: http://git.parking-turkeys.net/?a=commitdiff_plain;h=cd2d95bf05e733d39eda0bd641ef2f07571d7788;p=aichan-platformer.git bit more animation, fix some bugs (UNTESTED) --- diff --git a/bossfight.c b/bossfight.c index 8c8a465..ea909ac 100644 --- a/bossfight.c +++ b/bossfight.c @@ -6,34 +6,39 @@ #define PROMEMAXHP 262144 #define PLAYERMAXHP 524288 -#define PROMEIMGPATH "dialogue-img/aichan-default.png" //REPLACE LATER!! +char *PROMEIMGPATH = "dialogue-img/aichan-default.png"; //REPLACE LATER!! #define BRICKCOOLDOWNFULL 5 #define SKILLCOUNT 2 #define ENEMYSKILLCOUNT 1 -#define DEFAULTANIMFRAME "dialogue-img/aichan-default.png" //REPLACE LATER--this is the default image in the animation window, should be Ai holding the banhammer +char *DEFAULTANIMFRAME = "dialogue-img/aichan-default.png"; //REPLACE LATER--this is the default image in the animation window, should be Ai holding the banhammer #define PLAYERIMGWIDTH 320 #define PLAYERIMGHEIGHT 240 +#define ENEMYIMGWIDTH 280 +#define ENEMYIMGHEIGHT 360 + + //int player_atk = 64; //may seem little but. the whole point is to spam. also itll go up later //int brick_atk = 1024; //int prome_atk = 256; //int prome_atk_time = 0.2; int curr_enemy_attack = -1; //-1 for no attack, then the index in enemy_skills[] -int enemy_img_time_shown = 0; //the time the current image has been shown; only relevant if curr_enemy_attack > 0 so it goes back to the original image +float enemy_img_time_shown = 0; //the time the current image has been shown; only relevant if curr_enemy_attack > 0 so it goes back to the original image Texture2D enemy_img_txtr; //just for like easy int curr_player_attack = -1; //-1 for no attack, then the index in skills[]; important to note that it only switches back once the animation is over; if the player is spamming enough it should stay pretty long at 0 but each time the "animation" is restarted -int player_img_time_shown = 0; //restarts at new frame lol +float player_img_time_shown = 0; //restarts at new frame lol int player_img_frame = 0; //only relevant for animations ig Texture2D player_img_txtr; + //the "update" function is the only one with access to delta, so all of the updating should be done there and then draw should draw based on variables set in "update" struct sp_attack { int keybind; - char *keybind_str; + char (*keybind_str); char *filename; char *atkspritesheet; //spritesheet :D (320x240) int animframes; //yeah default to 1 @@ -51,17 +56,18 @@ struct enemy_attack { float cooldown_left; float cooldown_max; int enabled; + float framelength; }; //really shouldnt do this all in here but idc static struct sp_attack skills[SKILLCOUNT] = { - { inputs[4], GetKeyName(inputs[4]), "dialogue-img/aichan-default.png", "dialogue-img/aichan-default.png", 1, 0.0333, 64, 0, 0, 1} + { KEY_H, "H", "dialogue-img/aichan-default.png", "dialogue-img/aichan-default.png", 1, 0.0333, 64, 0, 0, 1}, { KEY_ONE, "1", "dialogue-img/brick.png", "img/brickatk/sheet.png", 3, 0.2, 1024,0,5,0}, }; static struct enemy_attack enemy_skills[ENEMYSKILLCOUNT] = { - { "dialogue-img/aichan-default.png", "attack!", 256, 0, 0.2, 1} + { "dialogue-img/aichan-default.png", "attack!", 256, 0, 0.2, 1, 0.1} }; @@ -119,6 +125,7 @@ int update_boss_screen(float delta) update_cooldowns(delta); curr_player_attack = get_player_attack(); curr_enemy_attack = get_enemy_attack(); + update_player_texture(); break; default: @@ -128,6 +135,35 @@ int update_boss_screen(float delta) return 1; }; +static int update_enemy_texture(void) +{ + static char *last_enemy_texture = ""; + //get enemy image + char *enemy_img_name = ""; + if (curr_enemy_attack == -1) { //no attack! + enemy_img_name = PROMEIMGPATH; + } else if (curr_enemy_attack < ENEMYSKILLCOUNT) { + struct enemy_attack *s = enemy_skills+curr_enemy_attack; + enemy_img_name = s->enemy_attack_img; + if (enemy_img_time_shown >= s->framelength) { + //switch to default image + curr_enemy_attack = -1; + enemy_img_time_shown = 0; + enemy_img_name = PROMEIMGPATH; + }; + } else { + printf("bad error happen :( [enemy attack doesnt exist]\n"); + return 0; + }; + if (last_enemy_texture != enemy_img_name) { + last_enemy_texture = enemy_img_name; + Image img = LoadImage(enemy_img_name); + ImageResize(&img, ENEMYIMGWIDTH, ENEMYIMGHEIGHT); + enemy_img_txtr = LoadTextureFromImage(img); + UnloadImage(img); + }; + return 1; +}; static int update_player_texture(void) { @@ -135,11 +171,21 @@ static int update_player_texture(void) static int last_player_frame = 0; //get player frame + animation char *player_img_name = ""; - int player_frame; if (curr_player_attack == -1) { //no attack shown rn player_img_name = DEFAULTANIMFRAME; } else if (curr_player_attack < SKILLCOUNT) { + struct sp_attack *s = skills+curr_player_attack; + player_img_name = s->atkspritesheet; //check if a new frame needs to be started/the animation ended + if (player_img_time_shown >= s->framelength) { + if (++player_img_frame >= s->animframes) { //update frame, check if it's too high + //end animation + curr_player_attack = -1; + player_img_time_shown = 0; + player_img_frame = 0; + player_img_name = DEFAULTANIMFRAME; + }; + }; //either end the animation and set it to the default or set time_shown to 0 and frame++ //then put the new frame into player_img_name } else { //curr_player_attack is not an existing attack?? @@ -147,10 +193,11 @@ static int update_player_texture(void) return 0; }; - if ((last_player_texture != player_img_name) || (last_player_frame != player_frame)) { //texture not loaded + if ((last_player_texture != player_img_name) || (last_player_frame != player_img_frame)) { //texture not loaded last_player_texture = player_img_name; + last_player_frame = player_img_frame; Image img = LoadImage(player_img_name); - ImageCrop(&img, (Rectangle){(PLAYERIMGWIDTH*player_frame), 0, PLAYERIMGWIDTH, PLAYERIMGHEIGHT}); + ImageCrop(&img, (Rectangle){(PLAYERIMGWIDTH*player_img_frame), 0, PLAYERIMGWIDTH, PLAYERIMGHEIGHT}); player_img_txtr = LoadTextureFromImage(img); UnloadImage(img); }; @@ -179,7 +226,7 @@ static int get_player_attack(void) int k; while ((k = GetKeyPressed()) != 0) { for (int i = 0; i < SKILLCOUNT; i++) { - if ((k == skills[i].keycode) && (skills[i].cooldown_left <= 0)) { + if ((skills[i].enabled) && (k == skills[i].keybind) && (skills[i].cooldown_left <= 0)) { //new attack so reset all of the animation and stuff player_img_time_shown = 0; player_img_frame = 0; @@ -194,7 +241,7 @@ static int get_player_attack(void) static int get_enemy_attack(void) { for (int i = ENEMYSKILLCOUNT - 1; i > -1; i--) { //start from the bottom just so later added ones are more important (presumably more powerful) - if (enemy_skills[i].cooldown_left <= 0) { + if ((enemy_skills[i].enabled) && (enemy_skills[i].cooldown_left <= 0)) { //new attack so reset all of the animation and stuff enemy_img_time_shown = 0; enemy_skills[i].cooldown_left = enemy_skills[i].cooldown_max; @@ -239,7 +286,7 @@ int draw_boss_screen(void) }; static int draw_hp_bar(int hp, int max_hp, Vector2 position); -static int draw_enemy_img(char *filename); +static int draw_enemy_img(void); static int draw_sp_attack(int cooldown_left, int cooldown_max, char *img_filename, char *keybind); static int draw_fight_screen(void) @@ -247,7 +294,7 @@ static int draw_fight_screen(void) //so like draw the enemy display for a bit DrawText("\"Context\"??:", 80,45,30,BLACK); //enemy name :) draw_hp_bar(prome_hp,PROMEMAXHP, (Vector2){300,40}); - draw_enemy_img(PROMEIMGPATH); + draw_enemy_img(); return 1; }; @@ -271,8 +318,9 @@ static int draw_hp_bar(int hp, int max_hp, Vector2 pos) Texture2D txtr; -static int draw_enemy_img(char *filename) +static int draw_enemy_img(void) { + /* static char *last_filename = ""; if (filename != last_filename) { printf("time to reimport the image"); @@ -282,13 +330,16 @@ static int draw_enemy_img(char *filename) UnloadImage(img); last_filename = filename; }; - DrawTexture(txtr,0,120,WHITE); + */ + DrawTexture(enemy_img_txtr,0,120,WHITE); return 1; }; int fight_cleanup(void) { UnloadTexture(txtr); + UnloadTexture(enemy_img_txtr); + UnloadTexture(player_img_txtr); return 1; };