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

liitos

parent 0de6714c
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,12 @@ using Jypeli.Controls;
using Jypeli.Widgets;
using System.IO;
using FSJoint = FarseerPhysics.Dynamics.Joints.DistanceJoint;
using FarseerPhysics.Factories;
using FarseerPhysics.Dynamics;
using Jypeli.Farseer;
/// @author vesal
/// @version 2.11.2014
/// <summary>
......@@ -167,6 +173,49 @@ public class Hirsipuu : PhysicsGame
/// </summary>
public class Hirsi : PhysicsObject
{
public class AxleJoint : Jypeli.AxleJoint
{
internal FSJoint InnerJoint
{
get
{
return (FSJoint)innerJoint;
}
set
{
innerJoint = value;
}
}
/// <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)
: 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;
InnerJoint = JointFactory.CreateDistanceJoint(world,
first.FSBody, second.FSBody,
axlePosition * FSConvert.DisplayToSim, ap2 * FSConvert.DisplayToSim);
// axlePosition2 * FSConvert.DisplayToSim);
InnerJoint.DampingRatio = 0.5f;
InnerJoint.Frequency = 50;
//InnerJoint.Enabled = false;
}
}
private static readonly Image Kuva = Game.LoadImage("puupalikka");
private readonly PhysicsGame peli;
private readonly IntMeter palikoita = new IntMeter(0);
......@@ -247,14 +296,14 @@ public class Hirsi : PhysicsObject
PhysicsObject torso = LuoOlio(peli, paa.Position + new Vector(0, -90), 130, 200, Game.LoadImage("torso"));
peli.Add(new AxleJoint(torso, paa,new Vector(7, torso.Height/2-10)));
PhysicsObject vasenKasi = LuoOlio(peli, paa.Position + new Vector(50 + 75, -20), 150, 40, Game.LoadImage("kasi"));
peli.Add(new AxleJoint(vasenKasi, torso, new Vector(-vasenKasi.Width/2*0, 0)));
vasenKasi.Angle = Angle.FromDegrees(-90);
//PhysicsObject vasenKasi = LuoOlio(peli, paa.Position + new Vector(50 + 75, -20), 150, 40, Game.LoadImage("kasi"));
//peli.Add(new AxleJoint(vasenKasi, torso, new Vector(-vasenKasi.Width/2*0, 0)));
//vasenKasi.Angle = Angle.FromDegrees(-90);
PhysicsObject oikeaKasi = LuoOlio(peli, paa.Position + new Vector(-50 + -65, -20), 150, 40, Game.LoadImage("kasi"));
oikeaKasi.Angle = Angle.FromDegrees(180);
peli.Add(new AxleJoint(oikeaKasi, torso, new Vector(oikeaKasi.Width/2, 0)));
peli.Add(new AxleJoint(torso, oikeaKasi, new Vector(-torso.Width/2, -torso.Height/2)));
PhysicsObject vasenJalka = LuoOlio(peli, torso.Position + new Vector(40, -110 - 75), 75, 190, Game.LoadImage("jalka"));
peli.Add(new AxleJoint(vasenJalka, torso, new Vector(0, vasenJalka.Height)));
......
using Jypeli;
using Jypeli.Assets;
using Jypeli.Controls;
using Jypeli.Widgets;
using System;
using System.Collections.Generic;
using FSJoint = FarseerPhysics.Dynamics.Joints.DistanceJoint;
using FarseerPhysics.Factories;
using FarseerPhysics.Dynamics;
using Jypeli.Farseer;
using Jypeli.Physics;
using FarseerPhysics.Dynamics.Joints;
public class Liitos : PhysicsGame
{
......@@ -64,6 +57,7 @@ public class Liitos : PhysicsGame
osa1.MakeStatic();
osa1.AddCollisionIgnoreGroup(1);
Add(osa1);
var osa2 = new PhysicsObject(200, 30);
osa2.Position = new Vector(osa1.Width, 0);
osa2.AddCollisionIgnoreGroup(1);
......@@ -71,6 +65,14 @@ public class Liitos : PhysicsGame
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);
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