//for detecting enemies
        public Character(Sprite sprite, Body body, World world, CharacterDef charDef)
            : base(sprite, body, world)
        {
            _width = charDef.Width;
            _height = charDef.Height;
            _moveSpeed = charDef.MoveSpeed;

            //create surface sensor
            float xtmp = _width*CHAR_SENSOR_WIDTH_FACTOR*0.5f;
            float x1 = World.B2Value(-xtmp);
            float x2 = World.B2Value(xtmp);
            float ytmp = -_height*0.5f - 2.0f;
            float y1 = World.B2Value(ytmp - 1.0f);
            float y2 = World.B2Value(ytmp);
            var vertices = new Vector2[4];
            vertices[0].X = x2;
            vertices[0].Y = y2;
            vertices[1].X = x1;
            vertices[1].Y = y2;
            vertices[2].X = x1;
            vertices[2].Y = y1;
            vertices[3].X = x2;
            vertices[3].Y = y1;
            _surfaceSense = AttachPolygonSensor(vertices);
            _surfaceSense.SensorName = Constants.SURFACE_SENSOR;

            //create visual sensor
            _visualSense = AttachCircleSensor(Vector2.Zero, _width*VISUAL_RANGE);
            _visualSense.SensorName = Constants.VISUAL_SENSOR;

            HP = charDef.HP;
            MaxHP = charDef.MaxHP;

            //Load animation
            if (charDef.FrameDefs != null)
            {
                for (int i = 0; i < charDef.FrameDefs.Length; i++)
                {
                    FrameDef frameDef = charDef.FrameDefs[i];
                    var frame = new Frame(frameDef);
                    frame.Target = sprite;

                    _animations.Add(frame.Name, frame);
                }
            }

            //Load actions
            if (charDef.Actions != null)
            {
                for (int i = 0; i < charDef.Actions.Length; i++)
                {
                    AttachAction(Activator.CreateInstance(Type.GetType(charDef.Actions[i])) as IAction);
                }
            }

            //Load sound effects
            if (charDef.SoundEffects != null)
            {
                foreach (var i in charDef.SoundEffects)
                {
                    _soundEffects.Add(i.Key, AuditionManager.Instance.SoundEffects[i.Value]);
                }
            }

            //Load AI
            if (!string.IsNullOrEmpty(charDef.AI))
            {
                _ai = new AI.AI(charDef.AI, this);
            }
        }
 public override void Dispose()
 {
     _animations = null;
     _actions = null;
     _currentAnimation = null;
     _currentAction = null;
     _surfaceSense = null;
     base.Dispose();
 }
Beispiel #3
0
 public SensorInfo AttachPolygonSensor(Vector2[] verteces, int maxSense = 10)
 {
     Fixture fixture = AttachPolygon(verteces, 0, 0, 0);
     fixture.SetSensor(true);
     var info = new SensorInfo(this, fixture, maxSense);
     return info;
 }
Beispiel #4
0
 public SensorInfo AttachRectangleSensor(float width, float height,
     Vector2 center, float angle, int maxSense = 10)
 {
     Fixture fixture = AttachRectangle(width, height, center, angle, 0, 0, 0);
     fixture.SetSensor(true);
     var info = new SensorInfo(this, fixture, maxSense);
     return info;
 }
Beispiel #5
0
 public SensorInfo AttachCircleSensor(Vector2 center, float radius, int maxSense = 10)
 {
     Fixture fixture = AttachCircle(center, radius, 0, 0, 0);
     fixture.SetSensor(true);
     var info = new SensorInfo(this, fixture, maxSense);
     return info;
 }