Compare commits
3 Commits
main
...
e1741e793d
| Author | SHA1 | Date | |
|---|---|---|---|
| e1741e793d | |||
|
|
84abf9f447 | ||
|
|
506cef572d |
122
src/main.c
122
src/main.c
@@ -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 "resource_dir.h" // utility header for SearchAndSetResourceDir
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
typedef struct Player {
|
//------------------------------------------------------------------------------------
|
||||||
Vector2 position;
|
// Module Functions Declaration (local)
|
||||||
Vector2 size;
|
//------------------------------------------------------------------------------------
|
||||||
int life;
|
static void InitGame(void); // Initialize game
|
||||||
} Player;
|
static void UpdateGame(void); // Update game (one frame)
|
||||||
|
static void DrawGame(void); // Draw game (one frame)
|
||||||
static Player player = {0};
|
static void UnloadGame(void); // Unload game
|
||||||
|
static void UpdateDrawFrame(void); // Update and Draw (one frame)
|
||||||
static void characterMovement(void);
|
|
||||||
|
|
||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
@@ -42,6 +41,17 @@ 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);
|
||||||
|
|
||||||
|
// Character controller settings
|
||||||
|
int speed = 2;
|
||||||
|
|
||||||
|
|
||||||
// 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
|
||||||
{
|
{
|
||||||
@@ -52,11 +62,53 @@ int main ()
|
|||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
// DrawRectangle(HorizontalPosition, VerticalPosition, 10, 10, BLUE);
|
// DrawRectangle(HorizontalPosition, VerticalPosition, 10, 10, BLUE);
|
||||||
DrawTexture(emi, player.position.x, player.position.y, WHITE);
|
DrawTexture(emi, HorizontalPosition, VerticalPosition, WHITE);
|
||||||
|
|
||||||
|
|
||||||
characterMovement();
|
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();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,27 +120,29 @@ int main ()
|
|||||||
CloseWindow();
|
CloseWindow();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void characterMovement(void){
|
|
||||||
|
|
||||||
//up
|
void InitGame(void)
|
||||||
if (IsKeyDown(74) ) {
|
{
|
||||||
// draw some text using the default font
|
return;
|
||||||
player.position.y = player.position.y+10;
|
}
|
||||||
};
|
|
||||||
//down
|
void UpdateGame(void)
|
||||||
if (IsKeyDown(75) ) {
|
{
|
||||||
player.position.y = player.position.y-10;
|
return;
|
||||||
// draw some text using the default font
|
}
|
||||||
};
|
|
||||||
//left
|
void DrawGame(void)
|
||||||
if (IsKeyDown(72) ) {
|
{
|
||||||
player.position.x = player.position.x-10;
|
return;
|
||||||
// draw some text using the default font
|
}
|
||||||
};
|
|
||||||
//right
|
void UnloadGame(void)
|
||||||
if (IsKeyDown(76)) {
|
{
|
||||||
player.position.x = player.position.x+10;
|
return;
|
||||||
// draw some text using the default font
|
}
|
||||||
};
|
|
||||||
|
void UpdateDrawFrame(void)
|
||||||
}
|
{
|
||||||
|
UpdateGame();
|
||||||
|
DrawGame();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user