public Entity CreateTile(float x, float y, int gid, Ground g) { var offsetX = gid > 66 ? gid * cellSize.X - 2010 : gid * cellSize.X; var offsetY = gid > 66 ? 30 : 0; var destroyedPos = Vector2.Zero; var randForDestroyed = r.Next(3) * cellSize.X; if (g == Ground.Ground) { destroyedPos = new Vector2(510 + randForDestroyed, 0); } else if (g == Ground.Asphalt) { destroyedPos = new Vector2(1560 + randForDestroyed, 30); } else if (g == Ground.Sand) { destroyedPos = new Vector2(630 + randForDestroyed, 30); } var sprite = new Sprite(textureManager.Get(Images.Instance.TileSet), cellSize, Layers.Ground); var entity = CreateEntity(); var fsm = new EntityStateMachine(entity); fsm.CreateState(States.Alive) .Add <Display>().WithInstance(new Display(new Clip(sprite, new Vector2(offsetX, offsetY)))); fsm.CreateState(States.Destroyed) .Add <Display>().WithInstance(new Display(new Clip(sprite, destroyedPos))); fsm.ChangeState(States.Alive); return(entity .Add(new FSM(fsm)) .Add(new Position(x, y))); }
public Entity CreateTank(float x, float y, int level = 0) { var entity = CreateEntity(EntityType.RedTank); var position = new Position(x, y, AntEnum.Parse <Direction>(r.Next(1, 5).ToString())); var myvars = vars.LightTank[level]; var view = new TankView(myvars[5], 0, position.direction); var listFsm = new Dictionary <string, EntityStateMachine>(); var moveFSM = new EntityStateMachine(entity); var aiFSM = new EntityStateMachine(entity); var motionFSM = new EntityStateMachine(entity); moveFSM.CreateState(States.Stand).Add <Stand>().WithInstance(new Stand()); moveFSM.CreateState(States.Turn).Add <Turn>().WithInstance(new Turn()); moveFSM.CreateState(States.Walk).Add <Walk>().WithInstance(new Walk()); moveFSM.ChangeState(States.Stand); aiFSM.CreateState(States.Idle).Add <Idle>().WithInstance(new Idle(7)); aiFSM.CreateState(States.Pursuit).Add <Pursuit>().WithInstance(new Pursuit()); aiFSM.CreateState(States.Attack).Add <Attack>().WithInstance(new Attack()); aiFSM.ChangeState(States.Idle); var addSpeed = Mathf.FromPercent(0.5f, myvars[0]); motionFSM.CreateState(States.Fast).Add <Controls>() .WithInstance(new Controls(new Vector2(myvars[0] + addSpeed))); motionFSM.CreateState(States.Slow).Add <Controls>() .WithInstance(new Controls(new Vector2(myvars[0] - addSpeed))); motionFSM.CreateState(States.Normal).Add <Controls>() .WithInstance(new Controls(new Vector2(myvars[0]))); motionFSM.ChangeState(States.Normal); listFsm.Add("MoveFSM", moveFSM); listFsm.Add("AiFSM", aiFSM); listFsm.Add("MotionFSM", motionFSM); entity .Add(position) .Add(view.GetView()) .Add(new Health(myvars[2], myvars[4])) .Add(new Damage(100)) .Add(new Tank()) .Add(new FSM(listFsm)) .Add(new AI(360, 210, new[] { EntityType.GreenTank })) .Add(new Gun(myvars[1], myvars[3])) .Add(new Collision(cellSize, 15)) .Add(new Motion(Vector2.Zero, r.Next(CellType.Segment, 10000))) .Add(new ActionAfterDeath(() => { gameField.ClearCell(position.prevCell); CreateEnemyExplosion(position.position); CreateQuake(); })); CreateRedOverlay(entity); CreateGreenHealthBar(entity); return(entity); }
public Entity CreateTower(float x, float y, int level = 0) { var entity = CreateEntity(EntityType.RedTank); var listFsm = new Dictionary <string, EntityStateMachine>(); var moveFSM = new EntityStateMachine(entity); var aiFSM = new EntityStateMachine(entity); var position = new Position(x, y, AntEnum.Parse <Direction>(r.Next(1, 5).ToString())); var myvars = vars.Tower[level]; var view = new TowerView(myvars[5], position.direction); moveFSM.CreateState(States.Stand).Add <Stand>().WithInstance(new Stand()); moveFSM.CreateState(States.Turn).Add <Turn>().WithInstance(new Turn()); moveFSM.ChangeState(States.Stand); aiFSM.CreateState(States.Idle).Add <Idle>().WithInstance(new Idle(10)); aiFSM.CreateState(States.Attack).Add <Attack>().WithInstance(new Attack()); aiFSM.ChangeState(States.Idle); listFsm.Add("MoveFSM", moveFSM); listFsm.Add("AiFSM", aiFSM); entity .Add(position) .Add(view.GetView()) .Add(new Health(myvars[2], myvars[4])) .Add(new Damage(100)) .Add(new Tank()) .Add(new FSM(listFsm)) .Add(new AI(210, 210, new[] { EntityType.GreenTank })) .Add(new Gun(myvars[1], myvars[3])) .Add(new Collision(cellSize, 15)) .Add(new Motion(Vector2.Zero, r.Next(CellType.Segment, 10000))) .Add(new ActionAfterDeath(() => { gameField.ClearCell(position.position.Divide(cellSize.X)); CreateEnemyExplosion(position.position); CreateQuake(); })); CreateRedOverlay(entity); CreateGreenHealthBar(entity); AddCellToMap(x, y, CellType.Tower); return(entity); }
public Entity CreatePlayer(float x, float y) { var entity = CreateEntity(EntityType.GreenTank); var position = new Position(x, y, Direction.Left); var view = new TankView(32, 36, position.direction); var listFsm = new Dictionary <string, EntityStateMachine>(); var moveFSM = new EntityStateMachine(entity); var motionFSM = new EntityStateMachine(entity); moveFSM.CreateState(States.Stand).Add <Stand>().WithInstance(new Stand()); moveFSM.CreateState(States.Turn).Add <Turn>().WithInstance(new Turn()); moveFSM.CreateState(States.Walk).Add <Walk>().WithInstance(new Walk()); moveFSM.ChangeState(States.Stand); var speed = 1.5f; var addSpeed = Mathf.FromPercent(0.5f, speed); motionFSM.CreateState(States.Fast).Add <Controls>() .WithInstance(new Controls( Config.Instance.MoveUp, Config.Instance.MoveDown, Config.Instance.MoveLeft, Config.Instance.MoveRight, new Vector2(speed + addSpeed))); motionFSM.CreateState(States.Slow).Add <Controls>() .WithInstance(new Controls( Config.Instance.MoveUp, Config.Instance.MoveDown, Config.Instance.MoveLeft, Config.Instance.MoveRight, new Vector2(speed - addSpeed))); motionFSM.CreateState(States.Normal).Add <Controls>() .WithInstance(new Controls( Config.Instance.MoveUp, Config.Instance.MoveDown, Config.Instance.MoveLeft, Config.Instance.MoveRight, new Vector2(speed))); motionFSM.ChangeState(States.Normal); listFsm.Add("MoveFSM", moveFSM); listFsm.Add("MotionFSM", motionFSM); entity .Add(position) .Add(view.GetView()) .Add(new Health(100, 0)) .Add(new Damage(100)) .Add(new Player()) .Add(new FSM(listFsm)) .Add(new Gun(5, 500)) .Add(new GunControls(Config.Instance.GunTrigger)) .Add(new Motion(Vector2.Zero, r.Next(CellType.Segment, 10000))) .Add(new Collision(cellSize, 15)) .Add(new ActionAfterDeath(() => { gameField.ClearCell(position.prevCell); CreateEnemyExplosion(position.position); CreateQuake(); })); CreateGreenOverlay(entity); CreateGreenHealthBar(entity); return(entity); }