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
12 changes: 12 additions & 0 deletions samples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup>
<TargetFramework>$(DefaultNetVersion)</TargetFramework>
<Configuration>release</Configuration>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(QuackRoot)\src\KappaDuck.Quack\KappaDuck.Quack.csproj" />
</ItemGroup>
</Project>
56 changes: 56 additions & 0 deletions samples/graphics/clear.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env dotnet

// Copyright (c) KappaDuck.
// Licensed under the MIT license.

// This example code creates a window and renderer, and then clears the
// window to a different color every frame, so you'll effectively get a window
// that's smoothly fading between colors.

using KappaDuck.Quack.Core;
using KappaDuck.Quack.Events;
using KappaDuck.Quack.Graphics.Rendering;
using KappaDuck.Quack.Video.Pixels;
using KappaDuck.Quack.Windows;
using System.Diagnostics;

// Initialize the engine with metadata and the Video Subsystem
QuackEngine.SetMetadata(new ApplicationMetadata("Clear example", "1.0.0", "com.example.clear"));
using EngineScope _ = QuackEngine.Init(Subsystem.Video);

// Create a resizable window and a renderer
using Window window = new("Clear example", 640, 480) { Resizable = true };
using Renderer renderer = new(window)
{
Presentation = (640, 480, LogicalPresentation.Letterbox)
};

// Start a stopwatch for the sine wave
Stopwatch stopwatch = Stopwatch.StartNew();

// Run the main loop
while (window.IsOpen)
{
// Poll the events
while (window.Poll(out Event e))
{
// If the user requests to quit the application, it will automatically close the window and exit the loop.
if (e is QuitRequestedEvent)
return;
}

// Clear the window with a sine wave color
renderer.Clear(SineWave(stopwatch.Elapsed.TotalSeconds));

// Presents all the drawn content on the window
renderer.Present();
}

static ColorF SineWave(double seconds)
{
float r = (float)(0.5 + (0.5 * Math.Sin(seconds)));
float g = (float)(0.5 + (0.5 * Math.Sin(seconds + (Math.PI * 2 / 3))));
float b = (float)(0.5 + (0.5 * Math.Sin(seconds + (Math.PI * 4 / 3))));

return new ColorF(r, g, b);
}
43 changes: 43 additions & 0 deletions samples/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# How to use Quack! Engine examples 🦆

This document provides an overview of how to run and explore the Quack! game engine examples.
> You need to have **.NET 11.0 SDK** installed to run theses examples via [dotnet run app.cs].

## Prerequisites

- [.NET 11.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/10.0)

> Quack! examples are single-file C# scripts, so most IDEs cannot run them directly.
>
> VS Code provides intellisense but requires running via the terminal.

## Running Examples

Run the example directly in your terminal:

#### Window
```bash
dotnet ./examples/windows/window.cs
```

#### Linux
```bash
chmod +x ./examples/windows/window.cs # only needed once
./examples/windows/window.cs
```

Alternatively, you can open the example in VS Code for editing and exploring the code, but
execution must be done via the terminal as shown above.

> For more details on single-file, see [dotnet run app.cs]

## Examples

Each example demonstrates a specific feature or capability of the Quack! engine.

## Graphics

- [Clear](./graphics/clear.cs) - Clear the screen with a sine wave pattern.


[dotnet run app.cs]: https://devblogs.microsoft.com/dotnet/announcing-dotnet-run-app/