private LivingEntity GetLivingEntityNearestMouse(Location location) { MouseControllerInfo mci = Program.Engine.Controllers[mouseController][(int)Actions.MOUSEINFO].Info as MouseControllerInfo; Enemy nearest = null; return(location.GetEntities <Enemy>().Where( e => { if (e.IsDead()) { return false; } if (nearest == null) { nearest = e; return true; } if (e.Distance(mci.X, mci.Y) < nearest.Distance(mci.X, mci.Y)) { nearest = e; return true; } return false; }).Last()); }
private void Tick(Location location, Entity entity) { if (Program.Mouse[(int)Program.Actions.ACTION].IsPress()) { MouseControllerInfo mci = Program.Mouse[(int)Program.Actions.ACTION].Info as MouseControllerInfo; if (mci.X > this.X && mci.X < this.X + this.Width && mci.Y > this.Y && mci.Y < this.Y + this.Height) { action(); } } }
public Bitmap Draw() { if (bmp == null) { bmp = BitmapExtensions.CreateBitmap(this.Width, this.Height); gfx = Graphics.FromImage(bmp); } gfx.Clear(Color.Transparent); gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; gfx.ScaleTransform(4, 4); Font f = new Font(Program.FontCollection.Families[0], 18); Player player = Program.Engine.Location.GetEntities <Player>().FirstOrDefault(); DrawEntityHealth(gfx); DrawSkills(gfx, Program.Engine.Location.GetEntities <LivingEntity>()); DrawPlayerSkill(gfx, player); DrawTargetLine(gfx, player); DrawHotbar(gfx, player, f); DrawPlayerHud(gfx, player, f); gfx.ScaleTransform((float)0.25, (float)0.25); DrawDevInfo(gfx, f); string targetKey = Program.keyMap.First(kvp => kvp.Value == Actions.TARGET).Key.ToString(); string moveKey = Program.mouseMap.First(kvp => kvp.Value == Actions.MOVE).Key.ToString(); MouseControllerInfo movepmci = (Program.Engine.Controllers[mouseController][(int)Actions.MOVE].Info as MouseControllerInfo); MouseControllerInfo mouseInfopmci = (Program.Engine.Controllers[mouseController][(int)Actions.MOUSEINFO].Info as MouseControllerInfo); gfx.FillRectangle(Brushes.Black, 0, 0, Width, 52); gfx.DrawString($"{Program.tickTime}\t{movepmci?.X ?? 0:000},{movepmci?.Y ?? 0:000}\t{mouseInfopmci?.X ?? 0:000},{mouseInfopmci?.Y ?? 0:000}", f, Brushes.White, new Point(0, 0)); gfx.DrawString($"{Program.drawTime}", f, Brushes.White, new Point(0, 16)); gfx.DrawString($"{Program.tps} | {(Program.tickTime + Program.drawTime) * 100.0 / (TimeSpan.FromSeconds(1).Ticks/Program.TPS):##}%", f, Brushes.White, new Point(0, 32)); gfx.FillRectangle(Brushes.Black, 0, Height - 52, Width, 52); gfx.DrawString($"{moveKey} click to move", f, Brushes.White, new Point(0, Height - 52)); gfx.DrawString($"Hold {targetKey} to target", f, Brushes.White, new Point(0, Height - 36)); gfx.DrawString($"{targetKey} + {moveKey} click to attack", f, Brushes.White, new Point(0, Height - 20)); return(bmp); }
private LivingEntity GetLivingEntityAtMouse(Location location) { MouseControllerInfo info = Program.Engine.Controllers[mouseController][(int)Actions.CANCEL].Info as MouseControllerInfo; double dist = double.MaxValue; return(location.GetEntities <Enemy>().Where(e => { double d = e.Distance(info.X, info.Y + 8); if (d < dist) { dist = d; } return d < 8; }).LastOrDefault()); }
private void DrawDevInfo(Graphics gfx, Font f) { string targetKey = Program.keyMap.First(kvp => kvp.Value == Actions.TARGET).Key.ToString(); string moveKey = Program.mouseMap.First(kvp => kvp.Value == Actions.MOVE).Key.ToString(); MouseControllerInfo movepmci = (Program.Engine.Controllers[mouseController][(int)Actions.MOVE].Info as MouseControllerInfo); MouseControllerInfo mouseInfopmci = (Program.Engine.Controllers[mouseController][(int)Actions.MOUSEINFO].Info as MouseControllerInfo); gfx.FillRectangle(Brushes.Black, 0, 0, Width, 52); gfx.DrawString($"{Program.tickTime}\t{movepmci?.X ?? 0:000},{movepmci?.Y ?? 0:000}\t{mouseInfopmci?.X ?? 0:000},{mouseInfopmci?.Y ?? 0:000}", f, Brushes.White, new Point(0, 0)); gfx.DrawString($"{Program.drawTime}", f, Brushes.White, new Point(0, 16)); gfx.DrawString($"{Program.tps} | {(Program.tickTime + Program.drawTime) * 100.0 / (TimeSpan.FromSeconds(1).Ticks / Program.TPS):##}%", f, Brushes.White, new Point(0, 32)); gfx.FillRectangle(Brushes.Black, 0, Height - 52, Width, 52); gfx.DrawString($"{moveKey} click to move", f, Brushes.White, new Point(0, Height - 52)); gfx.DrawString($"Hold {targetKey} to target", f, Brushes.White, new Point(0, Height - 36)); gfx.DrawString($"{targetKey} + {moveKey} click to attack", f, Brushes.White, new Point(0, Height - 20)); }
public static void TopDown(Location location, object obj) { if (obj == null) { return; } if (location.GetEntities <Banner>().Any()) { return; } Description2D d2d = obj as Description2D; MouseControllerInfo mci = Program.Mouse[(int)Actions.MOUSEINFO].Info as MouseControllerInfo; double dir = 0; if (mci != null) { dir = d2d.Direction(new Point(mci.X, mci.Y)); } List <Description2D> walls = location.GetEntities <Wall>().Select(w => w as Description2D).ToList(); double speed = 3 * (Program.Referee.Piles[Rule.RuleType.SPEED].FirstOrDefault()?.Action(location, obj) ?? 1); if (Program.Keyboard[(int)Actions.RIGHT].IsDown()) { Move(d2d, speed * Math.Cos(dir + Math.PI / 2), speed * Math.Sin(dir + Math.PI / 2), walls); } if (Program.Keyboard[(int)Actions.UP].IsDown()) { Move(d2d, speed * Math.Cos(dir), speed * Math.Sin(dir), walls); } if (Program.Keyboard[(int)Actions.LEFT].IsDown()) { Move(d2d, speed * Math.Cos(dir - Math.PI / 2), speed * Math.Sin(dir - Math.PI / 2), walls); } if (Program.Keyboard[(int)Actions.DOWN].IsDown()) { Move(d2d, speed * Math.Cos(dir + Math.PI), speed * Math.Sin(dir + Math.PI), walls); } }
public new void Tick(Location location, Entity entity) { if (base.Tick(location, entity)) { return; } Marker markerD = Program.Engine.Location.GetEntities <Marker>().First(); if (Program.Engine.Controllers[keyController][(int)Actions.TARGET].State == HoldState.PRESS) { LockTarget = GetLivingEntityNearestMouse(location); } else if (Program.Engine.Controllers[keyController][(int)Actions.TARGET].State == HoldState.RELEASE) { LockTarget = null; } for (int i = (int)Actions.HOTBAR1; i <= (int)Actions.HOTBAR4; i++) { if (Program.Engine.Controllers[keyController][i].State == HoldState.PRESS) { Skill skill = Hotbar[i - (int)Actions.HOTBAR1] as Skill; if (skill != null && skill.CooldownTime == 0) { stamina -= skill.Stamina; this.PreppedSkill = null; this.ActiveSkill = null; Hotbar.Execute(i - (int)Actions.HOTBAR1, this); } } } MouseControllerInfo mci; MouseControllerInfo info = Program.Engine.Controllers[mouseController][(int)Actions.CANCEL].Info as MouseControllerInfo; if (Program.Engine.Controllers[mouseController][(int)Actions.CANCEL].IsDown()) { if (info.X > X - 4 && info.X < X + 4 && info.Y > Y - 24 && info.Y < Y - 16) { if (Program.Engine.Controllers[mouseController][(int)Actions.CANCEL].IsPress()) { base.CancelSkill(); } } else { if (Program.Engine.Controllers[keyController][(int)Actions.TARGET].IsDown()) { if (LockTarget != null) { markerD.SetCoords(LockTarget.X, LockTarget.Y); if (animations.Any() && animations.Peek().Peek().Name.Contains("move")) { animations.Pop(); } if (stamina > 2) { Attack(LockTarget, location, "sword"); } else { Attack(LockTarget, location, "punch"); } } } else { LivingEntity selected = GetLivingEntityAtMouse(location); if (selected != null) { if (animations.Any() && animations.Peek().Peek().Name.Contains("move")) { animations.Pop(); } if (stamina > 2) { Attack(selected, location, "sword"); } else { Attack(selected, location, "punch"); } } } } } if (Program.Engine.Controllers[mouseController][(int)Actions.MOVE].IsDown()) { mci = Program.Engine.Controllers[mouseController][(int)Actions.MOVE].Info as MouseControllerInfo; Point p = new Point(mci.X, mci.Y); if (p.Y > Program.SCREENHEIGHT - 16 * 2 && p.Y < Program.SCREENHEIGHT - 16) { int i = p.X / 16; if (Program.Engine.Controllers[mouseController][(int)Actions.MOVE].IsPress()) { Skill skill = Hotbar[i] as Skill; if (skill != null && skill.CooldownTime == 0 && stamina >= skill.Stamina) { stamina -= skill.Stamina; this.PreppedSkill = null; this.ActiveSkill = null; Hotbar.Execute(i, this); } } } else { while (animations.Any() && animations.Peek().Peek().Name.Contains("move")) { animations.Pop(); } markerD.SetCoords(p.X, p.Y); this.MoveTarget = p; animations.Push(new AnimationChain( AnimationManager.Instance["move"].MakeInterruptable().Trigger(pd => ((Player)pd).Distance(((Player)pd).MoveTarget) < 1))); combo.Reset(); } } }
public static void Rules() { // TODO: Make it so the "Player" is what is being controlled new TouchRule <Player, Goal>("Goal victory", Rule.RuleType.VICTORY, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { Referee.Stop(); Program.Engine.AddEntity(Banner.Create("you win")); if (Referee.OutofControl) { ArcadeWins++; } } }); new TouchRule <Player, Enemy>("Enemy victory", Rule.RuleType.VICTORY, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { Referee.Stop(); Program.Engine.AddEntity(Banner.Create("you win")); if (Referee.OutofControl) { ArcadeWins++; } } }); new TouchRule <Player, Powerup>("Powerup victory", Rule.RuleType.VICTORY, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { Referee.Stop(); Program.Engine.AddEntity(Banner.Create("you win")); if (Referee.OutofControl) { ArcadeWins++; } } }); new TouchRule <Player, Enemy>("Enemy hurty", Rule.RuleType.DEATH, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { if (Iframe == 0 && Lives-- == 1) { Referee.Stop(); if (!Referee.OutofControl) { Program.Engine.AddEntity(Banner.Create("you lose")); } else { Program.Engine.AddEntity(Banner.Create($"you lose. Score: {ArcadeWins}")); ArcadeWins = 0; } } if (Iframe == 0) { Iframe = TPS; } } }); new TouchRule <Player, Powerup>("Powerup hurty", Rule.RuleType.DEATH, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { if (Iframe == 0 && Lives-- == 1) { Referee.Stop(); if (!Referee.OutofControl) { Program.Engine.AddEntity(Banner.Create("you lose")); } else { Program.Engine.AddEntity(Banner.Create($"you lose. Score: {ArcadeWins}")); ArcadeWins = 0; } } if (Iframe == 0) { Iframe = TPS; } } }); new TouchRule <Player, Goal>("Goal hurty", Rule.RuleType.DEATH, (location, obj) => { if (!location.GetEntities <Banner>().Any() && Referee.IsStarted) { if (Iframe == 0 && Lives-- == 1) { Referee.Stop(); if (!Referee.OutofControl) { Program.Engine.AddEntity(Banner.Create("you lose")); } else { Program.Engine.AddEntity(Banner.Create($"you lose. Score: {ArcadeWins}")); ArcadeWins = 0; } } if (Iframe == 0) { Iframe = TPS; } } }); // TODO: Make it so the "Player" is what is being controlled new TouchRule <Player, Powerup>("Player pickup Powerup", Rule.RuleType.POWERUP, (location, obj) => { Powerup powerup = obj as Powerup; Program.Referee.AddRule(powerup.Rule); location.RemoveEntity(powerup.Id); ////Referee.AddRule(Rule.Rules["Enemy pickup Powerup"]); }); new TouchRule <Enemy, Powerup>("Enemy pickup Powerup", Rule.RuleType.POWERUP, (location, obj) => { Powerup powerup = obj as Powerup; Program.Referee.AddRule(powerup.Rule); location.RemoveEntity(powerup.Id); ////Referee.AddRule(Rule.Rules["Player pickup Powerup"]); }); new TouchRule <Description2D, Powerup>("Any pickup Powerup", Rule.RuleType.POWERUP, (location, obj) => { Powerup powerup = obj as Powerup; Program.Referee.AddRule(powerup.Rule); location.RemoveEntity(powerup.Id); ////Referee.AddRule(Rule.Rules["Player pickup Powerup"]); }); new Rule("clicky attack", Rule.RuleType.ATTACK, (location, obj) => { if (Program.Mouse[(int)Program.Actions.ACTION].IsPress()) { MouseControllerInfo mci = Program.Mouse[(int)Program.Actions.ACTION].Info as MouseControllerInfo; foreach (Enemy enemy in location.GetEntities <Enemy>()) { if (enemy.Distance(new Point(mci.X, mci.Y)) < 8) { location.RemoveEntity(enemy.Id); } } } }); new Rule("shoot Enemy", Rule.RuleType.ATTACK, (location, obj) => { if (location.GetEntities <DialogBox>().Any()) { return; } if (Program.Mouse[(int)Program.Actions.ACTION].IsPress()) { MouseControllerInfo mci = Program.Mouse[(int)Program.Actions.ACTION].Info as MouseControllerInfo; Player player = location.GetEntities <Player>().FirstOrDefault(); if (player == null) { return; } double dir = player.Direction(new Point(mci.X, mci.Y)); int spawnX = (int)(player.X + Math.Cos(dir) * 8); int spawnY = (int)(player.Y + Math.Sin(dir) * 8); location.AddEntity(Bullet <Enemy> .Create(spawnX, spawnY, dir)); } }); int shootTimer = 15; new Rule("shoot Boss", Rule.RuleType.ATTACK, (location, obj) => { if (location.GetEntities <DialogBox>().Any()) { return; } if (shootTimer-- <= 0 && Program.Mouse[(int)Program.Actions.ACTION].IsDown()) { shootTimer = 15; MouseControllerInfo mci = Program.Mouse[(int)Program.Actions.ACTION].Info as MouseControllerInfo; Player player = location.GetEntities <Player>().FirstOrDefault(); if (player == null) { return; } double dir = player.Direction(new Point(mci.X, mci.Y)); int spawnX = (int)(player.X + Math.Cos(dir) * 8); int spawnY = (int)(player.Y + Math.Sin(dir) * 8); location.AddEntity(Bullet <BulletNull> .Create(spawnX, spawnY, dir)); } }); new TouchRule <Player, Enemy>("Player kill Enemy", Rule.RuleType.ATTACK, (location, obj) => { Enemy enemy = obj as Enemy; location.RemoveEntity(enemy.Id); }); new TouchRule <Player, Goal>("Player kill Goal", Rule.RuleType.ATTACK, (location, obj) => { Goal goal = obj as Goal; location.RemoveEntity(goal.Id); }); new Rule("no attack. haha.", Rule.RuleType.ATTACK, (location, obj) => { }); new Rule("be fast", Rule.RuleType.SPEED, (location, obj) => { return(3); }); new Rule("be slow", Rule.RuleType.SPEED, (location, obj) => { return(0.8); }); new Rule("be normal", Rule.RuleType.SPEED, (location, obj) => { return(1); }); new Rule("spawn Powerup", Rule.RuleType.SPAWN, (location, obj) => { location.AddEntity(Powerup.Create(Rule.GetNameRandomRule(), Program.Random.Next(16, Program.ScreenWidth - 16), Program.Random.Next(16, Program.ScreenWidth - 16))); }); new Rule("spawn Enemy", Rule.RuleType.SPAWN, (location, obj) => { location.AddEntity(Enemy.Create(Program.Random.Next(16, Program.ScreenWidth - 16), Program.Random.Next(16, Program.ScreenWidth - 16))); }); new Rule("spawn Goal", Rule.RuleType.SPAWN, (location, obj) => { location.AddEntity(Goal.Create(Program.Random.Next(16, Program.ScreenWidth - 16), Program.Random.Next(16, Program.ScreenWidth - 16))); }); new Rule("control Player", Rule.RuleType.CONTROL, (location, obj) => { foreach (Player player in location.GetEntities <Player>()) { if (Referee.Piles[Rule.RuleType.PERSPECTIVE].Any()) { Referee.Piles[Rule.RuleType.PERSPECTIVE].Peek().Action(location, player); } } }); new Rule("control Enemy", Rule.RuleType.CONTROL, (location, obj) => { foreach (Enemy enemy in location.GetEntities <Enemy>()) { Referee.Piles[Rule.RuleType.PERSPECTIVE].Peek().Action(location, enemy); } }); new Rule("control Goal", Rule.RuleType.CONTROL, (location, obj) => { foreach (Goal goal in location.GetEntities <Goal>()) { Referee.Piles[Rule.RuleType.PERSPECTIVE].Peek().Action(location, goal); } }); new Rule("top-down", Rule.RuleType.PERSPECTIVE, ControlSchemas.TopDown); new Rule("platformer", Rule.RuleType.PERSPECTIVE, ControlSchemas.Platformer); new Rule("vvvvvv-platformer", Rule.RuleType.PERSPECTIVE, ControlSchemas.VVVVVVPlatformer); ////new Rule("colorblind", Rule.RuleType.OVERLAY, (location, obj) => ////{ ////}); ////new Rule("vertical-flip", Rule.RuleType.OVERLAY, (location, obj) => ////{ ////}); foreach (Rule.RuleType type in Enum.GetValues(typeof(Rule.RuleType))) { new Rule($"pop {type}", Rule.RuleType.POP, null); } Referee.AddRule(Rule.Rules["Goal victory"]); Referee.AddRule(Rule.Rules["Enemy hurty"]); Referee.AddRule(Rule.Rules["Player pickup Powerup"]); Referee.AddRule(Rule.Rules["clicky attack"]); Referee.AddRule(Rule.Rules["spawn Powerup"]); Referee.AddRule(Rule.Rules["control Player"]); Referee.AddRule(Rule.Rules["vvvvvv-platformer"]); for (int i = 0; i < 10; i++) { Referee.AddRule(Rule.GetNameRandomRule()); } }