Subversion Repositories AndroidProjects

Rev

Rev 1648 | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.ComponentModel;

using BauzoidNET.math;
using BauzoidNET.parser;
using BauzoidNET.graphics.sprite;
using BauzoidNET.graphics;


using BurutaruEditor.view;

namespace BurutaruEditor.file.enemies
{
    public class GarbageCollectorBossSpawner : EnemySpawner
    {
        public const float ENEMY_HEIGHT = 200;
        public const float ENEMY_WIDTH = (256.0f / 378.0f) * ENEMY_HEIGHT;


        //=================================================================================================================================

        [Category("Formation")]
        [TypeConverter(typeof(ExpandableObjectConverter))]
        public Vector2 InitPosition { get; set; }

        //=================================================================================================================================

        public GarbageCollectorBossSpawner(Document doc, string name)
            : base(doc, name)
        {
            InitPosition = new Vector2();
        }

        public override void Render()
        {
            base.Render();

            float triggerX = SpawnTrigger.x + Doc.View.CurrentPosition.x;
            float triggerY = SpawnTrigger.y + Doc.View.CurrentPosition.y;

            SpriteTransform t = DocumentView.Resources.GarbageCollectorBossSprite.getSpriteTransform();
            t.x = triggerX + SpawnPosition.x;
            t.y = triggerY + SpawnPosition.y;
            t.w = ENEMY_WIDTH;
            t.h = ENEMY_HEIGHT;
            t.centerPivot();
            DocumentView.Resources.GarbageCollectorBossSprite.getSpriteInstance().color.setFrom(mMultiplyColor);
            DocumentView.Resources.GarbageCollectorBossSprite.getSpriteInstance().color.w = mMultiplyFactor;
            DocumentView.Resources.GarbageCollectorBossSprite.getSpriteInstance().fogColor.setFrom(mLerpColor);
            DocumentView.Resources.GarbageCollectorBossSprite.getSpriteInstance().fogColor.w = mLerpFactor;
            DocumentView.Resources.GarbageCollectorBossSprite.render();

            float w = MainForm.App.getGraphics().getFont().getTextWidth(this.Name, Document.TEXT_SCALE);
            MainForm.App.getGraphics().getFont().drawTextDirect(this.Name, t.x - w / 2, t.y + ENEMY_HEIGHT / 2, Document.TEXT_COLOR, Document.TEXT_SCALE);

            RenderUtil.drawArrow(MainForm.App.getGraphics(), t.x, t.y, t.x + InitPosition.x, t.y + InitPosition.y, ARROW_COLOR);

            RenderUtil.drawArrow(MainForm.App.getGraphics(), triggerX, triggerY, t.x, t.y, ARROW_COLOR);
        }

        public override void RenderSelected(int selectedPart, bool forHover = false)
        {
            if (selectedPart != PART_SPAWN_POSITION)
            {
                base.RenderSelected(selectedPart, forHover);
            }

            float posX = SpawnTrigger.x + SpawnPosition.x + Doc.View.CurrentPosition.x;
            float posY = SpawnTrigger.y + SpawnPosition.y + Doc.View.CurrentPosition.y;

            float halfW = ENEMY_WIDTH / 2 + DocumentView.SELECTION_FRAME_OFFSET;
            float halfH = ENEMY_HEIGHT / 2 + DocumentView.SELECTION_FRAME_OFFSET;

            if (forHover)
                Doc.View.RenderSelectionFrame(posX - halfW, posY - halfH, posX + halfW, posY + halfH, DocumentView.SELECTION_FRAME_HOVER_ALPHA);
            else
                Doc.View.RenderSelectionFrame(posX - halfW, posY - halfH, posX + halfW, posY + halfH);
        }

        public override bool IsInside(float x, float y, out int selectedPart)
        {
            if (base.IsInside(x, y, out selectedPart))
                return true;

            float px = SpawnTrigger.x + SpawnPosition.x + Doc.View.CurrentPosition.x;
            float py = SpawnTrigger.y + SpawnPosition.y + Doc.View.CurrentPosition.y;

            if ((Math.Abs(px - x) <= (ENEMY_WIDTH / 2)) && (Math.Abs(py - y) < (ENEMY_HEIGHT / 2)))
            {
                selectedPart = PART_SPAWN_POSITION;
                return true;
            }

            return false;
        }

        public override void MoveBy(float dx, float dy, int selectedPart)
        {
            if (selectedPart == PART_SPAWN_POSITION)
            {
                SpawnPosition.x += (dx / Doc.View.ZoomFactor);
                SpawnPosition.y += (dy / Doc.View.ZoomFactor);
            }
            else
            {
                SpawnTrigger.x += (dx / Doc.View.ZoomFactor);
                SpawnTrigger.y += (dy / Doc.View.ZoomFactor);
            }
        }

        public override string GetPropertiesType()
        {
            return "GarbageCollectorBoss";
        }

        public override void WriteData(TextWriter tw)
        {
            base.WriteData(tw);

            LevelUtil.WriteProperty(tw, "initPosition", InitPosition, 1);
        }

        public override void WriteData(Serializer s)
        {
            base.WriteData(s);

            s.Write("initPosition"); s.Write(InitPosition);
        }

        public override bool ReadParameter(Tokenizer t, String id)
                {
            if (id.Equals("initPosition", StringComparison.OrdinalIgnoreCase))
            {
                InitPosition = ParseUtil.readVector2(t);
            }
            else
            {
                return base.ReadParameter(t, id);
            }

            t.readToken(";");
            return true;
                }
    }
}