Rev 1604 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1584 | 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 SpaceMineEnemySpawner : EnemySpawner |
||
| 20 | { |
||
| 21 | public const float ENEMY_SIZE = 100; |
||
| 22 | |||
| 23 | //================================================================================================================================= |
||
| 24 | |||
| 25 | [Category("Formation")] |
||
| 26 | public float ShootInterval { get; set; } |
||
| 27 | |||
| 28 | [Category("Formation")] |
||
| 29 | public float RotationSpeed { get; set; } |
||
| 30 | |||
| 31 | [Category("Formation")] |
||
| 32 | public float MoveSpeed { get; set; } |
||
| 33 | |||
| 34 | [Category("Formation")] |
||
| 35 | [TypeConverter(typeof(ExpandableObjectConverter))] |
||
| 36 | public Vector2 MoveDir { get; set; } |
||
| 37 | |||
| 1597 | chris | 38 | [Category("Formation")] |
| 39 | public float InitialAngle { get; set; } |
||
| 1584 | chris | 40 | |
| 41 | //================================================================================================================================= |
||
| 42 | |||
| 43 | public SpaceMineEnemySpawner(Document doc, string name) |
||
| 44 | : base(doc, name) |
||
| 45 | { |
||
| 46 | ShootInterval = 1.0f; |
||
| 47 | RotationSpeed = 70; |
||
| 48 | MoveDir = new Vector2(-1, 1); |
||
| 49 | MoveSpeed = 30; |
||
| 1597 | chris | 50 | InitialAngle = 0.0f; |
| 1584 | chris | 51 | } |
| 52 | |||
| 53 | public override void Render() |
||
| 54 | { |
||
| 55 | base.Render(); |
||
| 56 | |||
| 57 | float triggerX = SpawnTrigger.x + Doc.View.CurrentPosition.x; |
||
| 58 | float triggerY = SpawnTrigger.y + Doc.View.CurrentPosition.y; |
||
| 59 | |||
| 60 | SpriteTransform t = DocumentView.Resources.SpaceMineEnemySprite.getSpriteTransform(); |
||
| 61 | t.x = triggerX + SpawnPosition.x; |
||
| 62 | t.y = triggerY + SpawnPosition.y; |
||
| 63 | t.w = ENEMY_SIZE; |
||
| 64 | t.h = ENEMY_SIZE; |
||
| 65 | t.centerPivot(); |
||
| 1597 | chris | 66 | t.angle = InitialAngle; |
| 1584 | chris | 67 | DocumentView.Resources.SpaceMineEnemySprite.getSpriteInstance().color.setFrom(mMultiplyColor); |
| 68 | DocumentView.Resources.SpaceMineEnemySprite.getSpriteInstance().color.w = mMultiplyFactor; |
||
| 69 | DocumentView.Resources.SpaceMineEnemySprite.getSpriteInstance().fogColor.setFrom(mLerpColor); |
||
| 70 | DocumentView.Resources.SpaceMineEnemySprite.getSpriteInstance().fogColor.w = mLerpFactor; |
||
| 71 | DocumentView.Resources.SpaceMineEnemySprite.render(); |
||
| 72 | |||
| 73 | float w = MainForm.App.getGraphics().getFont().getTextWidth(this.Name, Document.TEXT_SCALE); |
||
| 74 | MainForm.App.getGraphics().getFont().drawTextDirect(this.Name, t.x - w / 2, t.y + ENEMY_SIZE/2,Document.TEXT_COLOR, Document.TEXT_SCALE); |
||
| 75 | |||
| 76 | RenderUtil.drawArrow(MainForm.App.getGraphics(), triggerX, triggerY, t.x, t.y, ARROW_COLOR); |
||
| 77 | } |
||
| 78 | |||
| 79 | public override void RenderSelected(int selectedPart, bool forHover = false) |
||
| 80 | { |
||
| 81 | if (selectedPart != PART_SPAWN_POSITION) |
||
| 82 | { |
||
| 83 | base.RenderSelected(selectedPart, forHover); |
||
| 84 | } |
||
| 85 | |||
| 86 | float posX = SpawnTrigger.x + SpawnPosition.x + Doc.View.CurrentPosition.x; |
||
| 87 | float posY = SpawnTrigger.y + SpawnPosition.y + Doc.View.CurrentPosition.y; |
||
| 88 | |||
| 89 | float halfSize = ENEMY_SIZE / 2 + DocumentView.SELECTION_FRAME_OFFSET; |
||
| 90 | |||
| 91 | if (forHover) |
||
| 92 | Doc.View.RenderSelectionFrame(posX - halfSize, posY - halfSize, posX + halfSize, posY + halfSize, DocumentView.SELECTION_FRAME_HOVER_ALPHA); |
||
| 93 | else |
||
| 94 | Doc.View.RenderSelectionFrame(posX - halfSize, posY - halfSize, posX + halfSize, posY + halfSize); |
||
| 95 | } |
||
| 96 | |||
| 97 | public override bool IsInside(float x, float y, out int selectedPart) |
||
| 98 | { |
||
| 99 | if (base.IsInside(x, y, out selectedPart)) |
||
| 100 | return true; |
||
| 101 | |||
| 102 | float px = SpawnTrigger.x + SpawnPosition.x + Doc.View.CurrentPosition.x; |
||
| 103 | float py = SpawnTrigger.y + SpawnPosition.y + Doc.View.CurrentPosition.y; |
||
| 104 | |||
| 105 | if ((Math.Abs(px - x) <= (ENEMY_SIZE / 2)) && (Math.Abs(py - y) < (ENEMY_SIZE / 2))) |
||
| 106 | { |
||
| 107 | selectedPart = PART_SPAWN_POSITION; |
||
| 108 | return true; |
||
| 109 | } |
||
| 110 | |||
| 111 | return false; |
||
| 112 | } |
||
| 113 | |||
| 114 | public override void MoveBy(float dx, float dy, int selectedPart) |
||
| 115 | { |
||
| 116 | if (selectedPart == PART_SPAWN_POSITION) |
||
| 117 | { |
||
| 118 | SpawnPosition.x += (dx / Doc.View.ZoomFactor); |
||
| 119 | SpawnPosition.y += (dy / Doc.View.ZoomFactor); |
||
| 120 | } |
||
| 121 | else |
||
| 122 | { |
||
| 123 | SpawnTrigger.x += (dx / Doc.View.ZoomFactor); |
||
| 124 | SpawnTrigger.y += (dy / Doc.View.ZoomFactor); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | public override string GetPropertiesType() |
||
| 129 | { |
||
| 130 | return "SpaceMineEnemy"; |
||
| 131 | } |
||
| 132 | |||
| 133 | public override void WriteData(TextWriter tw) |
||
| 134 | { |
||
| 135 | base.WriteData(tw); |
||
| 136 | |||
| 137 | tw.WriteLine("\tshootInterval " + ShootInterval + ";"); |
||
| 138 | tw.WriteLine("\trotationSpeed " + RotationSpeed + ";"); |
||
| 139 | tw.WriteLine("\tmoveSpeed " + MoveSpeed + ";"); |
||
| 140 | tw.WriteLine("\tmoveDir " + MoveDir.x + ", " + MoveDir.y + ";"); |
||
| 1604 | chris | 141 | tw.WriteLine("\tinitialAngle " + InitialAngle + ";"); |
| 1584 | chris | 142 | } |
| 143 | |||
| 1674 | chris | 144 | public override void WriteData(Serializer s) |
| 145 | { |
||
| 146 | base.WriteData(s); |
||
| 147 | |||
| 148 | s.Write("shootInterval"); s.Write(ShootInterval); |
||
| 149 | s.Write("rotationSpeed"); s.Write(RotationSpeed); |
||
| 150 | s.Write("moveSpeed"); s.Write(MoveSpeed); |
||
| 151 | s.Write("moveDir"); s.Write(MoveDir); |
||
| 152 | s.Write("initialAngle"); s.Write(InitialAngle); |
||
| 153 | } |
||
| 154 | |||
| 1584 | chris | 155 | public override bool ReadParameter(Tokenizer t, String id) |
| 156 | { |
||
| 157 | if (id.Equals("shootInterval", StringComparison.OrdinalIgnoreCase)) |
||
| 158 | { |
||
| 159 | ShootInterval = t.readNumber(); |
||
| 160 | } |
||
| 1597 | chris | 161 | else if (id.Equals("initialAngle", StringComparison.OrdinalIgnoreCase)) |
| 162 | { |
||
| 163 | InitialAngle = t.readNumber(); |
||
| 164 | } |
||
| 1584 | chris | 165 | else if (id.Equals("rotationSpeed", StringComparison.OrdinalIgnoreCase)) |
| 166 | { |
||
| 167 | RotationSpeed = t.readNumber(); |
||
| 168 | } |
||
| 169 | else if (id.Equals("moveSpeed", StringComparison.OrdinalIgnoreCase)) |
||
| 170 | { |
||
| 171 | MoveSpeed = t.readNumber(); |
||
| 172 | } |
||
| 173 | else if (id.Equals("moveDir", StringComparison.OrdinalIgnoreCase)) |
||
| 174 | { |
||
| 175 | MoveDir = ParseUtil.readVector2(t); |
||
| 176 | } |
||
| 177 | else |
||
| 178 | { |
||
| 179 | return base.ReadParameter(t, id); |
||
| 180 | } |
||
| 181 | |||
| 182 | t.readToken(";"); |
||
| 183 | return true; |
||
| 184 | } |
||
| 185 | } |
||
| 186 | } |