Skip to content
Snippets Groups Projects
Commit 4099fd81 authored by Vesa Lappalainen's avatar Vesa Lappalainen :bicyclist:
Browse files

AxleJoint ehdotus

parent bd87d877
No related branches found
No related tags found
No related merge requests found
......@@ -142,21 +142,31 @@ public class Hirsipuu : PhysicsGame
Add(varjo, 2);
varjo.MoveTo(kuu.Position - new Vector(kuu.Width, 0), 2);
// Pois Zoomaus
double z = Camera.ZoomFactor;
Timer timer = new Timer();
timer.Interval = 0.1;
Color c1 = Color.Brown;
double colorFactor = 0.999;
timer.Timeout += () =>
{
Camera.ZoomFactor = z;
z *= 0.999;
};
timer.Start();
timer.Interval = 0.1;
// Pimennys
Timer timer2 = new Timer();
Color c1 = Color.Brown;
double colorFactor = 0.9;
timer2.Timeout += () =>
{
Level.Background.CreateGradient(c1, Color.Black);
c1.GreenComponent = (byte)(c1.GreenComponent * colorFactor);
c1.RedComponent = (byte)(c1.RedComponent * colorFactor);
c1.BlueComponent = (byte)(c1.BlueComponent * colorFactor);
};
timer.Start();
timer2.Interval = 1;
timer2.Start();
KysyUusi("Hävisit");
}
......@@ -284,7 +294,7 @@ public class Hirsi : PhysicsObject
taso2 = LuoOlio(taso.Position - new Vector(0, 30), 600, 30, Kuva, 1, true, 0);
r1 = LuoOlio(new Vector(taso.Right - kirjaimenKoko * 1.4 - 40 - 20, taso.Top + tolppanKorkeus / 2 - 20 + 1), 40, tolppanKorkeus + 20, Kuva, -1, false, 1);
r2 = LuoOlio(new Vector(taso.Right - 20, taso.Top + tolppanKorkeus / 2 - 20 +1), 40, tolppanKorkeus + 20, Kuva, -1);
r2.CanRotate = false;
r1.CanRotate = r2.CanRotate = false;
peli.Add(new AxleJoint(r1, taso, new Vector(0, -r1.Height / 2 + 10 + 15)));
peli.Add(new AxleJoint(r2, taso, new Vector(0, -r2.Height / 2 + 10 + 15)));
......@@ -356,7 +366,7 @@ public class Hirsi : PhysicsObject
// peli.Remove(taso2);
taso2.Position -= new Vector(0, 100);
paa.Image = Game.LoadImage("kuollutpaa");
r2.CanRotate = true;
r1.CanRotate = r2.CanRotate = true;
Explosion rajahdys = new Explosion(jakkara.Width);
rajahdys.Position = new Vector(taso.Right, taso.Bottom);
......
......@@ -7,29 +7,91 @@ using Jypeli.Farseer;
public class Liitos : PhysicsGame
{
public class AxleJoint : Jypeli.AxleJoint
{
internal FSJoint InnerJoint
{
get
{
return (FSJoint)innerJoint;
}
set
{
innerJoint = value;
}
}
/// <summary>
/// Tällä voi säätää näytetäänkö liitospisteet
/// </summary>
public static bool DrawJointPoints { set; get; }
/// <summary>
/// Luo uuden akseliliitoksen kahden olion välille.
/// </summary>
/// <param name="firstObject">Ensimmäinen olio</param>
/// <param name="secondObject">Toinen olio</param>
/// <param name="axlePosition">Liitoksen akselin paikka</param>
public AxleJoint(PhysicsObject firstObject, PhysicsObject secondObject, Vector axlePosition, Vector axlePosition2)
: base(firstObject, secondObject, axlePosition)
{
World world = PhysicsGame.Instance.Engine as World;
var first = firstObject.Body as PhysicsBody;
var second = secondObject.Body as PhysicsBody;
var ap2 = firstObject.Position + axlePosition;
secondObject.Position = ap2 - axlePosition2;
InnerJoint = JointFactory.CreateDistanceJoint(world,
first.FSBody, second.FSBody,
axlePosition * FSConvert.DisplayToSim, axlePosition2 * FSConvert.DisplayToSim);
// axlePosition2 * FSConvert.DisplayToSim);
InnerJoint.DampingRatio = 0.5f;
InnerJoint.Frequency = 50;
if (!DrawJointPoints) return;
var dot = new GameObject(15, 15, Shape.Circle);
dot.Color = Color.Red;
dot.Position = firstObject.Position + axlePosition;
firstObject.Add(dot);
dot = new GameObject(10, 10, Shape.Circle);
dot.Color = Color.Green;
dot.Position = secondObject.Position + axlePosition2;
secondObject.Add(dot);
//InnerJoint.Enabled = false;
}
}
public override void Begin()
{
// AxleJoint.DrawJointPoints = true;
AxleJoint.DrawJointPoints = true;
double w = 100;
double h = 20;
Level.Background.Color = Color.Black;
var osa1 = new PhysicsObject(200, 30);
var osa1 = new PhysicsObject(w, h);
osa1.Position = new Vector(-w, 300);
osa1.MakeStatic();
osa1.AddCollisionIgnoreGroup(1);
// osa1.AddCollisionIgnoreGroup(1);
Add(osa1);
var osa2 = new PhysicsObject(200, 30);
osa2.Position = new Vector(osa1.Width, 0);
osa2.AddCollisionIgnoreGroup(1);
Add(osa2);
var liitos = new AxleJoint(osa1, osa2, new Vector(osa1.Width/2, 0));
// liitos.Softness = 0;
Add(liitos);
var osa3 = new PhysicsObject(200, 30);
osa3.Position = new Vector(osa1.Width+ osa2.Width, 0);
osa3.AddCollisionIgnoreGroup(1);
Add(osa3);
var liitos2 = new AxleJoint(osa2, osa3, new Vector(osa2.Width / 2, 0));
Add(liitos2);
var osa = osa1;
for (int i = 0; i < 5; i++)
{
var osa2 = new PhysicsObject(w, h);
// osa2.AddCollisionIgnoreGroup(1);
Add(osa2);
var liitos = new AxleJoint(osa, osa2, new Vector(osa.Width / 2, 0), new Vector(-osa2.Width / 2, 0));
// liitos.Softness = 0;
Add(liitos);
osa = osa2;
}
Gravity = new Vector(0, -400);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment