Just playing.
Does this seem a viable option for testing the movement bounds ??
I’d like to split some of this functionality out of main() , but I haven’t learnt how yet in C++
#include "raylib.h"
int main()
{
// window dimensions : braced initialization
int width{ 350 };
int height{ 200 };
int textHeight{ 30 };
InitWindow(width, height, "Phreds's Play Window");
int circle_x{ 175 };
int circle_y{ 100 };
float circle_radius{ 25 };
int move_distance{ 5 };
int min_x{ (int)circle_radius };
int max_x{ width - (int)circle_radius };
int min_y{ (int)circle_radius };
int max_y{ height - (int)circle_radius };
SetTargetFPS(60);
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(GRAY);
DrawCircle(circle_x, circle_y, circle_radius, BLUE);
// multiple keys accepted each frame for MOVEMENT.
if (IsKeyDown(KEY_D) || (IsKeyDown(KEY_RIGHT)))
{
circle_x += move_distance;
}
if (IsKeyDown(KEY_A) || (IsKeyDown(KEY_LEFT)))
{
circle_x -= move_distance;
}
if (IsKeyDown(KEY_W) || (IsKeyDown(KEY_UP)))
{
circle_y -= move_distance;
}
if (IsKeyDown(KEY_S) || (IsKeyDown(KEY_DOWN)))
{
circle_y += move_distance;
}
circle_x = circle_x < min_x ? min_x
: circle_x > max_x ? max_x
: circle_x;
circle_y = circle_y < min_y ? min_y
: circle_y > max_y ? max_y
: circle_y;
DrawText("Waiting . . . !", 40, 125, textHeight, RED);
EndDrawing();
}
return 0;
}