public void GoToPosition(PositionInGrid pos) { Direction direction = PositionInGrid.GetDirection(entity.Position, pos); if (!entity.IsMoving) if (!entity.Move(direction)) completed(); }
void it_knows_how_to_instantiate_itself_from_a_scalar_and_grid_size() { var position = PositionInGrid.FromScalarForGridOfSize(9, 4); position.row.should_be(2); position.column.should_be(1); }
public Player(Arman game, PositionInGrid positionInGrid, Texture2D texture, Block[,] gameArray, int oneBlockSize, int timeForMove, List<Entity> movableObjects, GameArea gameArea, Controls controls) : base(game, positionInGrid, texture, gameArray, oneBlockSize, timeForMove, movableObjects) { this.gameArea = gameArea; this.controls = controls; spawnPoint = positionInGrid; }
public override void ThingMoveToMe(Element element, PositionInGrid direction) { if (element is Character character) { ThingHoldMe(character); } }
protected override void Move(int Horizontal, int Vertical) { var canMove = true; var direction = new PositionInGrid(Horizontal, Vertical); foreach (var element in ChainedElements) { if (!element.CanMoveTo(direction)) { canMove = false; } } if (canMove) { foreach (var element in ChainedElements) { var xPrev = element.PositionInGrid.x - Horizontal; var yPrev = element.PositionInGrid.y + Vertical; var prevElement = Board.GetElementOfPosition(xPrev, yPrev); //Debug.Log("Try Moving Element: " + element + " PositionX: " + element.PositionInGrid.x + " y: " + element.PositionInGrid.y); //Debug.Log("xPrev: " + xPrev + " yPrev: " + yPrev + " prevElement: " + prevElement); if (!ChainedElements.Contains(prevElement)) { //Debug.Log("moving " + element); element.MoveTo(direction); } } } }
public Mob(PositionInGrid position, bool canPush, bool canBePushed, float speed, bool collides, double health, bool invulnerable, int scanRange, int wanderRange, int wanderChance) : base(position, "Mob", canPush, canBePushed, speed, collides, health, invulnerable) { Vision = scanRange; WanderRange = wanderRange; WanderChance = wanderChance; }
/// <summary> /// /// </summary> /// <param name="game">Main game</param> /// <param name="spriteBatch">Where to draw textures</param> /// <param name="position">Where it should be placed</param> public Block(Game game, SpriteBatch spriteBatch, PositionInGrid position) : base(game) { this.game = game; Position = position; this.spriteBatch = spriteBatch; }
public Detector(PositionInGrid position, double blastResistance, ArmanColor lockColor, bool blockMovableBlockOnApproach, bool isPartOfObjectives, PositionInGrid affectedPosition) : base(position, "Detector", false, blastResistance) { BlockMovableBlockOnApproach = blockMovableBlockOnApproach; LockColor = lockColor; IsPartOfObjectives = isPartOfObjectives; AffectedPosition = affectedPosition; }
public Detector(PositionInGrid position, string name, double blastResistance, ArmanColor lockColor, bool blockMovableBlockOnApproach, bool isPartOfObjectives) : base(position, name, false, blastResistance) { BlockMovableBlockOnApproach = blockMovableBlockOnApproach; LockColor = lockColor; IsPartOfObjectives = isPartOfObjectives; AffectedPosition = new PositionInGrid(-1); }
public Block(Arman game, BlockType type, PositionInGrid position, int oneBlockSize) : base(game) { this.game = game; Type = type; Position = position; this.oneBlockSize = oneBlockSize; }
public Entity(PositionInGrid position, string name, bool canPush, bool canBePushed, float speed, bool collides, double health, bool invulnerable) : base(position, name) { Collides = collides; Speed = speed; Health = health; Invulnerable = invulnerable; }
public override bool ThingCanMoveToMe(Element element, PositionInGrid direction) { if (element is Character character) { return(true); } return(false); }
public void CreateBlock(BlockType type, PositionInGrid position) { if (type == BlockType.movable) entities.Add(new MovableBlock(game, position, game.Content.Load<Texture2D>(@"Sprites/Blocks/movable"), gameArray, blockSize, gameSpeed, entities)); else if (type == BlockType.detector) gameArray[position.X, position.Y] = loadAndInitializeBlock(new Detector(game, BlockType.detector, position, blockSize, detectorActivated)); else gameArray[position.X, position.Y] = loadAndInitializeBlock(new Block(game, type, position, blockSize)); }
void it_is_able_to_retrieved_cells_by_position_in_grid() { var position = new PositionInGrid(1, 2); var cell = _subject.CellAt(position); cell.value.should_be(6); cell.position.column.should_be(position.column); cell.position.row.should_be(position.row); }
public override bool ThingCanMoveToMe(Element element, PositionInGrid direction) { bool CanMove = false; if (CanMoveTo(direction)) { CanMove = true; } return(CanMove); }
public virtual void MoveTo(PositionInGrid direction) { Board.ElementMoveTo(this, direction.x, direction.y); if (AudioSource && MoveSound) { AudioSource.clip = MoveSound; AudioSource.Play(); } OnMoving?.Invoke(this); transform.position += new Vector3(direction.x, direction.y); }
public Entity(Arman game, PositionInGrid positionInGrid, Texture2D texture, Block[,] gameArray, int oneBlockSize, int timeForMove, List<Entity> movableObjects) { Blocked = false; this.game = game; PositionInGrid = positionInGrid; this.Texture = texture; this.gameArray = gameArray; isMoving = false; this.timeForMove = timeForMove; this.oneBlockSize = oneBlockSize; this.movableObjects = movableObjects; movingDifference = 0.0F; movingDirection = Direction.up; }
public Mob(Arman game, PositionInGrid positionInGrid, Texture2D texture, Block[,] gameArray, int oneBlockSize, int timeForMove, List<Entity> entities, int range, int aditionalTimeForMove, int movingFrequency) : base(game, positionInGrid, texture, gameArray, oneBlockSize, timeForMove, entities) { players = from entity in entities where entity is Player select (Player)entity; mobs = from entity in entities where entity is Mob select (Mob)entity; this.movingFrequency = movingFrequency; Range = range; this.timeForMove += aditionalTimeForMove; }
public Entity(PositionInGrid position, bool canPush, bool canBePushed, float speed, bool collides, double health, bool invulnerable) : base(position, "Generic entity") { if (collides) { CanPush = canPush; CanBePushed = canBePushed; } else { CanPush = false; CanBePushed = false; } Collides = collides; Speed = speed; Health = health; Invulnerable = invulnerable; }
public MainWindow() { InitializeComponent(); data = new GameData(); dataStack = new Stack<GameData>(); data.OneBlockSize = 20; firstPosition = new PositionInGrid(0); secondPosition = new PositionInGrid(0); blocksLayerCheckBox.IsChecked = true; entitiesLayerCheckBox.IsChecked = true; activateDetectors.IsChecked = true; collectCoins.IsChecked = false; getHome.IsChecked = false; disableControlsForLevel(); }
public override void ThingMoveToMe(Element element, PositionInGrid direction) { MoveTo(direction); if (element is Character character) { if (this.character == null) { this.character = character; } if (this.character != character) { this.character.OnMoving -= WaitToActivate; this.character = character; } if (this.character != null) { this.character.OnMoving += WaitToActivate; } } }
public abstract void ThingMoveToMe(Element element, PositionInGrid direction);
public void SetPosition(PositionInGrid position) { PositionInGrid = position; }
public override bool ThingCanMoveToMe(Element element, PositionInGrid direction) { return(CanMoveTo(direction)); }
public bool CanMoveTo(PositionInGrid direction) { return(Board.CanMoveTo(this, direction.x, direction.y)); }
/// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="range"></param> /// <param name="speed"></param> /// <param name="movingFrequency">higher = smaller chance - number for random generator of direction</param> public void SpawnMob(PositionInGrid position, int range, int speed, int movingFrequency) { int movingFreq = movingFrequency + 4; //zamezení aby potvora nechodila poøád do jednoho smìru pøi zadání nízké hodnoty entities.Add(new Mob(game, position, game.Content.Load<Texture2D>(@"Sprites/potvora"), gameArray, blockSize, gameSpeed, entities, range, speed, movingFreq)); }
private void removeBlock_Checked(object sender, RoutedEventArgs e) { LevelView view = new LevelView(data); view.ShowDialog(); blockToRemove = view.choosenPosition; }
private void levelCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Point point = e.GetPosition((Canvas)sender); choosenPosition = new PositionInGrid((int)point.X / data.OneBlockSize, (int)point.Y / data.OneBlockSize); this.Close(); }
private void levelCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { Point point = e.GetPosition((Canvas)sender); PositionInGrid position = new PositionInGrid((int)point.X / data.OneBlockSize, (int)point.Y / data.OneBlockSize); firstPosition = position; }
private void levelCanvas_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { dataStack.Push(data.Clone()); // Příprava na následující akci blocksEnabled = (bool)blocksLayerCheckBox.IsChecked; entitiesEnabled = (bool)entitiesLayerCheckBox.IsChecked; Point point = e.GetPosition((Canvas)sender); PositionInGrid position2 = new PositionInGrid((int)point.X / data.OneBlockSize, (int)point.Y / data.OneBlockSize); secondPosition = position2; DoActionForEveryPositionInRectangle(firstPosition, secondPosition, delegate(PositionInGrid position) { if (blocksEnabled) { foreach (Block block in data.Blocks.ToList()) { if (block.Position == position && !(block is Air)) { data.Blocks.Add(new Air(position)); data.Blocks.Remove(block); } } } if (entitiesEnabled) { foreach (Entity entity in data.Entities.ToList()) { if (entity.Position == position) data.Entities.Remove(entity); } } }); refresh(); changesSaved = false; }
private void DoActionForEveryPositionInRectangle(PositionInGrid firstPosition, PositionInGrid secondPosition, Action<PositionInGrid> action) { List<PositionInGrid> positions = new List<PositionInGrid>(); if (firstPosition.Y <= secondPosition.Y) { for (int y = firstPosition.Y; y <= secondPosition.Y; y++) if (firstPosition.X <= secondPosition.X) for (int x = firstPosition.X; x <= secondPosition.X; x++) positions.Add(new PositionInGrid(x, y)); else for (int x = firstPosition.X; x >= secondPosition.X; x--) positions.Add(new PositionInGrid(x, y)); } else { for (int y = firstPosition.Y; y >= secondPosition.Y; y--) if (firstPosition.X <= secondPosition.X) for (int x = firstPosition.X; x <= secondPosition.X; x++) positions.Add(new PositionInGrid(x, y)); else for (int x = firstPosition.X; x >= secondPosition.X; x--) positions.Add(new PositionInGrid(x, y)); } foreach (PositionInGrid pos in positions) action(pos); }
private void levelCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { dataStack.Push(data.Clone()); Point point = e.GetPosition((Canvas)sender); PositionInGrid position2 = new PositionInGrid((int)point.X / data.OneBlockSize, (int)point.Y / data.OneBlockSize); secondPosition = position2; // Setblocks DoActionForEveryPositionInRectangle(firstPosition, secondPosition, delegate(PositionInGrid position) { switch (ChoosenTool) { case Tools.air: #region Air foreach (Block block in data.Blocks.ToList()) { if (block.Position == position) data.Blocks.Remove(block); } data.Blocks.Add(new Air(position)); #endregion break; case Tools.coin: #region Coin foreach (Block block in data.Blocks.ToList()) { if (block.Position == position) data.Blocks.Remove(block); } Windows.Coin coinWindow = new Windows.Coin(); coinWindow.ShowDialog(); try { data.Blocks.Add(new Coin(position, coinWindow.blastResistance.Value.Value, coinWindow.valueUpDown.Value.Value)); } catch (Exception ex) { MessageBox.Show("Error while parsing data from form - " + ex.Message, "Error"); } refresh(); #endregion break; case Tools.detector: #region Detector foreach (Block block in data.Blocks.ToList()) { if (block.Position == position) data.Blocks.Remove(block); } // prepare variables Color color; bool blockMovableBlockOnApproach, addToObjectives; Windows.Detector detector = new Windows.Detector(data); detector.ShowDialog(); try { blockMovableBlockOnApproach = detector.blockPlacedMovableBlockCheckBox.IsChecked.Value; color = detector.colorPicker.SelectedColor; addToObjectives = detector.objectives.IsChecked.Value; if (detector.removeBlock.IsChecked == true) data.Blocks.Add(new Detector(position, 69.0, ArmanColor.ParseWindowsColor(color), blockMovableBlockOnApproach, addToObjectives, detector.blockToRemove)); else data.Blocks.Add(new Detector(position, 69.0, ArmanColor.ParseWindowsColor(color), blockMovableBlockOnApproach, addToObjectives, new PositionInGrid(-1))); } catch (Exception ex) { MessageBox.Show("Error while parsing data from form - " + ex.Message, "Error"); } refresh(); #endregion break; case Tools.home: #region Home foreach (Block block in data.Blocks.ToList()) { if (block.Position == position) data.Blocks.Remove(block); } data.Blocks.Add(new Home(position, 69.0)); #endregion break; case Tools.mob: #region Mob foreach (Entity entity in data.Entities.ToList()) { if (entity.Position == position) data.Entities.Remove(entity); } // Prepare data Windows.Mob mob = new Windows.Mob(); mob.speedLabel.ToolTip = "Set speed of mob (-Infinity - " + data.OneBlockSize + ")"; mob.speed.ToolTip = "Set speed of mob (-Infinity - " + data.OneBlockSize + ")"; mob.ShowDialog(); try { data.Entities.Add(new Mob(position, mob.nameTextBox.Text, mob.canPushCheckBox.IsChecked.Value, mob.canBePushedCheckBox.IsChecked.Value, (float)mob.speed.Value.Value, mob.collides.IsChecked.Value, mob.health.Value.Value, mob.invulnerable.IsChecked.Value, mob.vision.Value.Value, mob.wanderRange.Value.Value, mob.wanderChance.Value.Value)); } catch (Exception ex) { MessageBox.Show("Error while parsing data from form - " + ex.Message, "Error"); } refresh(); #endregion break; case Tools.movable: #region Movable Block foreach (Entity entity in data.Entities) { if (entity.Position == position) data.Entities.Remove(entity); } // Prepare data Windows.MovableBlock mo = new Windows.MovableBlock(); mo.ShowDialog(); try { data.Entities.Add(new MovableBlock(position, mo.nameTextBox.Text, mo.canPushCheckBox.IsChecked.Value, mo.canBePushedCheckBox.IsChecked.Value, ArmanColor.ParseWindowsColor(mo.colorPicker.SelectedColor))); } catch (Exception ex) { MessageBox.Show("Error while parsing data from form - " + ex.Message, "Error"); } refresh(); #endregion break; case Tools.player: #region Player foreach (Entity entity in data.Entities.ToList()) { if (entity.Position == position) data.Entities.Remove(entity); } // Prepare data Windows.Player player = new Windows.Player(); player.speedLabel.ToolTip = "Set speed of player (-Infinity - " + data.OneBlockSize + ")"; player.speed.ToolTip = "Set speed of player (-Infinity - " + data.OneBlockSize + ")"; player.ShowDialog(); try { data.Entities.Add(new Player(position, player.nameTextBox.Text, player.canPushCheckBox.IsChecked.Value, player.canBePushedCheckBox.IsChecked.Value, (float)player.speed.Value, true, 69.0, (bool)player.invulnerable.IsChecked, new Controls(player.upText.Text, player.downText.Text, player.leftText.Text, player.rightText.Text), (int)player.lives.Value)); } catch (Exception ex) { MessageBox.Show("Error while parsing data from form - " + ex.Message, "Error"); } refresh(); #endregion break; case Tools.solid: #region Solid foreach (Block block in data.Blocks.ToList()) { if (block.Position == position) data.Blocks.Remove(block); } data.Blocks.Add(new Solid(position, 69.0)); #endregion break; } }); refresh(); changesSaved = false; }
public override void MoveTo(PositionInGrid direction) { Animator.SetTrigger("Move"); base.MoveTo(direction); }
public virtual bool ThingCanMoveToMe(Element element, PositionInGrid direction) { return(false); }
public Detector(Arman game, BlockType type, PositionInGrid position, int oneBlockSize, DetectorActivated detectorActivated) : base(game, type, position, oneBlockSize) { this.detectorActivated = detectorActivated; alreadyActivated = false; }
public Home(PositionInGrid position, double blastResistence) : base(position, "Home", false, blastResistence) { }
public Player(PositionInGrid position, bool canPush, bool canBePushed, float speed, bool collides, double health, bool invulnerable, Controls controls, int lives) : base(position, "Player", canPush, canBePushed, speed, collides, health, invulnerable) { Lives = lives; Controls = controls; }
public Home(PositionInGrid position, string name, double blastResistence) : base(position, name, false, blastResistence) { }
public CellLived() { position = new PositionInGrid(); }
public override bool TryMove(PositionInGrid position) { foreach(Mob mob in mobs) { if (mob.PositionInGrid == position) return false; } return base.TryMove(position); }
public override void ThingMoveToMe(Element element, PositionInGrid direction) { MoveTo(direction); }
public Cell <int> CellAt(PositionInGrid position) { return(new Cell <int>(this, position, position.row * position.column)); }
public CellLived(int row, int column) { position = new PositionInGrid(row, column); }
public void SpawnPlayer(PositionInGrid position, Controls controls) { entities.Add(new Player(game, position, game.Content.Load<Texture2D>(@"Sprites/player"), gameArray, blockSize, gameSpeed, entities, this, controls)); }
public CellDied() { position = new PositionInGrid(); }
public CellDied(int row, int column) { position = new PositionInGrid(row, column); }
void it_is_able_to_retrieve_out_of_bounds_cells_by_position_in_grid() { var position = new PositionInGrid(1, 4); _subject.CellAt(position).value.should_be(default(int)); }
public GameElement(PositionInGrid position, string name) { Position = position; Name = name; }
void before_each() { _subject = new PositionInGrid(2, 0); }