Skip to content

Commit

Permalink
???
Browse files Browse the repository at this point in the history
  • Loading branch information
susch19 committed Jan 8, 2017
1 parent 6e377e7 commit 3726902
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion GameJam2017/NoobFight.Contract/Map/IActiveTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IActiveTile

void OnAttack(IWorldManipulator manipulator, IEntity entity);

void OnClick(IWorldManipulator manipulator, IEntity entity, Vector2 clickPosition);
void OnClick(IWorldManipulator manipulator, IEntity entity);

void OnCollision(IWorldManipulator manipulator, IEntity entity);
}
Expand Down
2 changes: 1 addition & 1 deletion GameJam2017/NoobFight.Contract/Simulation/ISimulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface ISimulation

void Update(GameTime gameTime);

IPlayer CreateLocalPlayer(string name, string textureName);
IPlayer CreateLocalPlayer(long id, string name, string textureName);

void InsertPlayer(IPlayer player);

Expand Down
1 change: 1 addition & 0 deletions GameJam2017/NoobFight.Core/Map/Tiles/ActiveTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public virtual void OnClick(IWorldManipulator manipulator, IEntity entity)
{

}

}
}
5 changes: 0 additions & 5 deletions GameJam2017/NoobFight.Core/Map/Tiles/PortalTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,5 @@ public override void OnClick(IWorldManipulator manipulator, IEntity entity)
manipulator.ChangeArea(((IPlayer)entity), this.Property.destinationarea);
}
}

public override void OnClick(IWorldManipulator manipulator, IEntity entity, Vector2 clickPosition)
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override byte[] Serialize()
using (MemoryStream ms = new MemoryStream())
using (BinaryWriter bw = new BinaryWriter(ms))
{
bw.Write(Player.ID);
bw.Write(Player.PlayerID);
bw.Write(DestinationArea);
return ms.ToArray();
}
Expand Down
28 changes: 19 additions & 9 deletions GameJam2017/NoobFight.Core/Simulation/Events/ClickEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace NoobFight.Core.Simulation.Events
public class ClickEvent : WorldEvent
{
private IEntity entity;
private IActiveTile tile;
private Vector2 clickPosition;
private IActiveTile activeTile;
private IPlayer player;

public override WorldEventType EventType => WorldEventType.Click;

Expand All @@ -22,9 +22,25 @@ public ClickEvent()
{

}
public ClickEvent(IPlayer player, IEntity entity)
{
this.player = player;
this.entity = entity;
}

public ClickEvent(IPlayer player, IActiveTile activeTile)
{
this.player = player;
this.activeTile = activeTile;
}

public override void Dispatch(IWorld world, ISimulation simulation)
{
tile.OnClick(world.CreateNewManipulator(), entity, clickPosition);
if (this.activeTile != null)
activeTile.OnClick(world.CreateNewManipulator(), player);

if (this.entity != null)
entity.OnClick(world.CreateNewManipulator(), player);
}

public override byte[] Serialize()
Expand All @@ -40,11 +56,5 @@ public override void Deserialize(byte[] payload)
{
}

public ClickEvent(IActiveTile BlockType, IEntity entity, Vector2 clickPosition)
{
tile = BlockType;
this.entity = entity;
this.clickPosition = clickPosition;
}
}
}
2 changes: 1 addition & 1 deletion GameJam2017/NoobFight.Core/Simulation/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public IWorldManipulator CreateNewManipulator()

public IPlayer FindPlayerById(long playerid)
{
return _players.First(i => i.ID == playerid);
return _players.First(i => i.PlayerID == playerid);
}

public void Resume()
Expand Down
8 changes: 5 additions & 3 deletions GameJam2017/NoobFight.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ static void Main(string[] args)

private static void StartWorld(Client client, StartWorldRequest message)
{
var world = simulation.Worlds.FirstOrDefault(i => i.Players.Count() > 0 && i.Players.Any(p => p.ID == client.ID));
var world = simulation.Worlds.FirstOrDefault(i => i.Players.Count() > 0 && i.Players.Any(p => p.PlayerID == client.ID));

if (world != null)
{
var mapstart = new StartWorldMessage("Hallo");
world.Start(MapGenerator.CreateMap(mapstart.MapName));
var map = new Map(mapstart.MapName);
map.Load();
world.Start(map);

foreach (var player in world.Players.OfType<RemotePlayer>())
{
Expand All @@ -70,7 +72,7 @@ private static void CreateWorld(Client client, CreateWorldRequestMessage message
var world = simulation.CreateNewWorld(message.Mode, message.WorldName);
world.AddEventCallback = SendEvent;

var player = simulation.Players.First(i => i.ID == client.ID);
var player = simulation.Players.First(i => i.PlayerID == client.ID);
world.AddPlayer(player);

var joinmessage = new PlayerJoinResponseMessage(client.ID, player.Name, player.TextureName);
Expand Down
25 changes: 21 additions & 4 deletions GameJam2017/NoobFight/Components/NetworkComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ public NetworkComponent(NoobFight game) : base(game)

}

private void StartWorld(Client client, StartWorldMessage message)
public void StartWorld(Client client, StartWorldMessage message)
{
var map = new Map(message.MapName);
map.Load();
Game.SimulationComponent.World.Start(map);
}
public void StartWorld()
{
client.writeStream(new StartWorldRequest());
}


private void UpdateEntity(Client client, EntityDataUpdateMessage entitydata)
{
Expand Down Expand Up @@ -86,14 +91,14 @@ private void PlayerJoin(Client client, PlayerJoinResponseMessage message)

if (Game.SimulationComponent.Player.Id == message.Id)
{
Game.SimulationComponent.World.Manipulator.AddPlayer(Game.SimulationComponent.Player);
Game.SimulationComponent.World.AddPlayer(Game.SimulationComponent.Player);
Game.ScreenManager.NavigateToScreen(new LobbyScreen(Game.ScreenManager));
return;
}
var player = new RemotePlayer(client, message.Nick, message.TextureName);//TODO: texturename
Game.SimulationComponent.Simulation.InsertPlayer(player);

Game.SimulationComponent.World.Manipulator.AddPlayer(player);
Game.SimulationComponent.World.AddPlayer(player);


}
Expand All @@ -105,7 +110,7 @@ private void ConnectedPlayersResp(Client arg1, ConnectedPlayersResponseMessage m

private void PlayerLoginResponse(Client client, PlayerLoginResponseMessage message)
{
Game.SimulationComponent.Player = Game.SimulationComponent.Simulation.CreateLocalPlayer(Nick, TextureName);
Game.SimulationComponent.Player = Game.SimulationComponent.Simulation.CreateLocalPlayer(message.PlayerId, Nick, TextureName);
client.writeStream(new WorldListRequestMessage());
playerLoaded.Set();
}
Expand Down Expand Up @@ -133,6 +138,18 @@ public void JoinWorld(string worldName)
worldLoaded.Set();
client.writeStream(new PlayerJoinRequestMessage(worldName));
}
public void CreateWorld(string name, GameMode mode)
{
client.writeStream(new CreateWorldRequestMessage(name, mode));
}

private void CreateWorld(Client client, CreateWorldResponseMessage message)
{
if (client.Connected == false)
throw new NotSupportedException();
Game.SimulationComponent.World = Game.SimulationComponent.Simulation.CreateNewWorld(message.Mode, message.WorldName);
worldLoaded.Set();
}

public void Disconnect()
{
Expand Down
4 changes: 2 additions & 2 deletions GameJam2017/NoobFight/Components/SimulationComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public void CreateSinglePlayerSimulation(GameMode gamemode, string texturename,s
{
Simulation = new Simulation(SimulationMode.Single);
World = Simulation.CreateNewWorld(gamemode, "Default World");
Player = Simulation.CreateLocalPlayer( "Hallo", texturename); ;
World.Manipulator.AddPlayer(Player);
Player = Simulation.CreateLocalPlayer(1, "Hallo", texturename); ;
World.AddPlayer(Player);
var map = new Map(mapname);
map.Load();
World.Start(map);
Expand Down

0 comments on commit 3726902

Please sign in to comment.