Beispiel #1
0
        protected Enemy(Texture2D texture, SpawnAreas spawnArea, AiTypes aiType, float speed, List <Animation> animations)
        {
            switch (spawnArea)
            {
            case SpawnAreas.Left:
                spawnX = random.Next(spawnLeft.X, spawnLeft.X + spawnLeft.Width);
                spawnY = random.Next(spawnLeft.Y, spawnLeft.Y + spawnLeft.Height);
                break;

            case SpawnAreas.Middle:
                spawnX = random.Next(spawnMiddle.X, spawnMiddle.X + spawnMiddle.Width);
                spawnY = random.Next(spawnMiddle.Y, spawnMiddle.Y + spawnMiddle.Height);
                break;

            case SpawnAreas.Right:
                spawnX = random.Next(spawnRight.X, spawnRight.X + spawnRight.Width);
                spawnY = random.Next(spawnRight.Y, spawnRight.Y + spawnRight.Height);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(spawnArea), spawnArea, null);
            }

            CollidableObject = new CollidableObject(texture, new Vector2(spawnX, spawnY), new Rectangle(0, 0, 100, 100), 0f);
            _aiType          = aiType;
            this.speed       = speed;

            _animationSet = new AnimationSet(animations, AnimationStates.Walk, AnimationDirections.Down);


            Rectangle initialSourceRectangle = Rectangle.Empty;

            // Set initialSourceRectangle to the first frame in the first animation
            animations[0].SetToFrame(ref initialSourceRectangle, 0);


            // Set initial targets
            switch (aiType)
            {
            case AiTypes.Brute:
                SetTarget(Targets.Knight);
                break;

            case AiTypes.Smart:
                SetTarget(Targets.Door);
                break;

            case AiTypes.Rush:
                SetTarget(Targets.Door);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(aiType), aiType, null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Writes the data element into the given buffer (at its current position).
        /// </summary>
        /// <param name="buffer">The buffer where the data element should be deserialized into.</param>
        public void WriteData(RAMBuffer buffer)
        {
            ScenarioDataElementTools.AssertListLength(UnknownStrings, 32);
            UnknownStrings.ForEach(s => { buffer.WriteShort((short)s.Length); buffer.WriteString(s); });

            ScenarioDataElementTools.AssertListLength(AiNames, 16);
            AiNames.ForEach(s => { buffer.WriteShort((short)s.Length); buffer.WriteString(s); });

            ScenarioDataElementTools.AssertListLength(AiFiles, 16);
            AiFiles.ForEach(f => f.WriteData(buffer));

            ScenarioDataElementTools.AssertListLength(AiTypes, 16);
            AiTypes.ForEach(t => buffer.WriteByte(t));

            buffer.WriteUInteger(0xFFFFFF9D);

            ScenarioDataElementTools.AssertListLength(ResourceEntries, 16);
            ResourceEntries.ForEach(e => e.WriteData(buffer));
        }