Removing the obstruction element without flickering, better looking (& working) radar

This commit is contained in:
Regalis
2015-11-01 22:10:31 +02:00
parent 73bde75c2e
commit e4a048a54a
13 changed files with 167 additions and 57 deletions
+15 -7
View File
@@ -152,9 +152,17 @@ namespace Barotrauma
set { lowPassMultiplier = MathHelper.Clamp(value, 0.0f, 1.0f); } set { lowPassMultiplier = MathHelper.Clamp(value, 0.0f, 1.0f); }
} }
private float obstructVisionAmount;
public bool ObstructVision public bool ObstructVision
{ {
get; set; get
{
return obstructVisionAmount > 0.5f;
}
set
{
obstructVisionAmount = 1.0f;
}
} }
public float SoundRange public float SoundRange
@@ -831,6 +839,8 @@ namespace Barotrauma
{ {
if (!Enabled) return; if (!Enabled) return;
obstructVisionAmount = Math.Max(obstructVisionAmount - deltaTime, 0.0f);
AnimController.SimplePhysicsEnabled = (Character.controlled != this && Vector2.Distance(cam.WorldViewCenter, Position) > 5000.0f); AnimController.SimplePhysicsEnabled = (Character.controlled != this && Vector2.Distance(cam.WorldViewCenter, Position) > 5000.0f);
if (isDead) return; if (isDead) return;
@@ -839,12 +849,11 @@ namespace Barotrauma
{ {
bool protectedFromPressure = PressureProtection > 0.0f; bool protectedFromPressure = PressureProtection > 0.0f;
if (Submarine.Loaded!=null && Level.Loaded !=null) if (Submarine.Loaded!=null && Level.Loaded !=null)
{ {
protectedFromPressure = protectedFromPressure && (Position-Level.Loaded.Position).Y > SubmarineBody.DamageDepth; protectedFromPressure = protectedFromPressure && (Position-Level.Loaded.Position).Y > SubmarineBody.DamageDepth;
} }
if (!protectedFromPressure && if (!protectedFromPressure &&
(AnimController.CurrentHull == null || AnimController.CurrentHull.LethalPressure >= 100.0f)) (AnimController.CurrentHull == null || AnimController.CurrentHull.LethalPressure >= 100.0f))
{ {
@@ -865,7 +874,6 @@ namespace Barotrauma
if (aiTarget != null) aiTarget.SoundRange = 0.0f; if (aiTarget != null) aiTarget.SoundRange = 0.0f;
lowPassMultiplier = MathHelper.Lerp(lowPassMultiplier, 1.0f, 0.1f); lowPassMultiplier = MathHelper.Lerp(lowPassMultiplier, 1.0f, 0.1f);
ObstructVision = false;
if (needsAir) if (needsAir)
{ {
+6 -2
View File
@@ -87,8 +87,12 @@ namespace Barotrauma
DrawChildren(spriteBatch); DrawChildren(spriteBatch);
GUI.DrawRectangle(spriteBatch, new Rectangle(box.Rect.X + 2, box.Rect.Y + 2, box.Rect.Width - 4, box.Rect.Height - 4), GUI.DrawRectangle(spriteBatch, new Rectangle(box.Rect.X + 1, box.Rect.Y + 1, box.Rect.Width - 2, box.Rect.Height - 2),
selected ? Color.Green * 0.8f : Color.Black, true); box.State == ComponentState.Hover ? new Color(50,50,50,255) : Color.Black, true);
if (!selected) return;
GUI.DrawRectangle(spriteBatch, new Rectangle(box.Rect.X + 5, box.Rect.Y + 5, box.Rect.Width - 10, box.Rect.Height - 10),
Color.Green * 0.8f, true);
} }
} }
@@ -28,7 +28,7 @@ namespace Barotrauma.Items.Components
} }
} }
[HasDefaultValue(100.0f, false)] [HasDefaultValue(80.0f, false)]
public float MaxFlow public float MaxFlow
{ {
get { return maxFlow; } get { return maxFlow; }
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Xml.Linq; using System.Xml.Linq;
using Voronoi2;
namespace Barotrauma.Items.Components namespace Barotrauma.Items.Components
{ {
@@ -27,6 +28,8 @@ namespace Barotrauma.Items.Components
public Radar(Item item, XElement element) public Radar(Item item, XElement element)
: base(item, element) : base(item, element)
{ {
radarBlips = new List<RadarBlip>();
foreach (XElement subElement in element.Elements()) foreach (XElement subElement in element.Elements())
{ {
switch (subElement.Name.ToString().ToLower()) switch (subElement.Name.ToString().ToLower())
@@ -47,6 +50,12 @@ namespace Barotrauma.Items.Components
{ {
base.Update(deltaTime, cam); base.Update(deltaTime, cam);
for (int i = radarBlips.Count - 1; i >= 0; i-- )
{
radarBlips[i].FadeTimer -= deltaTime*0.5f;
if (radarBlips[i].FadeTimer <= 0.0f) radarBlips.RemoveAt(i);
}
if (voltage >= minVoltage) if (voltage >= minVoltage)
{ {
pingState = (pingState + deltaTime * 0.5f); pingState = (pingState + deltaTime * 0.5f);
@@ -77,7 +86,7 @@ namespace Barotrauma.Items.Components
if (voltage < minVoltage) return; if (voltage < minVoltage) return;
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 20, y + 20, 200, 30), "Activate Sonar")) if (GUI.DrawButton(spriteBatch, new Rectangle(x + 0, y + 0, 150, 30), "Activate Sonar"))
{ {
IsActive = !IsActive; IsActive = !IsActive;
item.NewComponentEvent(this, true, false); item.NewComponentEvent(this, true, false);
@@ -89,6 +98,9 @@ namespace Barotrauma.Items.Components
//voltage = 0.0f; //voltage = 0.0f;
} }
private List<RadarBlip> radarBlips;
private float prevPingRadius;
private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect) private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect)
{ {
@@ -98,10 +110,15 @@ namespace Barotrauma.Items.Components
if (!IsActive) return; if (!IsActive) return;
if (pingCircle!=null)
{ //if (pingCircle!=null)
//{
float pingRadius = (rect.Width / 2) * pingState;
pingCircle.Draw(spriteBatch, center, Color.White * (1.0f-pingState), 0.0f, (rect.Width/pingCircle.size.X)*pingState); pingCircle.Draw(spriteBatch, center, Color.White * (1.0f-pingState), 0.0f, (rect.Width/pingCircle.size.X)*pingState);
}
//}
float radius = rect.Width / 2.0f; float radius = rect.Width / 2.0f;
@@ -110,17 +127,41 @@ namespace Barotrauma.Items.Components
if (Level.Loaded != null) if (Level.Loaded != null)
{ {
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.Position, 7); List<VoronoiCell> cells = Level.Loaded.GetCells(-Level.Loaded.Position, 7);
Vector2 offset = Vector2.Zero; Vector2 offset = Vector2.Zero;
for (int i = 0; i < edges.Count; i++) foreach (VoronoiCell cell in cells)
{ {
if ((edges[i][0] * displayScale).Length() > radius) continue;
if ((edges[i][1] * displayScale).Length() > radius) continue;
GUI.DrawLine(spriteBatch, foreach (GraphEdge edge in cell.edges)
center + (edges[i][0] - offset) * displayScale, {
center + (edges[i][1] - offset) * displayScale, Color.White); //if (!edge.isSolid) continue;
float cellDot = Vector2.Dot(cell.Center + Level.Loaded.Position, (edge.point1 + edge.point2) / 2.0f - cell.Center);
if (cellDot > 0) continue;
Vector2 point1 = (edge.point1 + Level.Loaded.Position);
Vector2 point2 = (edge.point2 + Level.Loaded.Position);
for (float x=0; x<(point1-point2).Length(); x+=Rand.Range(600.0f, 800.0f))
{
Vector2 point = point1 + Vector2.Normalize(point2 - point1) * x;
float pointDist = point.Length() * displayScale;
if (pointDist > radius) continue;
if (pointDist > prevPingRadius && pointDist < pingRadius) {
for (float z = 0; z<radius-pointDist;z+=10.0f)
{
var blip = new RadarBlip(
point + Rand.Vector(150.0f) - Level.Loaded.Position + Vector2.Normalize(point) * z / displayScale,
Rand.Range(0.8f, 1.0f) / Math.Max(1.0f, z / 10.0f));
radarBlips.Add(blip);
}
}
}
}
} }
for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++) for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++)
@@ -130,30 +171,64 @@ namespace Barotrauma.Items.Components
Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * simScale; Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * simScale;
end.Y = -end.Y; end.Y = -end.Y;
GUI.DrawLine(spriteBatch, center + start, center + end, Color.White); GUI.DrawLine(spriteBatch, center + start, center + end, Color.Green);
} }
} }
foreach (Character c in Character.CharacterList) foreach (Character c in Character.CharacterList)
{ {
if (c.AnimController.CurrentHull != null) continue; if (c.AnimController.CurrentHull != null) continue;
Vector2 pos = c.Position * displayScale; foreach (Limb limb in c.AnimController.Limbs)
if (c.SimPosition == Vector2.Zero || pos.Length() > radius) continue; {
Vector2 pos = limb.Position;
float pointDist = pos.Length() * displayScale;
if (limb.SimPosition == Vector2.Zero || pointDist > radius) continue;
if (pointDist > radius) continue;
if (pointDist > prevPingRadius && pointDist < pingRadius)
{
var blip = new RadarBlip(pos - Level.Loaded.Position, 1.0f);
radarBlips.Add(blip);
}
}
int width = (int)MathHelper.Clamp(c.Mass / 20, 1, 10); //int width = (int)MathHelper.Clamp(c.Mass / 20, 1, 10);
pos.Y = -pos.Y; //pos.Y = -pos.Y;
pos += center; //pos += center;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X - width / 2, (int)pos.Y - width / 2, width, width), Color.White, true); //GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X - width / 2, (int)pos.Y - width / 2, width, width), Color.White, true);
} }
foreach (RadarBlip radarBlip in radarBlips)
{
Vector2 pos = (radarBlip.Position + Level.Loaded.Position) * displayScale;
pos.Y = -pos.Y;
//spriteBatch.Draw(radarBlipSprite, center+pos,
// new Rectangle((int)(radarBlip.SpriteIndex % 4 * 32), (int)(Math.Floor(radarBlip.SpriteIndex / 4.0f) * 32), 32, 32),
// Color.White * radarBlip.FadeTimer, 0.0f, new Vector2(16.0f, 16.0f), 0.5f, SpriteEffects.None, 0.0f);
pos.X = MathUtils.Round(pos.X, 4);
pos.Y = MathUtils.Round(pos.Y, 2);
GUI.DrawRectangle(spriteBatch, center+pos, new Vector2(4, 2), Color.Green * radarBlip.FadeTimer, true);
}
prevPingRadius = pingRadius;
if (screenOverlay!=null) if (screenOverlay!=null)
{ {
screenOverlay.Draw(spriteBatch, center, 0.0f, rect.Width/screenOverlay.size.X); screenOverlay.Draw(spriteBatch, center, 0.0f, rect.Width/screenOverlay.size.X);
} }
//prevPingRadius = pingRadius;
if (GameMain.GameSession == null) return; if (GameMain.GameSession == null) return;
@@ -239,6 +314,17 @@ namespace Barotrauma.Items.Components
return; return;
} }
} }
}
class RadarBlip
{
public float FadeTimer;
public Vector2 Position;
public RadarBlip(Vector2 pos, float fadeTimer)
{
Position = pos;
FadeTimer = fadeTimer;
}
} }
} }
@@ -119,7 +119,7 @@ namespace Barotrauma.Items.Components
GuiFrame.Draw(spriteBatch); GuiFrame.Draw(spriteBatch);
Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40); Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40);
GUI.DrawRectangle(spriteBatch, velRect, Color.White, false); //GUI.DrawRectangle(spriteBatch, velRect, Color.White, false);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + width - 150, y + height - 30, 150, 30), "Autopilot")) if (GUI.DrawButton(spriteBatch, new Rectangle(x + width - 150, y + height - 30, 150, 30), "Autopilot"))
{ {
+14 -1
View File
@@ -890,6 +890,19 @@ namespace Barotrauma
} }
} }
for (int side = 0; side < 2; side++)
{
for (int n = 0; n < 2; n++)
{
if (Vector2.Distance(wrappingWalls[side, n].MidPos, pos) > WrappingWall.WallWidth) continue;
foreach (VoronoiCell cell in wrappingWalls[side, n].Cells)
{
cells.Add(cell);
}
}
}
return cells; return cells;
} }
@@ -921,7 +934,7 @@ namespace Barotrauma
Vector2 end = cell.edges[i].point2 + Position; Vector2 end = cell.edges[i].point2 + Position;
end.Y = -end.Y; end.Y = -end.Y;
edges.Add(new Vector2[] { start, end }); edges.Add(new Vector2[] { start, end });
//GUI.DrawLine(spriteBatch, start, end, (cell.body != null && cell.body.Enabled) ? Color.Green : Color.Red); //GUI.DrawLine(spriteBatch, start, end, (cell.body != null && cell.body.Enabled) ? Color.Green : Color.Red);
} }
+4 -2
View File
@@ -79,6 +79,8 @@ namespace Barotrauma.Lights
spriteBatch.Begin(SpriteSortMode.Immediate, CustomBlendStates.Multiplicative); spriteBatch.Begin(SpriteSortMode.Immediate, CustomBlendStates.Multiplicative);
spriteBatch.Draw(losTexture, Vector2.Zero); spriteBatch.Draw(losTexture, Vector2.Zero);
spriteBatch.End(); spriteBatch.End();
ObstructVision = false;
} }
public void OnMapLoaded() public void OnMapLoaded()
@@ -164,8 +166,8 @@ namespace Barotrauma.Lights
Vector2 diff = lookAtPosition - ViewPos; Vector2 diff = lookAtPosition - ViewPos;
diff.Y = -diff.Y; diff.Y = -diff.Y;
float rotation = MathUtils.VectorToAngle(diff); float rotation = MathUtils.VectorToAngle(diff);
Vector2 scale = new Vector2(3.0f, 1.0f); Vector2 scale = new Vector2(MathHelper.Clamp(diff.Length()/256.0f, 2.0f, 5.0f), 2.0f);
spriteBatch.Draw(LightSource.LightTexture, new Vector2(ViewPos.X, -ViewPos.Y), null, Color.White, rotation, spriteBatch.Draw(LightSource.LightTexture, new Vector2(ViewPos.X, -ViewPos.Y), null, Color.White, rotation,
new Vector2(LightSource.LightTexture.Width*0.2f, LightSource.LightTexture.Height/2), scale, SpriteEffects.None, 0.0f); new Vector2(LightSource.LightTexture.Width*0.2f, LightSource.LightTexture.Height/2), scale, SpriteEffects.None, 0.0f);
+1 -1
View File
@@ -9,7 +9,7 @@ namespace Barotrauma.Networking
{ {
class BanList class BanList
{ {
const string SavePath = "Data/bannedplayers.xml"; const string SavePath = "Data/bannedplayers.txt";
private List<BannedPlayer> bannedPlayers; private List<BannedPlayer> bannedPlayers;
+6 -15
View File
@@ -10,32 +10,23 @@ namespace Barotrauma.Networking
{ {
Unknown, Unknown,
Login, Login, LoggedIn, LogOut,
LoggedIn,
LogOut,
PlayerJoined, PlayerJoined, PlayerLeft, KickedOut,
PlayerLeft,
KickedOut,
StartGame, StartGame, EndGame,
EndGame,
CharacterInfo, CharacterInfo,
Chatmessage, Chatmessage, UpdateNetLobby,
UpdateNetLobby,
NetworkEvent, NetworkEvent,
Traitor, Traitor,
Vote, Vote, VoteStatus,
VoteStatus,
ResendRequest, ResendRequest, ReliableMessage, LatestMessageID
ReliableMessage,
LatestMessageID
} }
enum VoteType enum VoteType
+10 -9
View File
@@ -67,24 +67,24 @@ namespace Barotrauma
//new GUITextBlock(new Rectangle(0, 0, 200, 25), //new GUITextBlock(new Rectangle(0, 0, 200, 25),
// save, Color.Transparent, Color.White, Alignment.Left, GUI.Style, leftPanel); // save, Color.Transparent, Color.White, Alignment.Left, GUI.Style, leftPanel);
GUITextBlock moneyText = new GUITextBlock(new Rectangle(0, 30, 200, 25), GUITextBlock moneyText = new GUITextBlock(new Rectangle(0, 30, 0, 25),
"", Color.Transparent, Color.White, Alignment.Left, GUI.Style, leftPanel); "", Color.Transparent, Color.White, Alignment.TopCenter, GUI.Style, leftPanel);
moneyText.TextGetter = GetMoney; moneyText.TextGetter = GetMoney;
GUIButton button = new GUIButton(new Rectangle(0, 70, 100, 30), "Map", null, Alignment.Left, GUI.Style, leftPanel); GUIButton button = new GUIButton(new Rectangle(0, 70, 100, 30), "Map", null, Alignment.TopCenter, GUI.Style, leftPanel);
button.UserData = PanelTab.Map; button.UserData = PanelTab.Map;
button.OnClicked = SelectRightPanel; button.OnClicked = SelectRightPanel;
SelectRightPanel(button, button.UserData); SelectRightPanel(button, button.UserData);
button = new GUIButton(new Rectangle(0, 110, 100, 30), "Crew", null, Alignment.Left, GUI.Style, leftPanel); button = new GUIButton(new Rectangle(0, 110, 100, 30), "Crew", null, Alignment.TopCenter, GUI.Style, leftPanel);
button.UserData = PanelTab.Crew; button.UserData = PanelTab.Crew;
button.OnClicked = SelectRightPanel; button.OnClicked = SelectRightPanel;
button = new GUIButton(new Rectangle(0, 150, 100, 30), "Hire", null, Alignment.Left, GUI.Style, leftPanel); button = new GUIButton(new Rectangle(0, 150, 100, 30), "Hire", null, Alignment.TopCenter, GUI.Style, leftPanel);
button.UserData = PanelTab.CurrentLocation; button.UserData = PanelTab.CurrentLocation;
button.OnClicked = SelectRightPanel; button.OnClicked = SelectRightPanel;
button = new GUIButton(new Rectangle(0, 190, 100, 30), "Store", null, Alignment.Left, GUI.Style, leftPanel); button = new GUIButton(new Rectangle(0, 190, 100, 30), "Store", null, Alignment.TopCenter, GUI.Style, leftPanel);
button.UserData = PanelTab.Store; button.UserData = PanelTab.Store;
button.OnClicked = SelectRightPanel; button.OnClicked = SelectRightPanel;
@@ -454,9 +454,10 @@ namespace Barotrauma
private bool StartShift(GUIButton button, object selection) private bool StartShift(GUIButton button, object selection)
{ {
//GameMain.ShowLoading(ShiftLoading()); GameMain.ShowLoading(ShiftLoading());
GameMain.GameSession.StartShift(selectedLevel, false);
GameMain.GameScreen.Select(); //GameMain.GameSession.StartShift(selectedLevel, false);
//GameMain.GameScreen.Select();
return true; return true;
} }
@@ -699,6 +699,7 @@ namespace Barotrauma
if (GameMain.NetworkMember.CharacterInfo == null) return true; if (GameMain.NetworkMember.CharacterInfo == null) return true;
GameMain.NetworkMember.CharacterInfo.HeadSpriteId += dir; GameMain.NetworkMember.CharacterInfo.HeadSpriteId += dir;
if (GameMain.Client != null) GameMain.Client.SendCharacterData();
UpdatePreviewPlayer(GameMain.NetworkMember.CharacterInfo); UpdatePreviewPlayer(GameMain.NetworkMember.CharacterInfo);
+4
View File
@@ -15,6 +15,10 @@ Submarine:
Creatures: Creatures:
- a new enemy that only spawns deep below the level - a new enemy that only spawns deep below the level
Items:
- diving suits and mask now obstruct vision when worn
- nicer looking sonar monitor
Misc: Misc:
- the levels aren't just enclosed tunnels anymore and it's possible to dive much deeper - the levels aren't just enclosed tunnels anymore and it's possible to dive much deeper
- settings menu - settings menu
Binary file not shown.