]> _ Git - aichan-platformer.git/commitdiff
idk why but it wont work sob. at least there's gravity now lmao
authorparking_turkeys <roya1060wien@gmail.com>
Tue, 14 Jul 2026 19:40:23 +0000 (15:40 -0400)
committerparking_turkeys <roya1060wien@gmail.com>
Tue, 14 Jul 2026 19:40:23 +0000 (15:40 -0400)
game.h
level.c
level_data.h [new file with mode: 0644]
main_v2.c
physics.c [new file with mode: 0644]
player.c

diff --git a/game.h b/game.h
index 0290a41..f728229 100644 (file)
--- a/game.h
+++ b/game.h
 #define ZeichnenAnfangen() BeginDrawing()
 #define ZeichnenAufhören() EndDrawing()
 
-#define SPEED 240
-#define GRAVITY 320
+#define SPEED 20
+#define GRAVITY 20
+#define FRAMELENGTH 0.1
+#define JUMPVELOCITY -40
 
-int spielersetup(void);
+struct character *spielersetup(void);
 
 int bühnezeichnen(void); //i dont think stage works here but it seems better than window
 int spielerzeichnen(void);
 
-int variables(float delta);
+int variables(float delta, struct character *player);
 int spieler_bewegen(float delta);
-int on_floor(struct Rectangle rect);
+int physics(float delta, struct character *player);
 
+int on_floor(struct Rectangle *rect);
+int in_floor(struct Rectangle *rect);
 
 //structures
 struct character {
@@ -51,3 +55,5 @@ struct stage {
 };
 
 //variables
+
+extern int level;
diff --git a/level.c b/level.c
index 24a4a5d..515576c 100644 (file)
--- a/level.c
+++ b/level.c
@@ -2,9 +2,40 @@
 #include <stdio.h>
 #include <math.h>
 #include "game.h"
+#include "level_data.h"
 
 int bühnezeichnen(void)
 {
-       ClearBackground(RAYWHITE);
+       ClearBackground(BLUE);
+       //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);
+       };
+
+
        return 1;
 }
+
+int in_floor(struct Rectangle *rect)
+{
+       for (int i = 0; i < stages[level].platform_count; i++) {
+               if (CheckCollisionRecs(*rect, stages[level].platforms[i].rect)) { return 1; };
+       };
+       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
+{
+       for (int i = 0; i < stages[level].platform_count; i++) {
+               if (rect->y == (stages[level].platforms[i].rect.y - 1)) {
+                       //check whether the X values match up uwu
+                       Rectangle eins = {rect->x, 1, rect->width, 1};
+                       Rectangle zwei = {stages[level].platforms[i].rect.x, 1, stages[level].platforms[i].rect.width, 1};
+                       if (CheckCollisionRecs(eins,zwei)) {
+                               return 1;
+                       };
+               };
+       };
+
+       return 0;
+};
diff --git a/level_data.h b/level_data.h
new file mode 100644 (file)
index 0000000..ba064cd
--- /dev/null
@@ -0,0 +1,24 @@
+#define STAGECOUNT 2
+#define DIALOGUECOUNT 4
+#define PLATFORMCOUNT 3
+
+#include "game.h"
+
+//icons are 40x40
+
+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}};
+
+struct platform platforms[PLATFORMCOUNT] = {
+       {{0,320,640,160},GREEN},
+       {{0,320,640,160},GREEN},
+       {{310, 300, 40, 20}, GREEN}
+};
+
+struct stage stages[STAGECOUNT] = {
+       {"Level 0", platforms, 1, dialogues, 4},
+       {"Level 1", platforms+1, 2, dialogues+4, 1}
+};     
index 659dd18..d7f4d69 100644 (file)
--- a/main_v2.c
+++ b/main_v2.c
 #include <math.h>
 #include <stdio.h> // seems useful
 
+int level = 0;
+
 int main(void)
 {
        InitWindow(SCREENWIDTH, SCREENHEIGHT, WINDOWTITEL);
        SetWindowIcon(LoadImage(ICONPATH));
        SetTargetFPS(FPS);
        
-       spielersetup();
+       struct character *player = spielersetup();
 
        while (!WindowShouldClose()) {
                //variables.
-               variables(GetFrameTime());
+               variables(GetFrameTime(), player);
                ZeichnenAnfangen();
                        bühnezeichnen();
                        spielerzeichnen();
@@ -32,9 +34,10 @@ int main(void)
        return 0;
 }
 
-int variables(float delta)
-{
+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
 }
diff --git a/physics.c b/physics.c
new file mode 100644 (file)
index 0000000..0811cec
--- /dev/null
+++ b/physics.c
@@ -0,0 +1,41 @@
+#include "raylib.h"
+#include <math.h>
+#include <stdio.h>
+#include "game.h"
+
+static int gravity(float delta, struct character *player);
+static int move_player(float delta, struct character *player);
+
+int physics(float delta, struct character *player)
+{
+       gravity(delta, player);
+       move_player(delta,player);
+       return 1;
+}
+
+static int gravity(float d, struct character *p)
+{
+       
+       return 1;
+}
+
+static int move_player(float d, struct character *p)
+{
+       printf("x velocity: %d; y velocity: %d; delta: %f\n", p->velocity.x, p->velocity.y, d);
+       Vector2 distance = {ceil(p->velocity.x*d), ceil(p->velocity.y*d)};
+       printf("x distance: %d; y distance: %d\n", distance.x, distance.y);
+       int steps, stepx, stepy;
+       if (distance.x == 0) {
+               steps = distance.y; stepy = 1; stepx = 0;
+       } else if (distance.y == 0) {
+               steps = distance.x; stepx = 1; stepy = 0;
+        } else if (distance.x > distance.y) { steps = distance.y; stepy = 1; stepx = round(distance.x/steps); } else { steps = distance.x; stepx = 1; stepy = round(distance.y/steps); };
+       for (int i = 0; i < steps; i++)
+       {
+               p->rect.x += stepx;
+               p->rect.y += stepy;
+               if (in_floor(&p->rect)) { p->rect.x -= stepx; p->rect.y -= stepy; return 1; };
+       };
+                       
+       return 1;
+}
index 1243b02..ac1ad39 100644 (file)
--- a/player.c
+++ b/player.c
@@ -6,21 +6,49 @@ struct character player = {{310,220,15,18},{0,0}};
 int inputs[3] = {KEY_A,KEY_D,KEY_H}; //left, right, jump/advance dialogue
 Image front_sheet;
 Texture2D front_single;
+static float delta_player;
 
-int spielersetup(void)
+struct character *spielersetup(void)
 {
        front_single = LoadTextureFromImage(LoadImage("aichan-front.png"));
 
        front_sheet = LoadImage("aichan-front-sheet.png");
+
+       return &player;
 }
 
 int spielerzeichnen(void)
 {
+       static float time_since_switch;
+       time_since_switch += delta_player;
+       if (time_since_switch >= FRAMELENGTH) {
+               //switch frame drawn
+               time_since_switch = 0;
+       }
        DrawTexture(front_single, player.rect.x, player.rect.y, WHITE);
 }
 
-int spieler_bewegen(float delta)
+int spieler_bewegen(float delta) // should actually only change velocity, physics file moves player based on velocity uwu
 {
+       delta_player = delta;
+       
+       if (on_floor(&(player.rect)) == 0) {
+               player.velocity.y += GRAVITY;
+       } else if (IsKeyDown(inputs[2])) {
+               player.velocity.y = JUMPVELOCITY;
+       };
+
+       int direction;
+       if ((IsKeyDown(inputs[0])) == (IsKeyDown(inputs[1]))) {
+               direction = 0;
+       } else if (IsKeyDown(inputs[0]) == 1) {
+               direction = -1;
+       } else {
+               direction = 1;
+       };
+       
+       player.velocity.x = direction * SPEED;
+
        return 1;
 }