Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@
*.mp4 filter=lfs diff=lfs merge=lfs -text
*.bmp filter=lfs diff=lfs merge=lfs -text
*.ico filter=lfs diff=lfs merge=lfs -text
*.iqm filter=lfs diff=lfs merge=lfs -text
*.vox filter=lfs diff=lfs merge=lfs -text
*.m3d filter=lfs diff=lfs merge=lfs -text
*.hdr filter=lfs diff=lfs merge=lfs -text
*.raw filter=lfs diff=lfs merge=lfs -text
*.glb filter=lfs diff=lfs merge=lfs -text
*.blend filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.flac filter=lfs diff=lfs merge=lfs -text
*.xm filter=lfs diff=lfs merge=lfs -text
*.ogg filter=lfs diff=lfs merge=lfs -text
28 changes: 28 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Build and Test

on: [push]

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore /m:1

- name: Test
run: dotnet test --no-build --verbosity normal
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,4 @@ MigrationBackup/
# Macbook data store file
.DS_Store

# pulumi profiles
Pulumi.*.yaml
!Community/resources/models/obj/*.png
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using Raylib_cs;

namespace RaylibCsExamples.Community.Core.BasicScreenManager;

internal enum GameScreen
{
Logo, Title, Gameplay, Ending
}

public class Program
{
public static int Main()
{
const int screenWidth = 800;
const int screenHeight = 450;

Raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic screen manaager");

var currentScreen = GameScreen.Logo;

var frameCounter = 0;

Raylib.SetTargetFPS(60);

while (!Raylib.WindowShouldClose())
{
switch (currentScreen)
{
case GameScreen.Logo:
{
frameCounter++;

if (frameCounter >= 120)
{
currentScreen = GameScreen.Title;
}
}
break;

case GameScreen.Title:
{
if (Raylib.IsKeyPressed(KeyboardKey.Enter) || Raylib.IsGestureDetected(Gesture.Tap))
{
currentScreen = GameScreen.Gameplay;
}
}
break;
case GameScreen.Gameplay:
{
if (Raylib.IsKeyPressed(KeyboardKey.Enter) || Raylib.IsGestureDetected(Gesture.Tap))
{
currentScreen = GameScreen.Ending;
}
}
break;
case GameScreen.Ending:
{
if (Raylib.IsKeyPressed(KeyboardKey.Enter) || Raylib.IsGestureDetected(Gesture.Tap))
{
currentScreen = GameScreen.Title;
}
}
break;

default:
break;
}

Raylib.BeginDrawing();
Raylib.ClearBackground(Color.RayWhite);

switch (currentScreen)
{
case GameScreen.Logo:
{
// TODO: Draw LOGO screen here!
Raylib.DrawText("LOGO SCREEN", 20, 20, 40, Color.LightGray);
Raylib.DrawText("WAIT for 2 SECONDS...", 290, 220, 20, Color.Gray);

}
break;
case GameScreen.Title:
{
// TODO: Draw TITLE screen here!
Raylib.DrawRectangle(0, 0, screenWidth, screenHeight, Color.Green);
Raylib.DrawText("TITLE SCREEN", 20, 20, 40, Color.DarkGreen);
Raylib.DrawText("PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120, 220, 20, Color.DarkGreen);

}
break;
case GameScreen.Gameplay:
{
// TODO: Draw GAMEPLAY screen here!
Raylib.DrawRectangle(0, 0, screenWidth, screenHeight, Color.Purple);
Raylib.DrawText("GAMEPLAY SCREEN", 20, 20, 40, Color.Maroon);
Raylib.DrawText("PRESS ENTER or TAP to JUMP to ENDING SCREEN", 130, 220, 20, Color.Maroon);

}
break;
case GameScreen.Ending:
{
// TODO: Draw ENDING screen here!
Raylib.DrawRectangle(0, 0, screenWidth, screenHeight, Color.Blue);
Raylib.DrawText("ENDING SCREEN", 20, 20, 40, Color.DarkBlue);
Raylib.DrawText("PRESS ENTER or TAP to RETURN to TITLE SCREEN", 120, 220, 20, Color.DarkBlue);
}
break;
}
Raylib.EndDrawing();
}

Raylib.CloseWindow();

return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Raylib_cs;

namespace RaylibCsExamples.Community.Core.BasicWindow;

public class Program
{
public static int Main()
{
const int screenWidth = 800;
const int screenHeight = 450;

Raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
Raylib.SetTargetFPS(60);

while (!Raylib.WindowShouldClose())
{
Raylib.BeginDrawing();
Raylib.ClearBackground(Color.White);
Raylib.DrawText("Congrats! You created your first window!", 190, 200, 20, Color.Maroon);
Raylib.EndDrawing();
}

Raylib.CloseWindow();

return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
158 changes: 158 additions & 0 deletions Community/Core/RaylibCsExamples.Community.Core.Camera2dDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@

using System.Numerics;
using Raylib_cs;

namespace RaylibCsExamples.Community.Core.Camera2dDemo;

internal sealed class Program
{
private static void Main(string[] args)
{
const int MaxBuildings = 100;

const int screenWidth = 800;
const int screenHeight = 450;

Raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");

var player = new Rectangle(400, 280, 40, 40);
var buildings = new (Rectangle rectangle, Color color)[MaxBuildings];

var spacing = 0;

for (var i = 0; i < MaxBuildings; i++)
{
var buildingHeight = Random.Shared.Next(50, 200);
var buildingWidth = Random.Shared.Next(100, 800);

buildings[i] = buildings[i] with
{
rectangle = new(
x: -6000 + spacing,
y: screenHeight - 130 - buildingHeight,
width: buildingWidth,
height: buildingHeight
),

color = new(
Random.Shared.Next(200, 240),
Random.Shared.Next(200, 240),
Random.Shared.Next(200, 240)
)
};

spacing += buildingWidth;
}

var camera = new Camera2D()
{
Target = new(player.X + 20, player.Y + 20),
Offset = new(screenWidth / 2, screenHeight / 2),
Rotation = 0.0f,
Zoom = 1.0f
};

Raylib.SetTargetFPS(60);

while (!Raylib.WindowShouldClose())
{
// Update
//----------------------------------------------------------------------------------

// Player movement
if (Raylib.IsKeyDown(KeyboardKey.Right))
{
player.X += 2;
}
else if (Raylib.IsKeyDown(KeyboardKey.Left))
{
player.X -= 2;
}

// Camera3D target follows player
camera.Target = new Vector2(player.X + 20, player.Y + 20);

// Camera3D rotation controls
if (Raylib.IsKeyDown(KeyboardKey.A))
{
camera.Rotation--;
}
else if (Raylib.IsKeyDown(KeyboardKey.S))
{
camera.Rotation++;
}

// Limit camera rotation to 80 degrees (-40 to 40)
if (camera.Rotation > 40)
{
camera.Rotation = 40;
}
else if (camera.Rotation < -40)
{
camera.Rotation = -40;
}

// Camera3D zoom controls
camera.Zoom += (float)Raylib.GetMouseWheelMove() * 0.05f;

if (camera.Zoom > 3.0f)
{
camera.Zoom = 3.0f;
}
else if (camera.Zoom < 0.1f)
{
camera.Zoom = 0.1f;
}

// Camera3D reset (zoom and rotation)
if (Raylib.IsKeyPressed(KeyboardKey.R))
{
camera.Zoom = 1.0f;
camera.Rotation = 0.0f;
}

Raylib.BeginDrawing();
Raylib.BeginMode2D(camera);
Raylib.ClearBackground(Color.RayWhite);
Raylib.DrawRectangle(-6000, 320, 13000, 8000, Color.DarkGray);

foreach (var (rectangle, color) in buildings)
{
Raylib.DrawRectangleRec(rectangle, color);
}

Raylib.DrawRectangleRec(player, Color.Red);
Raylib.DrawRectangle((int)camera.Target.X, -500, 1, screenHeight * 4, Color.Green);
Raylib.DrawLine(
-screenWidth * 10,
(int)camera.Target.Y,
screenWidth * 10,
(int)camera.Target.Y,
Color.Green
);

Raylib.EndMode2D();

Raylib.DrawText("SCREEN AREA", 640, 10, 20, Color.Red);

Raylib.DrawRectangle(posX: 0, posY: 0, width: screenWidth, height: 5, color: Color.Red);
Raylib.DrawRectangle(posX: 0, posY: 5, width: 5, height: screenHeight - 10, color: Color.Red);
Raylib.DrawRectangle(posX: screenWidth - 5, posY: 5, width: 5, height: screenHeight - 10, color: Color.Red);
Raylib.DrawRectangle(posX: 0, posY: screenHeight - 5, width: screenWidth, height: 5, color: Color.Red);

Raylib.DrawRectangle(posX: 10, posY: 10, width: 250, height: 113, color: Raylib.ColorAlpha(Color.SkyBlue, 0.5f));

Raylib.DrawRectangleLines(10, 10, 250, 113, Color.Blue);

Raylib.DrawText(text: "Free 2d camera controls:", posX: 20, posY: 20, fontSize: 10, color: Color.Black);
Raylib.DrawText(text: "- Right/Left to move Offset", posX: 40, posY: 40, fontSize: 10, color: Color.DarkGray);
Raylib.DrawText(text: "- Mouse Wheel to Zoom in-out", posX: 40, posY: 60, fontSize: 10, color: Color.DarkGray);
Raylib.DrawText(text: "- A / S to Rotate", posX: 40, posY: 80, fontSize: 10, color: Color.DarkGray);
Raylib.DrawText(text: "- R to reset Zoom and Rotation", posX: 40, posY: 100, fontSize: 10, color: Color.DarkGray);

Raylib.EndDrawing();
}

Raylib.CloseWindow();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Loading