Skip to content

Commit

Permalink
Merge pull request #17 from thoth-tech/tutorial-guide-improvements
Browse files Browse the repository at this point in the history
Improved Tutorial Guides (Thoth Tech T2 2024)
  • Loading branch information
macite authored Oct 18, 2024
2 parents 8044716 + 1adf02e commit 6f36aef
Show file tree
Hide file tree
Showing 16 changed files with 5,273 additions and 1,513 deletions.
195 changes: 194 additions & 1 deletion src/content/docs/guides/Animations/0-using-animations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Using Animations in SplashKit
description: Animations allow you to switch between different images to make a more visually dynamic entity on the screen. SplashKit allows you to create animations and use these together with sprite sheets to create these animations.
category: Guides
author: Various Authors
lastupdated: July 2024
lastupdated: October 2024
---

import { Tabs, TabItem } from "@astrojs/starlight/components";
Expand Down Expand Up @@ -231,6 +231,9 @@ This includes sample animation scripts, images, and sounds.
</TabItem>
<TabItem label="C#">
<Tabs syncKey="csharp-style">
<TabItem label="Top-level Statements">
```csharp
using SplashKitSDK;
using static SplashKitSDK.SplashKit;
Expand Down Expand Up @@ -299,6 +302,91 @@ This includes sample animation scripts, images, and sounds.
CloseAllWindows();
```

</TabItem>
<TabItem label="Object-Oriented">

```csharp
using SplashKitSDK;

namespace UsingAnimations
{
public class Program
{
public static void Main()
{
Window window = new Window("Animation Test", 120, 120);

// // We could load all of the resources in a bundle
// LoadResourceBundle("dance bundle", "dance_bundle.txt");
// // Then access by name
// AnimationScript danceScript = AnimationScriptNamed("WalkingScript");
// Bitmap frog = BitmapNamed("FrogBmp");
// Loading them separately
// Load image and set its cell details
Bitmap frog = new Bitmap("FrogBmp", "frog.png");
frog.SetCellDetails(73, 105, 4, 4, 16); // cell width, height, cols, rows, count
// Load the animation script
AnimationScript danceScript = new AnimationScript("WalkingScript", "kermit.txt");

// Create the animation
Animation frogAnimation = danceScript.CreateAnimation("WalkFront");

// Create a drawing option
DrawingOptions opt = SplashKit.OptionWithAnimation(frogAnimation);


// Basic event loop
while (!window.CloseRequested)
{
SplashKit.ProcessEvents();

// Draw the bitmap - using opt to link to animation
window.Clear(Color.White);
frog.Draw(20, 20, opt);
window.DrawText(frogAnimation.Name, Color.Black, 0, 0);
window.Refresh(60);

// Update the animation
frogAnimation.Update();

// Switch animations
if (SplashKit.KeyTyped(KeyCode.UpKey))
{
frogAnimation.Assign("WalkBack");
}
else if (SplashKit.KeyTyped(KeyCode.DownKey))
{
frogAnimation.Assign("WalkFront");
}
else if (SplashKit.KeyTyped(KeyCode.LeftKey))
{
frogAnimation.Assign("WalkLeft");
}
else if (SplashKit.KeyTyped(KeyCode.RightKey))
{
frogAnimation.Assign("WalkRight");
}
else if (SplashKit.KeyTyped(KeyCode.DKey))
{
frogAnimation.Assign("Dance");
}
}

SplashKit.CloseAllWindows();
}
}
}
```

</TabItem>
</Tabs>

</TabItem>
</Tabs>

Expand Down Expand Up @@ -410,6 +498,9 @@ Here is a another example, where the **Left Shift Key** can be **held down** to
</TabItem>
<TabItem label="C#">
<Tabs syncKey="csharp-style">
<TabItem label="Top-level Statements">
```csharp
using SplashKitSDK;
using static SplashKitSDK.SplashKit;
Expand Down Expand Up @@ -497,6 +588,108 @@ Here is a another example, where the **Left Shift Key** can be **held down** to
CloseAllWindows();
```

</TabItem>
<TabItem label="Object-Oriented">

```csharp
using SplashKitSDK;

namespace UsingAnimations
{
public class Program
{
public static void Main()
{
Window window = new Window("Animation Test", 120, 120);

// We could load all of the resources in a bundle
SplashKit.LoadResourceBundle("dance bundle", "dance_bundle.txt");

// Then access by name
AnimationScript danceScript = SplashKit.AnimationScriptNamed("WalkingScript");
Bitmap frog = SplashKit.BitmapNamed("FrogBmp");

// Create the animation
Animation frogAnimation = danceScript.CreateAnimation("WalkFront");

// Create a drawing option
DrawingOptions opt = SplashKit.OptionWithAnimation(frogAnimation);


// Basic event loop
while (!window.CloseRequested)
{
SplashKit.ProcessEvents();

// Draw the bitmap - using opt to link to animation
window.Clear(Color.White);
frog.Draw(20, 20, opt);
window.DrawText(frogAnimation.Name, Color.Black, 0, 0);
window.Refresh(60);

// Update the animation
frogAnimation.Update();

// Switch animations
if (SplashKit.KeyTyped(KeyCode.UpKey))
{
if (SplashKit.KeyDown(KeyCode.LeftShiftKey))
{
frogAnimation.Assign("MoonWalkBack");
}
else
{
frogAnimation.Assign("WalkBack");
}
}
else if (SplashKit.KeyTyped(KeyCode.DownKey))
{
if (SplashKit.KeyDown(KeyCode.LeftShiftKey))
{
frogAnimation.Assign("MoonWalkFront");
}
else
{
frogAnimation.Assign("WalkFront");
}
}
else if (SplashKit.KeyTyped(KeyCode.LeftKey))
{
if (SplashKit.KeyDown(KeyCode.LeftShiftKey))
{
frogAnimation.Assign("MoonWalkLeft");
}
else
{
frogAnimation.Assign("WalkLeft");
}
}
else if (SplashKit.KeyTyped(KeyCode.RightKey))
{
if (SplashKit.KeyDown(KeyCode.LeftShiftKey))
{
frogAnimation.Assign("MoonWalkRight");
}
else
{
frogAnimation.Assign("WalkRight");
}
}
else if (SplashKit.KeyTyped(KeyCode.DKey))
{
frogAnimation.Assign("Dance");
}
}

SplashKit.CloseAllWindows();
}
}
}
```

</TabItem>
</Tabs>

</TabItem>
</Tabs>

Expand Down
Loading

0 comments on commit 6f36aef

Please sign in to comment.