public GameField(GamefieldItems[,] gamefield, Vector2 totalSize, Vector2 fieldSize, Vector2 position) { Gamefield = gamefield; _fieldSize = fieldSize; _totalSize = totalSize; _position = position; float tempfieldScale = fieldSize.X / (WidthOfOneBlock * gamefield.GetLength(0)); FieldScale = fieldSize.Y / (HeigthOfOneBlock * gamefield.GetLength(1)); if (Math.Abs(tempfieldScale - FieldScale) > 0.2f) { MessageBox(new IntPtr(0), "OH no, The fields ratio's are off, this might look ugly", "Made a new gamefield", 0); } XLenght = gamefield.GetLength(0); YLenght = gamefield.GetLength(1); _explosionProtoType = new Explosion(); }
public Explosion Copy(ExplosionTypes explosionType) { Explosion output = new Explosion(); output._explosionType = explosionType; output.CollisionType = CollisionType; output._fixedExplosionType = true; output._explosionCross = _explosionCross; output._explosionDown = _explosionDown; output._explosionDownEnd = _explosionDownEnd; output._explosionLeft = _explosionLeft; output._explosionLeftEnd = _explosionLeftEnd; output._explosionRight = _explosionRight; output._explosionRightEnd = _explosionRightEnd; output._explosionUp = _explosionUp; output._explosionUpEnd = _explosionUpEnd; output._explosionTime = _explosionTime; return output; }
private void GetCorrectExplosionStyle(int xPoint, int yPoint, bool right, bool left, bool up, bool down, Explosion explosion) { //if (up && down && left && right) //{ // explosion.ExplosionType = ExplosionTypes.Cross; //} //else //{ bool unset = true; if (up && !down) { explosion.ExplosionType = ExplosionTypes.DownEnd; unset = false; } if (down && !up) { explosion.ExplosionType = ExplosionTypes.UpEnd; unset = false; } if (up && down) { if (FindExplosionCross(true, xPoint, yPoint, explosion)) { explosion.ExplosionType = ExplosionTypes.Up; unset = false; } else { explosion.ExplosionType = ExplosionTypes.Down; unset = false; } } if (left && !right) { explosion.ExplosionType = ExplosionTypes.RightEnd; unset = false; } if (right && !left) { explosion.ExplosionType = ExplosionTypes.LeftEnd; unset = false; } if (left && right) { if (FindExplosionCross(false, xPoint, yPoint, explosion)) { explosion.ExplosionType = ExplosionTypes.Left; unset = false; } else { explosion.ExplosionType = ExplosionTypes.Right; unset = false; } //} } if (unset) { throw new Exception("OhNO strange behavior"); } }
/// <summary> /// Look for the explosioncross to set the correct explosion type /// </summary> /// <param name="UpDown">Search up down or left right</param> /// <param name="xPoint"> </param> /// <param name="yPoint"> </param> /// <param name="explosion">the explosion</param> /// <returns>true for cross is down or left, flase for cross is up or right </returns> private bool FindExplosionCross(bool UpDown, int xPoint, int yPoint, Explosion explosion) { if (UpDown) { for (int i = yPoint; i > 0; i--) { List<Explosion> possibleCrossExplosions = _gamefield[xPoint, i].GetExplosions(); foreach (Explosion possibleCrossExplosion in possibleCrossExplosions) { if (possibleCrossExplosion != null) { if (possibleCrossExplosion.ExplosionType == ExplosionTypes.Cross) {//we found the cross in above us, return false; } } } } //we haven't returned for values above us, the cross must be downwards. return true; } else { for (int i = xPoint; i > 0; i--) { List<Explosion> possibleCrossExplosions = _gamefield[i, yPoint].GetExplosions(); foreach (var possibleCrossExplosion in possibleCrossExplosions) { if (possibleCrossExplosion != null) { if (possibleCrossExplosion.ExplosionType == ExplosionTypes.Cross) {//we found the cross on the right from us, return false; } } } } //we haven't returned for values right us, the cross must be on our left. return true; } }