Subversion Repositories AndroidProjects

Rev

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

Rev Author Line No. Line
1562 chris 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.IO;
1565 chris 7
using System.ComponentModel;
1562 chris 8
 
9
using BauzoidNET.graphics;
10
using BauzoidNET.graphics.sprite;
1565 chris 11
using BauzoidNET.math;
1562 chris 12
using BauzoidNET.parser;
13
 
14
using BurutaruEditor.view;
15
 
16
namespace BurutaruEditor.file.enemies
17
{
18
    public class CoreMechXlEnemySpawner : EnemySpawner
19
    {
20
        public const float ENEMY_WIDTH = 170;
21
        public const float ENEMY_HEIGHT = ENEMY_WIDTH;
22
 
1565 chris 23
        public const float DEFAULT_POS_X = -200;
24
        public const float DEFAULT_POS_A_Y = -50;
25
        public const float DEFAULT_POS_B_Y = 50;
26
 
27
        public const float MOVE_SPEED = 50;
28
 
29
        //=================================================================================================================================
30
 
31
        [Category("Formation")]
32
        public float MoveSpeed { get; set; }
33
 
34
        [Category("Formation")]
35
        [TypeConverter(typeof(ExpandableObjectConverter))]
36
        public Vector2 PointA { get; set; }
37
 
38
        [Category("Formation")]
39
        [TypeConverter(typeof(ExpandableObjectConverter))]
40
        public Vector2 PointB { get; set; }
41
 
1575 chris 42
        [Category("Formation")]
43
        public int ShootCount { get; set; }
44
 
1565 chris 45
        //=================================================================================================================================
46
 
1562 chris 47
        public CoreMechXlEnemySpawner(Document doc, string name)
48
            : base(doc, name)
49
        {
1565 chris 50
            PointA = new Vector2(DEFAULT_POS_X, DEFAULT_POS_A_Y);
51
            PointB = new Vector2(DEFAULT_POS_X, DEFAULT_POS_B_Y);
52
            MoveSpeed = MOVE_SPEED;
1575 chris 53
            ShootCount = 2;
1562 chris 54
        }
55
 
56
        public override void Render()
57
        {
58
            base.Render();
59
 
60
            float triggerX = SpawnTrigger.x + Doc.View.CurrentPosition.x;
61
            float triggerY = SpawnTrigger.y + Doc.View.CurrentPosition.y;
62
 
63
            SpriteTransform t = DocumentView.Resources.CoreMechXlEnemySprite.getSpriteTransform();
64
            t.x = triggerX + SpawnPosition.x;
65
            t.y = triggerY + SpawnPosition.y;
66
            t.w = ENEMY_WIDTH;
67
            t.h = ENEMY_HEIGHT;
68
            t.centerPivot();
69
            DocumentView.Resources.CoreMechXlEnemySprite.getSpriteInstance().color.setFrom(mMultiplyColor);
70
            DocumentView.Resources.CoreMechXlEnemySprite.getSpriteInstance().color.w = mMultiplyFactor;
71
            DocumentView.Resources.CoreMechXlEnemySprite.getSpriteInstance().fogColor.setFrom(mLerpColor);
72
            DocumentView.Resources.CoreMechXlEnemySprite.getSpriteInstance().fogColor.w = mLerpFactor;
73
            DocumentView.Resources.CoreMechXlEnemySprite.render();
74
 
75
            float w = MainForm.App.getGraphics().getFont().getTextWidth(this.Name, Document.TEXT_SCALE);
76
            MainForm.App.getGraphics().getFont().drawTextDirect(this.Name, t.x - w / 2, t.y + ENEMY_HEIGHT / 2, Document.TEXT_COLOR, Document.TEXT_SCALE);
77
 
78
            RenderUtil.drawArrow(MainForm.App.getGraphics(), triggerX, triggerY, t.x, t.y, ARROW_COLOR);
1565 chris 79
 
80
            RenderUtil.drawArrow(MainForm.App.getGraphics(), t.x, t.y, t.x + PointA.x, t.y + PointA.y, ARROW_COLOR);
81
            RenderUtil.drawArrow(MainForm.App.getGraphics(), t.x, t.y, t.x + PointB.x, t.y + PointB.y, ARROW_COLOR);
1562 chris 82
        }
83
 
84
        public override void RenderSelected(int selectedPart, bool forHover = false)
85
        {
86
            if (selectedPart != PART_SPAWN_POSITION)
87
            {
88
                base.RenderSelected(selectedPart, forHover);
89
            }
90
 
91
            float posX = SpawnTrigger.x + SpawnPosition.x + Doc.View.CurrentPosition.x;
92
            float posY = SpawnTrigger.y + SpawnPosition.y + Doc.View.CurrentPosition.y;
93
 
94
            float halfWidth = ENEMY_WIDTH / 2 + DocumentView.SELECTION_FRAME_OFFSET;
95
            float halfHeight = ENEMY_HEIGHT / 2 + DocumentView.SELECTION_FRAME_OFFSET;
96
 
97
            if (forHover)
98
                Doc.View.RenderSelectionFrame(posX - halfWidth, posY - halfHeight, posX + halfWidth, posY + halfHeight, DocumentView.SELECTION_FRAME_HOVER_ALPHA);
99
            else
100
                Doc.View.RenderSelectionFrame(posX - halfWidth, posY - halfHeight, posX + halfWidth, posY + halfHeight);
101
        }
102
 
103
 
104
        public override bool IsInside(float x, float y, out int selectedPart)
105
        {
106
            if (base.IsInside(x, y, out selectedPart))
107
                return true;
108
 
109
            float px = SpawnTrigger.x + SpawnPosition.x + Doc.View.CurrentPosition.x;
110
            float py = SpawnTrigger.y + SpawnPosition.y + Doc.View.CurrentPosition.y;
111
 
112
            if ((Math.Abs(px - x) <= (ENEMY_WIDTH / 2)) && (Math.Abs(py - y) < (ENEMY_HEIGHT / 2)))
113
            {
114
                selectedPart = PART_SPAWN_POSITION;
115
                return true;
116
            }
117
 
118
            return false;
119
        }
120
 
121
        public override void MoveBy(float dx, float dy, int selectedPart)
122
        {
123
            if (selectedPart == PART_SPAWN_POSITION)
124
            {
125
                SpawnPosition.x += (dx / Doc.View.ZoomFactor);
126
                SpawnPosition.y += (dy / Doc.View.ZoomFactor);
127
            }
128
            else
129
            {
130
                SpawnTrigger.x += (dx / Doc.View.ZoomFactor);
131
                SpawnTrigger.y += (dy / Doc.View.ZoomFactor);
132
            }
133
        }
134
 
135
        public override string GetPropertiesType()
136
        {
1564 chris 137
            return "CoreMechXlEnemy";
1562 chris 138
        }
139
 
140
        public override void WriteData(TextWriter tw)
141
        {
142
            base.WriteData(tw);
143
 
144
            //tw.WriteLine("\tmoveSpeed " + MoveSpeed + ";");
1575 chris 145
            tw.WriteLine("\tmoveSpeed " + MoveSpeed + ";");
146
            tw.WriteLine("\tpointA " + PointA.x + ", " + PointA.y + ";");
147
            tw.WriteLine("\tpointB " + PointB.x + ", " + PointB.y + ";");
148
            tw.WriteLine("\tShootCount " + ShootCount + ";");
1562 chris 149
        }
150
 
1674 chris 151
        public override void WriteData(Serializer s)
152
        {
153
            base.WriteData(s);
154
 
155
            s.Write("moveSpeed"); s.Write(MoveSpeed);
156
            s.Write("pointA"); s.Write(PointA);
157
            s.Write("pointB"); s.Write(PointB);
158
            s.Write("ShootCount"); s.Write(ShootCount);
159
        }
160
 
1562 chris 161
        public override bool ReadParameter(Tokenizer t, String id)
162
        {
163
            if (id.Equals("moveSpeed", StringComparison.OrdinalIgnoreCase))
164
            {
1565 chris 165
                MoveSpeed = t.readNumber();
1562 chris 166
            }
1565 chris 167
            else if (id.Equals("pointA", StringComparison.OrdinalIgnoreCase))
168
            {
169
                PointA = ParseUtil.readVector2(t);
170
            }
171
            else if (id.Equals("pointB", StringComparison.OrdinalIgnoreCase))
172
            {
173
                PointB = ParseUtil.readVector2(t);
174
            }
1575 chris 175
            else if (id.Equals("shootCount", StringComparison.OrdinalIgnoreCase))
176
            {
177
                ShootCount = (int)t.readNumber();
178
            }
1562 chris 179
            else
180
            {
181
                return base.ReadParameter(t, id);
182
            }
183
 
184
            t.readToken(";");
185
            return true;
186
        }
187
    }
188
}