Skip to content

Commit

Permalink
Update "Dodge the Creeps C#" demo
Browse files Browse the repository at this point in the history
  • Loading branch information
van800 committed Mar 2, 2023
1 parent 778baf0 commit 8df5b38
Show file tree
Hide file tree
Showing 25 changed files with 378 additions and 366 deletions.
10 changes: 8 additions & 2 deletions mono/dodge_the_creeps/Dodge the Creeps with C#.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<Project Sdk="Godot.NET.Sdk/4.0.0-dev5">
<Project Sdk="Godot.NET.Sdk/4.0.0">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>DodgeTheCreeps</RootNamespace>
</PropertyGroup>
<ItemGroup>
<None Include="**/*.tscn" />
</ItemGroup>
<ItemGroup>
<None Include="project.godot" />
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions mono/dodge_the_creeps/HUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public partial class HUD : CanvasLayer
{
[Signal]
public delegate void StartGame();
public delegate void StartGameEventHandler();

public void ShowMessage(string text)
{
Expand Down Expand Up @@ -36,9 +36,10 @@ public void UpdateScore(int score)
public void OnStartButtonPressed()
{
GetNode<Button>("StartButton").Hide();
EmitSignal(nameof(StartGame));
EmitSignal(SignalName.StartGame);
}


public void OnMessageTimerTimeout()
{
GetNode<Label>("MessageLabel").Hide();
Expand Down
70 changes: 30 additions & 40 deletions mono/dodge_the_creeps/HUD.tscn
Original file line number Diff line number Diff line change
@@ -1,65 +1,55 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=4 format=3 uid="uid://ccqoreueuxdb7"]

[ext_resource path="res://HUD.cs" type="Script" id=1]
[ext_resource path="res://fonts/Xolonium-Regular.ttf" type="FontData" id=2]
[ext_resource type="Script" path="res://HUD.cs" id="1"]

[sub_resource type="Font" id=1]
size = 64
use_mipmaps = true
font_data = ExtResource( 2 )
[sub_resource type="InputEventAction" id="InputEventAction_fopy7"]
action = &"start_game"

[sub_resource type="Font" id=2]
size = 64
use_mipmaps = true
font_data = ExtResource( 2 )

[sub_resource type="Font" id=3]
size = 64
use_mipmaps = true
font_data = ExtResource( 2 )
[sub_resource type="Shortcut" id="4"]
events = [SubResource("InputEventAction_fopy7")]

[node name="HUD" type="CanvasLayer"]
script = ExtResource( 1 )
script = ExtResource("1")

[node name="ScoreLabel" type="Label" parent="."]
anchor_left = 0.5
anchor_right = 0.5
offset_left = -25.0
offset_right = 25.0
offset_bottom = 100.0
custom_fonts/font = SubResource( 1 )
text = "0
"
align = 1
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 78.0
grow_horizontal = 2
theme_override_font_sizes/font_size = 60
text = "0"
horizontal_alignment = 1

[node name="MessageLabel" type="Label" parent="."]
anchor_left = 0.5
anchors_preset = 14
anchor_top = 0.5
anchor_right = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
offset_left = -200.0
offset_top = -150.0
offset_right = 200.0
custom_fonts/font = SubResource( 2 )
text = "Dodge the
Creeps!"
align = 1
valign = 1
offset_top = -79.5
offset_bottom = 79.5
grow_horizontal = 2
grow_vertical = 2
theme_override_font_sizes/font_size = 60
text = "Dodge the Creeps"
horizontal_alignment = 1

[node name="StartButton" type="Button" parent="."]
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -100.0
offset_left = -90.0
offset_top = -200.0
offset_right = 100.0
offset_right = 90.0
offset_bottom = -100.0
custom_fonts/font = SubResource( 3 )
grow_horizontal = 2
grow_vertical = 0
theme_override_font_sizes/font_size = 60
shortcut = SubResource("4")
text = "Start"

[node name="MessageTimer" type="Timer" parent="."]
wait_time = 2.0
one_shot = true

[connection signal="pressed" from="StartButton" to="." method="OnStartButtonPressed"]
Expand Down
11 changes: 3 additions & 8 deletions mono/dodge_the_creeps/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ public partial class Main : Node

public int score;

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

public void GameOver()
{
GetNode<Timer>("MobTimer").Stop();
Expand All @@ -34,7 +29,7 @@ public void NewGame()
score = 0;

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

GetNode<Timer>("StartTimer").Start();
Expand Down Expand Up @@ -67,10 +62,10 @@ public void OnMobTimerTimeout()

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

// Create a Mob instance and add it to the scene.
var mob = (Mob)mobScene.Instantiate();
var mob = mobScene.Instantiate<Mob>();
AddChild(mob);

// Set the mob's direction perpendicular to the path direction.
Expand Down
36 changes: 20 additions & 16 deletions mono/dodge_the_creeps/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=8 format=3 uid="uid://cyfwty2q3rdse"]

[ext_resource path="res://Main.cs" type="Script" id=1]
[ext_resource path="res://Mob.tscn" type="PackedScene" id=2]
[ext_resource path="res://Player.tscn" type="PackedScene" id=3]
[ext_resource path="res://HUD.tscn" type="PackedScene" id=4]
[ext_resource path="res://art/House In a Forest Loop.ogg" type="AudioStream" id=5]
[ext_resource path="res://art/gameover.wav" type="AudioStream" id=6]
[ext_resource type="Script" path="res://Main.cs" id="1"]
[ext_resource type="PackedScene" uid="uid://rkdnhqgf2hpj" path="res://Mob.tscn" id="2"]
[ext_resource type="PackedScene" uid="uid://4vwrqjegqwpj" path="res://Player.tscn" id="3"]
[ext_resource type="PackedScene" uid="uid://ccqoreueuxdb7" path="res://HUD.tscn" id="4"]
[ext_resource type="AudioStream" uid="uid://q2pf4fr8d0ks" path="res://art/House In a Forest Loop.ogg" id="5"]
[ext_resource type="AudioStream" uid="uid://dw26fpygeag8o" path="res://art/gameover.wav" id="6"]

[sub_resource type="Curve2D" id=1]
[sub_resource type="Curve2D" id="1"]
_data = {
"points": PackedVector2Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 480, 0, 0, 0, 0, 0, 480, 720, 0, 0, 0, 0, 0, 720, 0, 0, 0, 0, 0, 0)
}
point_count = 5

[node name="Main" type="Node"]
script = ExtResource( 1 )
mobScene = ExtResource( 2 )
script = ExtResource("1")
mobScene = ExtResource("2")

[node name="ColorRect" type="ColorRect" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.219608, 0.372549, 0.380392, 1)

[node name="Player" parent="." instance=ExtResource( 3 )]
[node name="Player" parent="." instance=ExtResource("3")]

[node name="MobTimer" type="Timer" parent="."]
wait_time = 0.5
Expand All @@ -32,21 +36,21 @@ wait_time = 0.5
wait_time = 2.0
one_shot = true

[node name="StartPosition" type="Position2D" parent="."]
[node name="StartPosition" type="Marker2D" parent="."]
position = Vector2(240, 450)

[node name="MobPath" type="Path2D" parent="."]
curve = SubResource( 1 )
curve = SubResource("1")

[node name="MobSpawnLocation" type="PathFollow2D" parent="MobPath"]

[node name="HUD" parent="." instance=ExtResource( 4 )]
[node name="HUD" parent="." instance=ExtResource("4")]

[node name="Music" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 5 )
stream = ExtResource("5")

[node name="DeathSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 6 )
stream = ExtResource("6")

[connection signal="Hit" from="Player" to="." method="GameOver"]
[connection signal="timeout" from="MobTimer" to="." method="OnMobTimerTimeout"]
Expand Down
6 changes: 3 additions & 3 deletions mono/dodge_the_creeps/Mob.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Godot;

public partial class Mob : RigidDynamicBody2D
public partial class Mob : RigidBody2D
{
public override void _Ready()
{
var animSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
animSprite.Playing = true;
string[] mobTypes = animSprite.Frames.GetAnimationNames();
animSprite.Play();
string[] mobTypes = animSprite.SpriteFrames.GetAnimationNames();
animSprite.Animation = mobTypes[GD.Randi() % mobTypes.Length];
}

Expand Down
53 changes: 24 additions & 29 deletions mono/dodge_the_creeps/Mob.tscn
Original file line number Diff line number Diff line change
@@ -1,54 +1,49 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=10 format=3 uid="uid://rkdnhqgf2hpj"]

[ext_resource path="res://Mob.cs" type="Script" id=1]
[ext_resource path="res://art/enemySwimming_1.png" type="Texture2D" id=2]
[ext_resource path="res://art/enemySwimming_2.png" type="Texture2D" id=3]
[ext_resource path="res://art/enemyWalking_1.png" type="Texture2D" id=4]
[ext_resource path="res://art/enemyWalking_2.png" type="Texture2D" id=5]
[ext_resource path="res://art/enemyFlyingAlt_1.png" type="Texture2D" id=6]
[ext_resource path="res://art/enemyFlyingAlt_2.png" type="Texture2D" id=7]
[ext_resource type="Script" path="res://Mob.cs" id="1"]
[ext_resource type="Texture2D" uid="uid://yqglrrsx7j1f" path="res://art/enemyFlyingAlt_1.png" id="2"]
[ext_resource type="Texture2D" uid="uid://bpot8awhdn6ph" path="res://art/enemyFlyingAlt_2.png" id="3"]
[ext_resource type="Texture2D" uid="uid://bu4221t7qpa7d" path="res://art/enemyWalking_1.png" id="4"]
[ext_resource type="Texture2D" uid="uid://booij5t7h4efb" path="res://art/enemyWalking_2.png" id="5"]
[ext_resource type="Texture2D" uid="uid://5lvm88ij4jqn" path="res://art/enemySwimming_1.png" id="6"]
[ext_resource type="Texture2D" uid="uid://bng45cvsgufqc" path="res://art/enemySwimming_2.png" id="7"]

[sub_resource type="SpriteFrames" id=1]
[sub_resource type="SpriteFrames" id="1"]
animations = [{
"frames": [ExtResource( 4 ), ExtResource( 5 )],
"frames": [ExtResource( "6" ), ExtResource( "7" )],
"loop": true,
"name": "walk",
"name": &"swim",
"speed": 4.0
}, {
"frames": [ExtResource( 6 ), ExtResource( 7 )],
"frames": [ExtResource( "2" ), ExtResource( "3" )],
"loop": true,
"name": "fly",
"name": &"fly",
"speed": 3.0
}, {
"frames": [ExtResource( 2 ), ExtResource( 3 )],
"frames": [ExtResource( "4" ), ExtResource( "5" )],
"loop": true,
"name": "swim",
"name": &"walk",
"speed": 4.0
}]

[sub_resource type="CapsuleShape2D" id=2]
radius = 35.8898
height = 29.3103
[sub_resource type="CapsuleShape2D" id="2"]
radius = 37.0
height = 100.0

[node name="Mob" type="RigidDynamicBody2D" groups=["mobs"]]
collision_mask = 0
gravity_scale = 0.0
script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
script = ExtResource( "1" )

[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
scale = Vector2(0.75, 0.75)
frames = SubResource( 1 )
animation = "walk"
frames = SubResource( "1" )
animation = &"walk"

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = 1.5708
shape = SubResource( 2 )
shape = SubResource( "2" )

[node name="Visibility" type="VisibleOnScreenNotifier2D" parent="."]
position = Vector2(-0.315128, -9.53674e-07)
scale = Vector2(5.00208, 3.58402)
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]

[connection signal="screen_exited" from="Visibility" to="." method="OnVisibilityScreenExited"]
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="OnVisibilityScreenExited"]
Loading

0 comments on commit 8df5b38

Please sign in to comment.