From: parking_turkeys Date: Tue, 14 Jul 2026 21:48:28 +0000 (-0400) Subject: fix some bugs, add level switching, change some of the physics X-Git-Tag: broken~6 X-Git-Url: http://git.p-t.hackclub.app/?a=commitdiff_plain;h=f1523e5a1c902df1c06d69c5c74db58c885d0271;p=aichan-platformer.git fix some bugs, add level switching, change some of the physics --- diff --git a/game.h b/game.h index a090eaf..3524a13 100644 --- a/game.h +++ b/game.h @@ -10,10 +10,12 @@ #define ZeichnenAnfangen() BeginDrawing() #define ZeichnenAufhören() EndDrawing() -#define SPEED 20 +#define SPEED 30 #define GRAVITY 20 #define FRAMELENGTH 0.1 -#define JUMPVELOCITY -90 +#define JUMPVELOCITY -130 + +#define LEVELS 3 struct character *spielersetup(void); diff --git a/level_data.h b/level_data.h index ba064cd..735b58f 100644 --- a/level_data.h +++ b/level_data.h @@ -1,6 +1,6 @@ -#define STAGECOUNT 2 -#define DIALOGUECOUNT 4 -#define PLATFORMCOUNT 3 +#define STAGECOUNT 3 +#define DIALOGUECOUNT 6 +#define PLATFORMCOUNT 5 #include "game.h" @@ -10,15 +10,21 @@ struct dialogue dialogues[DIALOGUECOUNT] = { {"Hello!! [press 'H' to advance dialogue]", "Ai-chan", "dialogue-img/aichan-default.png", GREEN}, {"My name is Ai-chan, and i;m the AI of the Hyperion battleship :3", "Ai-chan", "dialogue-img/aichan-default.png", GREEN}, {"(for context thsi is a honkai impact 3 reference... i swear it makes sense", "context", "dialogue-img/aichan-default.png", BLACK}, - {"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-default.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-default.png", GREEN}, + {"Press 'H' to JUMP", "Ai-chan", "dialogue-img/aichan-default.png", GREEN}, + {"YOU WIN!!", "Ai-chan", "dialogue-img/aichan-default.png", GREEN} +}; struct platform platforms[PLATFORMCOUNT] = { {{0,320,640,160},GREEN}, {{0,320,640,160},GREEN}, - {{310, 300, 40, 20}, GREEN} + {{310, 300, 40, 20}, GREEN}, + {{0, 320, 640, 160}, GREEN}, + {{320, 0, 320, 480}, GREEN} }; struct stage stages[STAGECOUNT] = { {"Level 0", platforms, 1, dialogues, 4}, - {"Level 1", platforms+1, 2, dialogues+4, 1} + {"Level 1", platforms+1, 2, dialogues+4, 1}, + {"End", platforms+3, 2, dialogues+5, 1} }; diff --git a/main_v2.c b/main_v2.c index d7f4d69..78e5434 100644 --- a/main_v2.c +++ b/main_v2.c @@ -22,11 +22,11 @@ int main(void) while (!WindowShouldClose()) { //variables. - variables(GetFrameTime(), player); - ZeichnenAnfangen(); - bühnezeichnen(); - spielerzeichnen(); - ZeichnenAufhören(); + variables(GetFrameTime(), player); + ZeichnenAnfangen(); + bühnezeichnen(); + spielerzeichnen(); + ZeichnenAufhören(); } CloseWindow(); diff --git a/physics.c b/physics.c index 6b8c83d..432fa56 100644 --- a/physics.c +++ b/physics.c @@ -10,6 +10,13 @@ int physics(float delta, struct character *player) { gravity(delta, player); move_player(delta,player); + if (player->rect.x > SCREENWIDTH) { + level++; + player->rect.x = 15; player->rect.y = 120; + if (level == LEVELS) { + //end game + }; + }; return 1; } @@ -23,16 +30,20 @@ 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 = ceil(p->velocity.x *d); distancey= ceil(p->velocity.y*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) { - steps_phys = abs(distance.y); stepy = ceil(distance.y/steps_phys); stepx = 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 = ceil(distance.x/steps_phys); stepy = 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); @@ -40,7 +51,7 @@ int move_player(float d, struct character *p) { p->rect.x += stepx; p->rect.y += stepy; - if (in_floor(&p->rect)) { + if (!on_floor(&p->rect) && 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; };}; diff --git a/player.c b/player.c index 3769613..d063abb 100644 --- a/player.c +++ b/player.c @@ -44,12 +44,12 @@ int spieler_bewegen(float delta) // should actually only change velocity, physic }; int direction; - if ((IsKeyDown(inputs[0]) && IsKeyDown(inputs[1])) || (!IsKeyDown(inputs[1]) && !IsKeyDown(inputs[0]))) { - direction = 0; + if (IsKeyDown(inputs[1])) { + direction = 1; } else if (IsKeyDown(inputs[0]) == 1) { direction = -1; } else { - direction = 1; + direction = 0; }; player.velocity.x = direction * SPEED;