diff options
Diffstat (limited to 'examples/web/textures/textures_rectangle.c')
| -rw-r--r-- | examples/web/textures/textures_rectangle.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/examples/web/textures/textures_rectangle.c b/examples/web/textures/textures_rectangle.c index c3b7eab..bb230d4 100644 --- a/examples/web/textures/textures_rectangle.c +++ b/examples/web/textures/textures_rectangle.c @@ -21,14 +21,14 @@ //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- -int screenWidth = 800; -int screenHeight = 450; +const int screenWidth = 800; +const int screenHeight = 450; // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) -Texture2D scarfy; +Texture2D scarfy = { 0 }; -Vector2 position; -Rectangle frameRec; +Vector2 position = { 0 }; +Rectangle frameRec = { 0 }; int currentFrame = 0; @@ -41,7 +41,7 @@ int framesSpeed = 8; // Number of spritesheet frames shown by second void UpdateDrawFrame(void); // Update and Draw one frame //---------------------------------------------------------------------------------- -// Main Enry Point +// Program Main Entry Point //---------------------------------------------------------------------------------- int main(void) { @@ -51,16 +51,16 @@ int main(void) scarfy = LoadTexture("resources/scarfy.png"); // Texture loading position = (Vector2){ 350.0f, 280.0f }; - + // NOTE: On PLATFORM_WEB, NPOT textures support is limited frameRec = (Rectangle){ 0, 0, scarfy.width/6, scarfy.height }; - + #if defined(PLATFORM_WEB) emscripten_set_main_loop(UpdateDrawFrame, 0, 1); #else SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- - + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { @@ -71,7 +71,7 @@ int main(void) // De-Initialization //-------------------------------------------------------------------------------------- UnloadTexture(scarfy); // Texture unloading - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- @@ -86,20 +86,20 @@ void UpdateDrawFrame(void) // Update //---------------------------------------------------------------------------------- framesCounter++; - + if (framesCounter >= (60/framesSpeed)) { framesCounter = 0; currentFrame++; - + if (currentFrame > 5) currentFrame = 0; - + frameRec.x = currentFrame*scarfy.width/6; } - + if (IsKeyPressed(KEY_RIGHT)) framesSpeed++; else if (IsKeyPressed(KEY_LEFT)) framesSpeed--; - + if (framesSpeed > MAX_FRAME_SPEED) framesSpeed = MAX_FRAME_SPEED; else if (framesSpeed < MIN_FRAME_SPEED) framesSpeed = MIN_FRAME_SPEED; //---------------------------------------------------------------------------------- @@ -113,17 +113,17 @@ void UpdateDrawFrame(void) DrawTexture(scarfy, 15, 40, WHITE); DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME); DrawRectangleLines(15 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED); - + DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY); DrawText(FormatText("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY); DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, DARKGRAY); - + for (int i = 0; i < MAX_FRAME_SPEED; i++) { if (i < framesSpeed) DrawRectangle(250 + 21*i, 205, 20, 20, RED); DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON); } - + DrawTextureRec(scarfy, frameRec, position, WHITE); // Draw part of the texture DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); |
