public static void Kill(BHEntity mEntity, int mFrames) { var timelineKill = new Timeline(); timelineKill.Wait(mFrames); timelineKill.Action(mEntity.Destroy); mEntity.TimelinesUpdate.Add(timelineKill); }
public Timeline Clone() { var result = new Timeline(); foreach (var command in Commands) result.Commands.Add(command.Clone()); return result; }
public static void CutIn(BHGame mGame, BHStage mStage, Texture mTexture, bool mText = false, string mBackgroundText = "spell attack", Vector2i mVelocity = default(Vector2i), Vector2i mOffset = default(Vector2i), int mLength = 100) { var cutInTimeline = new Timeline(); var texts = new List<Text>(); var drawEvents = new List<Action>(); if (mText) { for (int iX = -2; iX < 3; iX++) { for (int i = 0; i < 35; i++) { var temp = new Text(mBackgroundText, Font.DefaultFont) { Position = new Vector2f(300 + (iX*84), (i*35) - 200), Color = Color.White, CharacterSize = 15, Rotation = 25 }; texts.Add(temp); Action drawEvent = () => mGame.GameWindow.RenderWindow.Draw(temp); drawEvents.Add(drawEvent); mGame.AddDrawAction(drawEvent); } } } var cutInSprite = new Sprite(mTexture) { Color = new Color(255, 255, 255, 0) }; var cutInEntity = new BHEntity(mGame) { DrawOrder = 100000, Sprite = cutInSprite, Position = mGame.Center + mOffset }; BHPresetTimelines.Fade(cutInEntity, 0, true, 16); BHPresetTimelines.Fade(cutInEntity, mLength, false, 16); cutInTimeline.Action(() => { foreach (var text in texts) text.Position -= new Vector2f(3, 1); }); cutInTimeline.Action(() => cutInEntity.Position += mVelocity); cutInTimeline.Wait(); cutInTimeline.Goto(mTimes: 200); cutInTimeline.Action(() => { foreach (var drawEvent in drawEvents) mGame.RemoveDrawAction(drawEvent); cutInEntity.Destroy(); }); mStage.TimelinesUpdate.Add(cutInTimeline); }
public static BHEntity Boss(BHGame mGame, int mRadius, int mHealth) { var deathTimeline = new Timeline(); var result = new BHEntity(mGame, "boss", "enemy", "character"); result.CollisionShape = new BHCSCircle(result, mRadius*mRadius); result.Parameters["health"] = mHealth; deathTimeline.Action(() => { if ((int) result.Parameters["health"] <= 0) {} }); deathTimeline.Wait(); deathTimeline.Goto(); result.TimelinesUpdate.Add(deathTimeline); return result; }
public static void MovementLerp(BHEntity mEntity, Vector2i mPosition, int mSteps = 100) { var startPosition = new SSVector2I(mEntity.Position.X, mEntity.Position.Y); var endPosition = new SSVector2I(mPosition.X, mPosition.Y); var timelineLerp = new Timeline(); for (int i = 0; i < mSteps; i++) { float value = i/100f; var lerp = Utils.Math.Vectors.Lerp(startPosition, endPosition, value); timelineLerp.Action(() => mEntity.Position = new Vector2i(lerp.X, lerp.Y)); // LAgs with 10000 test it out timelineLerp.Wait(); } mEntity.TimelinesUpdate.Add(timelineLerp); }
public static BHEntity Reimu(BHGame mGame) { var fireTimeline = new Timeline(); BHEntity result = BHPresetBase.Player(mGame, 4.ToUnits(), 2.ToUnits(), Assets.GetAnimation("playerleft"), Assets.GetAnimation("playerright"), Assets.GetAnimation("playerstill")); result.Sprite = Assets.GetTileset("p_reimu").GetSprite("s1", Assets.GetTexture("p_reimu")); fireTimeline.Action(() => { if (Keyboard.IsKeyPressed(Keyboard.Key.Z)) { Assets.GetSound("se_plst00").Play(); BHPresetBase.PlayerBullet(mGame, result.Position - new Vector2i(8.ToUnits(), 17.ToUnits()), 270, 27.ToUnits()).Sprite = new Sprite(Assets.GetTexture("b_player_reimu1")); BHPresetBase.PlayerBullet(mGame, result.Position - new Vector2i(-8.ToUnits(), 17.ToUnits()), 270, 27.ToUnits()).Sprite = new Sprite(Assets.GetTexture("b_player_reimu1")); } }); fireTimeline.Wait(4); fireTimeline.Goto(); result.TimelinesUpdate.Add(fireTimeline); return result; }
public static void Fade(BHEntity mEntity, int mDelay = 0, bool mFadeIn = true, int mSpeedMultiplier = 3) { int value = mSpeedMultiplier; if (!mFadeIn) value *= -1; var fadeTimeline = new Timeline(); fadeTimeline.Wait(mDelay); fadeTimeline.Action(() => { byte r = mEntity.Sprite.Color.R; byte g = mEntity.Sprite.Color.G; byte b = mEntity.Sprite.Color.B; if (mEntity.Sprite.Color.A + value > 255) mEntity.Sprite.Color = new Color(r, g, b, 255); else if (mEntity.Sprite.Color.A + value < 0) mEntity.Sprite.Color = new Color(r, g, b, 0); else mEntity.Sprite.Color = new Color(r, g, b, (byte) (mEntity.Sprite.Color.A + value)); } ); fadeTimeline.Wait(); fadeTimeline.Goto(1, 255/mSpeedMultiplier); mEntity.TimelinesUpdate.Add(fadeTimeline); }
public static BHEntity Enemy(BHGame mGame, int mRadius, int mHealth) { var deathTimeline = new Timeline(); var result = new BHEntity(mGame, "enemy", "character"); result.CollisionShape = new BHCSCircle(result, mRadius*mRadius); result.Parameters["health"] = mHealth; deathTimeline.Action(() => { if ((int) result.Parameters["health"] <= 0) { result.Destroy(); Assets.GetSound("se_enep00").Play(); } }); deathTimeline.Wait(); deathTimeline.Goto(); result.TimelinesUpdate.Add(deathTimeline); return result; }
public static BHEntity EnemyFairy1(BHGame mGame, Vector2i mPosition, bool mRight, string mTexture, int mMultiplier = 1) { int dir = -1; if (mRight) dir = 1; int s = 2; BHEntity result = BHPresetBase.Enemy(mGame, 20.ToUnits(), 2); result.Sprite = Assets.GetTileset(mTexture).GetSprite("s1", Assets.GetTexture("enemyfairy")); result.IsSpriteFixed = true; result.Position = mPosition; result.Animation = Assets.GetAnimation("enemyfairystill"); BHPresetTimelines.Kill(result, 400); // MOVEMENT TIMELINES var timelineMovement = new Timeline(); for (int i = 0; i < 150; i++) { int i1 = i; timelineMovement.AddCommand(new Do(() => result.Velocity = new Vector2i((0.1f.ToUnits()*s - (i1*-3*s))*dir, 0 + (i1*3*s)))); if (i%3 == 0) timelineMovement.AddCommand(new Wait(1)); } // ------------------- // ATTACK TIMELINES var timelineAttack = new Timeline(); timelineAttack.AddCommand(new Do(() => EnemyFairy1Attack(mGame, result.Position, new Color(135, 135, 230, 255), mMultiplier))); timelineAttack.AddCommand(new Wait(25)); timelineAttack.AddCommand(new Goto(0, 8)); // ------------------- result.TimelinesUpdate.Add(timelineMovement); result.TimelinesUpdate.Add(timelineAttack); return result; }
public static BHEntity Player(BHGame mGame, int mSpeedNormal, int mSpeedFocus, Animation mAnimationLeft, Animation mAnimationRight, Animation mAnimationStill) { var updateTimeline = new Timeline(); var drawTimeline = new Timeline(); var hitboxSprite = new Sprite(Assets.GetTexture("p_hitbox")); var result = new BHEntity(mGame, "character", "player") {DrawOrder = -10000, IsSpriteFixed = true, BoundsOffset = 10.ToUnits(), Animation = mAnimationStill}; result.CollisionShape = new BHCSPoint(result); result.CollisionAgainstGroups.Add("deadlytoplayer"); result.OnOutOfBounds += BHPresetOutOfBounds.Stop; result.OnCollision += (entity, group) => { if (group == "deadlytoplayer") Assets.GetSound("pldead00").Play(); }; updateTimeline.Action(() => { int speed = mGame.Focus == 1 ? mSpeedFocus : mSpeedNormal; if (mGame.NextX != 0 && mGame.NextY != 0) speed = (int) (speed*0.7); if (mGame.NextX > 0 && mAnimationRight != null) result.Animation = mAnimationRight; else if (mGame.NextX < 0 && mAnimationLeft != null) result.Animation = mAnimationLeft; else if (mAnimationStill != null) result.Animation = mAnimationStill; result.Velocity = new Vector2i(mGame.NextX*speed, mGame.NextY*speed); hitboxSprite.Rotation++; }); updateTimeline.Wait(); updateTimeline.Goto(); drawTimeline.Action(() => { if (mGame.Focus == 0) return; hitboxSprite.Origin = new Vector2f(32, 32); hitboxSprite.Position = new Vector2f(result.Position.X.ToPixels(), result.Position.Y.ToPixels()); mGame.GameWindow.RenderWindow.Draw(hitboxSprite); }); drawTimeline.Wait(); drawTimeline.Goto(); result.TimelinesUpdate.Add(updateTimeline); result.TimelinesDrawAfter.Add(drawTimeline); return result; }
public static void EnemyMidboss1SpellCard2(BHGame mGame, BHEntity mBoss) { var spellcardTimeline = new Timeline(); spellcardTimeline.AddCommand(new Do(() => EnemyMidboss1SpellCardAttack3(mGame, mBoss.Position))); spellcardTimeline.AddCommand(new Wait(21)); spellcardTimeline.AddCommand(new Do(() => BHPresetTimelines.MovementLerp(mBoss, new Vector2i(Utils.Random.Next(mGame.Bounds.Left + 5.ToUnits(), mGame.Bounds.Right - 5.ToUnits()), mBoss.Position.Y)))); spellcardTimeline.AddCommand(new Goto(0)); var continueTimeline = new Timeline(); continueTimeline.AddCommand(new Wait(25)); continueTimeline.AddCommand(new Do(() => BHPresetTimelines.MovementLerp(mBoss, new Vector2i(mGame.Center.X, mBoss.Position.Y)))); continueTimeline.AddCommand(new Wait(75)); continueTimeline.AddCommand(new Do(mBoss.Destroy)); continueTimeline.AddCommand(new Do(() => Assets.GetSound("enep01").Play())); BHPresetStageControl.CutIn(mGame, mGame.CurrentStage, Assets.GetTexture("face07bs"), true, "u mad bro?", new Vector2i(6.ToUnits(), 1.ToUnits()), new Vector2i(-10.ToUnits(), 5.ToUnits()), 150); BHPresetStageControl.SpellCard(mGame, mGame.CurrentStage, mBoss, "HERE ARE SOME BULLETS 4 U", 150, 1000, 10000, continueTimeline, spellcardTimeline); }
public static BHEntity Laser(BHGame mGame, Sprite mSprite, Vector2i mPosition = default(Vector2i), float mAngle = 0, int mSpeed = 0, long mRadius = 0, int mLength = 0, bool mGrow = false, int mGrowSpeed = 0, bool mPrimed = false, int mPrimeTime = 50, int mPrimeSurviveTime = 50) { var primeTimeline = new Timeline(); var growTimeline = new Timeline(); var drawTimeline = new Timeline(); long radius = (mRadius/2)*(mRadius/2); var result = new BHEntity(mGame, "laser") {Position = mPosition, Velocity = BHUtils.CalculateVelocity(mAngle, mSpeed)}; if (!mPrimed) result.AddGroup("deadlytoplayer"); result.CollisionShape = mGrow ? new BHCSLine(result, mAngle, 0, radius) : new BHCSLine(result, mAngle, mLength, radius); result.BoundsOffset = -1000.ToUnits(); result.Sprite = mSprite; result.Sprite.Rotation = mAngle; result.Sprite.Transform.Scale(1, result.Sprite.Texture.Size.Y); result.Sprite.Origin = new Vector2f(0, result.Sprite.Origin.Y); //result.Sprite.BlendMode = BlendMode.Add; result.IsSpriteFixed = true; float height = (mRadius*2).ToPixels(); if (mPrimed) height = 1; // if (mPrimed) result.Sprite.BlendMode = BlendMode.Alpha; primeTimeline.Wait(mPrimeTime); primeTimeline.Action(() => { result.AddGroup("deadlytoplayer"); height = (mRadius*2).ToPixels(); // result.Sprite.BlendMode = BlendMode.Add; }); primeTimeline.Wait(mPrimeSurviveTime); primeTimeline.Action(result.Destroy); growTimeline.Action(() => { var lineShape = (BHCSLine) result.CollisionShape; if (lineShape.Length < mLength) { lineShape.Length += mGrowSpeed; result.Velocity = new Vector2i(0, 0); } else { result.Velocity = BHUtils.CalculateVelocity(mAngle, mSpeed); growTimeline.Finished = true; } }); growTimeline.Wait(); growTimeline.Goto(); drawTimeline.Action(() => { var lineShape = (BHCSLine) result.CollisionShape; result.Sprite.Rotation = lineShape.Degrees; result.Sprite.Transform.Scale(lineShape.Length.ToPixels(), height); result.Sprite.Origin = new Vector2f(0, result.Sprite.Origin.Y); }); drawTimeline.Wait(); drawTimeline.Goto(); if (mPrimed) result.TimelinesUpdate.Add(primeTimeline); result.TimelinesUpdate.Add(growTimeline); result.TimelinesDrawBefore.Add(drawTimeline); result.OnOutOfBounds += BHPresetOutOfBounds.Destroy; return result; }
public static BHEntity Polygon(BHGame mGame, List<Vector2i> mVertices) { var drawTimeline = new Timeline(); var result = new BHEntity(mGame, "deadlytoplayer") {Position = mGame.Center}; result.CollisionShape = new BHCSPolygon(result, mVertices.ToArray()); drawTimeline.Action(() => { var shape = (BHCSPolygon) result.CollisionShape; //foreach (Vector2i vertex in shape.Vertices) mGame.WindowManager.RenderWindow.Draw(new CircleShape(new Vector2f(vertex.X.ToPixels(), vertex.Y.ToPixels()), 2, Color.Red)); }); drawTimeline.Wait(); drawTimeline.Goto(); result.TimelinesDrawBefore.Add(drawTimeline); return result; }
public static void SpellCard(BHGame mGame, BHStage mStage, BHEntity mBoss, string mSpellCardName, int mHealth, int mTime, int mScore, Timeline mOnEnd, params Timeline[] mTimelines) { var spellCardTimeline = new Timeline(); mBoss.Parameters["health"] = mHealth; var drawEvents = new List<Action>(); var spellCardText = new Text(mSpellCardName, Font.DefaultFont) { Position = new Vector2f(32, 16), Color = Color.White, CharacterSize = 15, }; var mTimeText = new Text(mTime.ToString(), Font.DefaultFont) { Position = new Vector2f(384, 16), Color = Color.White, CharacterSize = 15 }; Action spellCardTextDrawEvent = () => mGame.GameWindow.RenderWindow.Draw(spellCardText); drawEvents.Add(spellCardTextDrawEvent); mGame.AddDrawAction(spellCardTextDrawEvent); Action timeTextDrawEvent = () => mGame.GameWindow.RenderWindow.Draw(mTimeText); drawEvents.Add(timeTextDrawEvent); mGame.AddDrawAction(timeTextDrawEvent); mStage.TimelinesUpdate.AddRange(mTimelines); Assets.GetSound("cat00").Play(); spellCardTimeline.Action(() => { mTime--; mTimeText.DisplayedString = mTime.ToString(); }); spellCardTimeline.Wait(); spellCardTimeline.AddCommand(new GotoConditional(() => mTime < 1 || (int) mBoss.Parameters["health"] < 1, 0, -1)); spellCardTimeline.Action(() => { foreach (var drawEvent in drawEvents) mGame.RemoveDrawAction(drawEvent); foreach (var timeline in mTimelines) timeline.Finished = true; ClearBullets(mGame, mStage); if (mOnEnd != null) mStage.TimelinesUpdate.Add(mOnEnd); }); mStage.TimelinesUpdate.Add(spellCardTimeline); }
public static void EnemyMidboss1SpellCardAttack1(BHGame mGame, Vector2i mPosition) { Assets.GetSound("lazer00").Play(); for (int i = 0; i < 60; i++) { BHEntity ent = BHPresetBase.Laser(mGame, new Sprite(Assets.GetTexture("b_laser")), mPosition, (360/12)*i + i, 0.5f.ToUnits() + i*10, 4.ToUnits(), 30.ToUnits() + (i*0.1f.ToUnits()), true, 250); var laserTimeline = new Timeline(); int i1 = i; laserTimeline.AddCommand(new Do(() => { var lineShape = (BHCSLine) ent.CollisionShape; lineShape.Degrees += i1/20f; lineShape.Length += 0.7f.ToUnits(); })); laserTimeline.AddCommand(new Wait(1)); laserTimeline.AddCommand(new Goto(0, 145)); ent.TimelinesUpdate.Add(laserTimeline); } }
public override void Update(float mFrameTime) { if (_speed < _speedMax) _speed += 3*mFrameTime; if (_rotationSpeed < 0.2f) _rotationSpeed += 0.002f * mFrameTime + (float)Utils.Random.NextDouble() / 1000f; if (_cTargeter.Target != null) { var targetAngle = _cTargeter.GetDegreesTowardsTarget(); _shootDelay += mFrameTime + (float) Utils.Random.NextDouble()/100f; if (_shootDelay > _shootDelayMax) { _timeline = new Timeline(); if (!_big) { _timeline.AddCommand(new Do(() => _game.Factory.Bullet(_cBody.Position.X, _cBody.Position.Y, targetAngle, 300, !Friendly))); _timeline.AddCommand(new Wait(3)); _timeline.AddCommand(new Do(() => _game.Factory.Bullet(_cBody.Position.X, _cBody.Position.Y, targetAngle + Utils.Random.Next(-10, 10), 300, !Friendly))); _timeline.AddCommand(new Wait(3)); _timeline.AddCommand(new Do(() => _game.Factory.Bullet(_cBody.Position.X, _cBody.Position.Y, targetAngle + Utils.Random.Next(-10, 10), 300, !Friendly))); } else { _timeline.AddCommand(new Do(() => { _game.Factory.BigBullet(_cBody.Position.X, _cBody.Position.Y, targetAngle + Utils.Random.Next(-25, 25), 250, !Friendly); _game.Factory.Bullet(_cBody.Position.X, _cBody.Position.Y, Utils.Random.Next(0, 360), 250, !Friendly); _game.Factory.Bullet(_cBody.Position.X, _cBody.Position.Y, Utils.Random.Next(0, 360), 250, !Friendly); _speed = 0; })); _timeline.AddCommand(new Wait(2)); _timeline.AddCommand(new Goto(0, 15)); } _timeline.AddCommand(new Wait(3)); _timeline.AddCommand(new Do(() => _cRender.Animation = Assets.GetAnimation("charidle"))); _shootDelay = 0; } if (_shootDelay > _shootDelayMax - 30) _cRender.Animation = Assets.GetAnimation("charfiring"); _angle = Utils.Math.Angles.RotateTowardsAngleDegrees(_angle, targetAngle, _rotationSpeed); } _cMovement.Angle = _angle; _cMovement.Speed = (int) _speed; if (_timeline != null) _timeline.Update(mFrameTime); }
public static BHEntity EnemyFairyBig1(BHGame mGame, Vector2i mPosition, string mTexture) { BHEntity result = BHPresetBase.Enemy(mGame, 30.ToUnits(), 40); result.Sprite = new Sprite(Assets.GetTexture(mTexture)); result.IsSpriteFixed = true; result.Position = mPosition; BHPresetTimelines.Kill(result, 900); // MOVEMENT TIMELINES var timelineMovement = new Timeline(); timelineMovement.Action(() => result.Velocity = new Vector2i(0, 150)); timelineMovement.Wait(100); timelineMovement.Action(() => result.Velocity = new Vector2i(0, 0)); timelineMovement.Wait(500); timelineMovement.Action(() => result.Velocity = new Vector2i(0, -150)); // ------------------- // ATTACK TIMELINES var timelineAttack = new Timeline(); timelineAttack.Parameters["angle"] = 0; timelineAttack.AddCommand(new Do(() => { var angle = (int) timelineAttack.Parameters["angle"]; for (int i = 0; i < 24; i++) { BHPresetBullets.Glow1(mGame, result.Position, (360/24)*i + angle, 5.ToUnits()); BHPresetBullets.Glow1(mGame, result.Position, (360/24)*i - angle, 5.ToUnits()); } timelineAttack.Parameters["angle"] = angle + 20; })); timelineAttack.AddCommand(new Wait(25)); timelineAttack.AddCommand(new Goto(0, 50)); var timelineAttack2 = new Timeline(); timelineAttack2.AddCommand(new Do(() => { Assets.GetSound("tan00").Play(); for (int i = 0; i < 16; i++) { var bulletTimeline = new Timeline(); BHEntity bullet = BHPresetBullets.RoundSmall(mGame, result.Position, (360/16)*i, 1.ToUnits()); bulletTimeline.AddCommand(new Wait(50)); bulletTimeline.AddCommand(new Do(() => { Assets.GetSound("kira01").Play(); var player = (BHEntity) mGame.Manager.EntityDictionary["player"][0]; float angle = BHUtils.GetAngleTowards(bullet, player) + Utils.Random.Next(-8, 8); var newVelocity = Utils.Math.Angles.ToVectorDegrees(angle)*4.ToUnits(); bullet.Velocity = new Vector2i((int) newVelocity.X, (int) newVelocity.Y); })); bullet.TimelinesUpdate.Add(bulletTimeline); } })); timelineAttack2.AddCommand(new Wait(50)); timelineAttack2.AddCommand(new Goto(0, 50)); // ------------------- result.TimelinesUpdate.Add(timelineMovement); result.TimelinesUpdate.Add(timelineAttack); result.TimelinesUpdate.Add(timelineAttack2); return result; }
public static BHStage TestScriptStage2(BHGame mGame) { var result = new BHStage(); var stageTimeline = new Timeline(); // FIRST FAIRY WAVE for (int i = 0; i < 200; i++) { int i1 = i; var position = new Vector2i(); if (i%2 == 0) position = new Vector2i(mGame.Bounds.Right, 0); stageTimeline.Wait(5); stageTimeline.Action(() => EnemyFairy1(mGame, position, i1%2 != 0, "enemyfairy")); } // ------------------- // DISPLAY STAGE IMAGE stageTimeline.Wait(150); stageTimeline.Action(() => BHPresetStageControl.CutIn(mGame, result, Assets.GetTexture("st01logo"), mOffset: new Vector2i(0, -50000), mLength: 200)); // ------------------- // FIRST BIG FAIRY stageTimeline.Wait(50); stageTimeline.Action(() => EnemyFairyBig1(mGame, new Vector2i(mGame.Center.X, 0), "enemyfairybig")); // ------------------- // SECOND FAIRY WAVE stageTimeline.Wait(200); for (int i = 0; i < 50; i++) { int i1 = i; var position = new Vector2i(); if (i%2 == 0) position = new Vector2i(mGame.Bounds.Right, 0); stageTimeline.Wait(8); stageTimeline.Action(() => EnemyFairy1(mGame, position, i1%2 != 0, "enemyfairy", 2)); } // ------------------- // SECOND AND THIRD BIG FAIRIES stageTimeline.Wait(180); stageTimeline.Action(() => EnemyFairyBig1(mGame, new Vector2i(mGame.Center.X - 100.ToUnits(), 0), "enemyfairybig")); stageTimeline.Action(() => EnemyFairyBig1(mGame, new Vector2i(mGame.Center.X + 100.ToUnits(), 0), "enemyfairybig")); stageTimeline.Wait(500); // ------------------- // MIDBOSS WITH 1 SPELLCARD stageTimeline.Action(() => EnemyMidboss1(mGame, new Vector2i(mGame.Center.X, 0))); // ------------------- result.TimelinesUpdate.Add(stageTimeline); return result; }
public override void Update(float mFrameTime) { if (_turnAroundDelay >= 0) _turnAroundDelay -= 1*mFrameTime; // Look for targets in the field of view var target = _cLineOfSight.Targets.FirstOrDefault(); // No targets = wander around // Target = check it out if (target == null) { if (_state == StateFoundTarget) _state = StateWait; } else _state = StateFoundTarget; if (_state != StateFoundTarget) _bulletSpeed = BulletSpeedBase; if (_state != StateWait) _waitDelay = 0; if (_state == StateWandering) { // Look where the AI is moving _cLineOfSight.Angle = Utils.Math.Angles.RotateTowardsAngleDegrees(_cLineOfSight.Angle, _currentDirection, 3.25f*mFrameTime); _wanderingDirectionDelay += 1*mFrameTime; if (_wanderingDirectionDelay >= WanderingDirectionDelayMax) { _wanderingDirectionDelay = 0; _currentDirection += Utils.Random.Next(-35, 35); if (Utils.Random.Next(0, 100) > 90) _currentDirection += 180; } _cMovement.Speed = WanderingSpeed; _cMovement.Angle = _currentDirection; } else if (_state == StateFoundTarget) { // Look where the AI is moving _cLineOfSight.Angle = Utils.Math.Angles.RotateTowardsAngleDegrees(_cLineOfSight.Angle, _currentDirection, 3.25f*mFrameTime); var targetAngle = Utils.Math.Angles.TowardsDegrees(new SSVector2F(_cBody.X, _cBody.Y), new SSVector2F(target.Item2)); _currentDirection = targetAngle; _shootDelay += mFrameTime + (float) Utils.Random.NextDouble()/100f; if (_shootDelay > ShootDelayMax) { _timeline = new Timeline(); _timeline.AddCommand( new Do( () => _game.Factory.Bullet(_cBody.Position.X, _cBody.Position.Y, targetAngle, _bulletSpeed, true))); _timeline.AddCommand(new Wait(3)); _timeline.AddCommand( new Do( () => _game.Factory.Bullet(_cBody.Position.X, _cBody.Position.Y, targetAngle + Utils.Random.Next(-5, 5), _bulletSpeed, true))); _timeline.AddCommand(new Wait(3)); _timeline.AddCommand( new Do( () => _game.Factory.Bullet(_cBody.Position.X, _cBody.Position.Y, targetAngle + Utils.Random.Next(-5, 5), _bulletSpeed, true))); _shootDelay = 0; if (_bulletSpeed < BulletSpeedMax) _bulletSpeed += BulletSpeedIncrease; } _cMovement.Speed = ChaseSpeed; _cMovement.Angle = _currentDirection; } else if (_state == StateWait) { _cMovement.Speed = 0; _cMovement.Angle = _currentDirection; _waitDelay += 1*mFrameTime; if (_waitDelay >= WaitDelayMax) _state = StateWandering; if (_waitDirection) _waitAngle += 0.5f*mFrameTime; else _waitAngle -= 0.5f*mFrameTime; // Look around _cLineOfSight.Angle = Utils.Math.Angles.RotateTowardsAngleDegrees(_cLineOfSight.Angle, _currentDirection + _waitAngle, 3.25f*mFrameTime); if (Math.Abs(_waitAngle) >= WaitAmplitude) _waitDirection = !_waitDirection; } if (_timeline != null) _timeline.Update(mFrameTime); }
public static BHEntity EnemyMidboss1(BHGame mGame, Vector2i mPosition) { BHEntity result = BHPresetBase.Boss(mGame, 30.ToUnits(), 100); result.Sprite = Assets.GetTileset("stg7enm").GetSprite("s1", Assets.GetTexture("stg7enm")); result.IsSpriteFixed = true; result.Position = mPosition; result.Animation = Assets.GetAnimation("stg7enmstill"); // MOVEMENT TIMELINES var startTimeline = new Timeline(); startTimeline.AddCommand(new Do(() => result.Velocity = new Vector2i(0, 0.7f.ToUnits()))); startTimeline.AddCommand(new Wait(210)); startTimeline.AddCommand(new Do(() => result.Velocity = new Vector2i(0, 0))); startTimeline.AddCommand(new Wait(25)); startTimeline.AddCommand(new Do(() => EnemyMidboss1SpellCard1(mGame, result))); // ------------------- result.TimelinesUpdate.Add(startTimeline); return result; }