Compare commits

...

2 Commits

Author SHA1 Message Date
056cdf9799 Merge branch 'features/character-movement'
This is for my sanity
2026-04-21 13:27:20 +02:00
a385a24d0f test movement du personnage 2026-04-21 13:19:08 +02:00

View File

@@ -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 "resource_dir.h" // utility header for SearchAndSetResourceDir
#include <stdlib.h> #include <stdlib.h>
typedef struct Player {
Vector2 position;
Vector2 size;
int life;
} Player;
static Player player = {0};
static void characterMovement(void);
int main () int main ()
{ {
// Tell the window to use vsync and work on high DPI displays // Tell the window to use vsync and work on high DPI displays
@@ -31,14 +42,6 @@ int main ()
int HorizontalPosition = 400; int HorizontalPosition = 400;
int VerticalPosition = 300; int VerticalPosition = 300;
int point = 0;
//Start point of the colectible
int positionXCollectible = GetRandomValue(0, 600);
int positionYCollectible = GetRandomValue(0, 800);
// game loop // game loop
while (!WindowShouldClose()) // run the loop until the user presses ESCAPE or presses the Close button on the window 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); ClearBackground(BLACK);
// DrawRectangle(HorizontalPosition, VerticalPosition, 10, 10, BLUE); // 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); characterMovement();
//draw score
DrawText(TextFormat("score : %d", point), 500,50,20,PINK);
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(); EndDrawing();
} }
@@ -107,3 +68,27 @@ int main ()
CloseWindow(); CloseWindow();
return 0; 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
};
}