Functional level generation + moving the submarine

This commit is contained in:
Regalis
2015-06-26 23:05:51 +03:00
parent bda9b31cbe
commit 9237a9efe2
48 changed files with 1629 additions and 750 deletions
+1 -1
View File
@@ -140,7 +140,7 @@ namespace Subsurface
null, null, null, null,
cam.Transform);
Map.Draw(spriteBatch, true);
Submarine.Draw(spriteBatch, true);
spriteBatch.End();
+1 -1
View File
@@ -229,7 +229,7 @@ namespace Subsurface
graphics.Clear(new Color(0.051f, 0.149f, 0.271f, 1.0f));
Map.Draw(spriteBatch, true);
Submarine.Draw(spriteBatch, true);
if (!characterMode)
{
+22 -16
View File
@@ -57,16 +57,16 @@ namespace Subsurface
AmbientSoundManager.Update();
//Vector2 targetMovement = Vector2.Zero;
//if (PlayerInput.KeyDown(Keys.I)) targetMovement.Y += 1.0f;
//if (PlayerInput.KeyDown(Keys.K)) targetMovement.Y -= 1.0f;
//if (PlayerInput.KeyDown(Keys.J)) targetMovement.X -= 1.0f;
//if (PlayerInput.KeyDown(Keys.L)) targetMovement.X += 1.0f;
if (Game1.GameSession.Level!=null)
{
Vector2 targetMovement = Vector2.Zero;
if (PlayerInput.KeyDown(Keys.I)) targetMovement.Y += 1.0f;
if (PlayerInput.KeyDown(Keys.K)) targetMovement.Y -= 1.0f;
if (PlayerInput.KeyDown(Keys.J)) targetMovement.X -= 1.0f;
if (PlayerInput.KeyDown(Keys.L)) targetMovement.X += 1.0f;
//foreach (MapEntity e in Structure.mapEntityList)
//{
// e.Move(targetMovement);
//}
Game1.GameSession.Submarine.Move(targetMovement*1000.0f, (float)deltaTime);
}
if (Game1.GameSession!=null) Game1.GameSession.Update((float)deltaTime);
//EventManager.Update(gameTime);
@@ -170,8 +170,8 @@ namespace Subsurface
if (y<0)
{
backgroundTop.SourceRect = new Rectangle(x, y, 1024, 1024);
backgroundTop.DrawTiled(spriteBatch, Vector2.Zero, new Vector2(Game1.GraphicsWidth, Math.Min(1024 - y, Game1.GraphicsHeight)),
backgroundTop.SourceRect = new Rectangle(x, y, 1024, Math.Min(-y,1024));
backgroundTop.DrawTiled(spriteBatch, Vector2.Zero, new Vector2(Game1.GraphicsWidth, Math.Min(-y, Game1.GraphicsHeight)),
Vector2.Zero, Color.White);
}
}
@@ -183,10 +183,8 @@ namespace Subsurface
BlendState.AlphaBlend,
null, null, null, null,
cam.Transform);
if (Game1.Level!=null) Game1.Level.Render(spriteBatch);
Map.DrawBack(spriteBatch);
Submarine.DrawBack(spriteBatch);
foreach (Character c in Character.characterList) c.Draw(spriteBatch);
@@ -257,10 +255,18 @@ namespace Subsurface
null, null, null, null,
cam.Transform);
Map.DrawFront(spriteBatch);
Submarine.DrawFront(spriteBatch);
spriteBatch.End();
if (Game1.GameSession != null && Game1.GameSession.Level != null)
{
Game1.GameSession.Level.Render(graphics, cam);
Game1.GameSession.Level.SetObserverPosition(cam.WorldViewCenter);
}
if (Game1.Level != null) Game1.Level.Render(graphics, cam);
LightManager.DrawFow(graphics,cam);
}
}
+62 -43
View File
@@ -9,10 +9,12 @@ namespace Subsurface
{
class LobbyScreen : Screen
{
enum PanelTab { Crew = 0, Map = 1, Hire = 2 }
GUIFrame leftPanel;
GUIFrame[] rightPanel;
GUIFrame shiftPanel;
GUIButton startButton;
int selectedRightPanel;
@@ -26,6 +28,8 @@ namespace Subsurface
Character previewCharacter;
Level selectedLevel;
public LobbyScreen()
{
Rectangle panelRect = new Rectangle(
@@ -44,62 +48,55 @@ namespace Subsurface
"", Color.Transparent, Color.White, Alignment.Left, leftPanel);
moneyText.TextGetter = GetMoney;
GUIButton button = new GUIButton(new Rectangle(0, 60, 100, 30), "Crew", GUI.style, Alignment.CenterX, leftPanel);
button.UserData = 0;
GUIButton button = new GUIButton(new Rectangle(0, 60, 100, 30), "Map", GUI.style, Alignment.Left, leftPanel);
button.UserData = PanelTab.Map;
button.OnClicked = SelectRightPanel;
button = new GUIButton(new Rectangle(0, 100, 100, 30), "Hire", GUI.style, Alignment.CenterX, leftPanel);
button.UserData = 1;
button = new GUIButton(new Rectangle(0, 100, 100, 30), "Crew", GUI.style, Alignment.Left, leftPanel);
button.UserData = PanelTab.Crew;
button.OnClicked = SelectRightPanel;
//--------------------------------------
button = new GUIButton(new Rectangle(0, 140, 100, 30), "Hire", GUI.style, Alignment.Left, leftPanel);
button.UserData = PanelTab.Hire;
button.OnClicked = SelectRightPanel;
//---------------------------------------------------------------
//---------------------------------------------------------------
panelRect = new Rectangle(
panelRect.X + panelRect.Width + (int)(GUI.style.largePadding.X),
panelRect.Y,
(int)GUI.style.largePadding.Y,
Game1.GraphicsWidth - panelRect.Width - (int)(GUI.style.largePadding.X * 3.0f),
(int)(Game1.GraphicsHeight * 0.3f) - (int)(GUI.style.largePadding.Y * 1.5f));
Game1.GraphicsHeight - (int)(GUI.style.largePadding.Y * 2));
shiftPanel = new GUIFrame(panelRect, GUI.style.backGroundColor);
shiftPanel.Padding = GUI.style.smallPadding;
rightPanel = new GUIFrame[3];
GUITextBlock dayText = new GUITextBlock(new Rectangle(0, 0, 200, 25),
"", Color.Transparent, Color.White, Alignment.Left, shiftPanel);
dayText.TextGetter = GetDay;
rightPanel[(int)PanelTab.Crew] = new GUIFrame(panelRect, GUI.style.backGroundColor);
rightPanel[(int)PanelTab.Crew].Padding = GUI.style.smallPadding;
GUIProgressBar progressBar = new GUIProgressBar(new Rectangle(0, 30, 200, 20), Color.Green, 0.0f, shiftPanel);
progressBar.ProgressGetter = GetWeekProgress;
new GUITextBlock(new Rectangle(0, 0, 200, 25), "Crew:", Color.Transparent, Color.White, Alignment.Left, rightPanel[(int)PanelTab.Crew]);
button = new GUIButton(new Rectangle(0,0,100,30), "Start", GUI.style,
(Alignment.Right | Alignment.Bottom), shiftPanel);
button.OnClicked = StartShift;
//---------------------------------------------------------------
//---------------------------------------------------------------
rightPanel = new GUIFrame[2];
panelRect = new Rectangle(
panelRect.X,
panelRect.Y + panelRect.Height + (int)(GUI.style.largePadding.Y),
panelRect.Width,
(int)(Game1.GraphicsHeight * 0.7f) - (int)(GUI.style.largePadding.Y * 1.5f));
rightPanel[0] = new GUIFrame(panelRect, GUI.style.backGroundColor);
rightPanel[0].Padding = GUI.style.smallPadding;
new GUITextBlock(new Rectangle(0, 0, 200, 25), "Crew:", Color.Transparent, Color.White, Alignment.Left, rightPanel[0]);
characterList = new GUIListBox(new Rectangle(0, 30, 300, 0), Color.White, rightPanel[0]);
characterList = new GUIListBox(new Rectangle(0, 30, 300, 0), Color.White, rightPanel[(int)PanelTab.Crew]);
characterList.OnSelected = SelectCharacter;
//---------------------------------------
rightPanel[1] = new GUIFrame(panelRect, GUI.style.backGroundColor);
rightPanel[1].Padding = GUI.style.smallPadding;
rightPanel[(int)PanelTab.Map] = new GUIFrame(panelRect, GUI.style.backGroundColor);
rightPanel[(int)PanelTab.Map].Padding = GUI.style.smallPadding;
hireList = new GUIListBox(new Rectangle(0, 30, 300, 0), Color.White, Alignment.Left, rightPanel[1]);
startButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", GUI.style,
Alignment.BottomRight, rightPanel[(int)PanelTab.Map]);
startButton.OnClicked = StartShift;
startButton.Enabled = false;
//---------------------------------------
rightPanel[(int)PanelTab.Hire] = new GUIFrame(panelRect, GUI.style.backGroundColor);
rightPanel[(int)PanelTab.Hire].Padding = GUI.style.smallPadding;
hireList = new GUIListBox(new Rectangle(0, 30, 300, 0), Color.White, Alignment.Left, rightPanel[(int)PanelTab.Hire]);
hireList.OnSelected = HireCharacter;
}
@@ -168,7 +165,22 @@ namespace Subsurface
previewCharacter.animController.UpdateAnim((float)Physics.step);
Game1.world.Step((float)Physics.step);
}
}
public void SelectLocation(Location location, LocationConnection connection)
{
GUIComponent locationPanel = rightPanel[(int)PanelTab.Map].GetChild("selectedlocation");
if (locationPanel != null) rightPanel[(int)PanelTab.Map].RemoveChild(locationPanel);
locationPanel = new GUIFrame(new Rectangle(0, 0, rightPanel[(int)PanelTab.Map].Rect.Width / 2 - 40, 190), Color.Transparent, rightPanel[(int)PanelTab.Map]);
locationPanel.UserData = "selectedlocation";
new GUITextBlock(new Rectangle(0,0,100,20), location.Name, Color.Transparent, Color.White, Alignment.TopLeft, locationPanel);
startButton.Enabled = true;
selectedLevel = connection.Level;
}
private void UpdateCharacterLists()
@@ -220,7 +232,7 @@ namespace Subsurface
leftPanel.Update((float)deltaTime);
rightPanel[selectedRightPanel].Update((float)deltaTime);
shiftPanel.Update((float)deltaTime);
//shiftPanel.Update((float)deltaTime);
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
@@ -239,10 +251,17 @@ namespace Subsurface
spriteBatch.Begin();
leftPanel.Draw(spriteBatch);
shiftPanel.Draw(spriteBatch);
rightPanel[selectedRightPanel].Draw(spriteBatch);
if (selectedRightPanel == (int)PanelTab.Map)
{
Game1.GameSession.map.Draw(spriteBatch, new Rectangle(
rightPanel[selectedRightPanel].Rect.Right - 20 - 400,
rightPanel[selectedRightPanel].Rect.Y + 20,
400, 400));
}
GUI.Draw((float)deltaTime, spriteBatch, null);
spriteBatch.End();
@@ -352,7 +371,7 @@ namespace Subsurface
private bool StartShift(GUIButton button, object selection)
{
Game1.GameSession.StartShift(TimeSpan.Zero);
Game1.GameSession.StartShift(TimeSpan.Zero, selectedLevel);
Game1.GameScreen.Select();
return true;
+3 -3
View File
@@ -64,7 +64,7 @@ namespace Subsurface
new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected map:", Color.Transparent, Color.Black, Alignment.Left, menuTabs[(int)Tabs.NewGame]);
mapList = new GUIListBox(new Rectangle(0, 60, 200, 400), Color.White, menuTabs[(int)Tabs.NewGame]);
foreach (Map map in Map.SavedMaps)
foreach (Submarine map in Submarine.SavedSubmarines)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
@@ -76,7 +76,7 @@ namespace Subsurface
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = map;
}
if (Map.SavedMaps.Count > 0) mapList.Select(Map.SavedMaps[0]);
if (Submarine.SavedSubmarines.Count > 0) mapList.Select(Submarine.SavedSubmarines[0]);
button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", GUI.style, Alignment.Right | Alignment.Bottom, menuTabs[(int)Tabs.NewGame]);
@@ -173,7 +173,7 @@ namespace Subsurface
private bool StartGame(GUIButton button, object obj)
{
Map selectedMap = mapList.SelectedData as Map;
Submarine selectedMap = mapList.SelectedData as Submarine;
if (selectedMap == null) return false;
Game1.GameSession = new GameSession(selectedMap, GameModePreset.list.Find(gm => gm.Name == "Single Player"));
+15 -15
View File
@@ -30,9 +30,9 @@ namespace Subsurface
public bool isServer;
public Map SelectedMap
public Submarine SelectedMap
{
get { return mapList.SelectedData as Map; }
get { return mapList.SelectedData as Submarine; }
}
@@ -135,9 +135,9 @@ namespace Subsurface
mapList.OnSelected = SelectMap;
mapList.Enabled = (Game1.Server!=null);
if (Map.SavedMaps.Count>0)
if (Submarine.SavedSubmarines.Count>0)
{
foreach (Map map in Map.SavedMaps)
foreach (Submarine map in Submarine.SavedSubmarines)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
@@ -245,10 +245,10 @@ namespace Subsurface
{
if (Game1.Server != null) Game1.Server.UpdateNetLobby(obj);
Map map = (Map)obj;
Submarine map = (Submarine)obj;
//map already loaded
if (Map.Loaded!=null && map.FilePath == Map.Loaded.FilePath) return true;
if (Submarine.Loaded!=null && map.FilePath == Submarine.Loaded.FilePath) return true;
map.Load();
@@ -281,13 +281,13 @@ namespace Subsurface
Game1.GameScreen.Cam.MoveCamera((float)deltaTime);
Vector2 pos = new Vector2(
Map.Borders.X + Map.Borders.Width / 2,
Map.Borders.Y - Map.Borders.Height / 2);
Submarine.Borders.X + Submarine.Borders.Width / 2,
Submarine.Borders.Y - Submarine.Borders.Height / 2);
camAngle += (float)deltaTime / 10.0f;
Vector2 offset = (new Vector2(
(float)Math.Cos(camAngle) * (Map.Borders.Width / 2.0f),
(float)Math.Sin(camAngle) * (Map.Borders.Height / 2.0f)));
(float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f),
(float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f)));
pos += offset * 0.8f;
@@ -466,7 +466,7 @@ namespace Subsurface
public void WriteData(NetOutgoingMessage msg)
{
Map selectedMap = mapList.SelectedData as Map;
Submarine selectedMap = mapList.SelectedData as Submarine;
if (selectedMap==null)
{
@@ -476,7 +476,7 @@ namespace Subsurface
else
{
msg.Write(Path.GetFileName(selectedMap.Name));
msg.Write(selectedMap.MapHash.MD5Hash);
msg.Write(selectedMap.Hash.MD5Hash);
}
msg.Write(modeList.SelectedIndex);
@@ -486,7 +486,7 @@ namespace Subsurface
public bool TrySelectMap(string mapName, string md5Hash)
{
Map map = Map.SavedMaps.Find(m => m.Name == mapName);
Submarine map = Submarine.SavedSubmarines.Find(m => m.Name == mapName);
if (map==null)
{
DebugConsole.ThrowError("The map ''" + mapName + "'' has been selected by the server.");
@@ -495,10 +495,10 @@ namespace Subsurface
}
else
{
if (map.MapHash.MD5Hash!=md5Hash)
if (map.Hash.MD5Hash!=md5Hash)
{
DebugConsole.ThrowError("Your version of the map file ''"+map.Name+"'' doesn't match the server's version!");
DebugConsole.ThrowError("Your file: "+map.Name+"(MD5 hash : "+map.MapHash.MD5Hash+")");
DebugConsole.ThrowError("Your file: "+map.Name+"(MD5 hash : "+map.Hash.MD5Hash+")");
DebugConsole.ThrowError("Server's file: " + mapName + "(MD5 hash : " + md5Hash + ")");
return false;
}