From a385a24d0ffb3a1110a6403ff9e2330837bd856e Mon Sep 17 00:00:00 2001 From: mrsh Date: Tue, 21 Apr 2026 13:19:08 +0200 Subject: [PATCH] test movement du personnage --- src/main.c | 89 +++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 52 deletions(-) diff --git a/src/main.c b/src/main.c index 23d8db9..97d973c 100644 --- a/src/main.c +++ b/src/main.c @@ -12,6 +12,17 @@ by Jeffery Myers is marked with CC0 1.0. To view a copy of this license, visit h #include "resource_dir.h" // utility header for SearchAndSetResourceDir #include +typedef struct Player { + Vector2 position; + Vector2 size; + int life; +} Player; + +static Player player = {0}; + +static void characterMovement(void); + + int main () { // Tell the window to use vsync and work on high DPI displays @@ -31,14 +42,6 @@ int main () int HorizontalPosition = 400; int VerticalPosition = 300; - int point = 0; - - //Start point of the colectible - - int positionXCollectible = GetRandomValue(0, 600); - int positionYCollectible = GetRandomValue(0, 800); - - // game loop while (!WindowShouldClose()) // run the loop until the user presses ESCAPE or presses the Close button on the window { @@ -49,53 +52,11 @@ int main () ClearBackground(BLACK); // DrawRectangle(HorizontalPosition, VerticalPosition, 10, 10, BLUE); - DrawTexture(emi, HorizontalPosition, VerticalPosition, WHITE); - + DrawTexture(emi, player.position.x, player.position.y, WHITE); - DrawCircle(positionXCollectible, positionYCollectible, 10, YELLOW); - - //draw score - DrawText(TextFormat("score : %d", point), 500,50,20,PINK); + characterMovement(); - if(point >= 10){ - DrawText("Emi la plus belle", 50,50,20,PINK); - if (IsKeyDown(74) ) { - point=0; - }; - }else{ - - //up - if (IsKeyDown(74) && VerticalPosition != 580 ) { - // draw some text using the default font - VerticalPosition = VerticalPosition+10; - }; - //down - if (IsKeyDown(75) && VerticalPosition != 0) { - VerticalPosition = VerticalPosition-10; - // draw some text using the default font - }; - //left - if (IsKeyDown(72) && HorizontalPosition != 0) { - HorizontalPosition = HorizontalPosition-10; - // draw some text using the default font - }; - //right - if (IsKeyDown(76)&& HorizontalPosition != 780) { - HorizontalPosition = HorizontalPosition+10; - // draw some text using the default font - }; - - } - - if (abs(positionXCollectible - HorizontalPosition) < 10 && - abs(positionYCollectible - VerticalPosition) < 10){ - positionXCollectible = GetRandomValue(0, 800); - positionYCollectible = GetRandomValue(0, 600); - point = point + 1; - } - - // end the frame and get ready for the next one (display frame, poll input, etc...) EndDrawing(); } @@ -107,3 +68,27 @@ int main () CloseWindow(); return 0; } +void characterMovement(void){ + + //up + if (IsKeyDown(74) ) { + // draw some text using the default font + player.position.y = player.position.y+10; + }; + //down + if (IsKeyDown(75) ) { + player.position.y = player.position.y-10; + // draw some text using the default font + }; + //left + if (IsKeyDown(72) ) { + player.position.x = player.position.x-10; + // draw some text using the default font + }; + //right + if (IsKeyDown(76)) { + player.position.x = player.position.x+10; + // draw some text using the default font + }; + +} \ No newline at end of file