public Ship(World world, SpawnData spawn, int id) { Ball = null; Id = id; IsThrusting = false; IsReversing = false; IsBoosting = false; IsLeftTurning = false; IsRightTurning = false; IsShooting = false; IsBlocked = false; IsBlockedFrame = false; Color = spawn.Color; var body = new Body(world); body.Rotation = FMath.Atan2(-spawn.Position.Y, -spawn.Position.X); body.Position = spawn.Position; var shape = new CircleShape(radius, 1f); body.BodyType = BodyType.Dynamic; body.FixedRotation = true; Fixture = body.CreateFixture(shape); Fixture.Restitution = restitution; var bodyGravity = new Body(world); bodyGravity.Position = spawn.Position; var shapeGravity = new CircleShape(radiusGravity, 1f); bodyGravity.FixedRotation = true; FixtureGravity = bodyGravity.CreateFixture(shapeGravity); FixtureGravity.IsSensor = true; }
public Simulation(MapCompiled map) { World = new World(Vector2.Zero); fixtureMap = new Dictionary<int, FixtureKey>(); Fixture fixture; FixtureKey key; Goalies = new Goalie[map.Goalies.Length]; for (int i = 0; i < map.Goalies.Length; i++) { Goalies[i] = new Goalie(World, map.Goalies[i]); key.Index = i; key.Kind = FixtureKind.Goalie; fixtureMap[Goalies[i].Fixture.FixtureId] = key; } Balls = new Ball[map.Balls.Length]; for (int i = 0; i < map.Balls.Length; i++) { Balls[i] = new Ball(this, map.Balls[i]); key.Index = i; key.Kind = FixtureKind.Ball; fixtureMap[Balls[i].Fixture.FixtureId] = key; } for (int i = 0; i < map.Walls.Count; i++) { var wall = new Wall(World, map.Walls[i]); foreach (var wallFixture in wall.Fixtures) { key.Index = i; key.Kind = FixtureKind.Wall; fixtureMap[wallFixture.FixtureId] = key; } } Ships = new Ship[map.Spawns.Length]; for (int i = 0; i < map.Spawns.Length; i++) { Ships[i] = new Ship(World, map.Spawns[i], i); key.Index = i; key.Kind = FixtureKind.Ship; fixtureMap[Ships[i].Fixture.FixtureId] = key; key.Kind = FixtureKind.Gravity; fixtureMap[Ships[i].FixtureGravity.FixtureId] = key; } Goals = new Color[map.NumGoalTriangles]; int goalCount = 0; foreach (var goal in map.Goals) { foreach (var tri in goal.Triangles) { var goalBody = new Body(World); var goalShape = new PolygonShape(tri, 1f); fixture = goalBody.CreateFixture(goalShape); fixture.IsSensor = true; key.Index = goalCount; key.Kind = FixtureKind.Goal; fixtureMap[fixture.FixtureId] = key; Goals[goalCount] = goal.Color; goalCount++; } } Speedups = new Vector2[map.NumSpeedupTriangles]; int speedupCount = 0; foreach (var speedup in map.Speedups) { foreach (var tri in speedup.Triangles) { var speedupBody = new Body(World); var speedupShape = new PolygonShape(tri, 1f); fixture = speedupBody.CreateFixture(speedupShape); fixture.IsSensor = true; key.Index = speedupCount; key.Kind = FixtureKind.Speedup; fixtureMap[fixture.FixtureId] = key; Speedups[speedupCount] = speedup.Force; speedupCount++; } } World.ContactManager.ContactFilter = ContactFilter; }
public void UnMarshal(BinaryReader reader) { Ball = null; byte flags = reader.ReadByte(); IsThrusting = (flags >> 0 & 1) == 1; IsReversing = (flags >> 1 & 1) == 1; IsBoosting = (flags >> 2 & 1) == 1; IsLeftTurning = (flags >> 3 & 1) == 1; IsRightTurning = (flags >> 4 & 1) == 1; IsBraking = (flags >> 5 & 1) == 1; IsShooting = (flags >> 6 & 1) == 1; IsBlocked = (flags >> 7 & 1) == 1; float x, y; if (IsShooting) { x = reader.ReadSingle(); y = reader.ReadSingle(); ShotVector = new Vector2(x, y); } x = reader.ReadSingle(); y = reader.ReadSingle(); Fixture.Body.Position = new Vector2(x, y); x = reader.ReadSingle(); y = reader.ReadSingle(); Fixture.Body.LinearVelocity = new Vector2(x, y); Fixture.Body.Rotation = reader.ReadSingle(); }