Last updated
Was this helpful?
Was this helpful?
using FlatRedBall;
using FlatRedBall.Math.Geometry;
using Microsoft.Xna.Framework;
using Genbox.VelcroPhysics.Dynamics;
using Genbox.VelcroPhysics.Factories;
namespace VelcroPhysicsTest.Screens;
public partial class GameScreen
{
//Farseer Objects
World mWorld;
Body mBallBody;
Body mPlatformBody;
//FlatRedBall Objects
Circle ball;
Polygon mPlatformPolygon;
void CustomInitialize()
{
// Farseer
float gravity = -80;
mWorld = new World(new Vector2(0, gravity));
//Create a ball body with a radius of 32 and density of 1
mBallBody = BodyFactory.CreateCircle(mWorld, 32, 1);
mBallBody.Restitution = 1f;
mBallBody.BodyType = BodyType.Dynamic;
//Create a rectangle platform with a width of 400, height of 30,
//density of 1, and position at 0, -12
//Then set the position and rotation
var rectangleWidth = 600;
mPlatformBody = BodyFactory.CreateRectangle(mWorld, rectangleWidth, 30, 1, new Vector2(0, -120));
mPlatformBody.Rotation = .1f;
mPlatformBody.Restitution = 1f;
mPlatformBody.BodyType = BodyType.Static;
//FRB
mPlatformPolygon = Polygon.CreateRectangle(rectangleWidth/2, 15f);
mPlatformPolygon.X = mPlatformBody.Position.X;
mPlatformPolygon.Y = mPlatformBody.Position.Y;
mPlatformPolygon.RotationZ = mPlatformBody.Rotation;
ShapeManager.AddPolygon(mPlatformPolygon);
ball = new Circle();
ball.Visible = true;
ball.Radius = 32;
ball.X = mBallBody.Position.X;
ball.Y = mBallBody.Position.Y;
}
void CustomActivity(bool firstTimeCalled)
{
//Farseer: Only need to step (update) the world you added the objects to
mWorld.Step(TimeManager.SecondDifference);
//FRB: Don't forget to update the visual representations as well!!
ball.X = mBallBody.Position.X;
ball.Y = mBallBody.Position.Y;
//mPlatformPolygon is static (doesn't move), so there is no need to update its position
}
void CustomDestroy()
{
}
static void CustomLoadStaticContent(string contentManagerName)
{
}
}