public void Begin() { Content = new EpisodeContentManager(Main.EpisodeContent.ServiceProvider, "Content"); RenderContext = new RenderContext(Content.Load<Effect>("draw"), Main.GraphicsDevice); Camera = new Gem.Render.FreeCamera(new Vector3(0, 0, 0), Vector3.UnitY, Vector3.UnitZ, Main.GraphicsDevice.Viewport); RenderContext.Camera = Camera; World = new World(16, 10, 3); var blockTile = World.AddTile("block", typeof(Game.Tiles.BlockTile), new TilePropertyBag { Texture = RenderContext.White }); var floorTile = World.AddTile("floor", typeof(Game.Tiles.FloorTile), new TilePropertyBag { Texture = Content.Load<Texture2D>("floor01") }); var rampTile = World.AddTile("ramp", typeof(Game.Tiles.RampTile), new TilePropertyBag { Texture = Content.Load<Texture2D>("floor01") }); World.Grid.ForEachTile((t, x, y, z) => { if (x == 0 || x == 15 || y == 9) t.Tile = blockTile; else if (z == 0) t.Tile = floorTile; }); World.Grid.CellAt(7, 3, 1).Tile = floorTile; World.Grid.CellAt(7, 4, 0).Tile = rampTile; World.Grid.CellAt(8, 4, 1).Tile = floorTile; World.Grid.CellAt(8, 3, 1).Tile = floorTile; SceneGraph = new Gem.Render.BranchNode(); var testActorProperties = new Actors.AnimatedSpritePropertyBag { Sprite = Content.Load<Texture2D>("char"), NormalMap = RenderContext.NeutralNormals, DropShadow = Content.Load<Texture2D>("shadow"), Height = 1.5f, Width = 1.0f, Animations = new Gem.AnimationSet( new Gem.Animation("idle", 0.15f, 0), new Gem.Animation("run", 0.15f, 1, 2, 3, 4, 5, 6)), SpriteSheet = new Gem.SpriteSheet(4, 4), HiliteOnHover = true, HoverOverlay = Content.Load<Texture2D>("outline") }; var commandSet = new List<Input.PlayerCommand>(); testActorProperties.Upsert("commands", commandSet); var walkCommand = new Input.PlayerCommand(World); walkCommand.Check("can-walk", "actor", "cell", "path"); walkCommand.Perform("do-walk", "actor", "path"); testActorProperties.Upsert("walk-command", walkCommand); World.GlobalRules.Check<Actor, CombatCell, Pathfinding<CombatCell>.PathNode>("can-walk") .When((a, c, n) => n.PathCost > a.Properties.GetPropertyAsOrDefault<int>("turn-energy") || n.PathCost < 1) .Do((a, c, n) => SharpRuleEngine.CheckResult.Disallow); World.GlobalRules.Check<Actor, CombatCell, Pathfinding<CombatCell>.PathNode>("can-walk") .Do((a, c, n) => SharpRuleEngine.CheckResult.Allow); World.GlobalRules.Perform<Actor, Pathfinding<CombatCell>.PathNode>("do-walk") .Do((a, p) => { var energy = a.Properties.GetPropertyAs<int>("turn-energy"); energy -= (int)p.PathCost; a.Properties.Upsert("turn-energy", energy); a.NextAction = new Actors.Actions.WalkPath(p.ExtractPath()); PushInputState(new Input.WaitForIdle(a)); return SharpRuleEngine.PerformResult.Continue; }); PlayerActor = World.SpawnActor(typeof(Actors.AnimatedSpriteActor), testActorProperties, new Vector3(4.5f, 4.5f, 0.25f)); World.SpawnActor(typeof(Actors.AnimatedSpriteActor), testActorProperties, new Vector3(4.5f, 6.5f, 0.25f)); Camera.Position = CameraFocus + new Vector3(0, -4, 3); Camera.LookAt(CameraFocus); Camera.Position = CameraFocus + (Camera.GetEyeVector() * CameraDistance); Main.Input.AddBinding("RIGHT", new KeyboardBinding(Keys.Right, KeyBindingType.Held)); Main.Input.AddBinding("LEFT", new KeyboardBinding(Keys.Left, KeyBindingType.Held)); Main.Input.AddBinding("UP", new KeyboardBinding(Keys.Up, KeyBindingType.Held)); Main.Input.AddBinding("DOWN", new KeyboardBinding(Keys.Down, KeyBindingType.Held)); Main.Input.AddBinding("CLICK", new MouseButtonBinding("LeftButton", KeyBindingType.Pressed)); Main.Input.AddBinding("GRID-UP", new KeyboardBinding(Keys.Q, KeyBindingType.Pressed)); Main.Input.AddBinding("GRID-DOWN", new KeyboardBinding(Keys.E, KeyBindingType.Pressed)); Main.Input.AddBinding("CAMERA-DISTANCE-TOGGLE", new KeyboardBinding(Keys.R, KeyBindingType.Held)); Main.ScriptBuilder.DeriveScriptsFrom("MonoCardCrawl.ScriptBase"); var StaticWorld = WorldModel.CreateStaticGeometryBuffers(World, Main.GraphicsDevice); SceneGraph.Add(StaticWorld); SceneGraph.Add(new ActorSceneNode(World)); World.PrepareCombatGrid(); PushInputState(new Input.TurnScheduler(World.Actors)); }
public BranchNode CreateSceneNode() { var result = new BranchNode(); WorldSceneNode = new WorldSceneNode(World, new WorldSceneNodeProperties { HiliteTexture = TileNames.HoverHilite, BlockSet = Blocks }); result.Add(WorldSceneNode); result.Add(new ActorSceneNode(Actors)); result.UpdateWorldTransform(Matrix.Identity); WorldSceneNode.UpdateGeometry(); return result; }
public void Begin() { Tables.Initialize(); CurrentBoard = Tables.InitialBoard; Content = new EpisodeContentManager(Main.EpisodeContent.ServiceProvider, "Content"); PieceTextures = new Texture2D[] { Content.Load<Texture2D>("blue-piece"), Content.Load<Texture2D>("white-piece") }; RenderContext = new RenderContext(Content.Load<Effect>("draw"), Main.GraphicsDevice); Camera = new FreeCamera(new Vector3(0.0f, -8.0f, 8.0f), Vector3.UnitY, Vector3.UnitZ, Main.GraphicsDevice.Viewport); Camera.Viewport = Main.GraphicsDevice.Viewport; Camera.LookAt(Vector3.Zero); RenderContext.Camera = Camera; SceneGraph = new Gem.Render.BranchNode(); Input.ClearBindings(); Input.AddAxis("MAIN", new MouseAxisBinding()); Main.Input.AddBinding("RIGHT", new KeyboardBinding(Keys.Right, KeyBindingType.Held)); Main.Input.AddBinding("LEFT", new KeyboardBinding(Keys.Left, KeyBindingType.Held)); Main.Input.AddBinding("UP", new KeyboardBinding(Keys.Up, KeyBindingType.Held)); Main.Input.AddBinding("DOWN", new KeyboardBinding(Keys.Down, KeyBindingType.Held)); Main.Input.AddBinding("CLICK", new MouseButtonBinding("LeftButton", KeyBindingType.Pressed)); Main.Input.AddBinding("CAMERA-DISTANCE-TOGGLE", new KeyboardBinding(Keys.R, KeyBindingType.Held)); Main.Input.AddBinding("EXIT", new KeyboardBinding(Keys.Escape, KeyBindingType.Pressed)); var hexMesh = Gem.Geo.Gen.CreateUnitPolygon(6); hexMesh = Gem.Geo.Gen.FacetCopy(Gem.Geo.Gen.TransformCopy(hexMesh, Matrix.CreateRotationZ((float)System.Math.PI / 2.0f))); Gem.Geo.Gen.ProjectTexture(hexMesh, new Vector3(1.0f, 1.0f, 0.0f), Vector3.UnitX * 2, Vector3.UnitY * 2); Gem.Geo.Gen.CalculateTangentsAndBiNormals(hexMesh); for (var x = 0; x < 19; ++x) { var hexNode = new NormalMapMeshNode() { Mesh = hexMesh, Texture = Content.Load<Texture2D>("hex"), NormalMap = Content.Load<Texture2D>("hex-normal"), }; hexNode.Orientation.Position = new Vector3(Tables.HexWorldPositions[x], 0.0f); SceneGraph.Add(hexNode); HexNodes.Add(hexNode); } var tetraMesh = Gem.Geo.Gen.CreateUnitPolygon(3); tetraMesh.verticies[0].Position = new Vector3(0.0f, 0.0f, 1.0f); Gem.Geo.Gen.Transform(tetraMesh, Matrix.CreateRotationZ((float)Math.PI)); tetraMesh = Gem.Geo.Gen.FacetCopy(tetraMesh); for (var i = 0; i < tetraMesh.indicies.Length; i += 3) { tetraMesh.verticies[tetraMesh.indicies[i]].TextureCoordinate = new Vector2(0.5f, 0); tetraMesh.verticies[tetraMesh.indicies[i + 1]].TextureCoordinate = new Vector2(1, 1); tetraMesh.verticies[tetraMesh.indicies[i + 2]].TextureCoordinate = new Vector2(0, 1); } Gem.Geo.Gen.CalculateTangentsAndBiNormals(tetraMesh); for (var x = 0; x < 36; ++x) { var tetraNode = new NormalMapMeshNode() { Mesh = tetraMesh, HiliteColor = new Vector3(1,0,0), HiliteMesh = tetraMesh, Hidden = true }; tetraNode.Orientation.Scale = new Vector3(0.4f, 0.4f, 0.4f); SceneGraph.Add(tetraNode); PieceNodes.Add(tetraNode); } for (var x = 0; x < 6; ++x) { var ghostNode = new NormalMapMeshNode() { Mesh = tetraMesh, HiliteColor = new Vector3(1, 0, 0), HiliteMesh = tetraMesh, Hidden = true, Alpha = 0.75f, Color = new Vector3(0.8f, 0.8f, 0.0f), }; ghostNode.Orientation.Scale = new Vector3(0.4f, 0.4f, 0.4f); SceneGraph.Add(ghostNode); GhostPieceNodes.Add(ghostNode); } var guiQuad = Gem.Geo.Gen.CreateQuad(); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateRotationX(Gem.Math.Angle.PI / 2.0f)); //Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateRotationY(Gem.Math.Angle.PI)); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateScale(10.0f, 1.0f, 5.0f)); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateTranslation(0.0f, 0.0f, 2.0f)); Gui = new Gem.Gui.GuiSceneNode(guiQuad, Main.GraphicsDevice, 1024, 512); Gui.uiRoot.AddPropertySet(null, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0, 0, 1), Transparent = true }); Gui.uiRoot.AddChild(new Gem.Gui.UIItem( "TURN-INDICATOR", new Gem.Gui.QuadShape(0, 0, 1, 1), new Gem.Gui.GuiProperties { Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(32, 32), TextColor = new Vector3(1, 0, 0), Label = "HELLO COERCEO", FontScale = 4.0f, Transparent = true })); Gui.uiRoot.AddChild(new Gem.Gui.UIItem( "TILE-COUNT", new Gem.Gui.QuadShape(0, 0, 1, 1), new Gem.Gui.GuiProperties { Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(32, 56), TextColor = new Vector3(1, 0, 0), Label = "TILE-COUNT", FontScale = 4.0f, Transparent = true })); Gui.uiRoot.AddChild(new Gem.Gui.UIItem( "STATS", new Gem.Gui.QuadShape(0, 0, 1, 1), new Gem.Gui.GuiProperties { Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(768, 32), TextColor = new Vector3(1, 0, 0), Label = "STATS", FontScale = 4.0f, Transparent = true })); Gui.RenderOnTop = true; Gui.DistanceBias = float.NegativeInfinity; SceneGraph.Add(Gui); PushInputState(new Input.TurnScheduler(PlayerTypes)); }
public void Begin() { Content = new EpisodeContentManager(Main.EpisodeContent.ServiceProvider, "Content"); RenderContext = new RenderContext(Content.Load<Effect>("draw"), Main.GraphicsDevice); Camera = new FreeCamera(new Vector3(0.0f, -8.0f, 8.0f), Vector3.UnitY, Vector3.UnitZ, Main.GraphicsDevice.Viewport); Camera.Viewport = Main.GraphicsDevice.Viewport; Camera.LookAt(Vector3.Zero); RenderContext.Camera = Camera; SceneGraph = new Gem.Render.BranchNode(); Main.Input.ClearBindings(); Input.AddAxis("MAIN", new MouseAxisBinding()); Main.Input.AddBinding("CLICK", new MouseButtonBinding("LeftButton", KeyBindingType.Pressed)); Main.Input.AddBinding("EXIT", new KeyboardBinding(Keys.Escape, KeyBindingType.Pressed)); var guiQuad = Gem.Geo.Gen.CreateQuad(); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateRotationX(Gem.Math.Angle.PI / 2.0f)); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateScale(10.0f, 1.0f, 5.0f)); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateTranslation(0.0f, 0.0f, 2.0f)); Gui = new Gem.Gui.GuiSceneNode(guiQuad, Main.GraphicsDevice, 1024, 512); Gui.uiRoot.AddPropertySet(null, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0, 0, 1), Transparent = true }); var button1 = new Gem.Gui.UIItem( "BUTTON", new Gem.Gui.QuadShape(32, 32, 512, 32), new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0.9f, 0.4f, 0.4f), Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(32, 32), TextColor = new Vector3(0, 0, 0), Label = "PLAYER VS PLAYER", FontScale = 4.0f, Transparent = false, ClickAction = () => { Main.Game = new WorldScreen(PlayerType.Player, PlayerType.Player); } }); button1.AddPropertySet(i => i.Hover, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(1, 0, 0) }); Gui.uiRoot.AddChild(button1); var button2 = new Gem.Gui.UIItem( "BUTTON", new Gem.Gui.QuadShape(32, 32 + 32 + 16, 512, 32), new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0.9f, 0.4f, 0.4f), Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(32, 32 + 32 + 16), TextColor = new Vector3(0, 0, 0), Label = "PLAYER VS AI", FontScale = 4.0f, Transparent = false, ClickAction = () => { Main.Game = new WorldScreen(PlayerType.Player, PlayerType.AI); } }); button2.AddPropertySet(i => i.Hover, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(1, 0, 0) }); Gui.uiRoot.AddChild(button2); var button3 = new Gem.Gui.UIItem( "BUTTON", new Gem.Gui.QuadShape(32, 128, 512, 32), new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0.9f, 0.4f, 0.4f), Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(32, 128), TextColor = new Vector3(0, 0, 0), Label = "AI VS AI", FontScale = 4.0f, Transparent = false, ClickAction = () => { Main.Game = new WorldScreen(PlayerType.AI, PlayerType.AI); } }); button3.AddPropertySet(i => i.Hover, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(1, 0, 0) }); Gui.uiRoot.AddChild(button3); Gui.RenderOnTop = true; Gui.DistanceBias = float.NegativeInfinity; SceneGraph.Add(Gui); }