Compare commits
2 Commits
93bca5b327
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 056cdf9799 | |||
| a385a24d0f |
91
src/main.c
91
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 "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);
|
||||||
|
|
||||||
|
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+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
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user