public GameLevelPhysicsScreen(Level Lvl, int LevelIndex) { this.CurrentLevel = Lvl; this._currentLevelIndex = LevelIndex; this.EnabledGestures = Microsoft.Xna.Framework.Input.Touch.GestureType.Tap; }
public GameLevelPhysicsScreen(Level Lvl, int LevelIndex, Vector2 CameraPos, Vector2 BallPos, int DistanceTravelled, int DiamondsCollected, Vector2 BackgroundPosition) : this(Lvl, LevelIndex) { this._cameraPosition = CameraPos; this._ballPosition = BallPos; this._distanceTravelled = DistanceTravelled; this._diamondsCollected = DiamondsCollected; this._backgroundPosition = BackgroundPosition; }
private void PlottLevelData(Level lvl) { int TotalColumns = lvl.Width / Assets.CELLSIZE; int TotalRows = lvl.Height / Assets.CELLSIZE; //Create Cell Matrix int[,] matrix = new int[TotalRows, TotalColumns]; for (int i = 0; i < TotalRows; i++) for (int j = 0; j < TotalColumns; j++) matrix[i, j] = 0; //Create Physics Object from Entity _ballEntity = null; bool CreateRectangle = false; string TextureForRectangle = string.Empty; GameObjectData additionData; Body body; Vertices vertices; foreach (Entity item in lvl.LevelEntities) { CreateRectangle = false; TextureForRectangle = string.Empty; additionData = new GameObjectData(GameObjectType.NONE); body = BodyFactory.CreateBody(World); body.SleepingAllowed = true; switch (item.Type) { case EntityType.Obstacle1: case EntityType.Obstacle2: case EntityType.Obstacle3: case EntityType.Obstacle4: case EntityType.Obstacle5: case EntityType.Obstacle6: TextureForRectangle = Assets.Obstacle(item.Type); CreateRectangle = true; additionData.Type = GameObjectType.NONE; break; case EntityType.SpikeRight: vertices = CreateRightSpike(matrix, body, item); break; case EntityType.SpikeLeft: vertices = CreateLeftSpike(matrix, body, item); break; case EntityType.SpikeUp: vertices = CreateUpSpike(matrix, body, item); break; case EntityType.SpikeDown: vertices = CreateDownSpike(matrix, body, item); break; case EntityType.FloorLeft: case EntityType.FloorMiddle: case EntityType.FloorRight: CreateFloor(body, item); //Fill Matrix Position matrix[item.Y, item.X] = 1; matrix[item.Y + 1, item.X] = 1; break; case EntityType.Ball: _ballEntity = item; //Fill Matrix Position matrix[item.Y, item.X] = 1; matrix[item.Y + 1, item.X] = 1; matrix[item.Y, item.X + 1] = 1; matrix[item.Y + 1, item.X + 1] = 1; break; case EntityType.WoodDiamond: CreateDiamond(body, item); //Fill Matrix Position matrix[item.Y, item.X] = 1; matrix[item.Y + 1, item.X] = 1; matrix[item.Y, item.X + 1] = 1; matrix[item.Y + 1, item.X + 1] = 1; break; } if (CreateRectangle) { if (item.Type == EntityType.Obstacle1 || item.Type == EntityType.Obstacle2 || item.Type == EntityType.Obstacle3 || item.Type == EntityType.Obstacle4 || item.Type == EntityType.Obstacle5 || item.Type == EntityType.Obstacle6) { FixtureFactory.CreateRectangle(ConvertUnits.ToSimUnits(Assets.CELLSIZE - 2), 0.1f, Assets.DENSITY, new Vector2(0, 1.7f), body, new RenderMaterial(GetTexture(TextureForRectangle), TextureForRectangle, Assets.CELLSIZE_FARSEER) { Color = Color.White, UserData = new GameObjectData(GameObjectType.SOLIDOBJECT) }); } FixtureFactory.CreateRectangle(Assets.CELLSIZE_FARSEER, Assets.CELLSIZE_FARSEER, Assets.DENSITY, new Vector2(0, 0), body, new RenderMaterial(GetTexture(TextureForRectangle), TextureForRectangle, Assets.CELLSIZE_FARSEER) { UserData = additionData }); body.IsStatic = true; body.Position = Camera2D.ConvertScreenToWorld(new Vector2(item.X * Assets.CELLSIZE + Assets.CELLSIZE / 2, item.Y * Assets.CELLSIZE + Assets.CELLSIZE / 2)); //Fill Matrix Position matrix[item.Y, item.X] = 1; } if (body != null) { foreach (Fixture fixture in body.FixtureList) { fixture.Restitution = Assets.RESTITUTION; fixture.Friction = Assets.FRICTION; } } } //Create Ball. CreateBall(); //Create Solid Floor where no other object placed. CreateSolidFloor(TotalColumns, TotalRows, matrix); //Cerate Level Completion wall. CreateLevelCompletedWall(TotalColumns, TotalRows); }