Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommended setup for Rider #2

Closed
wants to merge 6 commits into from
Closed
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ mono_crash.*.json
# System/tool-specific ignores
.directory
*~

# IDE
**/.idea
12 changes: 11 additions & 1 deletion mono/dodge_the_creeps/Dodge the Creeps with C#.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<Project Sdk="Godot.NET.Sdk/3.2.3">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net472</TargetFramework>
<RootNamespace>DodgeTheCreeps</RootNamespace>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="$(MicrosoftNETFrameworkReferenceAssembliesLatestPackageVersion)" IsImplicitlyDefined="true" Condition="'$(_FullFrameworkReferenceAssemblyPaths)' == ''"/>
</ItemGroup>

<ItemGroup>
<None Include="**/*.tscn"/>
</ItemGroup>
</Project>
83 changes: 43 additions & 40 deletions mono/dodge_the_creeps/HUD.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
using Godot;

public class HUD : CanvasLayer
namespace DodgeTheCreeps
{
[Signal]
public delegate void StartGame();

public void ShowMessage(string text)
{
var messageLabel = GetNode<Label>("MessageLabel");
messageLabel.Text = text;
messageLabel.Show();

GetNode<Timer>("MessageTimer").Start();
}

public async void ShowGameOver()
{
ShowMessage("Game Over");

var messageTimer = GetNode<Timer>("MessageTimer");
await ToSignal(messageTimer, "timeout");

var messageLabel = GetNode<Label>("MessageLabel");
messageLabel.Text = "Dodge the\nCreeps!";
messageLabel.Show();

GetNode<Button>("StartButton").Show();
}

public void UpdateScore(int score)
{
GetNode<Label>("ScoreLabel").Text = score.ToString();
}

public void OnStartButtonPressed()
{
GetNode<Button>("StartButton").Hide();
EmitSignal(nameof(StartGame));
}

public void OnMessageTimerTimeout()
public class HUD : CanvasLayer
{
GetNode<Label>("MessageLabel").Hide();
[Signal]
public delegate void StartGame();

public void ShowMessage(string text)
{
var messageLabel = GetNode<Label>("MessageLabel");
messageLabel.Text = text;
messageLabel.Show();

GetNode<Timer>("MessageTimer").Start();
}

public async void ShowGameOver()
{
ShowMessage("Game Over");

var messageTimer = GetNode<Timer>("MessageTimer");
await ToSignal(messageTimer, "timeout");

var messageLabel = GetNode<Label>("MessageLabel");
messageLabel.Text = "Dodge the\nCreeps!";
messageLabel.Show();

GetNode<Button>("StartButton").Show();
}

public void UpdateScore(int score)
{
GetNode<Label>("ScoreLabel").Text = score.ToString();
}

public void OnStartButtonPressed()
{
GetNode<Button>("StartButton").Hide();
EmitSignal(nameof(StartGame));
}

public void OnMessageTimerTimeout()
{
GetNode<Label>("MessageLabel").Hide();
}
}
}
127 changes: 65 additions & 62 deletions mono/dodge_the_creeps/Main.cs
Original file line number Diff line number Diff line change
@@ -1,89 +1,92 @@
using Godot;

public class Main : Node
namespace DodgeTheCreeps
{
public class Main : Node
{
#pragma warning disable 649
// We assign this in the editor, so we don't need the warning about not being assigned.
[Export]
private PackedScene _mobScene;
// We assign this in the editor, so we don't need the warning about not being assigned.
[Export]
private PackedScene _mobScene;
#pragma warning restore 649

private int _score;
private int _score;

public override void _Ready()
{
GD.Randomize();
}
public override void _Ready()
{
GD.Randomize();
}

public void GameOver()
{
GetNode<Timer>("MobTimer").Stop();
GetNode<Timer>("ScoreTimer").Stop();
public void GameOver()
{
GetNode<Timer>("MobTimer").Stop();
GetNode<Timer>("ScoreTimer").Stop();

GetNode<HUD>("HUD").ShowGameOver();
GetNode<HUD>("HUD").ShowGameOver();

GetNode<AudioStreamPlayer>("Music").Stop();
GetNode<AudioStreamPlayer>("DeathSound").Play();
}
GetNode<AudioStreamPlayer>("Music").Stop();
GetNode<AudioStreamPlayer>("DeathSound").Play();
}

public void NewGame()
{
// Note that for calling Godot-provided methods with strings,
// we have to use the original Godot snake_case name.
GetTree().CallGroup("mobs", "queue_free");
_score = 0;
public void NewGame()
{
// Note that for calling Godot-provided methods with strings,
// we have to use the original Godot snake_case name.
GetTree().CallGroup("mobs", "queue_free");
_score = 0;

var player = GetNode<Player>("Player");
var startPosition = GetNode<Position2D>("StartPosition");
player.Start(startPosition.Position);
var player = GetNode<Player>("Player");
var startPosition = GetNode<Position2D>("StartPosition");
player.Start(startPosition.Position);

GetNode<Timer>("StartTimer").Start();
GetNode<Timer>("StartTimer").Start();

var hud = GetNode<HUD>("HUD");
hud.UpdateScore(_score);
hud.ShowMessage("Get Ready!");
var hud = GetNode<HUD>("HUD");
hud.UpdateScore(_score);
hud.ShowMessage("Get Ready!");

GetNode<AudioStreamPlayer>("Music").Play();
}
GetNode<AudioStreamPlayer>("Music").Play();
}

public void OnStartTimerTimeout()
{
GetNode<Timer>("MobTimer").Start();
GetNode<Timer>("ScoreTimer").Start();
}
public void OnStartTimerTimeout()
{
GetNode<Timer>("MobTimer").Start();
GetNode<Timer>("ScoreTimer").Start();
}

public void OnScoreTimerTimeout()
{
_score++;
public void OnScoreTimerTimeout()
{
_score++;

GetNode<HUD>("HUD").UpdateScore(_score);
}
GetNode<HUD>("HUD").UpdateScore(_score);
}

public void OnMobTimerTimeout()
{
// Note: Normally it is best to use explicit types rather than the `var`
// keyword. However, var is acceptable to use here because the types are
// obviously PathFollow2D and Mob, since they appear later on the line.
public void OnMobTimerTimeout()
{
// Note: Normally it is best to use explicit types rather than the `var`
// keyword. However, var is acceptable to use here because the types are
// obviously PathFollow2D and Mob, since they appear later on the line.

// Choose a random location on Path2D.
var mobSpawnLocation = GetNode<PathFollow2D>("MobPath/MobSpawnLocation");
mobSpawnLocation.Offset = GD.Randi();
// Choose a random location on Path2D.
var mobSpawnLocation = GetNode<PathFollow2D>("MobPath/MobSpawnLocation");
mobSpawnLocation.Offset = GD.Randi();

// Create a Mob instance and add it to the scene.
var mobInstance = (Mob)_mobScene.Instance();
AddChild(mobInstance);
// Create a Mob instance and add it to the scene.
var mobInstance = (Mob)_mobScene.Instance();
AddChild(mobInstance);

// Set the mob's direction perpendicular to the path direction.
float direction = mobSpawnLocation.Rotation + Mathf.Tau / 4;
// Set the mob's direction perpendicular to the path direction.
float direction = mobSpawnLocation.Rotation + Mathf.Tau / 4;

// Set the mob's position to a random location.
mobInstance.Position = mobSpawnLocation.Position;
// Set the mob's position to a random location.
mobInstance.Position = mobSpawnLocation.Position;

// Add some randomness to the direction.
direction += (float)GD.RandRange(-Mathf.Tau / 8, Mathf.Tau / 8);
mobInstance.Rotation = direction;
// Add some randomness to the direction.
direction += (float)GD.RandRange(-Mathf.Tau / 8, Mathf.Tau / 8);
mobInstance.Rotation = direction;

// Choose the velocity.
mobInstance.LinearVelocity = new Vector2((float)GD.RandRange(mobInstance.minSpeed, mobInstance.maxSpeed), 0).Rotated(direction);
// Choose the velocity.
mobInstance.LinearVelocity = new Vector2((float)GD.RandRange(mobInstance.minSpeed, mobInstance.maxSpeed), 0).Rotated(direction);
}
}
}
42 changes: 22 additions & 20 deletions mono/dodge_the_creeps/Mob.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
using Godot;
using System;

public class Mob : RigidBody2D
namespace DodgeTheCreeps
{
[Export]
public int minSpeed;
public class Mob : RigidBody2D
{
[Export]
public int minSpeed;

[Export]
public int maxSpeed;
[Export]
public int maxSpeed;

public override void _Ready()
{
var animSprite = GetNode<AnimatedSprite>("AnimatedSprite");
animSprite.Playing = true;
string[] mobTypes = animSprite.Frames.GetAnimationNames();
animSprite.Animation = mobTypes[GD.Randi() % mobTypes.Length];
}
public override void _Ready()
{
var animSprite = GetNode<AnimatedSprite>("AnimatedSprite");
animSprite.Playing = true;
string[] mobTypes = animSprite.Frames.GetAnimationNames();
animSprite.Animation = mobTypes[GD.Randi() % mobTypes.Length];
}

public void OnVisibilityScreenExited()
{
QueueFree();
}
public void OnVisibilityScreenExited()
{
QueueFree();
}

public void OnStartGame()
{
QueueFree();
public void OnStartGame()
{
QueueFree();
}
}
}
Loading