Skip to content

Instantly share code, notes, and snippets.

@JeffM2501
Created April 2, 2021 14:10
Show Gist options
  • Save JeffM2501/588d8b632d1bf49c7f010dde0a9dcbee to your computer and use it in GitHub Desktop.
Save JeffM2501/588d8b632d1bf49c7f010dde0a9dcbee to your computer and use it in GitHub Desktop.
test showing how frame based motion can be problematic
/*******************************************************************************************
*
* raylib [core] example - Basic window
*
* Welcome to raylib!
*
* To test examples, just press F6 and execute raylib_compile_execute script
* Note that compiled executable is placed in the same folder as .c file
*
* You can find all basic examples on C:\raylib\raylib\examples folder or
* raylib official webpage: www.raylib.com
*
* Enjoy using raylib. :)
*
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
Vector2 pos = { 10, 50 };
bool useTime = true;
float speedTime = 100;
float speedFrames = 2;
float dir = 1;
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
SetTargetFPS(GetRandomValue(30, 120)); // Set our game to run at 60 frames-per-second
if (IsKeyPressed(KEY_SPACE))
useTime = !useTime;
if (useTime)
{
pos.x += speedTime * GetFrameTime() * dir;
}
else
{
pos.x += speedFrames * dir;
}
if (pos.x > 780 && dir > 0)
dir = -1;
if (pos.x < 10 && dir < 0)
dir = 1;
BeginDrawing();
ClearBackground(RAYWHITE);
DrawCircle(pos.x, pos.y, 10, RED);
DrawText("Press Space to Toggle Mode", 60, GetScreenHeight()-20, 20, LIGHTGRAY);
DrawFPS(0, 0);
DrawText(useTime ? "Using Time" : "Using Frames", 120, 0, 20, BLACK);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment