You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/*
Raylib example file.
This is an example main file for a simple C/C++raylib project.
*/
#include "raylib.h"
#include "raymath.h"
// global for pause state
bool Paused = false;
int main ()
{
// set up the window
InitWindow(1280, 800, "Raylib Pause Example");
SetTargetFPS(144);
// setup ball info
float radius = 20;
float speed = 400;
Vector2 pos = { radius, 400 };
Vector2 dir = { 1,0 };
// game loop
while (!WindowShouldClose())
{
// check to see if we need to change the pause state
if (IsKeyPressed(KEY_SPACE))
Paused = !Paused;
// only update our position if we are not paused
if (!Paused)
{
// move the ball based on the speed and the frame time
pos = Vector2Add(pos, Vector2Scale(dir, GetFrameTime() * speed));
if (pos.x > GetScreenWidth() - radius) // check if we have gone over the right edge, and if so, bounce us
{
pos.x = GetScreenWidth() - radius;
dir.x = -1;
}
else if (pos.x < radius) // check if we have gone over the left edge
{
pos.x = radius;
dir.x = 1;
}
}
// drawing
BeginDrawing();
ClearBackground(BLACK);
// draw the ball where it is
DrawCircleV(pos, radius, RED);
// if we are paused, draw a pause messages
if (Paused)
DrawText("Paused", 600, 380, 40, GREEN);
EndDrawing();
}
// cleanup
CloseWindow();
return 0;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Beta Was this translation helpful? Give feedback.
All reactions