diff --git a/MetoderUppgift/Form1.Designer.cs b/MetoderUppgift/Form1.Designer.cs index e1fb2a3..ba33ed2 100644 --- a/MetoderUppgift/Form1.Designer.cs +++ b/MetoderUppgift/Form1.Designer.cs @@ -2,7 +2,7 @@ namespace MetoderUppgift { - partial class Form1 + partial class BilSimulation { /// /// Required designer variable. @@ -48,45 +48,50 @@ namespace MetoderUppgift // // Throttle // - Throttle.Location = new Point(12, 438); + Throttle.Location = new Point(6, 205); + Throttle.Margin = new Padding(2, 1, 2, 1); Throttle.Maximum = 4; Throttle.Name = "Throttle"; - Throttle.Size = new Size(208, 90); + Throttle.Size = new Size(112, 45); Throttle.TabIndex = 0; Throttle.Value = 2; // // lblThr // lblThr.AutoSize = true; - lblThr.Location = new Point(50, 514); + lblThr.Location = new Point(27, 241); + lblThr.Margin = new Padding(2, 0, 2, 0); lblThr.Name = "lblThr"; - lblThr.Size = new Size(126, 32); + lblThr.Size = new Size(63, 15); lblThr.TabIndex = 1; lblThr.Text = "GaspÃ¥drag"; // // lblVel // lblVel.AutoSize = true; - lblVel.Location = new Point(26, 327); + lblVel.Location = new Point(14, 153); + lblVel.Margin = new Padding(2, 0, 2, 0); lblVel.Name = "lblVel"; - lblVel.Size = new Size(116, 32); + lblVel.Size = new Size(58, 15); lblVel.TabIndex = 2; lblVel.Text = "Hastighet"; // // lblAcc // lblAcc.AutoSize = true; - lblAcc.Location = new Point(26, 378); + lblAcc.Location = new Point(14, 177); + lblAcc.Margin = new Padding(2, 0, 2, 0); lblAcc.Name = "lblAcc"; - lblAcc.Size = new Size(145, 32); + lblAcc.Size = new Size(73, 15); lblAcc.TabIndex = 3; lblAcc.Text = "Acceleration"; // // btnStart // - btnStart.Location = new Point(26, 260); + btnStart.Location = new Point(14, 122); + btnStart.Margin = new Padding(2, 1, 2, 1); btnStart.Name = "btnStart"; - btnStart.Size = new Size(150, 46); + btnStart.Size = new Size(81, 22); btnStart.TabIndex = 4; btnStart.Text = "Starta"; btnStart.UseVisualStyleBackColor = true; @@ -102,50 +107,55 @@ namespace MetoderUppgift Car.BackColor = Color.Transparent; Car.BackgroundImageLayout = ImageLayout.None; Car.Image = Properties.Resources.Car; - Car.Location = new Point(552, 277); + Car.Location = new Point(331, 106); + Car.Margin = new Padding(2, 1, 2, 1); Car.Name = "Car"; - Car.Size = new Size(148, 159); + Car.Size = new Size(153, 150); Car.SizeMode = PictureBoxSizeMode.Zoom; Car.TabIndex = 7; Car.TabStop = false; // // tbxAcceleration // - tbxAcceleration.Location = new Point(26, 153); + tbxAcceleration.Location = new Point(14, 72); + tbxAcceleration.Margin = new Padding(2, 1, 2, 1); tbxAcceleration.Name = "tbxAcceleration"; - tbxAcceleration.Size = new Size(288, 39); + tbxAcceleration.Size = new Size(268, 23); tbxAcceleration.TabIndex = 8; // // tbxVelocity // - tbxVelocity.Location = new Point(26, 64); + tbxVelocity.Location = new Point(14, 30); + tbxVelocity.Margin = new Padding(2, 1, 2, 1); tbxVelocity.Name = "tbxVelocity"; - tbxVelocity.Size = new Size(288, 39); + tbxVelocity.Size = new Size(268, 23); tbxVelocity.TabIndex = 9; // // lblMaxAcceleration // lblMaxAcceleration.AutoSize = true; - lblMaxAcceleration.Location = new Point(26, 118); + lblMaxAcceleration.Location = new Point(14, 55); + lblMaxAcceleration.Margin = new Padding(2, 0, 2, 0); lblMaxAcceleration.Name = "lblMaxAcceleration"; - lblMaxAcceleration.Size = new Size(280, 32); + lblMaxAcceleration.Size = new Size(248, 15); lblMaxAcceleration.TabIndex = 10; - lblMaxAcceleration.Text = "MaxAcceleration [m/s^2]"; + lblMaxAcceleration.Text = "MaxAcceleration [m/s^2] (Recommended 10)"; // // lblMaxHastighet // lblMaxHastighet.AutoSize = true; - lblMaxHastighet.Location = new Point(26, 29); + lblMaxHastighet.Location = new Point(14, 14); + lblMaxHastighet.Margin = new Padding(2, 0, 2, 0); lblMaxHastighet.Name = "lblMaxHastighet"; - lblMaxHastighet.Size = new Size(226, 32); + lblMaxHastighet.Size = new Size(223, 15); lblMaxHastighet.TabIndex = 11; - lblMaxHastighet.Text = "Max hastighet [m/s]"; + lblMaxHastighet.Text = "Max hastighet [m/s] (Recommended: 30)"; // - // Form1 + // BilSimulation // - AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1083, 622); + ClientSize = new Size(583, 292); Controls.Add(lblMaxHastighet); Controls.Add(lblMaxAcceleration); Controls.Add(tbxVelocity); @@ -156,9 +166,10 @@ namespace MetoderUppgift Controls.Add(lblVel); Controls.Add(lblThr); Controls.Add(Throttle); + Margin = new Padding(2, 1, 2, 1); MaximizeBox = false; - Name = "Form1"; - Text = "Form1"; + Name = "BilSimulation"; + Text = "Bil Simulation"; Load += Form1_Load; ((System.ComponentModel.ISupportInitialize)Throttle).EndInit(); ((System.ComponentModel.ISupportInitialize)Car).EndInit(); diff --git a/MetoderUppgift/Form1.cs b/MetoderUppgift/Form1.cs index 1f920af..2537422 100644 --- a/MetoderUppgift/Form1.cs +++ b/MetoderUppgift/Form1.cs @@ -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ändringshastighet av hastighet. stripeY += gap; - if ((stripeOffset) > 200) + if ((stripeOffset) > 80) { stripeOffset = 0; // Flytta tillbaka strecken om de hamnar utanför rutan. } @@ -120,6 +121,5 @@ namespace MetoderUppgift private void Form1_Load(object sender, EventArgs e) { } - } } diff --git a/MetoderUppgift/MetoderUppgift.csproj b/MetoderUppgift/MetoderUppgift.csproj index afba0ba..c196df0 100644 --- a/MetoderUppgift/MetoderUppgift.csproj +++ b/MetoderUppgift/MetoderUppgift.csproj @@ -27,4 +27,16 @@ + + + Always + + + Always + + + Always + + + \ No newline at end of file diff --git a/MetoderUppgift/Program.cs b/MetoderUppgift/Program.cs index 464b69f..58a08dc 100644 --- a/MetoderUppgift/Program.cs +++ b/MetoderUppgift/Program.cs @@ -11,7 +11,7 @@ namespace MetoderUppgift // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new BilSimulation()); } } } \ No newline at end of file