Uppdatering
This commit is contained in:
@@ -7,12 +7,14 @@ namespace MetoderUppgift
|
||||
float vMax; // [m/s]
|
||||
float aMax; // [m/s^2]
|
||||
float engineBraking = 2; // [m/s^2]
|
||||
float dt = 0.1f; // [s]
|
||||
float dt = 1 / 50f; // 50 FPS
|
||||
float stripeOffset = 0; // horizontal offset for stripes
|
||||
|
||||
public BilSimulation()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Timer.Interval = (int)(1000 * dt); // s -> ms
|
||||
}
|
||||
void UpdateUI(float acceleration)
|
||||
{
|
||||
@@ -41,12 +43,11 @@ namespace MetoderUppgift
|
||||
|
||||
UpdateUI(acceleration); // Uppdatera kontroller
|
||||
UpdateStripes(); // Uppdatera strecken p<> v<>gen f<>r att simulera grafisk hastighet
|
||||
|
||||
}
|
||||
|
||||
void UpdateStripes()
|
||||
{
|
||||
stripeOffset += 10 * velocity * dt; // Uppdatera avst<73>nd fr<66>n initial plats f<>r varje streck p<> v<>gen
|
||||
stripeOffset += 20 * velocity * dt; // Uppdatera avst<73>nd fr<66>n initial plats f<>r varje streck p<> v<>gen
|
||||
}
|
||||
float GetThrottlePercentage() //Omvanlda gasp<73>drag (0-4) till %
|
||||
{
|
||||
@@ -62,7 +63,7 @@ namespace MetoderUppgift
|
||||
}
|
||||
|
||||
float ratio = (float)throttle / (float)Throttle.Maximum;
|
||||
float acceleration = ratio * aMax * (1.1f - velocity / vMax); // Formel f<>r att g<>ra fysik mer realistisk
|
||||
float acceleration = ratio * aMax * (1.2f - velocity / vMax); // Formel f<>r att g<>ra fysik mer realistisk
|
||||
float netAcceleration = acceleration - engineBraking;
|
||||
|
||||
return netAcceleration;
|
||||
@@ -88,9 +89,9 @@ namespace MetoderUppgift
|
||||
int roadX = 400;
|
||||
int roadWidth = 100;
|
||||
g.FillRectangle(Brushes.DimGray, roadX, 0, roadWidth, ClientSize.Height);
|
||||
|
||||
Car.Location = new Point(roadX + roadWidth/2, ClientSize.Height / 2);
|
||||
Car.Size = new Size(roadWidth/2, roadWidth/2);
|
||||
|
||||
Car.Location = new Point(roadX + roadWidth / 2, ClientSize.Height / 2);
|
||||
Car.Size = new Size(roadWidth / 2, roadWidth / 2);
|
||||
|
||||
|
||||
// Streck
|
||||
@@ -101,14 +102,15 @@ namespace MetoderUppgift
|
||||
int stripeX = roadX + roadWidth / 2 - stripeWidth / 2;
|
||||
int stripeY = 0;
|
||||
|
||||
if ((stripeOffset) > 80)
|
||||
{
|
||||
stripeOffset = 0; // Flytta tillbaka strecken om de hamnar utanf<6E>r rutan.
|
||||
}
|
||||
|
||||
for (int i = 0; i < stripesCount; i++)
|
||||
{
|
||||
g.FillRectangle(Brushes.White, stripeX, stripeY + stripeOffset, stripeWidth, stripeHeight); // Offset uppdateras varje tick. F<>r<EFBFBD>ndringshastighet av hastighet.
|
||||
stripeY += gap;
|
||||
if ((stripeOffset) > 80)
|
||||
{
|
||||
stripeOffset = 0; // Flytta tillbaka strecken om de hamnar utanf<6E>r rutan.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -121,5 +123,10 @@ namespace MetoderUppgift
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void lblMaxHastighet_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user