Rev 1543 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.ComponentModel;
using BauzoidNET.parser;
using BauzoidNET.graphics.sprite;
using BauzoidNET.graphics;
using BauzoidNET.math;
using BurutaruEditor.view;
namespace BurutaruEditor
.file.enemies
{
public class BlobEnemySpawner
: EnemySpawner
{
public const float BLOB_ENEMY_SIZE
= 60;
//=================================================================================================================================
[Category
("Formation")]
[TypeConverter
(typeof(ExpandableObjectConverter
))]
public Vector2 MoveDir
{ get
; set
; }
//=================================================================================================================================
public BlobEnemySpawner
(Document doc,
string name
)
: base(doc, name
)
{
MoveDir
= new Vector2
(0,
0);
}
public override void Render
()
{
base.Render();
float triggerX
= SpawnTrigger
.x + Doc
.View.CurrentPosition.x;
float triggerY
= SpawnTrigger
.y + Doc
.View.CurrentPosition.y;
SpriteTransform t
= DocumentView
.Resources.BlobEnemySprite.getSpriteTransform();
t
.x = triggerX
+ SpawnPosition
.x;
t
.y = triggerY
+ SpawnPosition
.y;
t
.w = BLOB_ENEMY_SIZE
;
t
.h = BLOB_ENEMY_SIZE
;
t
.centerPivot();
DocumentView
.Resources.BlobEnemySprite.getSpriteInstance().color.setFrom(mMultiplyColor
);
DocumentView
.Resources.BlobEnemySprite.getSpriteInstance().color.w = mMultiplyFactor
;
DocumentView
.Resources.BlobEnemySprite.getSpriteInstance().fogColor.setFrom(mLerpColor
);
DocumentView
.Resources.BlobEnemySprite.getSpriteInstance().fogColor.w = mLerpFactor
;
DocumentView
.Resources.BlobEnemySprite.render();
float w
= MainForm
.App.getGraphics().getFont().getTextWidth(this.Name, Document
.TEXT_SCALE);
MainForm
.App.getGraphics().getFont().drawTextDirect(this.Name, t
.x - w
/ 2, t
.y + BLOB_ENEMY_SIZE
/2,Document
.TEXT_COLOR, Document
.TEXT_SCALE);
RenderUtil
.drawArrow(MainForm
.App.getGraphics(), triggerX, triggerY, t
.x, t
.y, ARROW_COLOR
);
Vector2 m
= new Vector2
(MoveDir
.x, MoveDir
.y);
m
.setLength(100);
RenderUtil
.drawArrow(MainForm
.App.getGraphics(), t
.x, t
.y, t
.x + m
.x, t
.y + m
.y, ARROW_COLOR
);
}
public override void RenderSelected
(int selectedPart,
bool forHover
= false)
{
if (selectedPart
!= PART_SPAWN_POSITION
)
{
base.RenderSelected(selectedPart, forHover
);
}
float posX
= SpawnTrigger
.x + SpawnPosition
.x + Doc
.View.CurrentPosition.x;
float posY
= SpawnTrigger
.y + SpawnPosition
.y + Doc
.View.CurrentPosition.y;
float halfSize
= BLOB_ENEMY_SIZE
/ 2 + DocumentView
.SELECTION_FRAME_OFFSET;
if (forHover
)
Doc
.View.RenderSelectionFrame(posX
- halfSize, posY
- halfSize, posX
+ halfSize, posY
+ halfSize, DocumentView
.SELECTION_FRAME_HOVER_ALPHA);
else
Doc
.View.RenderSelectionFrame(posX
- halfSize, posY
- halfSize, posX
+ halfSize, posY
+ halfSize
);
}
public override bool IsInside
(float x,
float y,
out int selectedPart
)
{
if (base.IsInside(x, y,
out selectedPart
))
return true;
float px
= SpawnTrigger
.x + SpawnPosition
.x + Doc
.View.CurrentPosition.x;
float py
= SpawnTrigger
.y + SpawnPosition
.y + Doc
.View.CurrentPosition.y;
if ((Math
.Abs(px
- x
) <= (BLOB_ENEMY_SIZE
/ 2)) && (Math
.Abs(py
- y
) < (BLOB_ENEMY_SIZE
/ 2)))
{
selectedPart
= PART_SPAWN_POSITION
;
return true;
}
return false;
}
public override void MoveBy
(float dx,
float dy,
int selectedPart
)
{
if (selectedPart
== PART_SPAWN_POSITION
)
{
SpawnPosition
.x += (dx
/ Doc
.View.ZoomFactor);
SpawnPosition
.y += (dy
/ Doc
.View.ZoomFactor);
}
else
{
SpawnTrigger
.x += (dx
/ Doc
.View.ZoomFactor);
SpawnTrigger
.y += (dy
/ Doc
.View.ZoomFactor);
}
}
public override string GetPropertiesType
()
{
return "BlobEnemy";
}
public override void WriteData
(TextWriter tw
)
{
base.WriteData(tw
);
tw
.WriteLine("\tmoveDir " + MoveDir
.x + ", " + MoveDir
.y + ";");
}
public override bool ReadParameter
(Tokenizer t,
String id
)
{
if (id
.Equals("moveDir", StringComparison
.OrdinalIgnoreCase))
{
MoveDir
= ParseUtil
.readVector2(t
);
}
else
{
return base.ReadParameter(t, id
);
}
t
.readToken(";");
return true;
}
}
}