Compare commits

..

2 Commits

Author SHA1 Message Date
Émi Lefèvre
84abf9f447 Add static methods for better architecture (wip) 2026-04-21 13:04:37 +02:00
Émi Lefèvre
506cef572d Add speed variable 2026-04-21 13:04:37 +02:00

View File

@@ -12,15 +12,14 @@ 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 <stdlib.h>
typedef struct Player {
Vector2 position;
Vector2 size;
int life;
} Player;
static Player player = {0};
static void characterMovement(void);
//------------------------------------------------------------------------------------
// Module Functions Declaration (local)
//------------------------------------------------------------------------------------
static void InitGame(void); // Initialize game
static void UpdateGame(void); // Update game (one frame)
static void DrawGame(void); // Draw game (one frame)
static void UnloadGame(void); // Unload game
static void UpdateDrawFrame(void); // Update and Draw (one frame)
int main ()
@@ -42,6 +41,17 @@ 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);
// Character controller settings
int speed = 2;
// game loop
while (!WindowShouldClose()) // run the loop until the user presses ESCAPE or presses the Close button on the window
{
@@ -52,11 +62,53 @@ int main ()
ClearBackground(BLACK);
// DrawRectangle(HorizontalPosition, VerticalPosition, 10, 10, BLUE);
DrawTexture(emi, player.position.x, player.position.y, WHITE);
characterMovement();
DrawTexture(emi, HorizontalPosition, VerticalPosition, WHITE);
DrawCircle(positionXCollectible, positionYCollectible, 10, YELLOW);
//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+speed;
};
//down
if (IsKeyDown(75) && VerticalPosition != 0) {
VerticalPosition = VerticalPosition-speed;
// draw some text using the default font
};
//left
if (IsKeyDown(72) && HorizontalPosition != 0) {
HorizontalPosition = HorizontalPosition-speed;
// draw some text using the default font
};
//right
if (IsKeyDown(76)&& HorizontalPosition != 780) {
HorizontalPosition = HorizontalPosition+speed;
// 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();
}
@@ -68,27 +120,29 @@ 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
};
void InitGame(void)
{
return;
}
void UpdateGame(void)
{
return;
}
void DrawGame(void)
{
return;
}
void UnloadGame(void)
{
return;
}
void UpdateDrawFrame(void)
{
UpdateGame();
DrawGame();
}