Subversion Repositories AndroidProjects

Rev

Rev 1621 | 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;
1433 chris 6
using System.ComponentModel;
1493 chris 7
using System.IO;
1543 chris 8
using System.Drawing;
9
using System.Drawing.Design;
1432 chris 10
 
11
using BauzoidNET.math;
12
using BauzoidNET.parser;
1448 chris 13
using BauzoidNET.graphics.sprite;
1432 chris 14
 
1448 chris 15
using BurutaruEditor.view;
16
 
1432 chris 17
namespace BurutaruEditor.file.enemies
18
{
19
    public abstract class EnemySpawner : LevelObject
20
    {
1543 chris 21
 
1448 chris 22
        public const float SPAWNER_SIZE = 32;
1459 chris 23
 
24
        public const int PART_SPAWN_TRIGGER = 0;
25
        public const int PART_SPAWN_POSITION = 32;
26
 
1458 chris 27
        public static readonly Vector4 ARROW_COLOR = new Vector4(1, 0, 0, 0.5f);
1448 chris 28
 
1543 chris 29
        //=================================================================================================================================
30
 
31
        public enum PowerUpType
32
        {
33
            NONE = -1,
34
            SPEED_UP = 0,
35
            MISSILE,
36
            BOMB,
37
            BEAM_SHOT,
38
            SPREAD_SHOT,
39
            NAPALM_SHOT,
40
            FORCE_FIELD
41
        }
42
 
43
        //=================================================================================================================================
44
 
1432 chris 45
        private Vector2 mSpawnTrigger = new Vector2();
1433 chris 46
 
1477 chris 47
        [Category("Basic Parameters")]
1433 chris 48
        [TypeConverter(typeof(ExpandableObjectConverter))]
1432 chris 49
        public Vector2 SpawnTrigger { get { return mSpawnTrigger; } }
50
 
51
        private Vector2 mSpawnPosition = new Vector2();
1477 chris 52
 
53
        [Category("Basic Parameters")]
1433 chris 54
        [TypeConverter(typeof(ExpandableObjectConverter))]
1432 chris 55
        public Vector2 SpawnPosition { get { return mSpawnPosition; } }
56
 
1543 chris 57
        private PowerUpType mPowerUpType = PowerUpType.NONE;
58
        [Category("Basic Parameters")]
59
        public PowerUpType LeavePowerUp
60
        {
61
            get
62
            {
63
                return mPowerUpType;
64
            }
65
            set
66
            {
67
                mPowerUpType = value;
68
            }
69
        }
70
 
1481 chris 71
        [Browsable(false)]
72
        public string DisplayName
73
        {
74
            get
75
            {
76
                return Name + " [" + GetPropertiesType() + "]";
77
            }
78
        }
79
 
1543 chris 80
        protected Vector4 mMultiplyColor = new Vector4(1, 1, 1, 1);
81
        protected Vector4 mLerpColor = new Vector4(0, 0, 0, 0);
82
 
83
        [Category("Basic Parameters")]
84
        [Editor(typeof(ColorEditor), typeof(UITypeEditor))] // specify editor for the property
85
        public Color MultiplyColor
86
        {
87
            get
88
            {
89
                return Color.FromArgb(255, (int)(mMultiplyColor.x * 255), (int)(mMultiplyColor.y * 255), (int)(mMultiplyColor.z * 255));
90
            }
91
            set
92
            {
93
                mMultiplyColor.set((float)value.R / 255.0f, (float)value.G / 255.0f, (float)value.B / 255.0f, 1.0f);
94
            }
95
        }
96
 
97
        protected float mMultiplyFactor = 1.0f;
98
        [Category("Basic Parameters")]
99
        public float MultiplyFactor
100
        {
101
            get { return mMultiplyFactor; }
102
            set { mMultiplyFactor = MathUtil.clamp(value, 0, 1); }
103
        }
104
 
105
        [Category("Basic Parameters")]
106
        [Editor(typeof(ColorEditor), typeof(UITypeEditor))] // specify editor for the property
107
        public Color LerpColor
108
        {
109
            get
110
            {
111
                return Color.FromArgb(255, (int)(mLerpColor.x * 255), (int)(mLerpColor.y * 255), (int)(mLerpColor.z * 255));
112
            }
113
            set
114
            {
115
                mLerpColor.set((float)value.R / 255.0f, (float)value.G / 255.0f, (float)value.B / 255.0f, 1.0f);
116
            }
117
        }
118
 
119
        protected float mLerpFactor = 0.0f;
120
        [Category("Basic Parameters")]
121
        public float LerpFactor
122
        {
123
            get { return mLerpFactor; }
124
            set { mLerpFactor = MathUtil.clamp(value, 0, 1); }
125
        }
126
 
1548 chris 127
        [Category("Basic Parameters")]
128
        public float Alpha { get; set; }
129
 
1496 chris 130
        //=================================================================================================================================
131
 
1432 chris 132
        public EnemySpawner(Document doc, string name)
133
            : base(doc, name)
134
        {
1548 chris 135
            Alpha = 1.0f;
1432 chris 136
        }
137
 
1448 chris 138
        public virtual void Render()
139
        {
140
            SpriteTransform t = DocumentView.Resources.Spawner.getSpriteTransform();
141
            t.x = SpawnTrigger.x + Doc.View.CurrentPosition.x;
142
            t.y = SpawnTrigger.y + Doc.View.CurrentPosition.y;
143
            t.w = SPAWNER_SIZE;
144
            t.h = SPAWNER_SIZE;
145
            t.centerPivot();
146
            DocumentView.Resources.Spawner.render();
147
        }
1432 chris 148
 
1463 chris 149
        public override void RenderSelected(int selectedPart, bool forHover = false)
1460 chris 150
        {
151
            float triggerX = SpawnTrigger.x + Doc.View.CurrentPosition.x;
152
            float triggerY = SpawnTrigger.y + Doc.View.CurrentPosition.y;
153
 
154
            float halfSize = (SPAWNER_SIZE / 2 + DocumentView.SELECTION_FRAME_OFFSET);
155
 
1463 chris 156
            if (forHover)
157
                Doc.View.RenderSelectionFrame(triggerX - halfSize, triggerY - halfSize, triggerX + halfSize, triggerY + halfSize, DocumentView.SELECTION_FRAME_HOVER_ALPHA);
158
            else
159
                Doc.View.RenderSelectionFrame(triggerX - halfSize, triggerY - halfSize, triggerX + halfSize, triggerY + halfSize);
1460 chris 160
        }
161
 
1459 chris 162
        public override bool IsInside(float x, float y, out int selectedPart)
1448 chris 163
        {
1459 chris 164
            selectedPart = -1;
1448 chris 165
            float px = SpawnTrigger.x + Doc.View.CurrentPosition.x;
166
            float py = SpawnTrigger.y + Doc.View.CurrentPosition.y;
167
 
168
            if ((Math.Abs(px - x) <= (SPAWNER_SIZE / 2)) && (Math.Abs(py - y) < (SPAWNER_SIZE / 2)))
1459 chris 169
            {
170
                selectedPart = PART_SPAWN_TRIGGER;
1448 chris 171
                return true;
1459 chris 172
            }
1448 chris 173
 
174
            return false;
175
        }
176
 
1493 chris 177
        public override void WriteData(TextWriter tw)
178
        {
1548 chris 179
            tw.WriteLine("\tspawnTrigger " + mSpawnTrigger.x.ToString("F") + ", " + mSpawnTrigger.y.ToString("F") + ";");
180
            tw.WriteLine("\tspawnPosition " + mSpawnPosition.x.ToString("F") + ", " + mSpawnPosition.y.ToString("F") + ";");
1543 chris 181
            tw.WriteLine("\tleavePowerUp " + (int)mPowerUpType + ";");
182
            tw.WriteLine("\tmultiplyColor " + mMultiplyColor.x + ", " + mMultiplyColor.y + ", " + mMultiplyColor.z + ", " + mMultiplyFactor + ";");
183
            tw.WriteLine("\tlerpColor " + mLerpColor.x + ", " + mLerpColor.y + ", " + mLerpColor.z + ", " + mLerpFactor + ";");
1548 chris 184
            tw.WriteLine("\talpha " + Alpha + ";");
1493 chris 185
        }
186
 
1674 chris 187
        public override void WriteData(Serializer s)
188
        {
189
            s.Write("spawnTrigger"); s.Write(mSpawnTrigger);
190
            s.Write("spawnPosition"); s.Write(mSpawnPosition);
191
            s.Write("leavePowerUp"); s.Write((int)mPowerUpType);
192
            s.Write("multiplyColor"); s.Write(mMultiplyColor);
193
            s.Write("lerpColor"); s.Write(mLerpColor);
194
            s.Write("alpha"); s.Write(Alpha);
195
            /*s.Write("position"); s.Write(Position);
196
            s.Write("freeScroll"); s.Write(FreeScroll);
197
            s.Write("continueCondition"); s.Write(ContinueCondition);
198
            s.Write("scrollSpeed"); s.Write(ScrollSpeed);
199
            s.Write("starFieldStatus"); s.Write((int)StarFieldStatus);
200
            s.Write("starFieldStatusSwitchTime"); s.Write(StarFieldStatusSwitchTime);*/
201
        }
202
 
1432 chris 203
        public override bool ReadParameter(Tokenizer t, string id)
204
            {
205
                    if (id.Equals("spawnTrigger", StringComparison.OrdinalIgnoreCase))
206
                    {
207
                mSpawnTrigger = ParseUtil.readVector2(t);
208
                    }
209
            else if (id.Equals("spawnPosition", StringComparison.OrdinalIgnoreCase))
210
                    {
211
                mSpawnPosition = ParseUtil.readVector2(t);
212
                    }
1543 chris 213
            else if (id.Equals("leavePowerUp", StringComparison.OrdinalIgnoreCase))
214
            {
215
                mPowerUpType = (PowerUpType)((int)t.readNumber());
216
            }
217
            else if (id.Equals("multiplyColor", StringComparison.OrdinalIgnoreCase))
218
            {
219
                mMultiplyColor = ParseUtil.readVector4(t);
220
                mMultiplyFactor = mMultiplyColor.w;
221
                mMultiplyColor.w = 1.0f;
222
            }
223
            else if (id.Equals("lerpColor", StringComparison.OrdinalIgnoreCase))
224
            {
225
                mLerpColor = ParseUtil.readVector4(t);
226
                mLerpFactor = mLerpColor.w;
227
                mLerpColor.w = 1.0f;
228
            }
1548 chris 229
            else if (id.Equals("alpha", StringComparison.OrdinalIgnoreCase))
230
            {
231
                Alpha = t.readNumber();
232
            }
1543 chris 233
            else
234
            {
235
                return false;
236
            }
1432 chris 237
 
238
                    t.readToken(";");
239
                    return true;
240
            }
241
 
242
        public static EnemySpawner createSpawner(Document doc, string enemyType, string enemyName)
243
        {
244
            if (enemyType.Equals("BlobEnemy"))
245
            {
246
                return new BlobEnemySpawner(doc, enemyName);
247
            }
1541 chris 248
            else if (enemyType.Equals("CoreMechEnemy"))
249
            {
250
                return new CoreMechEnemySpawner(doc, enemyName);
251
            }
1565 chris 252
            else if (enemyType.Equals("CoreMechXlEnemy"))
253
            {
254
                return new CoreMechXlEnemySpawner(doc, enemyName);
255
            }
1575 chris 256
            else if (enemyType.Equals("CoreTurretEnemy"))
257
            {
258
                return new CoreTurretEnemySpawner(doc, enemyName);
259
            }
1584 chris 260
            else if (enemyType.Equals("SpaceMineEnemy"))
261
            {
262
                return new SpaceMineEnemySpawner(doc, enemyName);
263
            }
1621 chris 264
            else if (enemyType.Equals("GarbageCollectorBoss"))
265
            {
266
                return new GarbageCollectorBossSpawner(doc, enemyName);
267
            }
1432 chris 268
 
269
            return null;
270
        }
1477 chris 271
 
272
        public override string GetPropertiesType()
273
        {
1493 chris 274
            return "EnemySpawner";
1477 chris 275
        }
1432 chris 276
    }
277
}