-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9ee2a7b
Showing
22 changed files
with
392 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.png filter=lfs diff=lfs merge=lfs -text | ||
*.dll filter=lfs diff=lfs merge=lfs -text | ||
*.ico filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: .NET | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
workflow_dispatch: | ||
|
||
env: | ||
VERSION: 0.1.${{ github.run_number }} | ||
|
||
jobs: | ||
build: | ||
runs-on: windows-latest | ||
|
||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
lfs: true | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v2 | ||
with: | ||
dotnet-version: 6.0.x | ||
|
||
- name: Restore dependencies | ||
run: dotnet restore | ||
|
||
- name: Build and Publish | ||
run: dotnet publish --configuration Release -p:Version=${{ env.VERSION }} --self-contained --no-restore -o publish | ||
|
||
- name: Archive Release | ||
uses: thedoctor0/zip-release@main | ||
with: | ||
type: zip | ||
directory: publish | ||
filename: roguelike-${{ env.VERSION }}.zip | ||
|
||
- name: Publish Release | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
tag: ${{ env.VERSION }} | ||
commit: master | ||
artifacts: publish/roguelike-${{ env.VERSION }}.zip | ||
generateReleaseNotes: true | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
obj/ | ||
bin/ | ||
publish/ | ||
*.user |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"Black": "#151515", | ||
"Blue": "#6c99ba", | ||
"BrightBlack": "#505050", | ||
"BrightBlue": "#6c99ba", | ||
"BrightCyan": "#7dd5cf", | ||
"BrightGreen": "#7e8d50", | ||
"BrightMagenta": "#9e4e85", | ||
"BrightRed": "#ac4142", | ||
"BrightWhite": "#f5f5f5", | ||
"BrightYellow": "#e5b566", | ||
"Cyan": "#7dd5cf", | ||
"Green": "#7e8d50", | ||
"Magenta": "#9e4e85", | ||
"Red": "#ac4142", | ||
"White": "#d0d0d0", | ||
"Yellow": "#e5b566", | ||
"Background": "#202020" | ||
} |
Git LFS file not shown
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Roguelike; | ||
|
||
public static partial class Engine | ||
{ | ||
public static string GetAssetPath(string path) | ||
{ | ||
return Path.Combine("Assets", path); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Globalization; | ||
using Raylib_cs; | ||
|
||
namespace Roguelike.Extensions; | ||
|
||
public static class ColorEx | ||
{ | ||
public static string ToHexString(this Color c) | ||
{ | ||
return $"#{c.r:X2}{c.g:X2}{c.b:X2}"; | ||
} | ||
|
||
/// <summary> | ||
/// Implicitly converts hex string to color. | ||
/// </summary> | ||
/// <param name="str">The hex string to convert.</param> | ||
/// <returns>A Color instance.</returns> | ||
public static Color FromHexString(string str) | ||
{ | ||
var hex = str.Replace("#", string.Empty); | ||
const NumberStyles numberStyle = NumberStyles.HexNumber; | ||
|
||
var r = byte.Parse(hex[..2], numberStyle); | ||
var g = byte.Parse(hex[2..4], numberStyle); | ||
var b = byte.Parse(hex[4..6], numberStyle); | ||
|
||
return new Color(r, g, b, byte.MaxValue); | ||
} | ||
|
||
public static Color DARKESTGRAY = new Color(32, 32, 32, (int)byte.MaxValue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Numerics; | ||
using Raylib_cs; | ||
|
||
namespace Roguelike; | ||
|
||
public class Tileset | ||
{ | ||
internal readonly Texture2D Texture; | ||
internal readonly Vector2 TileSize; | ||
|
||
public Tileset(Texture2D texture, Vector2 tileSize) | ||
{ | ||
this.Texture = texture; | ||
this.TileSize = tileSize; | ||
} | ||
|
||
public Rectangle GetRect(uint tileX, uint tileY) | ||
{ | ||
return new Rectangle(tileX * TileSize.X, tileY * TileSize.Y, TileSize.X, TileSize.Y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Raylib_cs; | ||
using Roguelike.Extensions; | ||
|
||
namespace Roguelike.Utility; | ||
|
||
#pragma warning disable IL2026 | ||
|
||
public class ColorPalette | ||
{ | ||
private Dictionary<string, Color> _colors = new(); | ||
|
||
public Color this[string key] => _colors.TryGetValue(key, out var value) ? value : default; | ||
|
||
public static ColorPalette LoadFromJson(string assetPath) | ||
{ | ||
var path = Engine.GetAssetPath(assetPath); | ||
var jsonString = File.ReadAllText(path); | ||
|
||
var options = new JsonSerializerOptions(); | ||
options.Converters.Add(new ColorJsonConverter()); | ||
|
||
var colors = JsonSerializer.Deserialize<Dictionary<string, Color>>(jsonString, options) ?? new Dictionary<string, Color>(); | ||
|
||
return new ColorPalette | ||
{ | ||
_colors = colors | ||
}; | ||
} | ||
} | ||
|
||
internal class ColorJsonConverter : JsonConverter<Color> | ||
{ | ||
public override Color Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return ColorEx.FromHexString(reader.GetString()!); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, Color value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value.ToHexString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System.Numerics; | ||
using System.Reflection; | ||
using Raylib_cs; | ||
using Roguelike.Utility; | ||
using static Raylib_cs.Raylib; | ||
|
||
namespace Roguelike; | ||
|
||
internal class Game | ||
{ | ||
private static Vector2 TileSize => new(16, 16); | ||
|
||
private readonly Tileset _tileset; | ||
private readonly ColorPalette _palette; | ||
|
||
private Vector2 _playerPosition; | ||
|
||
private const float PlayerWalkSpeed = 4f; // in tiles per second | ||
private double _playerLastMove; | ||
|
||
private Game() | ||
{ | ||
_tileset = new Tileset(LoadTexture(Engine.GetAssetPath("16x16-RogueYun-AgmEdit.png")), TileSize); | ||
_palette = ColorPalette.LoadFromJson("AfterglowTheme.json"); | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (_playerLastMove + (1f/PlayerWalkSpeed) < GetTime()) | ||
{ | ||
var playerMove = new Vector2(); | ||
|
||
if (IsKeyDown(KeyboardKey.KEY_LEFT) || IsKeyDown(KeyboardKey.KEY_A)) | ||
playerMove.X = -1; | ||
if (IsKeyDown(KeyboardKey.KEY_RIGHT) || IsKeyDown(KeyboardKey.KEY_D)) | ||
playerMove.X = 1; | ||
if (IsKeyDown(KeyboardKey.KEY_UP) || IsKeyDown(KeyboardKey.KEY_W)) | ||
playerMove.Y = -1; | ||
if (IsKeyDown(KeyboardKey.KEY_DOWN) || IsKeyDown(KeyboardKey.KEY_S)) | ||
playerMove.Y = 1; | ||
|
||
if (playerMove.X != 0 || playerMove.Y != 0) | ||
{ | ||
_playerPosition += new Vector2(playerMove.X * TileSize.X, playerMove.Y * TileSize.Y); | ||
_playerLastMove = GetTime(); | ||
} | ||
} | ||
|
||
if (IsKeyPressed(KeyboardKey.KEY_ESCAPE)) | ||
Environment.Exit(0); | ||
} | ||
|
||
private void Draw() | ||
{ | ||
DrawTextureRec(_tileset.Texture, _tileset.GetRect(0, 4), _playerPosition, _palette["Yellow"]); | ||
} | ||
|
||
private static void Main() | ||
{ | ||
var title = "Roguelike"; | ||
var version = Assembly.GetEntryAssembly()?.GetName().Version; | ||
title = version == null ? title : $"{title} v{version.ToString(3)}"; | ||
|
||
InitWindow(800, 640, title); | ||
|
||
var iconImg = LoadImage(Engine.GetAssetPath("icon.png")); | ||
|
||
SetWindowIcon(iconImg); | ||
|
||
SetTargetFPS(60); | ||
|
||
var game = new Game(); | ||
|
||
while (!WindowShouldClose()) | ||
{ | ||
game.Update(); | ||
|
||
BeginDrawing(); | ||
ClearBackground(game._palette["Background"]); | ||
game.Draw(); | ||
EndDrawing(); | ||
} | ||
|
||
CloseWindow(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/graphnode/roguelike/.NET)](https://github.com/graphnode/roguelike/actions) | ||
[![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/graphnode/roguelike?include_prereleases)](https://github.com/graphnode/roguelike/releases/latest) | ||
|
||
# RoguelikeDev Does The Complete Roguelike Tutorial 2022 | ||
|
||
![RoguelikeDev Does The Complete Roguelike Tutorial](README/roguelikedev-logo.png) | ||
|
||
## Information | ||
Implementation of [/r/roguelikedev](https://reddit.com/r/roguelikedev/)'s annual [Roguelike Tutorial](https://old.reddit.com/r/roguelikedev/comments/vhfsda/roguelikedev_does_the_complete_roguelike_tutorial/) using C# and [Raylib-cs](https://github.com/ChrisDill/Raylib-cs). | ||
|
||
## Download | ||
[Download the latest release here.](https://github.com/graphnode/roguelike/releases/latest) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.