Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using GTA;
- using LemonUI.Elements;
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- public class Test : Script
- {
- ScaledRectangle rectangle;
- const int slidingDuration = 3000;
- bool isSlidingRight = true;
- int slidingStartTick;
- int startingPosition;
- bool isSliding = false;
- bool isXPressed = false; // Add this flag
- public Test()
- {
- Tick += OnTick;
- KeyDown += OnKeyDown;
- rectangle = new ScaledRectangle(new PointF(100, 410), new SizeF(400, 400));
- }
- private float lerp(float a, float b, float t)
- {
- return a + (b - a) * t;
- }
- private void OnTick(object sender, EventArgs e)
- {
- if (isSliding)
- {
- float progress = (float)(Game.GameTime - slidingStartTick) / slidingDuration;
- float xPosition = lerp(startingPosition, isSlidingRight ? -500 : 100, progress);
- rectangle.Position = new PointF(xPosition, 410);
- if (progress >= 1f)
- {
- isSliding = false;
- if (isSlidingRight)
- {
- rectangle.Position = new PointF(-500, 410);
- }
- else
- {
- rectangle.Position = new PointF(100, 410);
- }
- }
- }
- if (isXPressed) // Only draw the rectangle if 'X' has been pressed
- {
- rectangle.Draw();
- }
- }
- private void OnKeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.X)
- {
- isSliding = false;
- rectangle.Position = new PointF(100, 410);
- isXPressed = true; // Set the flag to true when 'X' is pressed
- }
- else if (e.KeyCode == Keys.Y)
- {
- if (!isSliding)
- {
- isSliding = true;
- slidingStartTick = Game.GameTime;
- startingPosition = (int)rectangle.Position.X;
- isSlidingRight = !isSlidingRight;
- }
- else
- {
- isSliding = false;
- startingPosition = (int)rectangle.Position.X;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement