Skip to content

Commit

Permalink
Added Infinite world + 1.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
IrishBruse committed Mar 27, 2021
1 parent 64ad019 commit dc5a766
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 138 deletions.
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/ConwaysGameOfLife/bin/Debug/net5.0/ConwaysGameOfLife.dll",
"cwd": "${workspaceFolder}/ConwaysGameOfLife/",
"args": [],
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
105 changes: 105 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/${workspaceFolderBasename}/${workspaceFolderBasename}.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "clean",
"command": "dotnet",
"type": "process",
"args": [
"clean",
"${workspaceFolder}/${workspaceFolderBasename}/${workspaceFolderBasename}.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile",
},
{
"label": "restore",
"command": "dotnet",
"type": "process",
"args": [
"restore",
"${workspaceFolder}/${workspaceFolderBasename}/${workspaceFolderBasename}.csproj",
"-property:GenerateFullPaths=true",
"-consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish windows",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"-c",
"Release",
"-r",
"win-x64",
"-o",
"bin/Windows x64",
"--no-self-contained",
"-p:PublishSingleFile=true",
"${workspaceFolder}/${workspaceFolderBasename}/${workspaceFolderBasename}.csproj",
"-property:GenerateFullPaths=true",
"-consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish linux",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"-c",
"Release",
"-r",
"linux-x64",
"-o",
"bin/Linux x64",
"--no-self-contained",
"-p:PublishSingleFile=true",
"${workspaceFolder}/${workspaceFolderBasename}/${workspaceFolderBasename}.csproj",
"-property:GenerateFullPaths=true",
"-consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish macos",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"-c",
"Release",
"-r",
"osx-x64",
"-o",
"bin/MacOS x64",
"--no-self-contained",
"-p:PublishSingleFile=true",
"${workspaceFolder}/${workspaceFolderBasename}/${workspaceFolderBasename}.csproj",
"-property:GenerateFullPaths=true",
"-consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
]
}
55 changes: 55 additions & 0 deletions ConwaysGameOfLife/Camera.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace ConwaysGameOfLife
{
public class Camera
{
public Vector2 Position { get; private set; }
public Vector2 Origin { get; private set; }
public float Zoom { get; private set; } = 1;
public Matrix Matrix { get; private set; }
public Matrix InverseMatrix { get; private set; }

private MouseState oldMouse;

public void Update(GameTime time)
{
var mouse = Mouse.GetState();

if (mouse.MiddleButton == ButtonState.Pressed)
{
Point pos = mouse.Position - oldMouse.Position;
Position += new Vector2(pos.X, pos.Y) * 30 / (Zoom * 0.5f) * (float)time.ElapsedGameTime.TotalSeconds;
}

int scrollDelta = mouse.ScrollWheelValue - oldMouse.ScrollWheelValue;

if (scrollDelta < 0)
{
Zoom /= 2;
if (Zoom < 0.0125f)
{
Zoom = 0.0125f;
}
}
else if (scrollDelta > 0)
{
Zoom *= 2;
if (Zoom > 4)
{
Zoom = 4;
}
}

Matrix = Matrix.CreateTranslation(Position.X, Position.Y, 0) * Matrix.CreateScale(Zoom) * Matrix.CreateTranslation(Origin.X, Origin.Y, 0);
InverseMatrix = Matrix.Invert(Matrix);
oldMouse = mouse;
}

public void Resize(int width, int height)
{
Origin = new Vector2(width / 2f, height / 2f);
}
}
}
16 changes: 10 additions & 6 deletions ConwaysGameOfLife/ConwaysGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace ConwaysGameOfLife
{
public class ConwaysGame : Game
{
private GraphicsDeviceManager graphics;
private readonly GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;

private Camera camera;
Grid grid;

public ConwaysGame()
Expand All @@ -19,11 +19,14 @@ protected override void Initialize()
{
Window.Title = "Conway's Game Of Life";
Window.AllowUserResizing = true;
Content.RootDirectory = "Content";
IsMouseVisible = true;

grid = new Grid(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
Window.ClientSizeChanged += (o, e) => grid.Resize(graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height);

camera = new Camera();
camera.Resize(graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height);
Window.ClientSizeChanged += (o, e) => camera.Resize(graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height);

grid = new Grid(camera);

base.Initialize();
}
Expand All @@ -37,6 +40,7 @@ protected override void LoadContent()

protected override void Update(GameTime gameTime)
{
camera.Update(gameTime);
grid.Update();

base.Update(gameTime);
Expand All @@ -51,4 +55,4 @@ protected override void Draw(GameTime gameTime)
base.Draw(gameTime);
}
}
}
}
2 changes: 2 additions & 0 deletions ConwaysGameOfLife/ConwaysGameOfLife.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -12,6 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FontStashSharp.MonoGame" Version="0.9.2" />
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
</ItemGroup>

Expand Down
Loading

0 comments on commit dc5a766

Please sign in to comment.