/// <summary> /// Calculates monster's next position that will bring /// monster nearer to the target. /// </summary> /// <param name="target"> /// Any canvas object /// </param> public void MoveToObject(IObject2D target) { // Instantiate random Random random = new Random(); // Define position direction int directionX = (target.Position[0] == Position[0]) ? 0 : target.Position[0] < Position[0] ? -1 : 1; int directionY = (target.Position[1] == Position[1]) ? 0 : (target.Position[1] < Position[1]) ? -1 : 1; // Randomize current direction (null one number) if (directionX != 0 && directionY != 0) { // 1 to 4 that monster will prefer to go up/down instead of going right/left if (random.Next(4) == 0) { directionX = 0; } else { directionY = 0; } } // Move the monster ((IObject2D)this).MoveDirection(directionX, directionY); }
public override void Visit(IObject parentObject) { if (parentObject is IObject2D) { IObject2D object2D = parentObject as IObject2D; object2D.CustomZoom = new Vector2f((float)(Math.Cos(this.currentValue) * this.length), object2D.CustomZoom.Y); } }
public void Visit(IObject2D parentObject2D) { this.mutex.WaitOne(); parentObject2D.SetCanevas(this.animation[this.currentIndex]); this.mutex.ReleaseMutex(); }
/// <summary> /// Check if monster is in the same position as the target. /// </summary> /// <param name="target"> /// Any canvas object /// </param> /// <returns> /// Boolean that represents if objects touch each other /// </returns> public bool IsTouchingObject(IObject2D target) { // Check if entites are on the same position bool isXSame = target.Position[0] == Position[0]; bool isYSame = target.Position[1] == Position[1]; // Return the result return(isXSame && isYSame); }
public void StopMusics(IObject2D owner) { if (this.object2DToMusics.TryGetValue(owner, out MusicObject2D music)) { music.PlayAnimation(1); this.oldMusics.Add(music); } }
/// <summary> /// Konstruktor dwuparametrowy. /// </summary> /// <param name="x">Wspolrzedna startowa x.</param> /// <param name="y">Wspolrzedna startowa y.</param> /// <param name="planeSpeed">Wektor ruchu.</param> /// <param name="level">Referencja do obiektu Level.</param> /// <author>Michal Ziober</author> public Bomb(float x, float y, PointD planeSpeed, Level level, float angle, IObject2D owner) : base(level, angle, owner) { //prostokat opisujacy obiekt. boundRectangle = new Quadrangle(new PointD(x, y - 1), BombWidth, BombHeight); //wektor ruchu. moveVector = new PointD(WidthCoefficient * planeSpeed.X, HeightCoefficient); }
public BunkerShellBullet BunkerShellFire(IObject2D obj, float fireAngle) { // Console.WriteLine("Flak fire angle:"+fireAngle); BunkerShellBullet shell = new BunkerShellBullet(ammunitionOwner.Center.X, ammunitionOwner.Center.Y, refToLevel, ammunitionOwner, obj, fireAngle, GameConsts.FlakBunker.InitialFlakSpeed); RegisterWeaponToModelEvent(shell); refToLevel.Controller.OnRegisterBunkerShellBullet(shell); return(shell); }
public FlakBullet FlakFire(IObject2D obj, float fireAngle) { // Console.WriteLine("Flak fire angle:"+fireAngle); FlakBullet flak = new FlakBullet(ammunitionOwner.Center.X, ammunitionOwner.Center.Y, refToLevel, ammunitionOwner, obj, fireAngle, GameConsts.FlakBunker.InitialFlakSpeed); RegisterWeaponToModelEvent(flak); refToLevel.Controller.OnRegisterFlakBullet(flak); return(flak); }
public IAnimation GetAnimationFromAObject2D(IObject2D object2D) { IAnimation animation = null; if (this.animationsToPlay.ContainsKey(object2D)) { animation = this.animationsToPlay[object2D]; } return(animation); }
/// <summary> /// Sprawdza czy punkt przeciecia jest w zasiegu samolotu. /// </summary> /// <param name="cut">Punkt przeciecia dwoch prostych.</param> /// <param name="plane"></param> /// <returns>true jesli punkt przeciecia jest w zasiegu, false /// w przeciwnym przypadku.</returns> /// <author>Michal Ziober</author> private static bool IsCutInRange(PointD cut, IObject2D target) { // PointD diff = (cut - plane); PointD tpoint = target.Bounds.Center; // return diff.EuclidesLength < (new PointD(Plane.Width, Plane.Height).EuclidesLength) * 0.5f ; return (((cut.Y > tpoint.Y - target.Bounds.Height) && (cut.Y < tpoint.Y + target.Bounds.Height)) && ((cut.X > tpoint.X - target.Bounds.Width) && (cut.X < tpoint.X + target.Bounds.Width))); }
public void StopSounds(IObject2D owner) { if (this.object2DToSounds.TryGetValue(owner, out List <SoundObject2D> sounds)) { foreach (SoundObject2D sound in sounds) { sound.Dispose(); } this.object2DToSounds.Remove(owner); } }
public BunkerShellBullet(float x, float y, Level level, IObject2D owner, IObject2D target, float fireAngle, float initialSpeed) : base(x, y, GetInitialVector(owner, target, initialSpeed), level, fireAngle, owner) { this.target = target; boundRectangle = new Quadrangle(new PointD(x, y), 3, 3); PointD diffVector = (target.Center - owner.Center); maxFlyingDistance = diffVector.EuclidesLength * mRand.Next(90, 110) / 100.0f; diffVector.Normalise(); diffVector.X *= -1; SetZRotationPerSecond(diffVector.X * 2.9f); // zaginanie toru lotu do ziemi }
public void PlayAnimation(IObject2D object2D, ZoomAnimation animation) { animation.Reset(); if (this.animationsToPlay.ContainsKey(object2D)) { this.animationsToPlay[object2D] = animation; } else { this.animationsToPlay.Add(object2D, animation); } }
/// <summary> /// Publiczny konstruktor bezargumentowy. Tworzy obiekt amunicji /// o podanych parametrach. /// </summary> /// <param name="planeSpeed">Wektor ruchu.</param> /// <param name="level">Referencja do obiektu level.</param> /// <param name="angle">Kat nachylenia.</param> /// <param name="owner">Wlasciciel broni.</param> /// <author>Michal Ziober</author> public Ammunition(Level level, float angle, IObject2D owner) { //referencja na obiekt Level refToLevel = level; //kat pod jakim spada pocisk relativeAngle = angle; //ustawiam pocisk jako niezniszczony. state = MissileState.Intact; //wlasciciel broni. ammunitionOwner = owner; }
/// <summary> /// Publiczny konstruktor dwuparametrowy. /// </summary> /// <param name="refLevel">Referncja do planszy.</param> /// <param name="owner">Wlasciciel broni.</param> /// <param name="rocketCount">Maksymalna liczba rakiet.</param> /// <param name="bombCount">Maksymalna liczba bomb.</param> /// <param name="torpedoCount">Maksymalna liczba torped.</param> public WeaponManager(LevelRef refLevel, IObject2D owner, int rocketCount, int bombCount, int torpedoCount) { refToLevel = refLevel; lastFireTick = Environment.TickCount; maxBombs = bombCount; maxRockets = rocketCount; MaxTorpedoes = torpedoCount; this.bombCount = maxBombs; this.rocketCount = maxRockets; this.torpedoCount = MaxTorpedoes; actualWeapon = WeaponType.Gun; ammunitionOwner = owner; gun = new Gun(refLevel); }
public IAnimation GetAnimationFromAObject2D(IObject2D object2D) { this.mutex.WaitOne(); IAnimation animation = null; if (this.animationsToPlay.ContainsKey(object2D)) { animation = this.animationsToPlay[object2D]; } this.mutex.ReleaseMutex(); return(animation); }
public AAudioObject2D(ALayer2D parentLayer, IObject2D owner) : base(parentLayer, null, true) { this.Owner = owner; this.Owner.PropertyChanged += this.OnOwnerPropertyChanged; parentLayer.ViewChanged += this.OnViewChanged; IAnimation fadeInAnimation = new AudioVolumeAnimation(0, VOLUME, SFML.System.Time.FromSeconds(FADE_PERIOD), AnimationType.ONETIME, InterpolationMethod.LINEAR); this.animationsList.Add(fadeInAnimation); IAnimation fadeOutAnimation = new AudioVolumeAnimation(VOLUME, 0, SFML.System.Time.FromSeconds(FADE_PERIOD), AnimationType.ONETIME, InterpolationMethod.LINEAR); this.animationsList.Add(fadeOutAnimation); }
public void PlayAnimation(IObject2D object2D, IAnimation animation) { this.mutex.WaitOne(); animation.Reset(); if (this.animationsToPlay.ContainsKey(object2D)) { this.animationsToPlay[object2D] = animation; } else { this.animationsToPlay.Add(object2D, animation); } this.mutex.ReleaseMutex(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Moves player in the target direction. /// </summary> /// <param name="directionX"> /// Movement direction in the X axis /// </param> /// <param name="directionY"> /// Movement direction in the Y axis /// </param> /// <returns> /// Boolean that represents if player currently touching the canvas border /// </returns> private bool MovePlayer(int directionX, int directionY) { // Validate arguments if (Math.Abs(directionX) > 1 || Math.Abs(directionY) > 1) { throw new Exception($"Invalid direction. Value should be 1, -1 or 0. Got: {directionX}:{directionY}"); } // Convert to its object2d interface, since it contains premade movement methods IObject2D objectPlayer = myPlayer; // Move the player objectPlayer.MoveDirection(directionX, directionY); // Check if player is touching the border -> Return result return(CheckPlayerTouchesBorder()); }
protected static PointD GetInitialVector(IObject2D owner, IObject2D target, float initialSpeed) { float speedCoeff = 2 * target.MovementVector.EuclidesLength / GameConsts.P47Plane.Singleton.MaxSpeed; float distanceCoeff = 2.0f; float xSpread = distanceCoeff * speedCoeff * target.Bounds.Width; float ySpread = distanceCoeff * speedCoeff * target.Bounds.Height; float xPos = mRand.Next((int)(target.Bounds.Center.X - xSpread * 0.5f), (int)(target.Bounds.Center.X + xSpread * 0.5f)); float yPos = mRand.Next((int)(target.Bounds.Center.Y * 1.0f - ySpread * 0.5f), (int)(target.Bounds.Center.Y * 1.0f + ySpread * 0.5f)); PointD flakPosition = new PointD(xPos, yPos); PointD direction = (flakPosition - owner.Center); direction.Normalise(); return(initialSpeed * direction); }
protected bool isTurnedTowardsFaceOf(IObject2D obj) { if (direction == obj.Direction) { return(false); } if (direction == Model.Level.Direction.Right) { return(obj.Bounds.RightMostX > bounds.LeftMostX); } if (direction == Model.Level.Direction.Left) { return(obj.Bounds.LeftMostX < bounds.RightMostX); } return(false); }
public float GetDamage(IObject2D obj) { float dist = (obj.Bounds.Center - Position).EuclidesLength; if (obj.Bounds.Intersects(this.Bounds)) { float damage = GameConsts.Gun.BaseDamage * GameConsts.GenericPlane.CurrentUserPlane.HitCoefficient; if (obj is Wof.Model.Level.Planes.Plane) { if (!(obj as Wof.Model.Level.Planes.Plane).IsEnemy) { damage *= 0.5f; } } return(damage); } return(0); }
public float GetDamage(IObject2D obj) { float dist = (obj.Bounds.Center - Position).EuclidesLength; if (dist < GameConsts.FlakBunker.DamageRange) { float illuminationMultiplier = 1.0f; if (ammunitionOwner is BunkerTile) { if ((ammunitionOwner as BunkerTile).IsIlluminatedShot) { illuminationMultiplier = 2.0f; } } float damageCoeff = ((GameConsts.FlakBunker.DamageRange - dist) / GameConsts.FlakBunker.DamageRange); float damage = illuminationMultiplier * GameConsts.FlakBunker.MaxDamagePerHit * damageCoeff * GameConsts.GenericPlane.CurrentUserPlane.HitCoefficient; return(damage); } return(0); }
protected bool isChasedBy(IObject2D obj) { if (obj.MovementVector.EuclidesLength < 0.01f) { return(false); } if (direction != obj.Direction) { return(false); } if (direction == Model.Level.Direction.Right) { return(obj.Center.X < Center.X); } if (direction == Model.Level.Direction.Left) { return(obj.Center.X > Center.X); } return(false); }
/* public static bool CanHitObjectByGun(IObject2D owner, IObject2D target) * { * return CanHitObjectByGun(owner, target, 0); * } * public static bool CanHitObjectByGun(IObject2D owner, IObject2D target, float tolerance) * { * return CanHitObjectByGun(owner, target, tolerance, false); * }*/ /// <summary> /// Funkcja sprawdza czy samolot bedzie mogl trafic dzialkiem w inny obiekt. /// </summary> /// <param name="owner">Samolot strzelajacy.</param> /// <param name="target">Samolot do ktorego strzelaja.</param> /// <param name="tolerance">Tolerancja. 0 - oznacza pewne trafienie.</param> /// <returns>Zwraca true jesli moze trafic wrogi samolot; false - w przeciwnym /// przypadku.</returns> /// <author>Michal Ziober</author> public static bool CanHitObjectByGun(IObject2D owner, IObject2D target, float tolerance, bool biDirectional) { // UWAGA: Zakladamy ze if (!biDirectional) { Direction gunDirection = owner.MovementVector.X > 0 ? Direction.Right : Direction.Left; // Console.WriteLine( (int)owner.Direction * (owner.Bounds.Peaks[2].X - owner.Bounds.Peaks[1].X)); if (gunDirection == Direction.Right && owner.Center.X > target.Center.X) { return(false); } if (gunDirection == Direction.Left && owner.Center.X < target.Center.X) { return(false); } } /* if (System.Math.Abs(owner.Center.X - target.Center.X) < 10 && * System.Math.Abs(owner.Center.Y - target.Center.Y) < 10) * return false; */ /* * if ((owner.Bounds.Center - target.Bounds.Center).EuclidesLength > Math.Sqrt(RangeX * RangeX + RangeY * RangeY)) * { * return false; * } * */ Quadrangle ownerBound = owner.Bounds; Quadrangle targetBound = target.Bounds; Line lineA = new Line(ownerBound.Peaks[1], ownerBound.Peaks[2]); for (int i = 0; i < targetBound.Peaks.Count - 1; i++) { PointD start = targetBound.Peaks[i]; start += new PointD(Math.RangeRandom(-tolerance * 0.5f, -tolerance * 0.5f), Math.RangeRandom(-tolerance * 0.5f, -tolerance * 0.5f)); PointD finish = targetBound.Peaks[i + 1]; finish += new PointD(Math.RangeRandom(-tolerance * 0.5f, -tolerance * 0.5f), Math.RangeRandom(-tolerance * 0.5f, -tolerance * 0.5f)); Line lineB = new Line(start, finish); PointD cut = lineA.Intersect(lineB); if (cut == null) { continue; } if (IsCutInRange(cut, target)) { return(true); } } return(false); }
public MusicObject2D(ALayer2D parentLayer, IObject2D owner, string musicPath) : base(parentLayer, owner) { this.music = new Music(musicPath); }
// protected abstract PointD GetInitialFlyVector() { // // } /// <summary> /// Konstruktor piecioparametrowy.Tworzy /// nowa rakiete na planszy. /// </summary> /// <param name="position">Pozycja rakiety.</param> /// <param name="initialVelocity">Wektor ruchu.</param> /// <param name="level">Referencja do obiektu planszy.</param> /// <param name="angle">Kat nachylenia.</param> /// <param name="owner">Wlasciciel rakiety.</param> /// <author>Michal Ziober</author> public MissileBase(PointD position, PointD initialVelocity, Level level, float angle, IObject2D owner) : this(position.X, position.Y, initialVelocity, level, angle, owner) { }
/// <summary> /// Konstruktor szescioparametrowy. Tworzy /// nowa rakiete na planszy. /// </summary> /// <param name="x">Wspolrzedna x.</param> /// <param name="y">Wspolrzedna y.</param> /// <param name="initialVelocity">Wektor ruchu.</param> /// <param name="level">Referencja do obiektu planszy.</param> /// <param name="angle">Kat nachylenia.</param> /// <param name="owner">Wlasciciel amunicji.</param> /// <author>Michal Ziober</author> public MissileBase(float x, float y, PointD initialVelocity, Level level, float angle, IObject2D owner) : base(level, angle, owner) { timeCounter = 0; this.initialVelocity = initialVelocity; //prostokat opisujacy obiekt. if (initialVelocity.X >= 0) { boundRectangle = new Quadrangle(new PointD(x - WidthShift, y - HeightShift), RocketWidth, RocketHeight); } else { boundRectangle = new Quadrangle(new PointD(x + WidthShift, y - HeightShift), RocketWidth, RocketHeight); } float yDropSpeed; yDropSpeed = owner.Bounds.IsObverse ? -DropSpeed : DropSpeed; //kierunek ruchu podczas lotu z silnikiem. // float speedX = initialVelocity.X >= 0 ? GameConsts.Rocket.BaseSpeed : -GameConsts.Rocket.BaseSpeed; //wektor ruchu podczas spadania. moveVector = new PointD(initialVelocity.X, yDropSpeed); if (initialVelocity.EuclidesLength < GameConsts.Rocket.BaseSpeed) { initialVelocity.EuclidesLength = GameConsts.Rocket.BaseSpeed; } //weektor ruchu podczas pracy silnika. if (initialVelocity.X >= 0) { flyVector = new PointD(initialVelocity.X * 0.7f * GameConsts.Rocket.BaseSpeed, initialVelocity.Y * 0.7f * GameConsts.Rocket.BaseSpeed); } else { flyVector = new PointD(initialVelocity.X * 0.7f * GameConsts.Rocket.BaseSpeed, initialVelocity.Y * 0.7f * GameConsts.Rocket.BaseSpeed); } }
// (reversed ? Mogre.Math.PI - fireAngle : fireAngle) public GunBullet(float x, float y, Quaternion launchOrientation, Level level, IObject2D owner, bool reversed, bool doubleView) : base(x, y, (reversed ? -1 : 1) * owner.MovementVector, level, 0, owner) { this.launchOrientation = launchOrientation; // flyVector = new PointD(GameConsts.Rocket.BaseSpeed, GameConsts.Rocket.BaseSpeed); isReversed = reversed; isDoubleView = doubleView; boundRectangle = new Quadrangle(new PointD(x, y), 1, 1); maxFlyingDistance = baseMaxDistance * mRand.Next(90, 110) / 100.0f; this.planeTurningProgress = planeTurningProgress; position3 = new Vector3(x, y, 0); }
/// <summary> /// Konstruktor szescioparametrowy. Tworzy /// nowa rakiete na planszy. /// </summary> /// <param name="x">Wspolrzedna x.</param> /// <param name="y">Wspolrzedna y.</param> /// <param name="initialVelocity">Wektor ruchu.</param> /// <param name="level">Referencja do obiektu planszy.</param> /// <param name="angle">Kat nachylenia.</param> /// <param name="owner">Wlasciciel amunicji.</param> /// <author>Michal Ziober</author> public Rocket(float x, float y, PointD initialVelocity, Level level, float angle, IObject2D owner) : base(x, y, initialVelocity, level, angle, owner) { }