Subversion Repositories AndroidProjects

Rev

Rev 1597 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1432 chris 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
1493 chris 6
using System.IO;
1597 chris 7
using System.ComponentModel;
1432 chris 8
 
9
using BauzoidNET.parser;
10
using BauzoidNET.graphics.sprite;
1458 chris 11
using BauzoidNET.graphics;
1597 chris 12
using BauzoidNET.math;
1432 chris 13
 
1458 chris 14
 
1432 chris 15
using BurutaruEditor.view;
16
 
17
namespace BurutaruEditor.file.enemies
18
{
19
    public class BlobEnemySpawner : EnemySpawner
20
    {
21
        public const float BLOB_ENEMY_SIZE = 60;
22
 
1496 chris 23
        //=================================================================================================================================
24
 
1597 chris 25
        [Category("Formation")]
26
        [TypeConverter(typeof(ExpandableObjectConverter))]
27
        public Vector2 MoveDir { get; set; }
28
 
29
        //=================================================================================================================================
30
 
1432 chris 31
        public BlobEnemySpawner(Document doc, string name)
32
            : base(doc, name)
33
        {
1597 chris 34
            MoveDir = new Vector2(0, 0);
1432 chris 35
        }
36
 
37
        public override void Render()
38
        {
1448 chris 39
            base.Render();
40
 
1458 chris 41
            float triggerX = SpawnTrigger.x + Doc.View.CurrentPosition.x;
42
            float triggerY = SpawnTrigger.y + Doc.View.CurrentPosition.y;
43
 
1432 chris 44
            SpriteTransform t = DocumentView.Resources.BlobEnemySprite.getSpriteTransform();
1458 chris 45
            t.x = triggerX + SpawnPosition.x;
46
            t.y = triggerY + SpawnPosition.y;
1432 chris 47
            t.w = BLOB_ENEMY_SIZE;
48
            t.h = BLOB_ENEMY_SIZE;
49
            t.centerPivot();
1543 chris 50
            DocumentView.Resources.BlobEnemySprite.getSpriteInstance().color.setFrom(mMultiplyColor);
51
            DocumentView.Resources.BlobEnemySprite.getSpriteInstance().color.w = mMultiplyFactor;
52
            DocumentView.Resources.BlobEnemySprite.getSpriteInstance().fogColor.setFrom(mLerpColor);
53
            DocumentView.Resources.BlobEnemySprite.getSpriteInstance().fogColor.w = mLerpFactor;
1432 chris 54
            DocumentView.Resources.BlobEnemySprite.render();
1458 chris 55
 
56
            float w = MainForm.App.getGraphics().getFont().getTextWidth(this.Name, Document.TEXT_SCALE);
57
            MainForm.App.getGraphics().getFont().drawTextDirect(this.Name, t.x - w / 2, t.y + BLOB_ENEMY_SIZE/2,Document.TEXT_COLOR, Document.TEXT_SCALE);
58
 
59
            RenderUtil.drawArrow(MainForm.App.getGraphics(), triggerX, triggerY, t.x, t.y, ARROW_COLOR);
1597 chris 60
 
61
            Vector2 m = new Vector2(MoveDir.x, MoveDir.y);
62
            m.setLength(100);
63
 
64
            RenderUtil.drawArrow(MainForm.App.getGraphics(), t.x, t.y, t.x + m.x, t.y + m.y, ARROW_COLOR);
65
 
1432 chris 66
        }
67
 
1463 chris 68
        public override void RenderSelected(int selectedPart, bool forHover = false)
1460 chris 69
        {
70
            if (selectedPart != PART_SPAWN_POSITION)
71
            {
1463 chris 72
                base.RenderSelected(selectedPart, forHover);
1460 chris 73
            }
74
 
75
            float posX = SpawnTrigger.x + SpawnPosition.x + Doc.View.CurrentPosition.x;
76
            float posY = SpawnTrigger.y + SpawnPosition.y + Doc.View.CurrentPosition.y;
77
 
78
            float halfSize = BLOB_ENEMY_SIZE / 2 + DocumentView.SELECTION_FRAME_OFFSET;
79
 
1463 chris 80
            if (forHover)
81
                Doc.View.RenderSelectionFrame(posX - halfSize, posY - halfSize, posX + halfSize, posY + halfSize, DocumentView.SELECTION_FRAME_HOVER_ALPHA);
82
            else
83
                Doc.View.RenderSelectionFrame(posX - halfSize, posY - halfSize, posX + halfSize, posY + halfSize);
1460 chris 84
        }
85
 
1459 chris 86
        public override bool IsInside(float x, float y, out int selectedPart)
1441 chris 87
        {
1459 chris 88
            if (base.IsInside(x, y, out selectedPart))
1448 chris 89
                return true;
90
 
1459 chris 91
            float px = SpawnTrigger.x + SpawnPosition.x + Doc.View.CurrentPosition.x;
92
            float py = SpawnTrigger.y + SpawnPosition.y + Doc.View.CurrentPosition.y;
1448 chris 93
 
1447 chris 94
            if ((Math.Abs(px - x) <= (BLOB_ENEMY_SIZE / 2)) && (Math.Abs(py - y) < (BLOB_ENEMY_SIZE / 2)))
1459 chris 95
            {
96
                selectedPart = PART_SPAWN_POSITION;
1447 chris 97
                return true;
1459 chris 98
            }
1447 chris 99
 
1441 chris 100
            return false;
101
        }
102
 
1459 chris 103
        public override void MoveBy(float dx, float dy, int selectedPart)
1441 chris 104
        {
1459 chris 105
            if (selectedPart == PART_SPAWN_POSITION)
106
            {
107
                SpawnPosition.x += (dx / Doc.View.ZoomFactor);
108
                SpawnPosition.y += (dy / Doc.View.ZoomFactor);
109
            }
110
            else
111
            {
112
                SpawnTrigger.x += (dx / Doc.View.ZoomFactor);
113
                SpawnTrigger.y += (dy / Doc.View.ZoomFactor);
114
            }
1441 chris 115
        }
116
 
1477 chris 117
        public override string GetPropertiesType()
118
        {
1493 chris 119
            return "BlobEnemy";
1477 chris 120
        }
121
 
1493 chris 122
        public override void WriteData(TextWriter tw)
123
        {
124
            base.WriteData(tw);
1597 chris 125
 
126
            tw.WriteLine("\tmoveDir " + MoveDir.x + ", " + MoveDir.y + ";");
1493 chris 127
        }
128
 
1674 chris 129
        public override void WriteData(Serializer s)
130
        {
131
            base.WriteData(s);
132
 
133
            s.Write("moveDir"); s.Write(MoveDir);
134
        }
135
 
1432 chris 136
        public override bool ReadParameter(Tokenizer t, String id)
137
                {
1597 chris 138
            if (id.Equals("moveDir", StringComparison.OrdinalIgnoreCase))
139
            {
140
                MoveDir = ParseUtil.readVector2(t);
141
            }
142
            else
143
            {
144
                return base.ReadParameter(t, id);
145
            }
146
 
147
            t.readToken(";");
148
            return true;
1432 chris 149
                }
150
    }
151
}