public void resetMap( PuzzleMap pMap, BasicActor topActor) { this.pMap = pMap; actor = topActor; updateText(); this.Refresh(); }
public ActorDoActionAction(BasicActor actor, HexGrid.HexGrid hexGrid, string actionName, Dictionary <ActionArgs, string> actionArgs) { ElementName = actionName; //make some custom one :TODO #region choose texture string assetPath = ""; switch (actionName) { case "rotateC": assetPath = @"Content\UIElements\rotateClockWise.png"; break; case "rotateCC": assetPath = @"Content\UIElements\rotateCounterClockWise.png"; break; case "move": assetPath = @"Content\UIElements\move.png"; break; default: assetPath = @"Modules\" + actionArgs[Actors.ActionArgs.ModuleName] + @"\" + actionArgs[Actors.ActionArgs.Texture]; break; } #endregion FileStream fs = new FileStream(assetPath, FileMode.Open); Texture = Texture2D.FromStream(GraphicsDevice, fs); fs.Close(); HexGrid = hexGrid; Actor = actor; ActionArgs = actionArgs; }
public static void CreateActiveActorUIElements(HexGrid.HexGrid hexMap, BasicActor actionableActor) { if (hexMap.ActiveActor == actionableActor) { //:TODO dynamically choose formatting, maybe how many other elements a UI element will let share a line with it UIGridBag actorActionsUIBag = new UIGridBag(UIGridBagLocationCordinates.Left, new List <int>() { 1, 2, 1 }); ActiveHexUIElements.AvailibleUIElements.Remove(UIGridBagLocations.Left); //maybe just loop through, remove all actor related ones, get list first, remove second :TODO var placedElementCount = 0; hexMap.ActiveActor.DefaultActions.ForEach(a => { UIDrawable actionElement = (ActionHandler.ActionsList.ContainsKey(a)) ? new ActorDoActionAction(hexMap.ActiveActor, hexMap, a, ActionHandler.ActionsList[a]) : new ActorDoActionAction(hexMap.ActiveActor, hexMap, a, new Dictionary <ActionArgs, string> { { ActionArgs.Type, a } }); actorActionsUIBag.GridElements.Add(actionElement); //:TODO dubious if (actorActionsUIBag.PerRow.Sum() <= placedElementCount) { actorActionsUIBag.PerRow.Add(1); } placedElementCount++; }); ActiveHexUIElements.AvailibleUIElements[UIGridBagLocations.Left] = actorActionsUIBag; } }
//any? specific for if selecting non active actor? //should also have textures around them //also harcoding, bad :TODO public static void CreateTextUIElements(HexGrid.HexGrid hexMap, BasicActor actionableActor) { if (ActiveHexUIElements.AvailibleUIElements[UIGridBagLocations.Left] == null) { UIGridBag actorActionsUIBag = new UIGridBag(UIGridBagLocationCordinates.Left, new List <int>()); ActiveHexUIElements.AvailibleUIElements[UIGridBagLocations.Left] = actorActionsUIBag; } ActiveHexUIElements.AvailibleUIElements[UIGridBagLocations.Left].GridElements.Add(new TextUIElement(hexMap.ActiveActor, TextUIStatics.ActorStats.CurrentHP)); ActiveHexUIElements.AvailibleUIElements[UIGridBagLocations.Left].PerRow.Add(1); }
public Form1(PuzzleMap pMap, BasicActor topActor) { sForm = new SettingsForm(); DoubleBuffered = true; this.pMap = pMap; actor = topActor; InitializeComponent(); rand = new Random(); initialize(); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); pMap = new PuzzleMap(200, 40, 8); BasicActor a = new BasicActor(1, 1, 10, 10, 100, 'a', pMap, Color.Red, new Random() ); form = new Form1(pMap, a ); Application.Run(form); form.pMap = pMap; form.Refresh(); }
public void SetNextActorControl() { if (!ActiveBoard.ActorStorage.Any()) { //no ones on the board?? } ActiveActor = ActiveBoard.ActorStorage.FirstOrDefault(a => (a.TurnState == ActorTurnState.WaitingForTurn || a.TurnState == ActorTurnState.OnTurn)); if (ActiveActor == null) { //no one left to move/action, reset it all, re sort, asign ActiveBoard.ActorStorage.ForEach(a => a.TurnState = ActorTurnState.WaitingForTurn); ActiveBoard.ActorStorage = ActiveBoard.ActorStorage.OrderBy(a => a.Speed).ToList(); ActiveActor = ActiveBoard.ActorStorage.FirstOrDefault(a => a.TurnState == ActorTurnState.WaitingForTurn); } }
private void FillGrid(Dictionary <string, Dictionary <string, string> > actorData, string moduleName) { for (var r = 0; r < Rows; r++) { for (var q = 0; q < Cols; q++) { int hexR = r; int hexQ = q - (r / 2); //placing tiles into drawable storage var tilePlacementKeyExists = SpecificTilePlacements.Where(p => p.Key.Equals(new HexPoint(hexR, hexQ))).ToList(); if (tilePlacementKeyExists.Any()) { var placementKey = tilePlacementKeyExists[0]; Hex hex = new Hex(new HexPoint(hexR, hexQ), SpecificTilePlacements[placementKey.Key], TileData[SpecificTilePlacements[placementKey.Key]], moduleName); //HexStorage[hexR, hexQ - -1 * (hexR / 2)] = hex; HexStorage[new HexPoint(hexR, hexQ)] = hex; } else { Hex hex = new Hex(new HexPoint(hexR, hexQ), DefaultTile, TileData[DefaultTile], moduleName); //HexStorage[hexR, hexQ - -1 * (hexR / 2)] = hex; HexStorage[new HexPoint(hexR, hexQ)] = hex; } //placing actors into actor storage var actorPlacementKeyExists = SpecificActorPlacements.Where(p => p.Key.Equals(new HexPoint(hexR, hexQ))).ToList(); if (actorPlacementKeyExists.Any()) { var placementKey = actorPlacementKeyExists[0]; string actorType = placementKey.Value.Split('-')[0]; bool controllable = placementKey.Value.Split('-')[1] == "PC" ? true : false; int rotation = Convert.ToInt32(placementKey.Value.Split('-')[2]); BasicActor actor = new BasicActor(new HexPoint(hexR, hexQ), actorType, actorData[actorType], rotation, controllable, moduleName, this); //choose the AI ActorStorage.Add(actor); } } } if (ActorStorage.Any()) { ActorStorage = ActorStorage.OrderBy(h => h.Speed).ToList(); } }
void StObjConstruct(BasicActor actor) { }
public static void TacticalViewMouseHandle(HexGrid.HexGrid hexMap, Camera camera, BasicActor actionableActor) { //Probably in whatever houses the ActorActions instantiation //var actorUi = new ActorActions(new ); //actorUi.DrawActorActions(); var conv = Vector2.Transform(MouseCords, Matrix.Invert(camera.Transform)); var selHex = hexMap.SelectedHex(conv); hexMap.HexStorage.ToList().ForEach(h => h.Value.Hovered = false); //:TODO also annoying if (selHex != null) { Debugger.Log("Hover Hex " + selHex.R + ", " + selHex.Q); // :TODO this is annoying to do hexMap.HexStorage.Where(h => h.Key.Equals(selHex)).First().Value.Hovered = true; } if (CompletedClick /*mouseInfo.MouseState.LeftButton == ButtonState.Pressed*/) { //Debug.Log("Clicked ScreenCords " + MouseCords.X + ", " + MouseCords.Y); //Debug.Log("Clicked MouseCords " + conv.X + ", " + conv.Y); foreach (var bag in ActiveHexUIElements.AvailibleUIElements) { foreach (var visibleElement in bag.Value.GridElements) { Vector2 elementLoc = Vector2.Transform(visibleElement.StartV, Matrix.Invert(camera.Transform)); Vector2 elementSize = visibleElement.Size; if (conv.X >= elementLoc.X && conv.Y >= elementLoc.Y && conv.X <= elementLoc.X + elementSize.X && conv.Y <= elementLoc.Y + elementSize.Y) { visibleElement.OnClick(); return; } } } if (selHex != null) { var hexKey = hexMap.HexStorage.FirstOrDefault(h => h.Key.Equals(selHex)); var actorKey = hexMap.ActorStorage.FirstOrDefault(actor => actor.Location.Equals(selHex)); //probably should be moved somewhere hexMap.UnHighlightAll(); if (hexKey.Key != null) { hexMap.ActiveHex = hexKey; } if (hexMap.ActiveActor != null && hexMap.ActiveActor.Controllable) { hexKey.Value.Highlighted = true; var seeable = hexMap.ActiveActor.CanSee(); hexMap.HighlightHexes(seeable); #region create actor UI elements //UIGridBag -> where do we put it //show some text ui stats if not actionable :TODO CreateActiveActorUIElements(hexMap, actionableActor); CreateTextUIElements(hexMap, actionableActor); #endregion } if (hexMap.ActiveActor == null) { hexMap.ActiveActor = actorKey; } } } //temp, not all conditions for UI in, remove :TODO if (MouseState.RightButton == ButtonState.Pressed) { hexMap.ActiveHex = new KeyValuePair <HexPoint, Hex>(); hexMap.ActiveActor = null; ActiveHexUIElements.AvailibleUIElements.Remove(UIGridBagLocations.Left); hexMap.UnHighlightAll(); } }
//:TODO should have a texture property public TextUIElement(BasicActor actor, TextUIStatics.ActorStats actorStatType, string defaultText = null) { Actor = actor; ActorStatType = actorStatType; UIText = defaultText ?? ""; }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { MouseState mouseState = Mouse.GetState(); KeyboardState keyboardState = Keyboard.GetState(); // Allows the game to exit if (keyboardState.IsKeyDown(Keys.Escape)) { this.Exit(); } //Change camera mode if (keyboardState.IsKeyDown(Keys.D1)) { CameraMode = ECameraMode.Target; } if (keyboardState.IsKeyDown(Keys.D2)) { CameraMode = ECameraMode.Free; } if (keyboardState.IsKeyDown(Keys.D3)) { CameraMode = ECameraMode.ArcBall; } if (keyboardState.IsKeyDown(Keys.D4)) { CameraMode = ECameraMode.Chase; } //mouseState float deltaX = (float)LastMouseState.X - (float)mouseState.X; float deltaY = (float)LastMouseState.Y - (float)mouseState.Y; float scrollDelta = (float)LastMouseState.ScrollWheelValue - (float)mouseState.ScrollWheelValue; //Update camera base on mod and input switch (CameraMode) { case ECameraMode.Free: FreeCamera fc = (FreeCamera)Cam; //handle camera rotation fc.Rotate(deltaX * CAMERA_MOVE_FACTOR, deltaY * CAMERA_MOVE_FACTOR); //Handle camera movement Vector3 translation = Vector3.Zero; if (keyboardState.IsKeyDown(Keys.W)) { translation += Vector3.Forward; } if (keyboardState.IsKeyDown(Keys.S)) { translation += Vector3.Backward; } if (keyboardState.IsKeyDown(Keys.A)) { translation += Vector3.Left; } if (keyboardState.IsKeyDown(Keys.D)) { translation += Vector3.Right; } //move 3 units per millisecond translation *= 1.5f * (float)gameTime.ElapsedGameTime.TotalMilliseconds; fc.Move(translation); break; case ECameraMode.ArcBall: ArcBallCamera abc = (ArcBallCamera)Cam; //rotate cam abc.Rotate(deltaX * CAMERA_MOVE_FACTOR, deltaY * CAMERA_MOVE_FACTOR); //move cam abc.Move(scrollDelta); break; case ECameraMode.Chase: ChaseCamera cc = (ChaseCamera)Cam; BasicActor ship = Actors[1]; //Handle rotation Vector3 rotationChange = Vector3.Zero; if (keyboardState.IsKeyDown(Keys.W)) { rotationChange += new Vector3(-1, 0, 0); } if (keyboardState.IsKeyDown(Keys.S)) { rotationChange += new Vector3(1, 0, 0); } if (keyboardState.IsKeyDown(Keys.A)) { rotationChange += new Vector3(0, 1, 0); } if (keyboardState.IsKeyDown(Keys.D)) { rotationChange += new Vector3(0, -1, 0); } ship.Rotation += rotationChange * 0.025f; //handle movement if (keyboardState.IsKeyDown(Keys.Space)) { Matrix rotation = Matrix.CreateFromYawPitchRoll(ship.Rotation.Y, ship.Rotation.X, ship.Rotation.Z); ship.Position += Vector3.Transform(Vector3.Forward, rotation) * (float)gameTime.ElapsedGameTime.TotalMilliseconds * 4; } //Update camera cc.Move(ship.Position, ship.Rotation); break; } //Update camera Cam.Update(); LastMouseState = mouseState; base.Update(gameTime); }