This commit is contained in:
2026-01-18 22:45:59 +01:00
parent 427812a138
commit d28cf14342
4 changed files with 64 additions and 41 deletions

View File

@@ -1,7 +1,7 @@
using System.Drawing;
namespace MetoderUppgift
{
public partial class Form1 : Form
public partial class BilSimulation : Form
{
float velocity = 0; // [m/s]
float vMax; // [m/s]
@@ -10,11 +10,10 @@ namespace MetoderUppgift
float dt = 0.1f; // [s]
float stripeOffset = 0; // horizontal offset for stripes
public Form1()
public BilSimulation()
{
InitializeComponent();
}
void UpdateUI(float acceleration)
{
lblAcc.Text = "Acceleration: " + acceleration.ToString("0.00") + " [m/s<>]";
@@ -81,21 +80,23 @@ namespace MetoderUppgift
Application.Exit();
}
}
protected override void OnPaint(PaintEventArgs e) // Paint funktion f<>r grafik
{
base.OnPaint(e);
Graphics g = e.Graphics;
int roadX = 800;
int roadWidth = 150;
int roadX = 400;
int roadWidth = 100;
g.FillRectangle(Brushes.DimGray, roadX, 0, roadWidth, ClientSize.Height);
Car.Location = new Point(800, ClientSize.Height / 2);
Car.Location = new Point(roadX + roadWidth/2, ClientSize.Height / 2);
Car.Size = new Size(roadWidth/2, roadWidth/2);
// Streck
int stripeWidth = 10;
int stripeHeight = 30;
int gap = 200;
int stripeWidth = 5;
int stripeHeight = 15;
int gap = 80;
int stripesCount = 5;
int stripeX = roadX + roadWidth / 2 - stripeWidth / 2;
int stripeY = 0;
@@ -104,7 +105,7 @@ namespace MetoderUppgift
{
g.FillRectangle(Brushes.White, stripeX, stripeY + stripeOffset, stripeWidth, stripeHeight); // Offset uppdateras varje tick. F<>r<EFBFBD>ndringshastighet av hastighet.
stripeY += gap;
if ((stripeOffset) > 200)
if ((stripeOffset) > 80)
{
stripeOffset = 0; // Flytta tillbaka strecken om de hamnar utanf<6E>r rutan.
}
@@ -120,6 +121,5 @@ namespace MetoderUppgift
private void Form1_Load(object sender, EventArgs e)
{
}
}
}