Represents the Terrain.
예제 #1
0
        /// <summary>
        /// Removes the old terrain physics bodies and replaces them with new ones,
        /// generated from the given terrain.
        /// </summary>
        public void UpdateTerrainBody(Terrain terrain)
        {
            Terrain = terrain;
            foreach (var body in TerrainBodies)
            {
                var fixtures = body.FixtureList.ToArray();
                foreach (var fixture in fixtures)
                {
                    fixture.Dispose();
                }

                body.Dispose();
            }

            TerrainBodies.Clear();

            // Update the terrain explicitly
            terrain.Update();
            var outlines = terrain.GetOutline();
            
            foreach (var outline in outlines)
            {
                var vertices = new Vector2[outline.Count];

                for (int i = 0; i < outline.Count; i++)
                {
                    vertices[i] = outline[i] * terrain.Scale;
                }

                var shape = new ChainShape(new Vertices(vertices));

                var body = new Body(PhysicsWorld);
                body.BodyType = BodyType.Static;
                body.Friction = 1.0f;
                body.CreateFixture(shape);

                TerrainBodies.Add(body);
            }
        }
예제 #2
0
파일: World.cs 프로젝트: SpagAachen/Ballz
 public World(Terrain newTerrain)
 {
     StaticGeometry = newTerrain;
     Water = new Water(50,25);
 }
예제 #3
0
파일: World.cs 프로젝트: LukasBoersma/Ballz
 public World(List<Entity> newEntitites, Terrain newTerrain)
 {
     Entities = newEntitites;
     StaticGeometry = newTerrain;
 }
예제 #4
0
파일: Shot.cs 프로젝트: SpagAachen/Ballz
        public override void OnTerrainCollision(Terrain terrain, Vector2 position)
        {
            if (Ballz.The().Match.IsRemoteControlled)
                return;

            float impact = 0.04f * Velocity.Length() * BulletHoleRadius;
            if (impact > 0.2)
            {
                // Destroy terrain and die
                terrain.SubtractCircle(position.X, position.Y, impact);
            }

            onAnyCollision();
        }