Merge pull request #391 from aaronfranke/mono

Update and improve Mono demos and Dodge the Creeps GDScript
This commit is contained in:
Aaron Franke
2020-01-31 13:01:25 -05:00
committed by GitHub
79 changed files with 464 additions and 493 deletions

View File

@@ -1,7 +0,0 @@
extends Button
func _on_Button_pressed() -> void:
if Input.is_mouse_button_pressed(BUTTON_LEFT):
print("Left mouse button")
if Input.is_mouse_button_pressed(BUTTON_RIGHT):
print("Right mouse button")

View File

@@ -7,6 +7,7 @@ func show_message(text):
$MessageLabel.show()
$MessageTimer.start()
func show_game_over():
show_message("Game Over")
yield($MessageTimer, "timeout")
@@ -15,12 +16,15 @@ func show_game_over():
yield(get_tree().create_timer(1), 'timeout')
$StartButton.show()
func update_score(score):
$ScoreLabel.text = str(score)
func _on_StartButton_pressed():
$StartButton.hide()
emit_signal("start_game")
func _on_MessageTimer_timeout():
$MessageLabel.hide()
$MessageLabel.hide()

View File

@@ -4,21 +4,17 @@
[ext_resource path="res://fonts/Xolonium-Regular.ttf" type="DynamicFontData" id=2]
[sub_resource type="DynamicFont" id=1]
size = 64
font_data = ExtResource( 2 )
[sub_resource type="DynamicFont" id=2]
size = 64
font_data = ExtResource( 2 )
[sub_resource type="InputEventAction" id=3]
action = "ui_select"
[sub_resource type="ShortCut" id=4]
shortcut = SubResource( 3 )
[node name="HUD" type="CanvasLayer"]
@@ -57,6 +53,5 @@ text = "Start"
[node name="MessageTimer" type="Timer" parent="."]
one_shot = true
[connection signal="pressed" from="StartButton" to="." method="_on_StartButton_pressed"]
[connection signal="timeout" from="MessageTimer" to="." method="_on_MessageTimer_timeout"]

View File

@@ -6,6 +6,7 @@ var score
func _ready():
randomize()
func game_over():
$ScoreTimer.stop()
$MobTimer.stop()
@@ -13,6 +14,7 @@ func game_over():
$Music.stop()
$DeathSound.play()
func new_game():
score = 0
$Player.start($StartPosition.position)
@@ -21,20 +23,23 @@ func new_game():
$HUD.show_message("Get Ready")
$Music.play()
func _on_MobTimer_timeout():
$MobPath/MobSpawnLocation.offset = randi()
var mob = Mob.instance()
add_child(mob)
var direction = $MobPath/MobSpawnLocation.rotation + PI/2
var direction = $MobPath/MobSpawnLocation.rotation + PI / 2
mob.position = $MobPath/MobSpawnLocation.position
direction += rand_range(-PI/4, PI/4)
direction += rand_range(-PI / 4, PI / 4)
mob.rotation = direction
mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0).rotated(direction)
func _on_ScoreTimer_timeout():
score += 1
$HUD.update_score(score)
func _on_StartTimer_timeout():
$MobTimer.start()
$ScoreTimer.start()
$ScoreTimer.start()

View File

@@ -9,7 +9,7 @@
[sub_resource type="Curve2D" id=1]
_data = {
"points": PoolVector2Array( 0, 0, 0, 0, -0.901337, 0.225891, 0, 0, 0, 0, 480.262, 1.29041, 0, 0, 0, 0, 481.327, 700.681, 0, 0, 0, 0, 0.163177, 698.552, 0, 0, 0, 0, -0.901337, 0.225891 )
"points": PoolVector2Array( 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 )
}
[node name="Main" type="Node"]
@@ -19,7 +19,7 @@ Mob = ExtResource( 2 )
[node name="ColorRect" type="ColorRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.223529, 0.317647, 0.368627, 1 )
color = Color( 0.219608, 0.372549, 0.380392, 1 )
[node name="Player" parent="." instance=ExtResource( 3 )]
@@ -39,8 +39,6 @@ position = Vector2( 240, 450 )
curve = SubResource( 1 )
[node name="MobSpawnLocation" type="PathFollow2D" parent="MobPath"]
position = Vector2( -0.901337, 0.225891 )
rotation = 0.00221238
[node name="HUD" parent="." instance=ExtResource( 4 )]
@@ -49,7 +47,6 @@ stream = ExtResource( 5 )
[node name="DeathSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 6 )
[connection signal="hit" from="Player" to="." method="game_over"]
[connection signal="timeout" from="MobTimer" to="." method="_on_MobTimer_timeout"]
[connection signal="timeout" from="ScoreTimer" to="." method="_on_ScoreTimer_timeout"]

View File

@@ -1,5 +1,6 @@
extends RigidBody2D
#warning-ignore-all:unused_class_variable
export var min_speed = 150
export var max_speed = 250
var mob_types = ["walk", "swim", "fly"]
@@ -7,5 +8,6 @@ var mob_types = ["walk", "swim", "fly"]
func _ready():
$AnimatedSprite.animation = mob_types[randi() % mob_types.size()]
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
queue_free()

View File

@@ -1,20 +1,19 @@
[gd_scene load_steps=10 format=2]
[ext_resource path="res://Mob.gd" type="Script" id=1]
[ext_resource path="res://art/enemySwimming_1.png" type="Texture" id=2]
[ext_resource path="res://art/enemySwimming_2.png" type="Texture" id=3]
[ext_resource path="res://art/enemyFlyingAlt_1.png" type="Texture" id=2]
[ext_resource path="res://art/enemyFlyingAlt_2.png" type="Texture" id=3]
[ext_resource path="res://art/enemyWalking_1.png" type="Texture" id=4]
[ext_resource path="res://art/enemyWalking_2.png" type="Texture" id=5]
[ext_resource path="res://art/enemyFlyingAlt_1.png" type="Texture" id=6]
[ext_resource path="res://art/enemyFlyingAlt_2.png" type="Texture" id=7]
[ext_resource path="res://art/enemySwimming_1.png" type="Texture" id=6]
[ext_resource path="res://art/enemySwimming_2.png" type="Texture" id=7]
[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ ExtResource( 2 ), ExtResource( 3 ) ],
"loop": true,
"name": "swim",
"speed": 4.0
"name": "fly",
"speed": 3.0
}, {
"frames": [ ExtResource( 4 ), ExtResource( 5 ) ],
"loop": true,
@@ -23,12 +22,11 @@ animations = [ {
}, {
"frames": [ ExtResource( 6 ), ExtResource( 7 ) ],
"loop": true,
"name": "fly",
"speed": 3.0
"name": "swim",
"speed": 4.0
} ]
[sub_resource type="CapsuleShape2D" id=2]
radius = 35.2706
height = 23.3281
@@ -44,6 +42,7 @@ __meta__ = {
scale = Vector2( 0.75, 0.75 )
frames = SubResource( 1 )
animation = "walk"
frame = 1
playing = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
@@ -51,5 +50,4 @@ rotation = 1.5708
shape = SubResource( 2 )
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_screen_exited"]

View File

@@ -3,23 +3,18 @@ extends Area2D
signal hit
export var speed = 400
var extents
var screen_size
func _ready():
screen_size = get_viewport_rect().size
hide()
func _process(delta):
var velocity = Vector2()
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
if Input.is_action_pressed("ui_down"):
velocity.y += 1
velocity.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
velocity.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
if velocity.length() > 0:
velocity = velocity.normalized() * speed
$AnimatedSprite.play()
@@ -37,12 +32,14 @@ func _process(delta):
$AnimatedSprite.animation = "up"
$AnimatedSprite.flip_v = velocity.y > 0
func _on_Player_body_entered(body):
hide()
emit_signal("hit")
$CollisionShape2D.set_deferred("disabled", true)
func start(pos):
position = pos
show()
$CollisionShape2D.disabled = false
func _on_Player_body_entered(_body):
hide()
emit_signal("hit")
$CollisionShape2D.set_deferred("disabled", true)

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=13 format=2]
[ext_resource path="res://Player.gd" type="Script" id=1]
[ext_resource path="res://art/playerGrey_walk1.png" type="Texture" id=2]
@@ -23,7 +23,30 @@ animations = [ {
radius = 26.1701
height = 14.822
[sub_resource type="Gradient" id=3]
colors = PoolColorArray( 1, 1, 1, 0.501961, 1, 1, 1, 0 )
[sub_resource type="GradientTexture" id=4]
gradient = SubResource( 3 )
[sub_resource type="Curve" id=5]
_data = [ Vector2( 0.00501098, 0.5 ), 0.0, 0.0, 0, 0, Vector2( 0.994989, 0.324 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="CurveTexture" id=6]
curve = SubResource( 5 )
[sub_resource type="ParticlesMaterial" id=7]
flag_disable_z = true
gravity = Vector3( 0, 0, 0 )
initial_velocity = 1.0
orbit_velocity = 0.0
orbit_velocity_random = 0.0
scale = 0.75
scale_curve = SubResource( 6 )
color_ramp = SubResource( 4 )
[node name="Player" type="Area2D"]
z_index = 10
script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
@@ -37,4 +60,11 @@ animation = "right"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 2 )
[node name="Trail" type="Particles2D" parent="."]
z_index = -1
amount = 10
speed_scale = 2.0
local_coords = false
process_material = SubResource( 7 )
texture = ExtResource( 2 )
[connection signal="body_entered" from="." to="." method="_on_Player_body_entered"]

View File

@@ -5,4 +5,3 @@
[resource]
background_mode = 2
background_sky = SubResource( 1 )

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -24,6 +24,41 @@ config/icon="res://icon.png"
window/size/width=480
window/size/height=720
[input]
move_left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
]
}
move_right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
]
}
move_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
]
}
move_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
]
}
[rendering]
environment/default_environment="res://default_env.tres"

View File

@@ -1,19 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DodgeTheCreepsCS", "DodgeTheCreepsCS.csproj", "{7829C155-1795-447D-A78E-8775E3CF134E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Tools|Any CPU = Tools|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7829C155-1795-447D-A78E-8775E3CF134E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7829C155-1795-447D-A78E-8775E3CF134E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7829C155-1795-447D-A78E-8775E3CF134E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7829C155-1795-447D-A78E-8775E3CF134E}.Release|Any CPU.Build.0 = Release|Any CPU
{7829C155-1795-447D-A78E-8775E3CF134E}.Tools|Any CPU.ActiveCfg = Tools|Any CPU
{7829C155-1795-447D-A78E-8775E3CF134E}.Tools|Any CPU.Build.0 = Tools|Any CPU
EndGlobalSection
EndGlobal

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

View File

@@ -1,29 +0,0 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
config/name="DodgeTheCreepsCS"
run/main_scene="res://Main.tscn"
config/icon="res://icon.png"
[display]
window/size/width=480
window/size/height=720
[rendering]
environment/default_environment="res://default_env.tres"

View File

@@ -1,24 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7829C155-1795-447D-A78E-8775E3CF134E}</ProjectGuid>
<ProjectGuid>{0D99C680-A41E-4286-9B12-57CCAEA6DA97}</ProjectGuid>
<OutputType>Library</OutputType>
<OutputPath>.mono\temp\bin\$(Configuration)</OutputPath>
<RootNamespace>DodgeTheCreepsCS</RootNamespace>
<AssemblyName>DodgeTheCreepsCS</AssemblyName>
<OutputPath>.mono/temp/bin/$(Configuration)</OutputPath>
<RootNamespace>DodgetheCreepsC</RootNamespace>
<AssemblyName>Dodge the Creeps C#</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<BaseIntermediateOutputPath>.mono\temp\obj</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)\$(Configuration)</IntermediateOutputPath>
<ApiConfiguration Condition=" '$(Configuration)' != 'Release' ">Debug</ApiConfiguration>
<ApiConfiguration Condition=" '$(Configuration)' == 'Release' ">Release</ApiConfiguration>
<BaseIntermediateOutputPath>.mono/temp/obj</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)/$(Configuration)</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;</DefineConstants>
<DefineConstants>$(GodotDefineConstants);GODOT;DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
@@ -26,6 +24,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<DefineConstants>$(GodotDefineConstants);GODOT;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
@@ -34,19 +33,19 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;TOOLS;</DefineConstants>
<DefineConstants>$(GodotDefineConstants);GODOT;DEBUG;TOOLS;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="GodotSharp">
<HintPath>$(ProjectDir)/.mono/assemblies/GodotSharp.dll</HintPath>
<Private>False</Private>
<HintPath>$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/GodotSharp.dll</HintPath>
</Reference>
<Reference Include="GodotSharpEditor" Condition=" '$(Configuration)' == 'Tools' ">
<HintPath>$(ProjectDir)/.mono/assemblies/GodotSharpEditor.dll</HintPath>
<Private>False</Private>
<HintPath>$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/GodotSharpEditor.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
@@ -58,4 +57,4 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
</Project>

View File

@@ -0,0 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dodge the Creeps C#", "Dodge the Creeps C#.csproj", "{0D99C680-A41E-4286-9B12-57CCAEA6DA97}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Tools|Any CPU = Tools|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0D99C680-A41E-4286-9B12-57CCAEA6DA97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D99C680-A41E-4286-9B12-57CCAEA6DA97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D99C680-A41E-4286-9B12-57CCAEA6DA97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D99C680-A41E-4286-9B12-57CCAEA6DA97}.Release|Any CPU.Build.0 = Release|Any CPU
{0D99C680-A41E-4286-9B12-57CCAEA6DA97}.Tools|Any CPU.ActiveCfg = Tools|Any CPU
{0D99C680-A41E-4286-9B12-57CCAEA6DA97}.Tools|Any CPU.Build.0 = Tools|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -44,4 +44,4 @@ public class HUD : CanvasLayer
{
GetNode<Label>("MessageLabel").Hide();
}
}
}

View File

@@ -4,61 +4,33 @@
[ext_resource path="res://fonts/Xolonium-Regular.ttf" type="DynamicFontData" id=2]
[sub_resource type="DynamicFont" id=1]
size = 64
outline_size = 0
outline_color = Color( 1, 1, 1, 1 )
use_mipmaps = true
use_filter = false
font_data = ExtResource( 2 )
[sub_resource type="DynamicFont" id=2]
size = 64
outline_size = 0
outline_color = Color( 1, 1, 1, 1 )
use_mipmaps = true
use_filter = false
font_data = ExtResource( 2 )
[sub_resource type="DynamicFont" id=3]
size = 64
outline_size = 0
outline_color = Color( 1, 1, 1, 1 )
use_mipmaps = true
use_filter = false
font_data = ExtResource( 2 )
[node name="HUD" type="CanvasLayer"]
layer = 1
offset = Vector2( 0, 0 )
rotation = 0.0
scale = Vector2( 1, 1 )
transform = Transform2D( 1, 0, 0, 1, 0, 0 )
script = ExtResource( 1 )
[node name="ScoreLabel" type="Label" parent="."]
anchor_left = 0.5
anchor_top = 0.0
anchor_right = 0.5
anchor_bottom = 0.0
margin_left = -25.0
margin_right = 25.0
margin_bottom = 100.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
custom_fonts/font = SubResource( 1 )
text = "0
"
align = 1
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="MessageLabel" type="Label" parent="."]
anchor_left = 0.5
@@ -68,20 +40,11 @@ anchor_bottom = 0.5
margin_left = -200.0
margin_top = -150.0
margin_right = 200.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
custom_fonts/font = SubResource( 2 )
text = "Dodge the
Creeps!"
align = 1
valign = 1
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="StartButton" type="Button" parent="."]
anchor_left = 0.5
@@ -92,27 +55,11 @@ margin_left = -100.0
margin_top = -200.0
margin_right = 100.0
margin_bottom = -100.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_fonts/font = SubResource( 3 )
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = "Start"
flat = false
align = 1
[node name="MessageTimer" type="Timer" parent="."]
process_mode = 1
wait_time = 2.0
one_shot = true
autostart = false
[connection signal="pressed" from="StartButton" to="." method="OnStartButtonPressed"]
[connection signal="timeout" from="MessageTimer" to="." method="OnMessageTimerTimeout"]

View File

@@ -4,17 +4,13 @@ using System;
public class Main : Node
{
[Export]
public PackedScene Mob;
public PackedScene mob;
private int _score;
// We use 'System.Random' as an alternative to GDScript's random methods.
private Random _random = new Random();
public override void _Ready()
{
}
// We'll use this later because C# doesn't support GDScript's randi().
private float RandRange(float min, float max)
{
@@ -64,12 +60,16 @@ public class Main : Node
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 RigidBody2D, since they appear later on the line.
// Choose a random location on Path2D.
var mobSpawnLocation = GetNode<PathFollow2D>("MobPath/MobSpawnLocation");
mobSpawnLocation.SetOffset(_random.Next());
// Create a Mob instance and add it to the scene.
var mobInstance = (RigidBody2D)Mob.Instance();
var mobInstance = (RigidBody2D)mob.Instance();
AddChild(mobInstance);
// Set the mob's direction perpendicular to the path direction.

View File

@@ -14,12 +14,12 @@ _data = {
[node name="Main" type="Node"]
script = ExtResource( 1 )
Mob = ExtResource( 2 )
mob = ExtResource( 2 )
[node name="ColorRect" type="ColorRect" parent="."]
margin_right = 480.0
margin_bottom = 720.0
color = Color( 0.253451, 0.425288, 0.429412, 1 )
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.219608, 0.372549, 0.380392, 1 )
[node name="Player" parent="." instance=ExtResource( 3 )]
@@ -47,7 +47,6 @@ stream = ExtResource( 5 )
[node name="DeathSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 6 )
[connection signal="Hit" from="Player" to="." method="GameOver"]
[connection signal="timeout" from="MobTimer" to="." method="OnMobTimerTimeout"]
[connection signal="timeout" from="ScoreTimer" to="." method="OnScoreTimerTimeout"]

View File

@@ -4,16 +4,15 @@ using System;
public class Mob : RigidBody2D
{
[Export]
public int MinSpeed; // Minimum speed range.
public int minSpeed; // Minimum speed range.
[Export]
public int MaxSpeed; // Maximum speed range.
public int maxSpeed; // Maximum speed range.
private String[] _mobTypes = {"walk", "swim", "fly"};
private String[] _mobTypes = { "walk", "swim", "fly" };
// C# doesn't implement GDScript's random methods, so we use 'System.Random'
// as an alternative.
static private Random _random = new Random();
// C# doesn't have GDScript's random methods, so we use System.Random insetad.
private static Random _random = new Random();
public override void _Ready()
{
@@ -24,5 +23,4 @@ public class Mob : RigidBody2D
{
QueueFree();
}
}

View File

@@ -9,7 +9,6 @@
[ext_resource path="res://art/enemyFlyingAlt_2.png" type="Texture" id=7]
[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ ExtResource( 2 ), ExtResource( 3 ) ],
"loop": true,
@@ -28,39 +27,24 @@ animations = [ {
} ]
[sub_resource type="CapsuleShape2D" id=2]
custom_solver_bias = 0.0
radius = 35.8898
height = 29.3103
[node name="Mob" type="RigidBody2D"]
input_pickable = false
collision_layer = 1
collision_mask = 0
mode = 0
mass = 1.0
gravity_scale = 0.0
custom_integrator = false
continuous_cd = 0
contacts_reported = 0
contact_monitor = false
sleeping = false
can_sleep = true
linear_velocity = Vector2( 0, 0 )
linear_damp = -1.0
angular_velocity = 0.0
angular_damp = -1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
MinSpeed = 150
MaxSpeed = 250
minSpeed = 150
maxSpeed = 250
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
scale = Vector2( 0.75, 0.75 )
frames = SubResource( 1 )
animation = "walk"
frame = 1
playing = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
@@ -70,6 +54,4 @@ shape = SubResource( 2 )
[node name="Visibility" type="VisibilityNotifier2D" parent="."]
position = Vector2( -0.315128, -9.53674e-07 )
scale = Vector2( 5.00208, 3.58402 )
rect = Rect2( -10, -10, 20, 20 )
[connection signal="screen_exited" from="Visibility" to="." method="OnVisibilityScreenExited"]

View File

@@ -1,5 +1,4 @@
using Godot;
using System;
public class Player : Area2D
{
@@ -7,46 +6,27 @@ public class Player : Area2D
public delegate void Hit();
[Export]
public int Speed; // How fast the player will move (pixels/sec).
public int speed; // How fast the player will move (pixels/sec).
private Vector2 _screenSize; // Size of the game window.
public override void _Ready()
{
_screenSize = GetViewport().GetSize();
Hide();
}
public override void _Process(float delta)
{
var velocity = new Vector2(); // The player's movement vector.
if (Input.IsActionPressed("ui_right"))
{
velocity.x += 1;
}
if (Input.IsActionPressed("ui_left"))
{
velocity.x -= 1;
}
if (Input.IsActionPressed("ui_down"))
{
velocity.y += 1;
}
if (Input.IsActionPressed("ui_up"))
{
velocity.y -= 1;
}
Vector2 velocity; // The player's movement vector.
velocity.x = Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left");
velocity.y = Input.GetActionStrength("move_down") - Input.GetActionStrength("move_up");
var animatedSprite = GetNode<AnimatedSprite>("AnimatedSprite");
if (velocity.Length() > 0)
{
velocity = velocity.Normalized() * Speed;
velocity = velocity.Normalized() * speed;
animatedSprite.Play();
}
else
@@ -63,11 +43,11 @@ public class Player : Area2D
if (velocity.x != 0)
{
animatedSprite.Animation = "right";
// See the note below about boolean assignment
// See the note below about boolean assignment.
animatedSprite.FlipH = velocity.x < 0;
animatedSprite.FlipV = false;
}
else if(velocity.y != 0)
else if (velocity.y != 0)
{
animatedSprite.Animation = "up";
animatedSprite.FlipV = velocity.y > 0;
@@ -78,7 +58,7 @@ public class Player : Area2D
{
Position = pos;
Show();
// Must be deferred as we can't change physics properties on a physics callback
// Must be deferred as we can't change physics properties on a physics callback.
GetNode<CollisionShape2D>("CollisionShape2D").SetDeferred("Disabled", false);
}
@@ -86,7 +66,7 @@ public class Player : Area2D
{
Hide(); // Player disappears after being hit.
EmitSignal("Hit");
// Must be deferred as we can't change physics properties on a physics callback
// Must be deferred as we can't change physics properties on a physics callback.
GetNode<CollisionShape2D>("CollisionShape2D").SetDeferred("Disabled", true);
}
}

View File

@@ -7,7 +7,6 @@
[ext_resource path="res://art/playerGrey_up2.png" type="Texture" id=5]
[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ ExtResource( 2 ), ExtResource( 3 ) ],
"loop": true,
@@ -21,87 +20,38 @@ animations = [ {
} ]
[sub_resource type="CapsuleShape2D" id=2]
custom_solver_bias = 0.0
radius = 27.3777
height = 14.0303
[sub_resource type="Gradient" id=3]
offsets = PoolRealArray( 0, 1 )
colors = PoolColorArray( 1, 1, 1, 0.501961, 1, 1, 1, 0 )
[sub_resource type="GradientTexture" id=4]
flags = 4
gradient = SubResource( 3 )
width = 2048
[sub_resource type="Curve" id=6]
min_value = 0.0
max_value = 1.0
bake_resolution = 100
[sub_resource type="Curve" id=5]
_data = [ Vector2( 0.00451484, 0.5176 ), 0.0, 0.0, 0, 0, Vector2( 0.98702, 0.3152 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="CurveTexture" id=7]
[sub_resource type="CurveTexture" id=6]
curve = SubResource( 5 )
flags = 4
width = 2048
curve = SubResource( 6 )
[sub_resource type="ParticlesMaterial" id=5]
render_priority = 0
trail_divisor = 1
emission_shape = 0
flag_align_y = false
flag_rotate_y = false
[sub_resource type="ParticlesMaterial" id=7]
flag_disable_z = true
spread = 45.0
flatness = 0.0
gravity = Vector3( 0, 0, 0 )
initial_velocity = 1.0
initial_velocity_random = 0.0
angular_velocity = 0.0
angular_velocity_random = 0.0
orbit_velocity = 0.0
orbit_velocity_random = 0.0
linear_accel = 0.0
linear_accel_random = 0.0
radial_accel = 0.0
radial_accel_random = 0.0
tangential_accel = 0.0
tangential_accel_random = 0.0
damping = 0.0
damping_random = 0.0
angle = 0.0
angle_random = 0.0
scale = 1.0
scale_random = 0.0
scale_curve = SubResource( 7 )
scale = 0.75
scale_curve = SubResource( 6 )
color_ramp = SubResource( 4 )
hue_variation = 0.0
hue_variation_random = 0.0
anim_speed = 0.0
anim_speed_random = 0.0
anim_offset = 0.0
anim_offset_random = 0.0
anim_loop = false
[node name="Player" type="Area2D"]
input_pickable = true
gravity_vec = Vector2( 0, 1 )
gravity = 98.0
linear_damp = 0.1
angular_damp = 1.0
audio_bus_override = false
audio_bus_name = "Master"
z_index = 10
script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
Speed = 400
speed = 400
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
scale = Vector2( 0.5, 0.5 )
@@ -113,22 +63,10 @@ shape = SubResource( 2 )
[node name="Trail" type="Particles2D" parent="."]
show_behind_parent = true
emitting = true
z_index = -1
amount = 10
lifetime = 1.0
one_shot = false
preprocess = 0.0
speed_scale = 2.0
explosiveness = 0.0
randomness = 0.0
fixed_fps = 0
fract_delta = true
visibility_rect = Rect2( -100, -100, 200, 200 )
local_coords = false
process_material = SubResource( 5 )
process_material = SubResource( 7 )
texture = ExtResource( 2 )
normal_map = null
h_frames = 1
v_frames = 1
[connection signal="body_entered" from="." to="." method="OnPlayerBodyEntered"]

View File

@@ -3,7 +3,7 @@ using System.Reflection;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("DodgeTheCreepsCS")]
[assembly: AssemblyTitle("Dodge the Creeps C#")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@@ -9,4 +9,3 @@ ground_horizon_color = Color( 0.423529, 0.396078, 0.372549, 1 )
[resource]
background_mode = 2
background_sky = SubResource( 1 )

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,64 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
config/name="Dodge the Creeps C#"
run/main_scene="res://Main.tscn"
config/icon="res://icon.png"
[display]
window/size/width=480
window/size/height=720
[input]
move_left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
]
}
move_right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
]
}
move_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
]
}
move_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
]
}
[rendering]
environment/default_environment="res://default_env.tres"

View File

@@ -1,29 +0,0 @@
using Godot;
using System;
public class Ball : Area2D
{
private const int BallSpeed = 100;
private int speed = BallSpeed;
private Vector2 initialPos;
public Vector2 direction = new Vector2(-1, 0);
public void Reset()
{
SetPosition(initialPos);
speed = BallSpeed;
direction = new Vector2(-1, 0);
}
public override void _Ready()
{
initialPos = Position;
}
public override void _Process(float delta)
{
Position += direction * speed * delta;
}
}

View File

@@ -1,34 +0,0 @@
using Godot;
using System;
public class Paddle : Area2D
{
[Export]
private int ballDir = 1;
private const int MoveSpeed = 100;
public override void _Process(float delta)
{
String which = GetName();
// Move up and down based on input
if (Input.IsActionPressed(which + "_move_up") && Position.y > 0)
{
Position -= new Vector2(0, MoveSpeed * delta);
}
if (Input.IsActionPressed(which + "_move_down") && Position.y < GetViewportRect().Size.y)
{
Position += new Vector2(0, MoveSpeed * delta);
}
}
public void OnAreaEntered(Area2D area)
{
if (area is Ball ball)
{
// Assign new direction
ball.direction = new Vector2(ballDir, (float)new Random().NextDouble() * 2 - 1).Normalized();
}
}
}

View File

@@ -1,95 +0,0 @@
[gd_scene load_steps=13 format=2]
[ext_resource path="res://Paddle.cs" type="Script" id=1]
[ext_resource path="res://left_pallete.png" type="Texture" id=2]
[ext_resource path="res://right_pallete.png" type="Texture" id=3]
[ext_resource path="res://Ball.cs" type="Script" id=4]
[ext_resource path="res://ball.png" type="Texture" id=5]
[ext_resource path="res://separator.png" type="Texture" id=6]
[ext_resource path="res://Wall.cs" type="Script" id=7]
[ext_resource path="res://CeilingFloor.cs" type="Script" id=8]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 4, 16 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 4, 4 )
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 10, 200 )
[sub_resource type="RectangleShape2D" id=4]
extents = Vector2( 320, 10 )
[node name="game" type="Node2D"]
[node name="left" type="Area2D" parent="."]
position = Vector2( 67.6285, 192.594 )
script = ExtResource( 1 )
[node name="sprite" type="Sprite" parent="left"]
texture = ExtResource( 2 )
[node name="collision" type="CollisionShape2D" parent="left"]
shape = SubResource( 1 )
[node name="right" type="Area2D" parent="."]
position = Vector2( 563.815, 188.919 )
script = ExtResource( 1 )
ballDir = -1
[node name="sprite" type="Sprite" parent="right"]
texture = ExtResource( 3 )
[node name="collision" type="CollisionShape2D" parent="right"]
shape = SubResource( 1 )
[node name="ball" type="Area2D" parent="."]
position = Vector2( 320.5, 191.124 )
script = ExtResource( 4 )
[node name="sprite" type="Sprite" parent="ball"]
texture = ExtResource( 5 )
[node name="collision" type="CollisionShape2D" parent="ball"]
shape = SubResource( 2 )
[node name="separator" type="Sprite" parent="."]
position = Vector2( 320, 200 )
texture = ExtResource( 6 )
[node name="left_wall" type="Area2D" parent="."]
position = Vector2( -10, 200 )
script = ExtResource( 7 )
[node name="collision" type="CollisionShape2D" parent="left_wall"]
shape = SubResource( 3 )
[node name="right_wall" type="Area2D" parent="."]
position = Vector2( 650, 200 )
script = ExtResource( 7 )
[node name="collision" type="CollisionShape2D" parent="right_wall"]
shape = SubResource( 3 )
[node name="ceiling" type="Area2D" parent="."]
position = Vector2( 320, -10 )
script = ExtResource( 8 )
[node name="collision" type="CollisionShape2D" parent="ceiling"]
shape = SubResource( 4 )
[node name="floor" type="Area2D" parent="."]
position = Vector2( 320, 410 )
script = ExtResource( 8 )
yDirection = -1
[node name="collision" type="CollisionShape2D" parent="floor"]
shape = SubResource( 4 )
[connection signal="area_entered" from="left" to="left" method="OnAreaEntered"]
[connection signal="area_entered" from="right" to="right" method="OnAreaEntered"]
[connection signal="area_entered" from="left_wall" to="left_wall" method="OnWallAreaEntered"]
[connection signal="area_entered" from="right_wall" to="right_wall" method="OnWallAreaEntered"]
[connection signal="area_entered" from="ceiling" to="ceiling" method="OnAreaEntered"]
[connection signal="area_entered" from="floor" to="floor" method="OnAreaEntered"]

View File

@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4F9320CC-07E9-4CEA-AA42-A32C83303312}</ProjectGuid>
<ProjectGuid>{EBA5981B-C37E-48C5-A3B6-4390D9834F9A}</ProjectGuid>
<OutputType>Library</OutputType>
<OutputPath>.mono/temp/bin/$(Configuration)</OutputPath>
<RootNamespace>Pong with C#</RootNamespace>
<RootNamespace>PongwithC</RootNamespace>
<AssemblyName>Pong with C#</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<BaseIntermediateOutputPath>.mono/temp/obj</BaseIntermediateOutputPath>
@@ -14,25 +14,26 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;</DefineConstants>
<DefineConstants>$(GodotDefineConstants);GODOT;DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<DefineConstants>$(GodotDefineConstants);GODOT;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Tools|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;TOOLS;</DefineConstants>
<DefineConstants>$(GodotDefineConstants);GODOT;DEBUG;TOOLS;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
@@ -49,11 +50,11 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Ball.cs" />
<Compile Include="CeilingFloor.cs" />
<Compile Include="Paddle.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Wall.cs" />
<Compile Include="Scripts\Ball.cs" />
<Compile Include="Scripts\CeilingFloor.cs" />
<Compile Include="Scripts\Paddle.cs" />
<Compile Include="Scripts\Wall.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pong with C#", "Pong with C#.csproj", "{4F9320CC-07E9-4CEA-AA42-A32C83303312}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pong with C#", "Pong with C#.csproj", "{EBA5981B-C37E-48C5-A3B6-4390D9834F9A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -9,11 +9,11 @@ Global
Tools|Any CPU = Tools|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4F9320CC-07E9-4CEA-AA42-A32C83303312}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F9320CC-07E9-4CEA-AA42-A32C83303312}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F9320CC-07E9-4CEA-AA42-A32C83303312}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F9320CC-07E9-4CEA-AA42-A32C83303312}.Release|Any CPU.Build.0 = Release|Any CPU
{4F9320CC-07E9-4CEA-AA42-A32C83303312}.Tools|Any CPU.ActiveCfg = Tools|Any CPU
{4F9320CC-07E9-4CEA-AA42-A32C83303312}.Tools|Any CPU.Build.0 = Tools|Any CPU
{EBA5981B-C37E-48C5-A3B6-4390D9834F9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EBA5981B-C37E-48C5-A3B6-4390D9834F9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EBA5981B-C37E-48C5-A3B6-4390D9834F9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EBA5981B-C37E-48C5-A3B6-4390D9834F9A}.Release|Any CPU.Build.0 = Release|Any CPU
{EBA5981B-C37E-48C5-A3B6-4390D9834F9A}.Tools|Any CPU.ActiveCfg = Tools|Any CPU
{EBA5981B-C37E-48C5-A3B6-4390D9834F9A}.Tools|Any CPU.Build.0 = Tools|Any CPU
EndGlobalSection
EndGlobal

26
mono/pong/Scripts/Ball.cs Normal file
View File

@@ -0,0 +1,26 @@
using Godot;
public class Ball : Area2D
{
private const int BallSpeed = 100;
public Vector2 direction = Vector2.Left;
private Vector2 _initialPos;
public void Reset()
{
Position = _initialPos;
direction = Vector2.Left;
}
public override void _Ready()
{
_initialPos = Position;
}
public override void _Process(float delta)
{
Position += BallSpeed * delta * direction;
}
}

View File

@@ -1,16 +1,15 @@
using Godot;
using System;
public class CeilingFloor : Area2D
{
[Export]
private int yDirection = 1;
private int _bounceDirection = 1;
public void OnAreaEntered(Area2D area)
{
if (area is Ball ball)
{
ball.direction += new Vector2(0, yDirection);
ball.direction = (ball.direction + new Vector2(0, _bounceDirection)).Normalized();
}
}
}

View File

@@ -0,0 +1,39 @@
using Godot;
using System;
public class Paddle : Area2D
{
private const int MoveSpeed = 100;
// All three of these change for each paddle.
private int _ballDir;
private string _up;
private string _down;
public override void _Ready()
{
string name = Name.ToLower();
_up = name + "_move_up";
_down = name + "_move_down";
_ballDir = name == "left" ? 1 : -1;
}
public override void _Process(float delta)
{
// Move up and down based on input.
float input = Input.GetActionStrength(_down) - Input.GetActionStrength(_up);
Vector2 position = Position; // Required so that we can modify position.y.
position += new Vector2(0, input * MoveSpeed * delta);
position.y = Mathf.Clamp(position.y, 16, GetViewportRect().Size.y - 16);
Position = position;
}
public void OnAreaEntered(Area2D area)
{
if (area is Ball ball)
{
// Assign new direction
ball.direction = new Vector2(_ballDir, ((float)new Random().NextDouble()) * 2 - 1).Normalized();
}
}
}

View File

@@ -1,5 +1,4 @@
using Godot;
using System;
public class Wall : Area2D
{
@@ -7,7 +6,7 @@ public class Wall : Area2D
{
if (area is Ball ball)
{
// Oops, ball went out of game place, reset
// Ball went off the side of the screen, reset it.
ball.Reset();
}
}

View File

Before

Width:  |  Height:  |  Size: 149 B

After

Width:  |  Height:  |  Size: 149 B

View File

@@ -3,16 +3,21 @@
importer="texture"
type="StreamTexture"
path="res://.import/ball.png-9a4ca347acb7532f6ae347744a6b04f7.stex"
metadata={
"vram_texture": false
}
[deps]
source_md5="4219e9084f5485c8d1812297700f317d"
source_file="res://ball.png"
dest_files=[ "res://.import/ball.png-9a4ca347acb7532f6ae347744a6b04f7.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
@@ -22,6 +27,7 @@ flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true

View File

Before

Width:  |  Height:  |  Size: 583 B

After

Width:  |  Height:  |  Size: 583 B

View File

@@ -3,16 +3,21 @@
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]
source_md5="9be177e863d37787c0836d64924b3503"
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
@@ -22,6 +27,7 @@ flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true

View File

Before

Width:  |  Height:  |  Size: 138 B

After

Width:  |  Height:  |  Size: 138 B

View File

@@ -3,16 +3,21 @@
importer="texture"
type="StreamTexture"
path="res://.import/left_pallete.png-bc33611074a0f886142e37c77bd2545a.stex"
metadata={
"vram_texture": false
}
[deps]
source_md5="df76627349499ad47ebf48a7ca947cca"
source_file="res://left_pallete.png"
dest_files=[ "res://.import/left_pallete.png-bc33611074a0f886142e37c77bd2545a.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
@@ -22,6 +27,7 @@ flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true

95
mono/pong/pong.tscn Normal file
View File

@@ -0,0 +1,95 @@
[gd_scene load_steps=13 format=2]
[ext_resource path="res://Scripts/Paddle.cs" type="Script" id=1]
[ext_resource path="res://left_pallete.png" type="Texture" id=2]
[ext_resource path="res://right_pallete.png" type="Texture" id=3]
[ext_resource path="res://Scripts/Ball.cs" type="Script" id=4]
[ext_resource path="res://ball.png" type="Texture" id=5]
[ext_resource path="res://separator.png" type="Texture" id=6]
[ext_resource path="res://Scripts/Wall.cs" type="Script" id=7]
[ext_resource path="res://Scripts/CeilingFloor.cs" type="Script" id=8]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 4, 16 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 4, 4 )
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 10, 200 )
[sub_resource type="RectangleShape2D" id=4]
extents = Vector2( 320, 10 )
[node name="Pong" type="Node2D"]
[node name="Left" type="Area2D" parent="."]
position = Vector2( 67.6285, 192.594 )
script = ExtResource( 1 )
[node name="Sprite" type="Sprite" parent="Left"]
texture = ExtResource( 2 )
[node name="Collision" type="CollisionShape2D" parent="Left"]
shape = SubResource( 1 )
[node name="Right" type="Area2D" parent="."]
position = Vector2( 563.815, 188.919 )
script = ExtResource( 1 )
[node name="Sprite" type="Sprite" parent="Right"]
texture = ExtResource( 3 )
[node name="Collision" type="CollisionShape2D" parent="Right"]
shape = SubResource( 1 )
[node name="Ball" type="Area2D" parent="."]
position = Vector2( 320.5, 191.124 )
script = ExtResource( 4 )
[node name="Sprite" type="Sprite" parent="Ball"]
texture = ExtResource( 5 )
[node name="Collision" type="CollisionShape2D" parent="Ball"]
shape = SubResource( 2 )
[node name="Separator" type="Sprite" parent="."]
position = Vector2( 320, 200 )
texture = ExtResource( 6 )
[node name="Node2D" type="Node2D" parent="."]
[node name="LeftWall" type="Area2D" parent="."]
position = Vector2( -10, 200 )
script = ExtResource( 7 )
[node name="Collision" type="CollisionShape2D" parent="LeftWall"]
shape = SubResource( 3 )
[node name="RightWall" type="Area2D" parent="."]
position = Vector2( 650, 200 )
script = ExtResource( 7 )
[node name="Collision" type="CollisionShape2D" parent="RightWall"]
shape = SubResource( 3 )
[node name="Ceiling" type="Area2D" parent="."]
position = Vector2( 320, -10 )
script = ExtResource( 8 )
[node name="Collision" type="CollisionShape2D" parent="Ceiling"]
shape = SubResource( 4 )
[node name="Floor" type="Area2D" parent="."]
position = Vector2( 320, 410 )
script = ExtResource( 8 )
_bounceDirection = -1
[node name="Collision" type="CollisionShape2D" parent="Floor"]
shape = SubResource( 4 )
[connection signal="area_entered" from="Left" to="Left" method="OnAreaEntered"]
[connection signal="area_entered" from="Right" to="Right" method="OnAreaEntered"]
[connection signal="area_entered" from="LeftWall" to="LeftWall" method="OnWallAreaEntered"]
[connection signal="area_entered" from="RightWall" to="RightWall" method="OnWallAreaEntered"]
[connection signal="area_entered" from="Ceiling" to="Ceiling" method="OnAreaEntered"]
[connection signal="area_entered" from="Floor" to="Floor" method="OnAreaEntered"]

View File

@@ -35,21 +35,29 @@ singletons=[ ]
left_move_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
]
}
left_move_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
]
}
right_move_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":1,"axis_value":1.0,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
]
}
right_move_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":1,"axis_value":-1.0,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
]
}

View File

Before

Width:  |  Height:  |  Size: 138 B

After

Width:  |  Height:  |  Size: 138 B

View File

@@ -3,16 +3,21 @@
importer="texture"
type="StreamTexture"
path="res://.import/right_pallete.png-fc6e4a6a7c8197834656482b94708e47.stex"
metadata={
"vram_texture": false
}
[deps]
source_md5="d46f647d3f045dbee4d786089c309868"
source_file="res://right_pallete.png"
dest_files=[ "res://.import/right_pallete.png-fc6e4a6a7c8197834656482b94708e47.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
@@ -22,6 +27,7 @@ flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true

View File

Before

Width:  |  Height:  |  Size: 142 B

After

Width:  |  Height:  |  Size: 142 B

View File

@@ -3,16 +3,21 @@
importer="texture"
type="StreamTexture"
path="res://.import/separator.png-f981c8489b9148e2e1dc63398273da74.stex"
metadata={
"vram_texture": false
}
[deps]
source_md5="b6234b89455156532bbe1256249fcfd4"
source_file="res://separator.png"
dest_files=[ "res://.import/separator.png-f981c8489b9148e2e1dc63398273da74.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
@@ -22,6 +27,7 @@ flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true