/// <summary> /// Generates vertex and index information for this block. /// </summary> public VertexIndexData GenerateVertices(Room CurrentRoom, Vector3 Position) { Vector3 MasterBottomLeftFront = new Vector3(Size, Size, Size) * Position; Vector3 MasterTopRightBack = MasterBottomLeftFront + new Vector3(Size, Size, Size); Vector3 topLeftFront = new Vector3(MasterBottomLeftFront.X, MasterBottomLeftFront.Y, MasterTopRightBack.Z); Vector3 bottomLeftFront = MasterBottomLeftFront; Vector3 topRightFront = new Vector3(MasterTopRightBack.X, MasterBottomLeftFront.Y, MasterTopRightBack.Z); Vector3 bottomRightFront = new Vector3(MasterTopRightBack.X, MasterBottomLeftFront.Y, MasterBottomLeftFront.Z); Vector3 topLeftBack = new Vector3(MasterBottomLeftFront.X, MasterTopRightBack.Y, MasterTopRightBack.Z); Vector3 bottomLeftBack = new Vector3(MasterBottomLeftFront.X, MasterTopRightBack.Y, MasterBottomLeftFront.Z); Vector3 topRightBack = MasterTopRightBack; Vector3 bottomRightBack = new Vector3(MasterTopRightBack.X, MasterTopRightBack.Y, MasterBottomLeftFront.Z); Vector3 frontNormal = new Vector3(0.0f, -1.0f, 0.0f); Vector3 backNormal = new Vector3(0.0f, 1.0f, 0.0f); Vector3 topNormal = new Vector3(0.0f, 0.0f, 1.0f); Vector3 bottomNormal = new Vector3(0.0f, 0.0f, -1.0f); Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f); Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f); VertexIndexData _returnData = new VertexIndexData(); if (Position.Y > 0) if (CurrentRoom.GetGridBlock((int)Position.X, (int)Position.Y - 1, (int)Position.Z).Culling == false) { if (Tex[0] > 0) _returnData.AddData(PrimHelper.GenerateWallVertices(bottomLeftFront, topRightFront, frontNormal, TilesetMain.Tiles[Tex[0]])); } if (Position.Y < CurrentRoom.Depth - 1) if (CurrentRoom.GetGridBlock((int)Position.X, (int)Position.Y + 1, (int)Position.Z).Culling == false) { if (Tex[1] > 0) _returnData.AddData(PrimHelper.GenerateWallVertices(bottomRightBack, topLeftBack, backNormal, TilesetMain.Tiles[Tex[2]])); } if (Position.X > 0) if (CurrentRoom.GetGridBlock((int)Position.X - 1, (int)Position.Y, (int)Position.Z).Culling == false) { if (Tex[2] > 0) _returnData.AddData(PrimHelper.GenerateWallVertices(bottomLeftBack, topLeftFront, leftNormal, TilesetMain.Tiles[Tex[3]])); } if (Position.X < CurrentRoom.Width - 1) if (CurrentRoom.GetGridBlock((int)Position.X + 1, (int)Position.Y, (int)Position.Z).Culling == false) { if (Tex[3] > 0) _returnData.AddData(PrimHelper.GenerateWallVertices(bottomRightFront, topRightBack, rightNormal, TilesetMain.Tiles[Tex[1]])); } if (Position.Z > 0) if (CurrentRoom.GetGridBlock((int)Position.X, (int)Position.Y, (int)Position.Z - 1).Culling == false) { if (Tex[4] > 0) _returnData.AddData(PrimHelper.GenerateFloorVertices(bottomLeftBack, bottomRightFront, bottomNormal, TilesetMain.Tiles[Tex[4]])); } if (Position.Z < CurrentRoom.Height - 1) if (CurrentRoom.GetGridBlock((int)Position.X, (int)Position.Y, (int)Position.Z + 1).Culling == false) { if (Tex[5] > 0) _returnData.AddData(PrimHelper.GenerateFloorVertices(topLeftFront, topRightBack, topNormal, TilesetMain.Tiles[Tex[5]])); } return _returnData; }
/// <summary> /// Loads content and and game logic. /// </summary> protected override void LoadContent() { // The primitive manager and spritebatch is loaded. primManager = new PrimManager(this, Content.Load<Effect>("Texts/WorldEffect")); spriteBatch = new SpriteBatch(GraphicsDevice); // Loads textures and fonts. textureManager.LoadTexturesFromFile("textureinfo", Content); FontMain = Content.Load<SpriteFont>("Fonts/FontMain"); FontTiny = Content.Load<SpriteFont>("Fonts/FontTiny"); // ---- GAME SPECIFIC INITALIZATIONS ---- room = new Room(this, "blockset1", "plateau1"); screenManager.AddScreen(new LevelEditor(this)); cubeManager.AddCube(new Player(new Vector3(3, 3, 5), new PlayerAI(), textureManager.AniDic["player"])); cubeManager.AddCube(new PushCube(new Vector3(4,3,5), textureManager.TilesetList[0].Tiles[1])); // Places the light. primManager.myEffect.PlaceLightUsingDirection(this, 16); primManager.myEffect.UpdateShadowMap(this); }