-
Notifications
You must be signed in to change notification settings - Fork 10
/
Beginners_-_Player_Struct.c
66 lines (49 loc) · 2.17 KB
/
Beginners_-_Player_Struct.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "raylib.h"
// Our player struct
typedef struct Player {
Vector2 position;
Vector2 size;
float speed;
int energy;
} Player;
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib example.");
// Here we initialise our player.
Player player = {0};
player.position = (Vector2){400,200};
player.size = (Vector2){32,48};
player.speed = 1.5f;
player.energy = 10.0f;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
// Draw our player.
DrawRectangle(player.position.x,player.position.y,player.size.x,player.size.y,RED);
// Draw our player info.
DrawText(FormatText("Player x: %i ",player.position.x),0,0,20,BLACK);
DrawText(FormatText("Player y: %i ",player.position.y),0,20,20,BLACK);
DrawText(FormatText("Player speed: %02.02f ",player.speed),0,40,20,BLACK);
DrawText(FormatText("Player energy: %i ",player.energy),0,60,20,BLACK);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}