Files
test-game/src/main.c
2026-04-21 09:07:46 +02:00

108 lines
2.8 KiB
C

/*
Raylib example file.
This is an example main file for a simple raylib project.
Use this as a starting point or replace it with your code.
by Jeffery Myers is marked with CC0 1.0. To view a copy of this license, visit https://creativecommons.org/publicdomain/zero/1.0/
*/
#include "raylib.h"
#include "resource_dir.h" // utility header for SearchAndSetResourceDir
#include <stdlib.h>
int main ()
{
// Tell the window to use vsync and work on high DPI displays
SetConfigFlags(FLAG_VSYNC_HINT | FLAG_WINDOW_HIGHDPI);
// Create the window and OpenGL context
InitWindow(800, 600, "Hello Emi");
// Utility function from resource_dir.h to find the resources folder and set it as the current working directory so we can load from it
SearchAndSetResourceDir("resources");
// Load a texture from the resources directory
Image image = LoadImage("emi.png");
Texture2D emi = LoadTextureFromImage(image);
UnloadImage(image);
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
{
// drawing
BeginDrawing();
// Setup the back buffer for drawing (clear color and depth buffers)
ClearBackground(BLACK);
DrawRectangle(HorizontalPosition, VerticalPosition, 10, 10, BLUE);
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+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();
}
// cleanup
// unload our texture so it can be cleaned up
UnloadTexture(emi);
// destroy the window and cleanup the OpenGL context
CloseWindow();
return 0;
}