-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeightSistem.cs
93 lines (73 loc) · 2.85 KB
/
WeightSistem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Fizzhz
{
public class WeightSistem
{
public Vector2 Position;
public Slider a;
public Slider k;
public Slider m;
public Color Color;
public Button PlayStop;
public Button Reset;
public WeightSistem(Color color, Vector2 position)
{
Color = color;
Position = position;
a = new Slider(position - new Vector2(150, 100), 20, 0, 0, 100, "y0", true);
k = new Slider(position - new Vector2(150, 75), new float[] { 50, 100, 200}, 1, 100, "k");
m = new Slider(position - new Vector2(150, 50), new float[] { 50, 100, 200 }, 1, 100, "m");
PlayStop = new Button(new Vector2((int)position.X - 150, (int)position.Y), delegate {
Playing = !Playing;
}, "Play");
Reset = new Button(new Vector2((int)position.X - 150, (int)position.Y + 50), delegate {
TotalTime = 0;
}, "Reset");
}
public double TotalTime = 0;
public int Y = 0;
public bool Playing = false;
public void Update(GameTime gameTime){
PlayStop.Update(gameTime);
Reset.Update(gameTime);
a.Update();
k.Update();
m.Update();
if (!Playing)
return;
TotalTime += gameTime.ElapsedGameTime.TotalSeconds;
Y = (int)(a.CurrentValue * 3 * (float)Math.Sin(TotalTime / Math.Sqrt(k.CurrentValue / m.CurrentValue) + Math.PI/2));
}
public void Draw(SpriteBatch spriteBatch, GameTime gameTime){
a.Draw(spriteBatch);
k.Draw(spriteBatch);
m.Draw(spriteBatch);
PlayStop.Draw(spriteBatch, gameTime);
Reset.Draw(spriteBatch, gameTime);
//spriteBatch.DrawString(Game1.MainFont, String.Format("y = {0} * sin( pi * {1} * t + pi * {2})", a.CurrentValue, 2 / b.CurrentValue, c.CurrentValue), Position - new Vector2(150, 130), Color.White);
spriteBatch.Draw(
Game1.SpringTexture,
new Rectangle((int)Position.X, -100, 20 , (int)Position.Y + Y + 100),
null,
Color.White,
0f,
Vector2.Zero,
SpriteEffects.None,
0f
);
spriteBatch.Draw(
Game1.EmptyTexture,
new Rectangle((int)Position.X, (int)Position.Y + Y, 20, 20),
null,
Color,
0f,
Vector2.Zero,
SpriteEffects.None,
0f
);
spriteBatch.DrawString(Game1.MainFont, Math.Round(TotalTime, 3).ToString(), Position - new Vector2(150, -100), Color.White);
}
}
}