Skip to content

Commit

Permalink
Merge branch 'main' into Satchel-InputScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
SatchelF authored Apr 7, 2024
2 parents a4dc0d8 + cb24bb3 commit 6af08df
Show file tree
Hide file tree
Showing 26 changed files with 353 additions and 167 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ A game of Snake built using C# in the MonoGame framework, themed around everyone
- [ ] Satchel: Pick head, body, and tail texture for the sandworm
- [ ] Satchel: Keyboard vs. Mouse input menu screen - Satchel
- [ ] Caden: Map generation
- [ ] Max: Spice generation when we spawn
- [ ] Max: Snake Movement with the queue system

## Items to Develop

- [ ] Menu Screen to let player name themselves (probably similar to how control selection screen will work)
- [ ] 3 different animated sprites for the spice - Satchel
- [ ] Menu Screen to let player name themselves (probably similar to how control selection screen will work) - Satchel
- [ ] 3 different animated sprites for the spice
- [ ] Mouse input support on Menu Screens
- [ ] Sound effects on death of worm and when food is eaten - Satchel
- [ ] Collision detection. Know whether we hit spice or another sandworm
Expand All @@ -25,10 +25,13 @@ A game of Snake built using C# in the MonoGame framework, themed around everyone
- [ ] Record players score, kills and highest position. Probably can be added to the `GameScores` object.
- [ ] Game over screen with score, kills, and highest position achieved
- [ ] Particle system for the death of a sandworm
- [ ] Upgrade our movement system to reduce the lag in rotation
- [ ] Game continues to show/play even after the player dies
- [ ] The new player should join in a location that has the least density of other snakes; a safe location
- [ ] Spice generation when we spawn

## Done

- [x] Max: Upgrade our movement system to reduce the lag in rotation
- [x] Max: Add name support for the player
- [x] Max: Setup Snake Movement in the screen
- [x] Max: Decide how to build the snake. Tons of entities? Or one entity with a list of positions?
Expand Down
8 changes: 6 additions & 2 deletions src/Client/ClientMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
using System.Collections.Generic;
using Client.Components;
using Client.Systems;
using Shared.Components;
using Shared.Systems;

Expand Down Expand Up @@ -43,8 +45,10 @@ public ClientMain()
protected override void Initialize()
{
// For Graders: You can change the resolution here
m_graphics.PreferredBackBufferWidth = 1920;
m_graphics.PreferredBackBufferHeight = 1080;
// m_graphics.PreferredBackBufferWidth = 1920;
// m_graphics.PreferredBackBufferHeight = 1080;
m_graphics.PreferredBackBufferWidth = 1000;
m_graphics.PreferredBackBufferHeight = 750;
m_graphics.ApplyChanges();

// Load the controls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
using System.IO.IsolatedStorage;
using System.Runtime.Serialization.Json;
using System.Threading.Tasks;
using Shared.Components;

namespace Shared.Components
namespace Client.Components
{
[DataContract(Name = "Controls")]
public class Controls : Component
Expand Down
28 changes: 17 additions & 11 deletions src/Client/GameModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using Client.Components;
using Shared.Components;
using Shared.Entities;
using Shared.Systems;

namespace Client;

Expand All @@ -19,9 +20,9 @@ public class GameModel
private Systems.Network m_systemNetwork;
private Systems.Camera m_systemCamera;
private Systems.KeyboardInput m_systemKeyboardInput;
private Systems.MouseInput m_systemMouseInput;
private Systems.Interpolation m_systemInterpolation;
private Systems.Renderer m_systemRenderer;
private Systems.Renderer m_renderer;
private Shared.Systems.WormMovement m_systemWormMovement;
private Controls m_controls;
private GraphicsDeviceManager m_graphics;
private SpriteFont m_font;
Expand All @@ -33,7 +34,7 @@ public void update(TimeSpan elapsedTime)
{
m_systemNetwork.update(elapsedTime, MessageQueueClient.instance.getMessages());
m_systemKeyboardInput.update(elapsedTime);
m_systemMouseInput.update(elapsedTime);
m_systemWormMovement.update(elapsedTime);
m_systemInterpolation.update(elapsedTime);
m_systemCamera.update(elapsedTime);
}
Expand All @@ -44,7 +45,7 @@ public void update(TimeSpan elapsedTime)

public void render(TimeSpan elapsedTime, SpriteBatch spriteBatch)
{
m_systemRenderer.render(elapsedTime, spriteBatch);
m_renderer.render(elapsedTime, spriteBatch);
}

/// <summary>
Expand All @@ -59,7 +60,8 @@ public bool initialize(ContentManager contentManager, Controls controls, Graphic
m_entities = new Dictionary<uint, Entity>();
m_systemInterpolation = new Systems.Interpolation();
m_systemCamera = new Systems.Camera(new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
m_systemRenderer = new Systems.Renderer(m_systemCamera, graphics, m_font);
m_renderer = new Systems.Renderer(m_systemCamera, graphics, m_font);
m_systemWormMovement = new Shared.Systems.WormMovement();
m_systemNetwork = new Systems.Network();

m_systemNetwork.registerNewEntityHandler(handleNewEntity);
Expand All @@ -68,7 +70,6 @@ public bool initialize(ContentManager contentManager, Controls controls, Graphic

m_systemKeyboardInput = new Systems.KeyboardInput(new List<Tuple<Shared.Components.Input.Type, Keys>>
{ }, m_controls);
m_systemMouseInput = new Systems.MouseInput(m_controls);

return true;
}
Expand Down Expand Up @@ -137,6 +138,11 @@ private Entity createEntity(Shared.Messages.NewEntity message)
{
entity.add(new ChildId(message.childId));
}

if (message.hasWorm)
{
entity.add(new Worm());
}

if (message.hasName)
{
Expand All @@ -160,8 +166,8 @@ private void addEntity(Entity entity)
// NOTE: Update the systems we use here
m_entities[entity.id] = entity;
m_systemKeyboardInput.add(entity);
m_systemMouseInput.add(entity);
m_systemRenderer.add(entity);
m_systemWormMovement.add(entity);
m_renderer.add(entity);
m_systemNetwork.add(entity);
m_systemInterpolation.add(entity);
m_systemCamera.add(entity);
Expand All @@ -176,9 +182,9 @@ private void removeEntity(uint id)
// NOTE: Update the systems we use here
m_entities.Remove(id);
m_systemKeyboardInput.remove(id);
m_systemMouseInput.remove(id);
m_systemWormMovement.remove(id);
m_systemNetwork.remove(id);
m_systemRenderer.remove(id);
m_renderer.remove(id);
m_systemInterpolation.remove(id);
m_systemCamera.remove(id);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Client/Menu/ControlSettingsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Shared.Components;
using Shared.Entities;
using Shared.Systems;
using Client.Components;
using Client.Systems;

namespace Client.Menu
{
Expand All @@ -21,7 +23,7 @@ public class ControlSettingsView : GameStateView
private ControlStateEnum updatingKey = ControlStateEnum.None;
private bool isUpdatingKey = false;
private Controls m_controls;
private ControlsPersistence _mControlsPersistence = new ControlsPersistence();
private ControlsPersistence m_controlsPersistence = new ControlsPersistence();

public enum ControlStateEnum
{
Expand Down Expand Up @@ -81,7 +83,7 @@ public override void update(GameTime gameTime)
break;
}
// Now we persist any changes
_mControlsPersistence.SaveControls(m_controls);
m_controlsPersistence.SaveControls(m_controls);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Client/Menu/GamePlayView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Xna.Framework.Graphics;
using Client.IO;
using System.Runtime.Serialization;
using Client.Components;
using Microsoft.Xna.Framework.Input;
using Shared.Components;

Expand Down Expand Up @@ -96,7 +97,7 @@ public override void RegisterCommands()

private bool connectToServer()
{
return MessageQueueClient.instance.initialize("localhost", 3050);
return MessageQueueClient.instance.initialize("localhost", 3000);
}

private void escape(GameTime gameTime, float scale)
Expand All @@ -113,7 +114,7 @@ private MenuStateEnum handleSwitchToMainMenu()
try
{
MessageQueueClient.instance.sendMessage(new Shared.Messages.Disconnect());
MessageQueueClient.instance.shutdown();
MessageQueueClient.shutdown();
}
catch (SocketException e)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Client/Menu/MenuKeyboardInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Client.Menu;
using Shared.Components;
using Client.Components;


namespace Client.IO
Expand Down Expand Up @@ -40,7 +41,7 @@ public MenuKeyboardInput()



public void registerCommand(Control control, bool keyPressOnly, IInputDevice.CommandDelegate callback)
public void registerCommand(Client.Components.Control control, bool keyPressOnly, IInputDevice.CommandDelegate callback)
{
// If already registered, remove it!
if (m_commandEntries.ContainsKey(control))
Expand Down
17 changes: 11 additions & 6 deletions src/Client/MessageQueueClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ public bool initialize(string address, ushort port)
/// <summary>
/// Gracefully shutdown the network connection and related activities
/// </summary>
public void shutdown()

public static void shutdown()
{
m_keepRunning = false;
m_eventSendMessages.Set();
m_socketServer.Shutdown(SocketShutdown.Both);
m_socketServer.Disconnect(false);
m_socketServer.Close();
if (m_instance != null)
{
m_instance.m_keepRunning = false;
m_instance.m_eventSendMessages.Set();
m_instance.m_socketServer.Shutdown(SocketShutdown.Both);
m_instance.m_socketServer.Disconnect(false);
m_instance.m_socketServer.Close();
m_instance = null;
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using System;
using System.IO;
using Microsoft.Xna.Framework.Input;
using Shared.Components;
using System.IO.IsolatedStorage;
using System.Runtime.Serialization.Json;
using System.Threading.Tasks;
using Client.Components;


namespace Shared.Systems;
namespace Client.Systems;

public class ControlsPersistence: System
public class ControlsPersistence: Shared.Systems.System
{
// Now we want to make all of these control settings persist across game sessions. We will use the same serialization technique we used for the high scores.
private bool saving = false;
Expand Down
18 changes: 9 additions & 9 deletions src/Client/Systems/KeyboardInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Shared.Components;
using Client.Components;

namespace Client.Systems
{
Expand Down Expand Up @@ -35,23 +36,22 @@ public override void update(TimeSpan elapsedTime)
// We have a dictionary of entities, so we need to iterate through them
foreach (var entity in m_entities)
{
if (!entity.Value.contains<Input>())
{
continue;
}
var inputs = new List<Input.Type>();
if (keyPressed(m_controls.SnakeLeft.key))
if (keyNewlyPressed(m_controls.SnakeLeft.key))
{
inputs.Add(Input.Type.RotateLeft);
Utility.rotateLeft(entity.Value, elapsedTime, m_entities);
Shared.Systems.WormMovement.ninetyLeft(entity.Value, elapsedTime);

}
if (keyPressed(m_controls.SnakeRight.key))
if (keyNewlyPressed(m_controls.SnakeRight.key))
{
inputs.Add(Input.Type.RotateRight);
Utility.rotateRight(entity.Value, elapsedTime, m_entities);

Shared.Systems.WormMovement.ninetyRight(entity.Value, elapsedTime);
}
// Always add thrust
inputs.Add(Input.Type.SnakeUp);
Utility.thrust(entity.Value, elapsedTime, m_entities);

if (inputs.Count > 0)
{
// Assuming you have a messaging system to handle input
Expand Down
82 changes: 0 additions & 82 deletions src/Client/Systems/MouseInput.cs

This file was deleted.

Loading

0 comments on commit 6af08df

Please sign in to comment.