Exemplo n.º 1
0
        public DrawUnit(Sprite sprite, Body body, World world)
            : base(body, world)
        {
            _sprite = sprite;
            _eventManager = world.EventManager;

            _listener = new EventListener(Constants.TIME_TICKS_EVENT);
            _listener.Handler = e => Update();
            _eventManager.Register(_listener);
        }
Exemplo n.º 2
0
        public override void Dispose()
        {
            _eventManager.UnRegister(_listener);

            if (_sprite != null)
            {
                _sprite.Parent.Remove(_sprite);
                _sprite = null;
            }
            base.Dispose();
        }
Exemplo n.º 3
0
        //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);
            }
        }
Exemplo n.º 4
0
 public TargetCamera(Sprite target)
     : base(Constants.TIME_TICKS_EVENT)
 {
     _target = target;
 }