Update core_automation_events.c

This commit is contained in:
Ray 2023-10-27 00:45:00 +02:00
parent 99dac5451c
commit 654b4e6257

View file

@ -77,7 +77,7 @@ int main(void)
int frameCounter = 0; int frameCounter = 0;
int playFrameCounter = 0; int playFrameCounter = 0;
int currentFrame = 0; int currentPlayFrame = 0;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -87,7 +87,7 @@ int main(void)
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
float deltaTime = GetFrameTime(); float deltaTime = 0.015f;//GetFrameTime();
// Dropped files logic // Dropped files logic
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -106,6 +106,7 @@ int main(void)
// Reset scene state to play // Reset scene state to play
eventPlaying = true; eventPlaying = true;
playFrameCounter = 0; playFrameCounter = 0;
currentPlayFrame = 0;
player.position = (Vector2){ 400, 280 }; player.position = (Vector2){ 400, 280 };
player.speed = 0; player.speed = 0;
@ -163,8 +164,15 @@ int main(void)
if (IsKeyPressed(KEY_R)) if (IsKeyPressed(KEY_R))
{ {
camera.zoom = 1.0f; // Reset game state
player.position = (Vector2){ 400, 280 }; player.position = (Vector2){ 400, 280 };
player.speed = 0;
player.canJump = false;
camera.target = player.position;
camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f };
camera.rotation = 0.0f;
camera.zoom = 1.0f;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -193,7 +201,7 @@ int main(void)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Toggle events recording // Toggle events recording
if (IsKeyPressed(KEY_ONE)) if (IsKeyPressed(KEY_F2))
{ {
if (!eventPlaying) if (!eventPlaying)
{ {
@ -211,18 +219,37 @@ int main(void)
} }
} }
} }
else if (IsKeyPressed(KEY_F3))
{
if (!eventRecording && (aelist.count > 0))
{
// Reset scene state to play
eventPlaying = true;
playFrameCounter = 0;
currentPlayFrame = 0;
player.position = (Vector2){ 400, 280 };
player.speed = 0;
player.canJump = false;
camera.target = player.position;
camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f };
camera.rotation = 0.0f;
camera.zoom = 1.0f;
}
}
if (eventPlaying) if (eventPlaying)
{ {
if (playFrameCounter == aelist.events[currentFrame].frame) if (playFrameCounter >= aelist.events[currentPlayFrame].frame)
{ {
PlayAutomationEvent(aelist.events[currentFrame]); PlayAutomationEvent(aelist.events[currentPlayFrame]);
currentFrame++; currentPlayFrame++;
if (currentFrame == aelist.count) if (currentPlayFrame == aelist.count)
{ {
eventPlaying = false; eventPlaying = false;
currentFrame = 0; currentPlayFrame = 0;
playFrameCounter = 0; playFrameCounter = 0;
} }
} }
@ -253,28 +280,36 @@ int main(void)
EndMode2D(); EndMode2D();
// Draw game controls
DrawRectangle(10, 10, 290, 145, Fade(SKYBLUE, 0.5f));
DrawRectangleLines(10, 10, 290, 145, Fade(BLUE, 0.8f));
DrawText("Controls:", 20, 20, 10, BLACK);
DrawText("- RIGHT | LEFT: Player movement", 30, 40, 10, DARKGRAY);
DrawText("- SPACE: Player jump", 30, 60, 10, DARKGRAY);
DrawText("- R: Reset game state", 30, 80, 10, DARKGRAY);
DrawText("- F2: START/STOP RECORDING INPUT EVENTS", 30, 110, 10, BLACK);
DrawText("- F3: REPLAY LAST RECORDED INPUT EVENTS", 30, 130, 10, BLACK);
// Draw automation events recording indicator // Draw automation events recording indicator
if (eventRecording) if (eventRecording)
{ {
if (((frameCounter/15)%2) == 1) DrawRectangle(10, 160, 290, 30, Fade(RED, 0.3f));
{ DrawRectangleLines(10, 160, 290, 30, Fade(MAROON, 0.8f));
DrawCircle(GetScreenWidth() - 200, 20, 10, MAROON); DrawCircle(30, 175, 10, MAROON);
DrawText(TextFormat("RECORDING EVENTS... [%i]", aelist.count), GetScreenWidth() - 180, 15, 10, RED);
} if (((frameCounter/15)%2) == 1) DrawText(TextFormat("RECORDING EVENTS... [%i]", aelist.count), 50, 170, 10, MAROON);
} }
else if (eventPlaying) else if (eventPlaying)
{ {
if (((frameCounter/15)%2) == 1) DrawRectangle(10, 160, 290, 30, Fade(LIME, 0.3f));
{ DrawRectangleLines(10, 160, 290, 30, Fade(DARKGREEN, 0.8f));
DrawTriangle((Vector2){ GetScreenWidth() - 200, 10 }, (Vector2){ GetScreenWidth() - 200, 30 }, (Vector2){ GetScreenWidth() - 200 + 20, 20 }, DARKGREEN); DrawTriangle((Vector2){ 20, 155 + 10 }, (Vector2){ 20, 155 + 30 }, (Vector2){ 40, 155 + 20 }, DARKGREEN);
DrawText(TextFormat("PLAYING EVENTS... [%i]", currentFrame), GetScreenWidth() - 170, 15, 10, LIME);
} if (((frameCounter/15)%2) == 1) DrawText(TextFormat("PLAYING RECORDED EVENTS... [%i]", currentPlayFrame), 50, 170, 10, DARKGREEN);
} }
DrawText("Controls:", 20, 20, 10, BLACK);
DrawText("- Right/Left to move", 30, 40, 10, DARKGRAY);
DrawText("- Space to jump", 30, 60, 10, DARKGRAY);
DrawText("- Mouse Wheel to Zoom in-out, R to reset zoom", 30, 80, 10, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------