Subversion Repositories AndroidProjects

Rev

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

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