public ComputerControlledTank(
            ISoundManager soundManager,
            World world, 
            Collection<IDoodad> doodads, 
            Team team, 
            Vector2 position, 
            float rotation,
            Random random, 
            DoodadFactory doodadFactory,
            IEnumerable<Waypoint> waypoints)
            : base(soundManager, world, doodads, team, position, rotation, doodadFactory)
        {
            this.world = world;
            this.random = random;
            this.states = new Dictionary<Type, ITankState>();
            this.states.Add(typeof(MovingState), new MovingState(world, this.Body, this, waypoints, random));
            this.states.Add(typeof(AttackingState), new AttackingState(world, this.Body, this));
            this.states.Add(typeof(TurningState), new TurningState(this.Body, this));
            this.currentState = this.states[typeof(MovingState)];
            this.currentState.StateChanged += this.OnStateChanged;
            this.currentState.NavigateTo();

            this.sensor = BodyFactory.CreateBody(world, this.Position);

            var shape = new CircleShape(6, 0);
            Fixture sensorFixture = this.sensor.CreateFixture(shape);
            sensorFixture.Friction = 1f;
            sensorFixture.IsSensor = true;
            sensorFixture.CollisionCategories = PhysicsConstants.SensorCategory;
            sensorFixture.CollidesWith = PhysicsConstants.PlayerCategory | PhysicsConstants.ObstacleCategory |
                                         PhysicsConstants.MissileCategory;
        }
Exemple #2
0
        protected Tank(
            ISoundManager soundManager,
            World world, 
            Collection<IDoodad> doodads, 
            Team team, 
            Vector2 position, 
            float rotation, 
            DoodadFactory doodadFactory)
        {
            this.soundManager = soundManager;
            this.world = world;
            this.doodadFactory = doodadFactory;
            this.doodads = doodads;
            this.body = BodyFactory.CreateBody(world, position, this);
            this.body.Rotation = rotation;
            this.body.BodyType = BodyType.Dynamic;
            this.Team = team;
            this.Heading = rotation;
            this.activeMissiles = new List<Missile>();
            this.powerup = PowerUpType.None;

            var shape = new PolygonShape(0);
            shape.SetAsBox(15 / Constants.PixelsPerMeter, 15 / Constants.PixelsPerMeter);
            var fixture = this.body.CreateFixture(shape);
            fixture.CollisionCategories = this.CollisionCategory;
            fixture.CollidesWith = PhysicsConstants.MissileCategory;
            if (this is PlayerControlledTank)
            {
                fixture.CollidesWith |= PhysicsConstants.ObstacleCategory | PhysicsConstants.PitCategory |
                                        PhysicsConstants.SensorCategory;
            }
        }
        public Missile(
            ISoundManager soundManager, 
            World world, 
            Collection<IDoodad> doodads, 
            int numberOfBounces,
            Team team, 
            Vector2 position, 
            float rotation, 
            DoodadFactory doodadFactory)
        {
            this.soundManager = soundManager;
            this.doodadFactory = doodadFactory;
            this.world = world;
            this.doodads = doodads;
            this.numberOfBounces = numberOfBounces;
            this.body = BodyFactory.CreateBody(world, position, this);
            this.body.BodyType = BodyType.Dynamic;
            this.body.FixedRotation = true;

            CircleShape shape = new CircleShape(5 / Constants.PixelsPerMeter, 0.1f);
            Fixture fixture = body.CreateFixture(shape);
            fixture.Restitution = 1;
            fixture.Friction = 0;
            fixture.CollisionCategories = PhysicsConstants.MissileCategory;
            fixture.CollidesWith = PhysicsConstants.EnemyCategory | PhysicsConstants.PlayerCategory |
                                   PhysicsConstants.ObstacleCategory | PhysicsConstants.MissileCategory |
                                   PhysicsConstants.SensorCategory;
            obstacleCollisionCtr = 0;

            Vector2 force = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) * 3;
            this.body.ApplyForce(force);
        }
 public LevelFactory(
     ContentManager content, 
     DoodadFactory doodadFactory, 
     Collection<IDoodad> doodads,
     Level level)
 {
     this.doodadFactory = doodadFactory;
     this.doodads = doodads;
     this.level = level;
     this.content = content;
     this.currentLevel = 1;
 }
 public PlayerControlledTank(
     ISoundManager soundManager,
     DoodadFactory doodadFactory,
     World world,
     Collection<IDoodad> doodads,
     Team team,
     Random random,
     Vector2 position, 
     float rotation)
     : base(soundManager, world, doodads, team, position, rotation, doodadFactory)
 {
     this.random = random;
     this.FireMissileCommand = new RelayCommand<Vector2>(this.FireMissile, this.CanFireMissile);
     this.PointTurretCommand = new RelayCommand<Vector2>(this.PointTurret);
     speed = DEFAULT_SPEED;
     powerUpTime = DateTime.Now;
 }
        public PowerUp(
            ISoundManager soundManager, 
            World world,
            Random random, 
            Collection<IDoodad> doodads, 
            Vector2 position, 
            DoodadFactory doodadFactory)
        {
            this.soundManager = soundManager;
            this.doodadFactory = doodadFactory;
            this.world = world;
            this.doodads = doodads;
            this.body = BodyFactory.CreateBody(world, position, this);
            this.body.BodyType = BodyType.Dynamic;
            this.body.FixedRotation = true;

            PowerUpType powerUpType = PowerUpType.None;
            switch (random.Next(3))
            {
                case 0:
                    powerUpType = PowerUpType.Speed;
                    break;
                case 1:
                    powerUpType = PowerUpType.UnlimitedAmmo;
                    break;
                case 2:
                    powerUpType = PowerUpType.ExtraBounce;
                    break;
            }
            this.powerUp = powerUpType;

            CircleShape shape = new CircleShape(5 / Constants.PixelsPerMeter, 0.1f);
            Fixture fixture = body.CreateFixture(shape);
            fixture.IsSensor = true;
            fixture.CollisionCategories = PhysicsConstants.SensorCategory;
            fixture.CollidesWith = PhysicsConstants.PlayerCategory;
        }