public Ball(Simulation sim, BallData spawn) { simulation = sim; var body = new Body(sim.World); var shape = new CircleShape(radius, 1f); body.BodyType = BodyType.Dynamic; body.FixedRotation = true; body.LinearDamping = drag; body.IsBullet = true; Fixture = body.CreateFixture(shape); Fixture.Restitution = restitution; Fixture.Friction = 0f; Carrier = null; SpawnPos = spawn.Position; Spawn(); }
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) { float x, y; State = (BallState) reader.ReadByte(); switch (State) { case BallState.Carried: var id = reader.ReadInt32(); Carrier = simulation.Ships[id]; Fixture.Body.Enabled = false; simulation.Ships[id].Ball = this; break; case BallState.Free: Carrier = null; Fixture.Body.Enabled = true; 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); break; case BallState.Spawning: Carrier = null; Fixture.Body.Enabled = false; Fixture.Body.LinearVelocity = new Vector2(0f, 0f); Fixture.Body.Position = SpawnPos; SpawnClock = reader.ReadSingle(); break; } }
void HandleLoad(object sender, EventArgs e) { Programs.Load(); Fps = new Fps(); Starfield = new Starfield(); MapMesh = new MapMesh(map); GoalMesh = new SensorMesh<GoalCompiled>(map.Goals, new Texture("Images/goal.png")); SpeedupMesh = new SensorMesh<SpeedupCompiled>(map.Speedups, new Texture("Images/speedup.png")); ShipMesh = new ObjMesh("Models/ship.obj"); BallMesh = new ObjMesh("Models/ball.obj"); GoalieMesh = new ObjMesh("Models/goalie.obj"); Simulation = new Simulation(map); Ship = Simulation.Ships[0]; Nebula = new Image("Images/nebula.png", GameWindow.Width, GameWindow.Height); BallSpawn = new Image("Images/ballspawn.png", -1f, 1f, -1f, 1f); GL.ClearColor(Color.Black); GL.ClearDepth(1.0f); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); GL.Hint(HintTarget.GenerateMipmapHint, HintMode.Nicest); GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest); GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest); GL.Hint(HintTarget.PolygonSmoothHint, HintMode.Nicest); Programs.Material.Use(); Programs.Material.LightDiffuse = light_diffuse; Programs.Material.LightAmbient = light_ambient; Programs.Material.LightSpecular = light_specular; Programs.Material.LightPosition = light_position; }