Rev 1575 |
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.graphics;
using BauzoidNET.graphics.sprite;
using BauzoidNET.math;
using BauzoidNET.parser;
using BurutaruEditor.view;
namespace BurutaruEditor
.file.enemies
{
public class CoreMechXlEnemySpawner
: EnemySpawner
{
public const float ENEMY_WIDTH
= 170;
public const float ENEMY_HEIGHT
= ENEMY_WIDTH
;
public const float DEFAULT_POS_X
= -200;
public const float DEFAULT_POS_A_Y
= -50;
public const float DEFAULT_POS_B_Y
= 50;
public const float MOVE_SPEED
= 50;
//=================================================================================================================================
[Category
("Formation")]
public float MoveSpeed
{ get
; set
; }
[Category
("Formation")]
[TypeConverter
(typeof(ExpandableObjectConverter
))]
public Vector2 PointA
{ get
; set
; }
[Category
("Formation")]
[TypeConverter
(typeof(ExpandableObjectConverter
))]
public Vector2 PointB
{ get
; set
; }
[Category
("Formation")]
public int ShootCount
{ get
; set
; }
//=================================================================================================================================
public CoreMechXlEnemySpawner
(Document doc,
string name
)
: base(doc, name
)
{
PointA
= new Vector2
(DEFAULT_POS_X, DEFAULT_POS_A_Y
);
PointB
= new Vector2
(DEFAULT_POS_X, DEFAULT_POS_B_Y
);
MoveSpeed
= MOVE_SPEED
;
ShootCount
= 2;
}
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.CoreMechXlEnemySprite.getSpriteTransform();
t
.x = triggerX
+ SpawnPosition
.x;
t
.y = triggerY
+ SpawnPosition
.y;
t
.w = ENEMY_WIDTH
;
t
.h = ENEMY_HEIGHT
;
t
.centerPivot();
DocumentView
.Resources.CoreMechXlEnemySprite.getSpriteInstance().color.setFrom(mMultiplyColor
);
DocumentView
.Resources.CoreMechXlEnemySprite.getSpriteInstance().color.w = mMultiplyFactor
;
DocumentView
.Resources.CoreMechXlEnemySprite.getSpriteInstance().fogColor.setFrom(mLerpColor
);
DocumentView
.Resources.CoreMechXlEnemySprite.getSpriteInstance().fogColor.w = mLerpFactor
;
DocumentView
.Resources.CoreMechXlEnemySprite.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 + ENEMY_HEIGHT
/ 2, Document
.TEXT_COLOR, Document
.TEXT_SCALE);
RenderUtil
.drawArrow(MainForm
.App.getGraphics(), triggerX, triggerY, t
.x, t
.y, ARROW_COLOR
);
RenderUtil
.drawArrow(MainForm
.App.getGraphics(), t
.x, t
.y, t
.x + PointA
.x, t
.y + PointA
.y, ARROW_COLOR
);
RenderUtil
.drawArrow(MainForm
.App.getGraphics(), t
.x, t
.y, t
.x + PointB
.x, t
.y + PointB
.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 halfWidth
= ENEMY_WIDTH
/ 2 + DocumentView
.SELECTION_FRAME_OFFSET;
float halfHeight
= ENEMY_HEIGHT
/ 2 + DocumentView
.SELECTION_FRAME_OFFSET;
if (forHover
)
Doc
.View.RenderSelectionFrame(posX
- halfWidth, posY
- halfHeight, posX
+ halfWidth, posY
+ halfHeight, DocumentView
.SELECTION_FRAME_HOVER_ALPHA);
else
Doc
.View.RenderSelectionFrame(posX
- halfWidth, posY
- halfHeight, posX
+ halfWidth, posY
+ halfHeight
);
}
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
) <= (ENEMY_WIDTH
/ 2)) && (Math
.Abs(py
- y
) < (ENEMY_HEIGHT
/ 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 "CoreMechXlEnemy";
}
public override void WriteData
(TextWriter tw
)
{
base.WriteData(tw
);
//tw.WriteLine("\tmoveSpeed " + MoveSpeed + ";");
tw
.WriteLine("\tmoveSpeed " + MoveSpeed
+ ";");
tw
.WriteLine("\tpointA " + PointA
.x + ", " + PointA
.y + ";");
tw
.WriteLine("\tpointB " + PointB
.x + ", " + PointB
.y + ";");
tw
.WriteLine("\tShootCount " + ShootCount
+ ";");
}
public override void WriteData
(Serializer s
)
{
base.WriteData(s
);
s
.Write("moveSpeed"); s
.Write(MoveSpeed
);
s
.Write("pointA"); s
.Write(PointA
);
s
.Write("pointB"); s
.Write(PointB
);
s
.Write("ShootCount"); s
.Write(ShootCount
);
}
public override bool ReadParameter
(Tokenizer t,
String id
)
{
if (id
.Equals("moveSpeed", StringComparison
.OrdinalIgnoreCase))
{
MoveSpeed
= t
.readNumber();
}
else if (id
.Equals("pointA", StringComparison
.OrdinalIgnoreCase))
{
PointA
= ParseUtil
.readVector2(t
);
}
else if (id
.Equals("pointB", StringComparison
.OrdinalIgnoreCase))
{
PointB
= ParseUtil
.readVector2(t
);
}
else if (id
.Equals("shootCount", StringComparison
.OrdinalIgnoreCase))
{
ShootCount
= (int)t
.readNumber();
}
else
{
return base.ReadParameter(t, id
);
}
t
.readToken(";");
return true;
}
}
}