From f94040e804989beac582811f8f9ede5decfdca07 Mon Sep 17 00:00:00 2001 From: parking_turkeys Date: Tue, 3 Nov 2026 17:10:48 -0500 Subject: [PATCH] realized there was some uncommited stuff :/ --- html_build_script.txt | 1 + level.c | 2 +- level_data.h | 6 +- onefile.c | 1710 +++++++++++++++++++++++++++++++++++++++++ startgame.c | 6 + 5 files changed, 1722 insertions(+), 3 deletions(-) create mode 100644 html_build_script.txt create mode 100644 onefile.c diff --git a/html_build_script.txt b/html_build_script.txt new file mode 100644 index 0000000..fbff1d2 --- /dev/null +++ b/html_build_script.txt @@ -0,0 +1 @@ +emcc onefile.c -std=c99 -D_DEFAULT_SOURCE -Wno-everything -Os -I. -I C:/raylib/raylib/src -I C:/raylib/raylib/src/external -L. -L C:/raylib/raylib/src -s USE_GLFW=3 -s ASYNCIFY -s TOTAL_MEMORY=67108864 -s FORCE_FILESYSTEM=1 --shell-file C:/raylib/raylib/src/shell.html C:/raylib/raylib/src/libraylib.web.a -DPLATFORM_WEB -o index.html --preload-file img --preload-file dialogue-img --preload-file aichan-front-sheet.png --preload-file aichan_walk_sheet.png --preload-file coin.wav \ No newline at end of file diff --git a/level.c b/level.c index 692e482..6acea35 100644 --- a/level.c +++ b/level.c @@ -1,7 +1,7 @@ #include "raylib.h" #include #include -#include "game.h" +//#include "game.h" #include "level_data.h" #define ADVANCEKEY KEY_H diff --git a/level_data.h b/level_data.h index 8839d82..d10d2e5 100644 --- a/level_data.h +++ b/level_data.h @@ -1,3 +1,6 @@ +#include "game.h" +#include + #define PLATFORMCOUNT 83 #define DANGERCOUNT 34 #define OBJECTCOUNT 5 @@ -6,8 +9,7 @@ #define DIALOGUECOUNT 41 #define STAGECOUNT 13 -#include "game.h" -#include + //icons are 130x130 diff --git a/onefile.c b/onefile.c new file mode 100644 index 0000000..49f8c5c --- /dev/null +++ b/onefile.c @@ -0,0 +1,1710 @@ +//the entire gamein one file i swear there's a reason +#include "raylib.h" +#include +#include +#include + +#define SCREENWIDTH 640 +#define SCREENHEIGHT 480 +#define FPS 30 +#define WINDOWTITEL "platformer v2 (it works this time) (not really)" + +#define ICONPATH "icon.png" + +#define ZeichnenAnfangen() BeginDrawing() +#define ZeichnenAufhören() EndDrawing() + +#define SPEED 59 +#define GRAVITY 20 +#define FRAMELENGTH 0.1 +#define JUMPVELOCITY -160 + +#define LEVELS 13 + +//these are for the "mode" variable + +#define STARTGAMEMODE 0 +#define LEVELMODE 1 +#define BOSSFIGHTMODE 2 +#define ENDSCREENMODE 3 + +//structures +struct character { + struct Rectangle rect; + struct Vector2 velocity; +}; + +struct platform { + struct Rectangle rect; + Color colour; + +}; + +struct dialogue { + char *line; + char *charaname; + char *image; + Color characolour; +}; + +struct object { + Rectangle rect; + char *name; + char *imgfile; + struct dialogue *dialogues; + int dialogue_count; + int index; +}; + +struct coingroup { + Vector2 position; + int coin_count; + int *collected; + int padding; //default: 5px :D +}; + +struct stage { + char *name; + struct platform *platforms; + int platform_count; + struct dialogue *dialogues; + int dialogue_count; + struct platform *dangers; + int danger_count; + struct object *objects; + int object_count; + struct coingroup *coingroups; + int coingroup_count; +}; + +struct spritesheet { + Image img; + int width_each; + int height_each; + int columns; +}; + +//functions +struct character *spielersetup(void); +int next_level(struct character *player); +int kill_chara(struct character *player); +int interact(struct Rectangle *rect); + +int bühnezeichnen(void); //i dont think stage works here but it seems better than window +int spielerzeichnen(void); + +int variables(float delta, struct character *player); +int spieler_bewegen(float delta); +int physics(float delta, struct character *player); + + + +int on_floor(struct Rectangle *rect); +int in_floor(struct Rectangle *rect); +int sliding_wall(struct Rectangle *rect); +int is_killed(struct Rectangle *rect); + +int level_cleanup(void); +int player_cleanup(void); +int fight_cleanup(void); + +int drawstartgame(void); +int handlebuttons(void); +int drawendscreen(int game_seconds); + +int drawdialogue(struct dialogue *dialogueline); + +int update_boss_screen(float delta); +int draw_boss_screen(void); + +//variables + +int level; +int frozen; +int objects_interacted[]; +int mode; +int inputs[]; +int deaths; +int COIN_COUNT; +int drawhitboxes; + +//main_v2.c +int level = 0; +int frozen = 1; //0:game, 1:stage dialogue, 2+:object[frozen-2] dialogue || 0:fight 1:pre-fight dialogue +int mode = 0; //0:'start game', 1: 'levels', 2:'end screen' (later: 2 will be bossfight and 3 will be end screen lol) +int fullsectime = 0; +int deaths = 0; +int drawhitboxes = 0; + +int main(void) +{ + InitWindow(SCREENWIDTH, SCREENHEIGHT, WINDOWTITEL); + SetWindowIcon(LoadImage(ICONPATH)); + SetTargetFPS(FPS); + + SetTraceLogLevel(LOG_WARNING); + + struct character *player = spielersetup(); + frozen= 1; //for dialogue + + while (!WindowShouldClose()) { + switch (mode) { + case STARTGAMEMODE: + fullsectime = 0; + ZeichnenAnfangen(); + drawstartgame(); + handlebuttons(); + ZeichnenAufhören(); + break; + case LEVELMODE: + if (!frozen) {variables(GetFrameTime(), player);}; + if (IsKeyPressed(KEY_Q)) { drawhitboxes = 1; }; + if (mode == LEVELMODE) { + ZeichnenAnfangen(); + bühnezeichnen(); + if (!frozen) {spielerzeichnen();}; + DrawRectangle(1, 468, 45, 12, WHITE); + DrawText(TextFormat("FPS: %2i", GetFPS()), 2, 469, 10, BLACK); + DrawRectangle(1, 0, 115, 12, WHITE); + DrawText(TextFormat("Seconds played: %5.2f", GetTime()), 2, 0, 10, BLACK); + ZeichnenAufhören(); + }; + break; + case BOSSFIGHTMODE: + update_boss_screen(GetFrameTime()); + ZeichnenAnfangen(); + ClearBackground(RAYWHITE); + draw_boss_screen(); + ZeichnenAufhören(); + break; + case ENDSCREENMODE: + //printf("enddd"); + ZeichnenAnfangen(); + //printf("end"); + drawendscreen(fullsectime); + ZeichnenAufhören(); + break; + }; + }; + //cleanup stuff + level_cleanup(); + player_cleanup(); + fight_cleanup(); + + CloseWindow(); + + return 0; +} + +int variables(float delta, struct character *player) +{ + //hier sollten dann die variables (??) aktualisiert werden (aber nichts solltet schon gezeichnet werden) + spieler_bewegen(delta); //.... ich habe vergessen wie man deutsch redet haha + physics(delta, player); + return 1; // :p +} + +int next_level(struct character *player) +{ + level += 1; + //printf("incremented level"); + frozen = 1; + //printf("set frozen\n"); + player->rect.x = 0; player->rect.y = 300; + if (level == LEVELS) { + //printf("DONE"); + mode = ENDSCREENMODE; + fullsectime = (int)GetTime(); + //printf("time saved"); + }; + return 1; +} + +int kill_chara(struct character *player) +{ + player->rect.x = 0; player->rect.y = 300; + deaths += 1; + return 1; +} + +//level_data.h +#define PLATFORMCOUNT 83 +#define DANGERCOUNT 34 +#define OBJECTCOUNT 5 +#define COINCOUNT 405 +#define COINGROUPCOUNT 62 +#define DIALOGUECOUNT 41 +#define STAGECOUNT 13 + + + +//icons are 130x130 + +struct dialogue dialogues[DIALOGUECOUNT] = { + {"Hello!! [press 'H' to advance dialogue]", "Ai-chan", "dialogue-img/aichan-smile.png", GREEN}, + {"My name is Ai-chan, and i;m the AI of the Hyperion :3", "Ai-chan", "dialogue-img/aichan-smile.png", GREEN}, + {"(for context thsi is a honkai impact 3 reference... i swear it makes sense", "context", "dialogue-img/context.png", BLACK}, + {"So there's these girls Rozaliya and Liliya who think they can become the main characters of a game...", "Ai-chan", "dialogue-img/aichan-neutral.png", GREEN}, + {"I'm clearly way more awesome than them so I am becoming the main character of a game >:{", "Ai-chan", "dialogue-img/aichan-angry.png", GREEN}, + {"Now we have to find them and prove this!!", "Ai-chan", "dialogue-img/aichan-angry.png", GREEN}, + {"Please press 'A' and 'D' to move LEFT and RIGHT; advance to the RIGHT side of the screen to finish this level!!", "Ai-chan", "dialogue-img/aichan-smile.png", GREEN}, + + + {"Press 'H' to JUMP", "Ai-chan", "dialogue-img/aichan-smile.png", GREEN}, + + + {"Those red squares are dangerous!! Don't touch them.", "Ai-chan", "dialogue-img/aichan-angry.png", GREEN}, + + + {"To wall-jump, slide on a wall and press the JUMP key.", "Ai-chan", "dialogue-img/aichan-smile.png", GREEN}, + + + {"Huh? Is that Sin Mal over there?", "Ai-chan", "dialogue-img/aichan-neutral.png", GREEN}, + {"Well... we should say hi to her. (Press R to INTERACT)", "Ai-chan", "dialogue-img/aichan-smile.png", GREEN}, + {"This level may seem impossible but it is in fact possible.", "Context", "dialogue-img/context.png", BLACK}, + + + {"Hi Ai-chan >:(", "Sin Mal", "dialogue-img/sin_aaa.png", PINK}, + {"Rozaliya and Liliya want to challenge you to a super peak idol fight", "Sin Mal", "dialogue-img/sin_aaa.png", PINK}, + {"Ok sure", "Ai-chan", "dialogue-img/aichan-neutral.png", GREEN}, + {"The dialogue in this game keeps getting lower-effort...", "Context", "dialogue-img/context.png", BLACK}, + + + {"This seems a bit ominous...", "Ai-chan", "dialogue-img/aichan-neutral.png",GREEN}, + {"...lazy game design.", "Context", "dialogue-img/context.png", BLACK}, + + + {"Senti is over there... you could talk to her but well, it might not be the best idea :/", "Ai-chan", "dialogue-img/aichan-neutral.png", GREEN}, + {"Senti stands for \"Herrscher of Sentience\", she is well known for scamming people and being overall mischevious", "Context", "dialogue-img/context.png", BLACK}, + + {"ALL HAIL THE HERRSCHER OF SENTIENCE!!! oh hi Ai-chan", "Senti", "dialogue-img/senti.png", GRAY}, + {"...", "Ai-chan", "dialogue-img/aichan-neutral.png", GREEN}, + {"So do you want a brick. it's really awesome i swear. it's like a divine key, trust me bro", "Senti", "dialogue-img/senti.png", GRAY}, + {"Dear god the writing here is lazy. \"Divine Key: Brick\" is a real weapon in honkai impact btw", "context", "dialogue-img/context.png", BLACK}, + {"Seriously??? What kind of scam is this this time", "Ai-chan", "dialogue-img/aichan-angry.png", GREEN}, + {"It's so beautiful!!", "Senti", "img/brick.png", GRAY}, + {"SENTI!!! >:(((", "Ai-chan", "dialogue-img/aichan-angry.png", GREEN}, + + + {"the shape of the platforms here is a lazy reference to seele's stigmata in hi3. literally everything about this level is lazy.", "COntext", "dialogue-img/context.png", BLACK}, + + {"Bronya has been dragged into Roza and Lili's schemes again.", "Bronya", "dialogue-img/bronya.png", ORANGE}, + {"... \nHave you seen Seele?", "Bronya", "dialogue-img/bronya.png", ORANGE}, + {"This is probably some scheme by those two!!", "Ai-chan", "dialogue-img/aichan-angry.png", ORANGE}, + {"no actually it's just too annoying to add dialogue that's different based on other things", "CONTEXT", "dialogue-img/context.png", BLACK}, + + {"Hello! How are you, Ai-chan?", "Seele", "dialogue-img/aichan-default.png", DARKBLUE}, + {"... LITERALLY TERRIBLE BECAUSE OF YOUR FAKE IDOL FRIENDS >:(", "Ai-chan", "dialogue-img/aichan-angry", GREEN}, + {"It cannot be this serious.", "Context", "dialogue-img/context.png", BLACK}, + {"This cannot be this serious, can you just get it over with soon??", "Seele", "dialogue-img/seele_b.png", RED}, + {"?", "Ai-chan", "dialogue-img/aichan-smile.png", GREEN}, + + {"There are some cherries. Somehow, they're still good.", "Context", "dialogue-img/context.png", BLACK}, + + + {"Here's the last level... soon there will be a boss fight (never. there's no way the boss fight gets finished", "context", "dialogue-img/context.png", BLACK}, + + + {"YOU WIN!!", "Ai-chan", "dialogue-img/aichan-smile.png", GREEN} +}; + +struct platform platforms[PLATFORMCOUNT] = { + {{0,320,640,160},GREEN}, + + + {{0,320,640,160},GREEN}, + {{240, 300, 160, 20}, GREEN}, + + + {{0, 320, 640, 160}, GREEN}, + + + {{0,320,80,160},GREEN}, + {{100,300,80,10}, GREEN}, + {{200,270,60,10}, GREEN}, + {{280,240,230,10}, GREEN}, + {{560,420,80,160}, GREEN}, + + + {{0,320,640,160},GREEN}, + {{400,80,80,200}, GREEN}, + {{540,100,100,220},GREEN}, + + + {{0,400,170,80},GREEN}, + {{240,320,80,160},GREEN}, + {{100,290,80,80},GREEN}, + {{340,300,60,20},GREEN}, + {{440,320,60,20},GREEN}, + {{520,350,20,20},GREEN}, + {{560,410,80,70},GREEN}, + + + {{0,440,640,40},GREEN}, + {{320,320,10,100},GREEN}, + {{390,320,10,120},GREEN}, + {{390,320,160,10},GREEN}, + + + {{0,460,200,20},GREEN}, + {{180,160,20,300},GREEN}, + {{100,120,20,320},GREEN}, + {{200,160,160,20},GREEN}, + {{400,90,20,50},GREEN}, + {{360,20,20,80},GREEN}, + {{460,80,60,20},GREEN}, + {{480,140,80,20},GREEN}, + {{580,0,60,300},GREEN}, + {{480,320,80,80},GREEN}, + {{540,460,100,20},GREEN}, + + + {{0,400,160,80},GREEN}, + {{480,400,160,80},GREEN}, + + {{160,400,20,80},PINK}, + {{180,400,20,80},YELLOW}, + {{200,400,20,80},MAROON}, + + {{240,400,20,80},GRAY}, + {{260,400,20,80},BLUE}, + + {{300,400,20,80},GREEN}, + {{320,400,20,80},RED}, + + {{360,400,20,80},PURPLE}, + + {{400,400,20,80},YELLOW}, + {{420,400,20,80},MAROON}, + {{440,400,20,80},GREEN}, + {{460,400,20,80},PINK}, + + + {{0,400,640,80},GREEN}, + {{200,380,40,20},GREEN}, + {{235,360,5,20},GREEN}, + {{60,340,160,10},GREEN}, + {{60,160,20,180},GREEN}, + {{120,240,20,60},GREEN}, + {{120,220,160,20},GREEN}, + {{280,80,20,160},GREEN}, + {{220,80,20,100},GREEN}, + {{280,80,80,20},GREEN}, + {{340,0,20,80},GREEN}, + {{40,60,200,20},GREEN}, + {{40,0,20,80},GREEN}, + + + {{0,400,640,80},GREEN}, + {{320,240,10,140},GREEN}, + {{270,240,10,120},GREEN}, + {{180,240,90,10},GREEN}, + {{180,160,10,80},GREEN}, + {{190,160,60,10},GREEN}, + {{240,70,10,90},GREEN}, + {{310,40,10,80},GREEN}, + {{310,120,100,10},GREEN}, + {{390,130,20,100},GREEN}, + {{320,230,90,10},GREEN}, + {{250,205,40,10},GREEN}, + + + {{0,380,100,20},GREEN}, + {{170,380,10,20},GREEN}, + {{210,390,20,20},GREEN}, + {{290,390,30,20},GREEN}, + {{340,390,20,10},GREEN}, + {{430,390,15,10},GREEN}, + {{440,440,140,40},GREEN}, + + + {{0,350,240,10},GREEN}, + {{280,350,200,10},GREEN}, + {{500,350,140,10},GREEN} + +}; + +struct platform danger[DANGERCOUNT] = { + {{80,310,10,10}, RED}, + {{160,310,10,10}, RED}, + {{240,310,10,10}, RED}, + {{320,310,10,10}, RED}, + + + {{80,440,480,40}, RED}, + + + {{170,460,80,20},RED}, + {{100,270,80,20},RED}, + {{320,460,240,20},RED}, + {{460,350,60,20},RED}, + + + {{150,430,19,10},RED}, + {{420,310,10,10},RED}, + {{500,310,19,10},RED}, + + + {{205,155,9,9},RED}, + {{260,155,9,9},RED}, + {{355,155,5,5},RED}, + {{400,80,20,10},RED}, + {{570,0,10,300},RED}, + + + {{220,400,20,80},PINK}, + {{280,400,20,80},BLUE}, + {{340,400,20,80},PURPLE}, + {{380,400,20,80},YELLOW}, + + + {{240,390,65,10},RED}, + {{160,330,18,10},RED}, + {{150,210,10,10},RED}, + {{190,210,10,10},RED}, + {{190,50,10,10},RED}, + {{150,50,10,10},RED}, + {{400,395,19,5},RED}, + {{510,390,10,10},RED}, + {{560,395,5,5},RED}, + + + {{320,220,10,10},RED}, + + + {{0,420,440,60},RED}, + {{580,460,60,20},RED}, + + + {{0,400,640,80},RED} + +}; + +int collected_coins[COINCOUNT] = {0}; + +struct coingroup coins[COINGROUPCOUNT] = { + {{80,305},32,collected_coins, 5}, + + + {{75,305},11,collected_coins+32, 5}, + {{245,285},10,collected_coins+43,5}, + {{405,305},11,collected_coins+53,5}, + + + {{40,305},6,collected_coins+64,70}, + {{80,295},5,collected_coins+70,70}, + + + {{65,305},1,collected_coins+75,5}, + {{100,285},5,collected_coins+76,6}, + {{200,255},4,collected_coins+81,5}, + {{280,225},15,collected_coins+85,5}, + {{560,405},5,collected_coins+100,6}, + + + {{80,305},31,collected_coins+105,5}, + {{400,65},5,collected_coins+136,6}, + {{540,85},5,collected_coins+141,6}, + + + {{80,385},6,collected_coins+146,6}, + {{175,400},1,collected_coins+152,5}, + {{175,415},1,collected_coins+153,5}, + {{225,380},1,collected_coins+154,5}, + {{185,350},1,collected_coins+155,5}, + {{225,320},1,collected_coins+156,5}, + {{185,290},1,collected_coins+157,5}, + {{240,305},5,collected_coins+158,6}, + {{340,285},4,collected_coins+163,5}, + {{440,305},4,collected_coins+167,5}, + {{525,335},1,collected_coins+171,5}, + {{560,395},5,collected_coins+172,6}, + + + {{80,425},4,collected_coins+177,5}, + {{170,425},9,collected_coins+181,5}, + {{390,305},2,collected_coins+190,5}, + {{420,295},1,collected_coins+192,5}, + {{435,305},4,collected_coins+193,5}, + {{520,305},2,collected_coins+197,5}, + {{460,425},12,collected_coins+199,5}, + + + {{60,445},10,collected_coins+211,2}, + {{185,145},5,collected_coins+221,21}, + {{460,65},4,collected_coins+226,5}, + {{480,125},5,collected_coins+230,6}, + {{480,305},5,collected_coins+235,6}, + {{540,445},5,collected_coins+240,10}, + + + {{80,385},5,collected_coins+245,6}, + {{480,385},10,collected_coins+250,6}, + + + {{80,385},10,collected_coins+260,2}, + {{185,325},2,collected_coins+270,5}, + {{85,325},5,collected_coins+272,5}, + {{130,205},4,collected_coins+277,30}, + {{285,65},4,collected_coins+281,5}, + {{90,45},4,collected_coins+285,30}, + {{308,385},6,collected_coins+289,5}, + {{422,385},6,collected_coins+295,5}, + {{525,385},3,collected_coins+301,3}, + {{565,385},5,collected_coins+304,5}, + + + {{80,385},24,collected_coins+309,5}, + {{285,310},2,collected_coins+333,10}, + {{285,290},2,collected_coins+333,10}, + {{285,270},2,collected_coins+333,10}, + {{335,215},4,collected_coins+335,5}, + {{190,225},5,collected_coins+339,5}, + {{255,190},2,collected_coins+344,5}, + {{180,145},4,collected_coins+346,5}, + {{320,105},6,collected_coins+350,5}, + + + {{445,425},9,collected_coins+356,5}, + + + {{40,335},40,collected_coins+365,5} + + +}; + +struct object objects[OBJECTCOUNT] = { + {{440,418,15,22}, "Sin Mal", "img/sin_15_22.png" ,dialogues+13,4, 0}, + {{60,38,15,22}, "Herrscher of Sentience", "img/senti_15_22.png", dialogues+21,7, 1}, + {{200,222,15,18}, "Bronya Zaychik", "img/bronya_15_18.png", dialogues+29,4, 2}, + {{340,201,15,15}, "cherries", "img/cherries_15_15.png", dialogues+38,1, 3}, + {{330,100,15,20}, "Seele Vollerei", "img/seele_15_20.png", dialogues+33,5, 4} +}; + +struct stage stages[STAGECOUNT] = { + {"Movement", platforms, 1, dialogues, 7, danger, 0,NULL,0,coins,1}, + {"Jumping", platforms+1, 2, dialogues+7, 1, danger, 0,NULL,0,coins+1,3}, + {"Danger", platforms+3, 1, dialogues+8, 1, danger, 4,NULL,0,coins+4,2}, + {"(level)", platforms+4, 5, NULL,0,danger+4,1,NULL,0,coins+6,5}, + {"Wall-jumping", platforms+9, 3,dialogues+9,1,danger,0,NULL,0,coins+11,3}, + {"(level)", platforms+12, 7, NULL,0,danger+5,4,NULL,0,coins+14,12}, + {"Interact", platforms+19,4, dialogues+10,3,danger+9,3,objects,1,coins+26,7}, + {"(level)", platforms+23,11,NULL,0,danger+12,5,NULL,0,coins+33,6}, + {"Ominous", platforms+34,14,dialogues+17,2,danger+17,4,NULL,0,coins+39,2}, + {"Senti", platforms+48,13,dialogues+19,2,danger+21,9,objects+1,1,coins+41,10}, + {"Seele", platforms+61,12,dialogues+28,1,danger+30,1,objects+2,3,coins+51,9}, + {"(level)", platforms+73,7,NULL,0,danger+31,2,NULL,0,coins+60,1}, + {"Last level", platforms+80,3,dialogues+39,2,danger+33,1,NULL,0,coins+61,1} +}; + +//level.c +#define ADVANCEKEY KEY_H + +//dialogue display constants +#define DLGY 300 +#define DLGHEIGHT 180 +#define CHARADISPLAYWIDTH 140 +#define DLGPADDING 5 +#define CHARANAMETEXTSIZE 25 +#define DLGTEXTWIDTH SCREENWIDTH - DLGPADDING * 2 - CHARADISPLAYWIDTH + +#define COINPADDING 5 +#define COINWIDTH 10 + +int COIN_COUNT = COINCOUNT; + + +int current_dialogue = 0; + +int drawcharname(char *name, Color colour); +int drawcharimage(char *filename); +int drawdialogueline(char *line); + +int drawobject(struct object *object); +int drawcoingroup(struct coingroup *coingroup); +int collectcoin(struct coingroup *group, int index); + +int objects_interacted[OBJECTCOUNT] = {0}; + +int bühnezeichnen(void) +{ + ClearBackground(BLUE); + struct stage *currstage = stages+level; + //draw all the platforms and stuff + for (int i = 0; i < stages[level].platform_count; i++) { + DrawRectangleRec(stages[level].platforms[i].rect, stages[level].platforms[i].colour); + if (drawhitboxes) { DrawRectangleLinesEx(currstage->platforms[i].rect, 1, BLACK); }; + }; + + for (int i = 0; i < stages[level].danger_count; i++) { + DrawRectangleRec(stages[level].dangers[i].rect, stages[level].dangers[i].colour); + if (drawhitboxes) { DrawRectangleLinesEx(currstage->dangers[i].rect, 1, WHITE); }; + } + + for (int i = 0; i < currstage->object_count; i++) { + drawobject(currstage->objects+i); + } + for (int i = 0; i < currstage->coingroup_count; i++) { + drawcoingroup(currstage->coingroups+i); + + }; + + if (frozen == 1) { //currently in dialogue at beginning of stage + if (stages[level].dialogues == NULL) { + frozen = 0; + } else { + drawdialogue(stages[level].dialogues+current_dialogue); + if (IsKeyPressed(ADVANCEKEY)) { + if (++current_dialogue >= stages[level].dialogue_count) { //dialogue over + current_dialogue = 0; //is this not activating or smth... + frozen = 0; + } else { + int max_dialogue = currstage->dialogue_count; + }; + }; + }; + } else if (frozen > 1) { //currently interacting with an object + struct object *o = currstage->objects + (frozen - 2); + drawdialogue(o->dialogues + current_dialogue); + if (IsKeyPressed(ADVANCEKEY)) { + if (++current_dialogue == o->dialogue_count) { + current_dialogue = 0; + frozen = 0; + objects_interacted[o->index] = 1; + }; + }; + } + + return 1; +} + +int in_floor(struct Rectangle *rect) +{ + for (int i = 0; i < stages[level].platform_count; i++) { + Rectangle check = stages[level].platforms[i].rect; + if (CheckCollisionRecs(*rect, check)) { + if (!(check.y == rect->y + rect->height)) {// this would mean rect is just sitting on top of it + if (!(check.x == rect->x + rect->width) && !(check.x + check.width == rect->x)) { + return 1; //we dont want it to return 1 if they're just on the floor + } + }; + }; + }; + return 0; +} + +int on_floor(struct Rectangle *rect) //on floor == no overlap but right next to eachother ig?? like the bottom of rect is 1 less y than ground +{ + + int platcount = stages[level].platform_count; + for (int i = 0; i < platcount; i++) { + Rectangle *check = &(stages[level].platforms[i].rect); + if ((rect->y + rect->height) == (check->y)) { + //printf("same y..."); + //check whether the X values match up uwu + Rectangle eins = (struct Rectangle){rect->x,1,rect->width,1}; + Rectangle zwei = (struct Rectangle){check->x,1,check->width,1}; + if (CheckCollisionRecs(eins,zwei)) { + return 1; printf("on floor!"); + }; + }; + }; + + return 0; +}; + +int sliding_wall(struct Rectangle *rect) +{ + // definition of sliding: not on floor + wall collision rect is >1 high and 1 wide + if (on_floor(rect)) { + return 0; + } else { + for (int i = 0; i < stages[level].platform_count; i++) { + Rectangle *check = &(stages[level].platforms[i].rect); + //int checkx = check->x; int rectx = rect->x; + //printf("check->x:%d rect->x:%d\n", checkx, rectx); + Rectangle eins = (struct Rectangle){1,rect->y,1,rect->height}; + Rectangle zwei = (struct Rectangle){1,check->y,1,check->height}; + if (CheckCollisionRecs(eins,zwei)) { //overlapping y + if ((rect->x + rect->width) == (check->x)) { + return -1; + } else if ((rect->x) == (check->width + check->x)) { + return 1; + }; + }; + }; + }; + return 0; +}; + +int is_killed(struct Rectangle *rect) +{ + struct stage *s = &stages[level]; + for (int i = 0; i < s->danger_count; i++) { + if (CheckCollisionRecs(*rect, s->dangers[i].rect)) { //if they're killed ill ... just remove the coins here lmao :p not a good idea but like. it'll be fine + for (int n = 0; n < s->coingroup_count; n++) { + struct coingroup *cg = s->coingroups+n; + for (int x = 0; x < cg->coin_count; x++) { + cg->collected[x]=0; + }; + }; + return 1; + }; + }; + + //haha im just going to add checkign coins into here loll + for (int i = 0; i < (s->coingroup_count); i++) { + struct coingroup *cg = s->coingroups+i; + for (int n = 0; n < (cg->coin_count); n++) { + Rectangle cr = {(cg->position.x + 2 + n * (cg->padding + COINWIDTH)), (cg->position.y + 2), (COINWIDTH - 4), (COINWIDTH - 4)}; + if ((cg->collected[n] == 0) && (CheckCollisionRecs(*rect,cr))) { + collectcoin(cg, n); + }; + }; + }; + return 0; +}; + +int drawdialogue(struct dialogue *dlg) +{ + DrawRectangle(0,DLGY,640,DLGHEIGHT,RAYWHITE); + drawcharname(dlg->charaname,dlg->characolour); + drawcharimage(dlg->image); + drawdialogueline(dlg->line); + return 1; +}; + +int drawcharname(char *name, Color colour) +{ + DrawText(name,DLGPADDING,DLGY + DLGPADDING + (30 - CHARANAMETEXTSIZE) ,CHARANAMETEXTSIZE,colour); + return 1; +} + +static Texture2D txtr; + +int drawcharimage(char *filename) +{ + static char *lastfilename = ""; + if (lastfilename != filename) { + UnloadTexture(txtr); + Image img = LoadImage(filename); + ImageResize(&img, CHARADISPLAYWIDTH - DLGPADDING * 2, CHARADISPLAYWIDTH - DLGPADDING * 2); + txtr = LoadTextureFromImage(img); + UnloadImage(img); + lastfilename = filename; + } + DrawTexture(txtr,DLGPADDING,DLGY + CHARANAMETEXTSIZE + DLGPADDING * 3,WHITE); + +}; + + + +int drawdialogueline(char *l) +{ + //DLGTEXTWIDTH (i always forget how to type this) + //ok im going to try doing this letter by letter :) + int x = CHARADISPLAYWIDTH + DLGPADDING; + int y = DLGY + DLGPADDING * 2; + char c[2] = {'a', '\0'}; + int i = 0; + //printf(l); + while (l[i] != '\0') { + c[0] = l[i]; + //printf(c); + i++; + DrawText(c, x, y, 20, BLACK); + x += MeasureText(c, 20) + 1; + if (x >= DLGTEXTWIDTH + CHARADISPLAYWIDTH + DLGPADDING) {x = CHARADISPLAYWIDTH + DLGPADDING; y += 22;}; + }; + //printf("\nDone"); + + return 1; + + //DrawText(l, CHARADISPLAYWIDTH + DLGPADDING, DLGY + DLGPADDING * 2 ,20, BLACK); //add text wrapping later +}; + +Texture2D coin_txtr; +Sound coin_sound; + +int level_cleanup(void) +{ + UnloadTexture(txtr); + UnloadTexture(coin_txtr); + UnloadSound(coin_sound); + CloseAudioDevice(); + return 1; +} + +int drawobject(struct object *o) +{ + Texture2D t; + Image img = LoadImage(o->imgfile); + ImageResize(&img, o->rect.width,o->rect.height); + t = LoadTextureFromImage(img); + UnloadImage(img); + DrawTexture(t,o->rect.x,o->rect.y,WHITE); + if (drawhitboxes) { + DrawRectangleLinesEx(o->rect,1,PINK); + }; + //DrawText("R", <-- I was going to try to add an "R" tip but it seemed hard... ill do it sometime lol + return 1; +}; + +int interact(Rectangle *r) +{ + for (int i = 0; i < stages[level].object_count; i++) { + if (CheckCollisionRecs(*r, stages[level].objects[i].rect)) { + frozen = 2 + i; + } + } + return 1; +}; + +int drawcoingroup(struct coingroup *cg) +{ + static int coin_loaded = 0; + if (!coin_loaded) { + Image img = LoadImage("img/coin_10_10.png"); + coin_txtr = LoadTextureFromImage(img); + UnloadImage(img); + coin_loaded = 1; + }; + for (int i = 0; i < cg->coin_count; i++) { + if (cg->collected[i] == 0) { + //draw the coin :3 + DrawTexture(coin_txtr, cg->position.x + i * (COINWIDTH + cg->padding), cg->position.y, WHITE); + if (drawhitboxes) { + Rectangle cr = {(cg->position.x + 2 + i * (cg->padding + COINWIDTH)), (cg->position.y + 2), (COINWIDTH - 4), (COINWIDTH - 4)}; + DrawRectangleLinesEx(cr, 1, PINK); + }; + }; + }; +}; + + +int collectcoin(struct coingroup *cg, int i) +{ + static int sound_loaded = 0; + if (!sound_loaded) { + InitAudioDevice(); + coin_sound = LoadSound("coin.wav"); // the sound is taken from an UTAU i recorded (i wanted to make sure i had the rights to it, and, well, it's my voice :)) + if (IsSoundValid(coin_sound)) { + sound_loaded = 1; + }; + }; + if (sound_loaded) { + PlaySound(coin_sound); + }; + cg->collected[i] = 1; +}; + + +//player.c +struct character player = {{2,300,6,18},{0,0}}; +int inputs[6] = {KEY_A,KEY_D,KEY_W,KEY_S,KEY_H,KEY_R}; //left, right, up, down, jump/advance dialogue, interact + +static struct spritesheet front_sheet, walk_sheet; +static struct spritesheet *sheets[2]; + +static Texture2D front_single; +static Texture2D txtr; +static float delta_player; + + + +struct character *spielersetup(void) +{ + Image img = LoadImage("./aichan-front.png"); + front_single = LoadTextureFromImage(img); + UnloadImage(img); + img = LoadImage("./aichan-front-sheet.png"); + front_sheet = (struct spritesheet){ImageCopy(img), 15, 18, 13}; + //front_sheet.img = img; front_sheet.width_each = 15; front_sheet.height_each = 18; front_sheet.columns=13; + UnloadImage(img); + sheets[0] = &front_sheet; + txtr = LoadTextureFromImage(front_sheet.img); + + img = LoadImage("./aichan_walk_sheet.png"); + walk_sheet = (struct spritesheet){ImageCopy(img), 15, 18, 4}; + UnloadImage(img); + sheets[1] = &walk_sheet; + + return &player; +} + +int drawframe(struct spritesheet *sheet, Rectangle *croprec, int mirror); + +int spielerzeichnen(void) +{ + static float time_since_switch = FRAMELENGTH; + static Rectangle croprec = {0,0,15,18}; + static int x_offset = 0; + time_since_switch += delta_player; + if (time_since_switch >= FRAMELENGTH) { + if (IsKeyDown(inputs[1])) { + drawframe(sheets[1], &croprec, 0); + x_offset = -9; + } else if (IsKeyDown(inputs[0])) { + drawframe(sheets[1], &croprec, 1); + x_offset= 0; + } else { + drawframe(sheets[0], &croprec, 0); + x_offset = -3; + }; + + time_since_switch = 0.0; + } + DrawTexture(txtr, player.rect.x + x_offset, player.rect.y, WHITE); + if (drawhitboxes) { DrawRectangleLinesEx(player.rect, 1, YELLOW); }; +} + +int spieler_bewegen(float delta) // should actually only change velocity, physics file moves player based on velocity uwu +{ + int d; + + static float walljumpprogress= 0; + static int walljumpdir = 0; + delta_player = delta; + + int direction; + if (IsKeyDown(inputs[1])) { + direction = 1; + } else if (IsKeyDown(inputs[0]) == 1) { + direction = -1; + } else { + direction = 0; + }; + + player.velocity.x = direction * SPEED; + if (player.velocity.x != direction * SPEED) { printf("sad"); }; + + if (on_floor(&(player.rect)) == 0) { + player.velocity.y += GRAVITY; + } else { + player.velocity.y = 0; + //printf("ON FLOOR"); + }; + if (on_floor(&player.rect) && IsKeyDown(inputs[4])) { + player.velocity.y = JUMPVELOCITY; + //printf("JUMP"); + } else if (IsKeyDown(inputs[4]) && (d = sliding_wall(&player.rect))) { + player.velocity.y = JUMPVELOCITY * 1.5; + player.velocity.x = d * SPEED * 1.5; + walljumpprogress = 1; + walljumpdir = d; + }; + + if (walljumpprogress > 0) { + walljumpprogress -= delta; + player.velocity.x = walljumpdir * SPEED * 1.5; + } else if (walljumpprogress < 0) { + walljumpprogress = 0; + }; + + if (IsKeyDown(inputs[5])) { + interact(&player.rect); + }; + + + //printf("direction * SPEED: %d; velocity.x: %d; int playervelocityx = player.velocity.x:%d\n", direction * SPEED, (player.velocity.x), playervelocityx); + return 1; +} + +int player_cleanup(void) +{ + UnloadTexture(front_single); + UnloadTexture(txtr); + UnloadImage(sheets[0]->img); + return 1; +} + +int drawframe(struct spritesheet *s, Rectangle *c, int mirror) +{ + UnloadTexture(txtr); + Image imgy = ImageFromImage(s->img, *c); + if (mirror) {ImageFlipHorizontal(&imgy);}; + //ImageCrop(&imgy,croprec); + //ImageCrop(&imgy, croprec); + txtr = LoadTextureFromImage(imgy); + UnloadImage(imgy); + if (c->x < s->width_each * (s->columns - 1)) {c->x += s->width_each;} else {c->x = 0;}; +} + +//physics.c +static int gravity(float delta, struct character *player); +int move_player(float delta, struct character *player); + +int physics(float delta, struct character *player) +{ + gravity(delta, player); + move_player(delta,player); + if (player->rect.x > SCREENWIDTH) { + next_level(player); + //printf("brought to next level\n"); + return 1; + }; + if (player->rect.x < -1) { + kill_chara(player); + deaths -= 1; + }; + return 1; +} + +static int gravity(float d, struct character *p) +{ + + return 1; +} + +int move_player(float d, struct character *p) +{ + int veloy, velox; velox = p->velocity.x; veloy = p->velocity.y; + //printf("x velocity: %d; y velocity: %d; delta: %f\n", velox, veloy, d); + int distancex, distancey; + distancex = (p->velocity.x *d) > 0 ? ceil(p->velocity.x *d) : floor(p->velocity.x *d); + distancey= (p->velocity.y *d) > 0 ? ceil(p->velocity.y *d) : floor(p->velocity.y *d); + Vector2 distance; + distance.x = distancex; distance.y = distancey; + //printf("x distance: %d; y distance: %d\n", distance.x, distance.y); + int steps_phys, stepx, stepy; + steps_phys = stepx = stepy = 0; + if (distance.x == 0 && distance.y == 0) { + steps_phys = 0; stepy = 0; stepx = 0; + } else if (distance.x == 0) { + steps_phys = abs(distance.y); stepy = distance.y/steps_phys; stepx = 0; + } else if (distance.y == 0) { + steps_phys = abs(distance.x); stepx = (distance.x/steps_phys); stepy = 0; + } else if (abs(distance.x) > abs(distance.y)) { steps_phys = abs(distance.y); stepy = ceil(distance.y/steps_phys); stepx = ceil(distance.x/steps_phys); } else { steps_phys = abs(distance.x); stepx = ceil(distance.x/steps_phys); stepy = round(distance.y/steps_phys); }; + + //printf("stepx:%d; stepy:%d; steps: %d\n", stepx, stepy, steps_phys); + for (int i = 0; i < steps_phys; i++) + { + p->rect.x += stepx; + p->rect.y += stepy; + if (is_killed(&p->rect)) { + kill_chara(p); + }; + if (in_floor(&p->rect)) { + p->rect.x -= stepx; p->rect.y -= stepy; + for (;i < steps_phys; i++) { + if (stepx > 0) {p->rect.x += 1; if (in_floor(&p->rect)) { p->rect.x-=1; };} else if (stepx < 0) {p->rect.x -= 1; if (in_floor(&p->rect)) { p->rect.x+=1; };}; + if (stepy > 0) {p->rect.y += 1; if (in_floor(&p->rect)) { p->rect.y-=1; };} else if (stepy < 0) {p->rect.y -= 1; if (in_floor(&p->rect)) { p->rect.y+=1; };}; + } + + return 1; + }; + }; + + return 1; +} + +//startgame.c + +#define BUTTONCOUNT 1 + +//label names +#define STARTGAMELABEL "START" + +static int drawbutton(char *text, Rectangle *rect, Color colour, Color outline_colour, Color text_colour); + +struct button { + Rectangle *rect; + char *label; +}; + +struct button buttons[BUTTONCOUNT] = {0}; + +int checkbuttonsmouse(int (*is_clicked)[BUTTONCOUNT]); +int checkbuttonskbd(int (*is_clicked)[BUTTONCOUNT]); + +int handlebuttons(void) +{ + int is_clicked[BUTTONCOUNT] = {0}; + //check mouse clicks + checkbuttonsmouse(&is_clicked); + //printf("mouse clicks CHECKED\n"); + + //check wasd/r clicks + checkbuttonskbd(&is_clicked); + + for (int i = 0; i < BUTTONCOUNT; i++) { + if (is_clicked[i] == 1) { + if (buttons[i].label == STARTGAMELABEL) { + mode = 1; + }; + }; + }; + return 1; +}; + +int checkbuttonsmouse(int (*c)[BUTTONCOUNT]) +{ + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + for (int i = 0; i < BUTTONCOUNT; i++) { + if (CheckCollisionPointRec((Vector2){GetMouseX(),GetMouseY()}, *buttons[i].rect)) { + (*c)[i] = 1; + }; + }; + }; + return 1; +}; + +int checkbuttonskbd(int (*i)[BUTTONCOUNT]) +{ + static int s_i = 0; //selected index + //draw select on selected one + + DrawRectangleLinesEx(*buttons[s_i].rect,5,RED); + int c = 0; + while ((c = GetKeyPressed()) != 0) { + if (c == inputs[0]) { //left + s_i -= 1; + if (s_i < 0) { + s_i = BUTTONCOUNT- 1; + }; + } else if (c == inputs[1]) { //right + s_i += 1; + if (s_i == BUTTONCOUNT) { + s_i = 0; + }; + } else if (c == inputs[5]) { //interact/select + (*i)[s_i] = 1; + }; + }; + + return 1; + +} + +int drawstartgame(void) +{ + ClearBackground(BLUE); + //printf("%d\n", MeasureText("Ai-chan platformer", 50)); + DrawText("Ai-chan platformer", 80,80,50,GREEN); + drawbutton(STARTGAMELABEL, &(struct Rectangle){100,150,440,80}, GREEN, WHITE, WHITE); + + return 1; +} + +static int drawbutton(char *t, Rectangle *r, Color c, Color o, Color t_c) +{ + static int i = 0; + DrawRectangleRec(*r,c); + DrawRectangleLinesEx(*r,5,o); + int t_s, t_x, t_y; //text size, x, and y + int n_w = r->width - 20; //needed width + t_s = r->height - 20; + t_x = r->x + 10; + t_y = r->y + 10; + while (MeasureText(t,t_s) > n_w) + { + t_s -= 1; + }; + t_x += (n_w - MeasureText(t,t_s))/2; + DrawText(t, t_x, t_y, t_s, t_c); + if (i != BUTTONCOUNT) { + buttons[i] = (struct button){r,t}; + i++; + }; + + return 1; +}; + +//bossfight.c +#define DLGCOUNT 20 + +#define PROMEMAXHP 262144 +#define PLAYERMAXHP 524288 +char *PROMEIMGPATH = "img/context_fight/normal.png"; +#define BRICKCOOLDOWNFULL 5 +#define SKILLCOUNT 2 +#define ENEMYSKILLCOUNT 1 +char *DEFAULTANIMFRAME = "img/defaultatk/default.png"; + +#define PLAYERIMGWIDTH 320 +#define PLAYERIMGHEIGHT 240 + +#define ENEMYIMGWIDTH 280 +#define ENEMYIMGHEIGHT 360 + +#define ATKDISPLAYX 300 +#define ATKDISPLAYY 90 +#define ATKDISPLAYWIDTH 80 +#define ATKDISPLAYPADDING 10 +#define ATKDISPLAYFONTSIZE 10 +#define COOLDOWNDISPLAYCOLOUR (Color){0,0,0,64} + +#define ENABLE_BRICK_DEFAULT 0 //for debug purposes + + +//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[] +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 +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 *filename; //attack thumbnail + char *atkspritesheet; //spritesheet :D (320x240) + int animframes; //yeah default to 1 + float framelength; //in seconds + int atk; + float cooldown_left; + float cooldown_max; + int enabled; +}; + +struct enemy_attack { + char *enemy_attack_img; + char *name; + int atk; + 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] = { + { KEY_H, "H", "img/defaultatk/icon.png", "img/defaultatk/sheet.png", 1, 0.0333, 256, 0, 0, 1}, + { KEY_ONE, "1", "img/brick.png", "img/brickatk/sheet.png", 3, 0.0666, 4096,0,5,ENABLE_BRICK_DEFAULT}, +}; + +static struct enemy_attack enemy_skills[ENEMYSKILLCOUNT] = { + { "img/context_fight/normal.png", "attack!", 512, 0, 0.2, 1, 0.1} +}; + + +static struct dialogue boss_dialogues[DLGCOUNT] = { + {"It's time to have an epic idol fight!!", "Rozaliya", "dialogue-img/rozaliya.png", PINK}, + {"Roza... is this really a good idea?", "Liliya", "dialogue-img/liliya.png", BLUE}, + {"(Liliya!! Stop it!)\nAnyway, we're totally going to win and stuff!!", "Rozaliza", "dialogue-img/rozaliya_angry.png", PINK}, + {"No way!! WE'RE going to win!!", "Ai-chan", "dialogue-img/aichan-angry.png", GREEN}, + {"I can't even take this anymore. the dialogue. is too bad.", "Context", "dialogue-img/context.png", BLACK}, + {"Who are you?", "olenyevas", "dialogue-img/olenyevas.png", PURPLE}, + {"I'm...\ngoing to beat all of you in a fight.", "context [?]", "dialogue-img/context.png", BLACK}, + {"FUCK YOU!! WERE ALL GOING TO BEAT YOU", "Ai-chan", "dialogue-img/aichan-angry.png", GREEN}, + {"Please just stop talking", "evil context??", "dialogue-img/context.png", BLACK}, + + + {"well you won i guess", "???", "dialogue-img/context.png", BLACK}, + {"Who are you?? and WHY did you interrupt our super epic awesome idol fight??", "Rozaliya", "dialogue-img/rozaliya_angry.png", PINK}, + {"I'm the will of Honkai", "tWoH?????", "dialogue-img/context.png", BLACK}, + {"WHAT??? NOOOOOOOO", "Rozaliya", "dialogue-img/rozaliya_what.png", PINK}, + {"...PROMETHEUS?", "Liliya", "dialogue-img/liliya.png", BLUE}, + {"Actually, it's PROMETHEUS no.17.", "PROMETHEUS", "dialogue-img/prome.png",GRAY}, + {"Why are you here?", "Ai-chan", "dialogue-img/aichan=angry.png", GREEN}, + {"I honestly dont know but i really dont want to listen to you guys talk any more", "PROMETHEUS", "dialogue-img/prome.png", GRAY}, + + + {"Well i won ig", "PROMETHEUS", "dialogue-img/prome.png", GRAY}, + {"PROMETHEUS???", "AI-chan", "dialogue-img/aichan-angry.png", GREEN}, + {"yk im a bit bored of this game sorry", "PROMETHEUS", "dialogue-img/prome.png",GRAY} +}; + +int current_dlg = 0; + +struct dialogue *pre_dialogue = boss_dialogues; +int pre_dialogue_count = 9; + +struct dialogue *post_win_dialogue = boss_dialogues+9; +int post_win_dialogue_count = 2; + +int prome_hp = PROMEMAXHP; //2^18 +int player_hp = PLAYERMAXHP; //2^19 + +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 brick_cooldown = 0; + +//static functions +static int draw_fight_screen(void); + +static int update_cooldowns(float delta); //also updates animation shown times lol +static int get_player_attack(void); +static int get_enemy_attack(void); +static int update_player_texture(void); +static int update_enemy_texture(void); +static int execute_attack(int atk, int *target_hp); + +int update_boss_screen(float delta) +{ + switch (frozen) { + case 0: + update_cooldowns(delta); + //printf("cooldowns updated!\n"); + curr_player_attack = get_player_attack(); + //printf("player attack handled!\n"); + curr_enemy_attack = get_enemy_attack(); + //printf("enemy attack handled!\n"); + update_player_texture(); + //printf("player textures handled!\n"); + update_enemy_texture(); + //printf("enemy textures handled!\n"); + + if (prome_hp <= 0) { + frozen = 2; + } else if (player_hp <= 0) { + frozen = 3; + }; + break; + case 1: + //just going to check for the brick here LMAO + if (objects_interacted[1] == 1) { + skills[1].enabled = 1; //you have to have interacted with Senti to get the divine key: brick + }; + break; + default: + //nothing? + break; + }; + return 1; +}; + +static int execute_attack(int atk, int *hp) +{ + *hp -= atk; + 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) +{ + static char *last_player_texture = ""; + static int last_player_frame = 0; + //get player frame + animation + char *player_img_name = ""; + 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?? + printf("bad error happen :( sad\n"); + return 0; + }; + + 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_img_frame), 0, PLAYERIMGWIDTH, PLAYERIMGHEIGHT}); + ImageResize(&img, PLAYERIMGWIDTH, PLAYERIMGHEIGHT); + player_img_txtr = LoadTextureFromImage(img); + UnloadImage(img); + }; +}; + +static int update_cooldowns(float d) +{ + //SKILL COOLDOWNS + //first player ones + for (int i = 0; i < SKILLCOUNT; i++) { + skills[i].cooldown_left -= d; + }; + //then enemy ones + for (int i = 0; i < ENEMYSKILLCOUNT; i++) { + enemy_skills[i].cooldown_left -= d; + }; + + //ANIMATION SHOWN LENGTHS + player_img_time_shown += d; + enemy_img_time_shown += d; + return 1; +}; + +static int get_player_attack(void) +{ + int k; + while ((k = GetKeyPressed()) != 0) { + for (int i = 0; i < SKILLCOUNT; i++) { + if ((skills[i].enabled) && (k == skills[i].keybind) && (skills[i].cooldown_left <= 0) && (curr_player_attack < 1)) { + //new attack so reset all of the animation and stuff + player_img_time_shown = 0; + player_img_frame = 0; + skills[i].cooldown_left = skills[i].cooldown_max; + execute_attack(skills[i].atk, &prome_hp); + return i; + }; + }; + }; + return curr_player_attack; +}; + +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].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; + execute_attack(enemy_skills[i].atk, &player_hp); + return i; + }; + }; + return curr_enemy_attack; //if nothing happens we want to just return the old one lol so nothing changes +}; + +int draw_boss_screen(void) +{ + switch (frozen) { + case 1: //pre-fight dialogue + drawdialogue(pre_dialogue+current_dlg); + if (IsKeyPressed(inputs[5]) || IsKeyPressed(inputs[4])) { + if (++current_dlg >= pre_dialogue_count) { //dialogue over + current_dlg = 0; + frozen = 0; + }; + }; + break; + case 0: + //fight + draw_fight_screen(); + break; + case 2: + //post-fight-win dialogue + drawdialogue(post_win_dialogue+current_dlg); + if (IsKeyPressed(inputs[5]) || IsKeyPressed(inputs[4])) { + if (++current_dlg >= post_win_dialogue_count) { //dialogue over + current_dlg = 0; + frozen = 0; + mode = ENDSCREENMODE; + }; + }; + break; + case 3: + //post-fight-lose dialogue + break; + }; + return 1; +}; + +static int draw_hp_bar(int hp, int max_hp, Vector2 position); +static int draw_enemy_img(void); +static int draw_player_img(void); +static int draw_attacks(struct sp_attack **attacks); + +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(); + //printf("enemy display DRAWN!\n"); + //draw the player display next!! + draw_hp_bar(player_hp,PLAYERMAXHP,(Vector2){320,420}); + draw_player_img(); + //printf("player display DRAWN!\n"); + struct sp_attack *a = &(skills[0]); + draw_attacks(&a); + //printf("attack display DRAWN!\n"); + + return 1; +}; + +static int draw_sp_attack(struct sp_attack *attack, Vector2 position); + +static int draw_attacks(struct sp_attack **a) +{ + Vector2 position = {ATKDISPLAYX, ATKDISPLAYY}; + for (int i = 0; i < SKILLCOUNT; i++) { + if ((*a+i)->enabled == 1) { + + draw_sp_attack(((*a)+i), position); + position.x += ATKDISPLAYWIDTH + ATKDISPLAYPADDING; + }; + }; +}; + +Texture2D textr; + +static int draw_sp_attack(struct sp_attack *a, Vector2 p) +{ + //get the image, resize, and draw (too lazy to not get the new image each time + //uhhh later when cleaning up this code maybe grab the texture before starting to draw?? + //some sort of error is happening here lmaooooo + //it is somehow... drawing the animation?? i think. uh. it's probably a weird memory thing haha + //char *imgfilename = a->filename; + //printf(imgfilename); + Image imgy = LoadImage(a->filename); + ImageResize(&imgy, ATKDISPLAYWIDTH,ATKDISPLAYWIDTH); + textr = LoadTextureFromImage(imgy); + DrawTexture(textr,p.x,p.y,WHITE); + UnloadImage(imgy); + //UnloadTexture(textr); THIS BROKE IT????? + + //draw the border + Rectangle rect = {p.x,p.y,ATKDISPLAYWIDTH,ATKDISPLAYWIDTH}; + DrawRectangleLinesEx(rect,2,BLACK); + + //draw the cooldown + if (a->cooldown_left > 0) { //otherwise you're drawing nothing lol + rect.height = a->cooldown_left/a->cooldown_max * ATKDISPLAYWIDTH; + rect.y += ATKDISPLAYWIDTH - rect.height; + DrawRectangleRec(rect, COOLDOWNDISPLAYCOLOUR); + }; + + //draw the keybind + int text_width = MeasureText(a->keybind_str, ATKDISPLAYFONTSIZE); + int text_x = p.x + ATKDISPLAYWIDTH/2 - text_width/2; + int text_y = p.y - ATKDISPLAYFONTSIZE/2; + Rectangle text_bg_rec = {text_x - 1, text_y - 1, text_width + 2, ATKDISPLAYFONTSIZE + 2}; + DrawRectangleRec(text_bg_rec, WHITE); //maybe add a border... + DrawText(a->keybind_str, text_x, text_y, ATKDISPLAYFONTSIZE, BLACK); + + //... add it to a list of buttons? maybe later haha +}; + + + + +static int draw_player_img(void) +{ + DrawTexture(player_img_txtr,320,160,WHITE); + return 1; +}; + +static int draw_hp_bar(int hp, int max_hp, Vector2 pos) +{ + int percent = (float)hp/(float)max_hp * 100; + int hp_width = (float)hp/(float)max_hp * 300; + //ok so i think green for HP, red for used up HP, black for the border would be good? + Vector2 bar_size = {300,40}; + //draw the background + DrawRectangleV(pos, bar_size, RED); + //draw the hp the character has. i think. 3px/percentage btw + DrawRectangleV(pos, (Vector2){hp_width,40}, GREEN); + //draw the outline!! + DrawRectangleLinesEx((Rectangle){pos.x, pos.y, bar_size.x, bar_size.y}, 2, BLACK); + //draw + + return 1; +}; + +//Texture2D txtr; + +static int draw_enemy_img(void) +{ + /* + static char *last_filename = ""; + if (filename != last_filename) { + printf("time to reimport the image"); + Image img = LoadImage(filename); + ImageResize(&img,280,360); + txtr = LoadTextureFromImage(img); + UnloadImage(img); + last_filename = filename; + }; + */ + DrawTexture(enemy_img_txtr,0,120,WHITE); + return 1; +}; + +int fight_cleanup(void) +{ + //UnloadTexture(txtr); + UnloadTexture(textr); + UnloadTexture(enemy_img_txtr); + UnloadTexture(player_img_txtr); + return 1; +}; + +//endscreen.c +extern int collected_coins[]; +struct time { + int min; + int sec; +}; + +static struct time *formattime(int seconds); +static int getcoincount(int *collected, int coin_count); + +int drawendscreen(int seconds) +{ + //printf("Time to draw an end screen :)"); + ClearBackground(RAYWHITE); + DrawText("Game End",80,80,100,BLACK); + struct time *gametime = formattime(seconds); + //printf("time to draw the gametime"); + DrawText(TextFormat("Time: %02d:%02d",gametime->min,gametime->sec),80,240,20, GRAY); + DrawText(TextFormat("Deaths: %d",deaths),240,240,20,GRAY); + DrawText(TextFormat("Coins: %d/%d",getcoincount(collected_coins,COIN_COUNT), COIN_COUNT),400,240,20,GRAY); + return 1; +}; + +static struct time *formattime(int s) +{ + struct time *t = &(struct time){0,0}; + t->min = s/60; //integer division rounds towards 0 + t->sec = s - t->min * 60; //fairly simple :p + return t; +} + +static int getcoincount(int *c, int count) +{ + int r = 0; + for (int i = 0; i < count; i++) { + r += c[i]; + }; + return r; +}; + + diff --git a/startgame.c b/startgame.c index 9076d44..5cface7 100644 --- a/startgame.c +++ b/startgame.c @@ -36,6 +36,7 @@ int handlebuttons(void) }; }; }; + return 1; }; int checkbuttonsmouse(int (*c)[BUTTONCOUNT]) @@ -47,6 +48,7 @@ int checkbuttonsmouse(int (*c)[BUTTONCOUNT]) }; }; }; + return 1; }; int checkbuttonskbd(int (*i)[BUTTONCOUNT]) @@ -72,6 +74,8 @@ int checkbuttonskbd(int (*i)[BUTTONCOUNT]) }; }; + return 1; + } int drawstartgame(void) @@ -104,4 +108,6 @@ static int drawbutton(char *t, Rectangle *r, Color c, Color o, Color t_c) buttons[i] = (struct button){r,t}; i++; }; + + return 1; }; -- 2.47.3