-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
554 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Godot-specific ignores | ||
.import/ | ||
export.cfg | ||
export_presets.cfg | ||
|
||
# Mono-specific ignores | ||
.mono/ | ||
data_*/ | ||
|
||
# System/tool-specific ignores | ||
.directory | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Godot; | ||
|
||
public class Ball : Area2D | ||
{ | ||
|
||
[Export] | ||
private int speed = 250; | ||
[Export] | ||
private Vector2 initialPosition = new Vector2(512, 300); | ||
[Export] | ||
private Vector2 initialDirection = new Vector2(-1, 0); | ||
private Vector2 currentPosition; | ||
public Vector2 currentDirection { get; set; } | ||
|
||
public override void _Ready() | ||
{ | ||
Reset(); | ||
} | ||
|
||
public void Reset() | ||
{ | ||
this.currentPosition = initialPosition; | ||
this.currentDirection = initialDirection; | ||
} | ||
|
||
public override void _Process(float delta) | ||
{ | ||
this.currentPosition += currentDirection * speed * delta; | ||
|
||
SetPosition(this.currentPosition); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Godot; | ||
|
||
public class Exit : Area2D | ||
{ | ||
|
||
public void OnExitAreaEntered(Area2D area) | ||
{ | ||
if (area.GetName().Equals("ball")) | ||
{ | ||
Ball ball = area as Ball; | ||
ball.Reset(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Godot; | ||
using System; | ||
|
||
public class Paddle : Area2D | ||
{ | ||
|
||
private static readonly String INPUT_MOVE_UP_SUFFIX = "MoveUp"; | ||
private static readonly String INPUT_MOVE_DOWN_SUFFIX = "MoveDown"; | ||
[Export] | ||
private int speed = 250; | ||
[Export] | ||
private int ballDirection = 1; | ||
private RandomNumberGenerator randomNumberGenerator; | ||
public override void _Ready() | ||
{ | ||
this.randomNumberGenerator = new RandomNumberGenerator(); | ||
} | ||
|
||
public override void _Process(float delta) | ||
{ | ||
String name = GetName(); | ||
Vector2 currentPosition = GetPosition(); | ||
|
||
if (Input.IsActionPressed(name + INPUT_MOVE_UP_SUFFIX) && currentPosition.y > 40) | ||
{ | ||
currentPosition = new Vector2(currentPosition.x, currentPosition.y - speed * delta); | ||
} | ||
|
||
if (Input.IsActionPressed(name + INPUT_MOVE_DOWN_SUFFIX) && currentPosition.y < 560) | ||
{ | ||
currentPosition = new Vector2(currentPosition.x, currentPosition.y + speed * delta); | ||
} | ||
|
||
SetPosition(currentPosition); | ||
} | ||
|
||
public void OnPaddleAreaEntered(Area2D area) | ||
{ | ||
if (area.GetName().Equals("ball")) | ||
{ | ||
Ball ball = area as Ball; | ||
Vector2 newDirection = new Vector2(ballDirection, this.randomNumberGenerator.Randf() * 2 - 1).Normalized(); | ||
ball.currentDirection = newDirection; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
[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://Exit.cs" type="Script" id=6] | ||
[ext_resource path="res://Wall.cs" type="Script" id=7] | ||
[ext_resource path="res://separator.png" type="Texture" id=8] | ||
|
||
[sub_resource type="RectangleShape2D" id=1] | ||
extents = Vector2( 4, 16 ) | ||
|
||
[sub_resource type="CircleShape2D" id=2] | ||
radius = 5.0 | ||
|
||
[sub_resource type="RectangleShape2D" id=3] | ||
extents = Vector2( 5, 300 ) | ||
|
||
[sub_resource type="RectangleShape2D" id=4] | ||
extents = Vector2( 512, 5 ) | ||
|
||
[node name="Pong" type="Node2D"] | ||
|
||
[node name="leftPaddle" type="Area2D" parent="."] | ||
position = Vector2( 100, 300 ) | ||
script = ExtResource( 1 ) | ||
|
||
[node name="Sprite" type="Sprite" parent="leftPaddle"] | ||
scale = Vector2( 1, 2 ) | ||
texture = ExtResource( 2 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="leftPaddle"] | ||
scale = Vector2( 1, 2 ) | ||
shape = SubResource( 1 ) | ||
|
||
[node name="rightPaddle" type="Area2D" parent="."] | ||
position = Vector2( 924, 300 ) | ||
script = ExtResource( 1 ) | ||
ballDirection = -1 | ||
|
||
[node name="Sprite" type="Sprite" parent="rightPaddle"] | ||
scale = Vector2( 1, 2 ) | ||
texture = ExtResource( 3 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="rightPaddle"] | ||
scale = Vector2( 1, 2 ) | ||
shape = SubResource( 1 ) | ||
|
||
[node name="ball" type="Area2D" parent="."] | ||
position = Vector2( 512, 300 ) | ||
script = ExtResource( 4 ) | ||
|
||
[node name="Sprite" type="Sprite" parent="ball"] | ||
scale = Vector2( 2, 2 ) | ||
texture = ExtResource( 5 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="ball"] | ||
scale = Vector2( 2, 2 ) | ||
shape = SubResource( 2 ) | ||
|
||
[node name="leftExit" type="Area2D" parent="."] | ||
position = Vector2( 0, 300 ) | ||
script = ExtResource( 6 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="leftExit"] | ||
shape = SubResource( 3 ) | ||
|
||
[node name="rightExit" type="Area2D" parent="."] | ||
position = Vector2( 1024, 300 ) | ||
script = ExtResource( 6 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="rightExit"] | ||
shape = SubResource( 3 ) | ||
|
||
[node name="topWall" type="Area2D" parent="."] | ||
position = Vector2( 512, 0 ) | ||
script = ExtResource( 7 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="topWall"] | ||
shape = SubResource( 4 ) | ||
|
||
[node name="bottomWall" type="Area2D" parent="."] | ||
position = Vector2( 512, 600 ) | ||
script = ExtResource( 7 ) | ||
yDirection = -1 | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="bottomWall"] | ||
shape = SubResource( 4 ) | ||
|
||
[node name="separator" type="Sprite" parent="."] | ||
position = Vector2( 512, 300 ) | ||
scale = Vector2( 1, 1.5 ) | ||
texture = ExtResource( 8 ) | ||
[connection signal="area_entered" from="leftPaddle" to="leftPaddle" method="OnPaddleAreaEntered"] | ||
[connection signal="area_entered" from="rightPaddle" to="rightPaddle" method="OnPaddleAreaEntered"] | ||
[connection signal="area_entered" from="leftExit" to="leftExit" method="OnExitAreaEntered"] | ||
[connection signal="area_entered" from="rightExit" to="rightExit" method="OnExitAreaEntered"] | ||
[connection signal="area_entered" from="topWall" to="topWall" method="OnWallAreaEntered"] | ||
[connection signal="area_entered" from="bottomWall" to="bottomWall" method="OnWallAreaEntered"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Reflection; | ||
|
||
// Information about this assembly is defined by the following attributes. | ||
// Change them to the values specific to your project. | ||
|
||
[assembly: AssemblyTitle("pong-cs")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("")] | ||
[assembly: AssemblyCopyright("")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". | ||
// The form "{Major}.{Minor}.*" will automatically update the build and revision, | ||
// and "{Major}.{Minor}.{Build}.*" will update just the revision. | ||
|
||
[assembly: AssemblyVersion("1.0.*")] | ||
|
||
// The following attributes are used to specify the signing key for the assembly, | ||
// if desired. See the Mono documentation for more information about signing. | ||
|
||
//[assembly: AssemblyDelaySign(false)] | ||
//[assembly: AssemblyKeyFile("")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# pong-cs | ||
Pong CS | ||
|
||
C# Godot translation of the following Godot example: https://godotengine.org/asset-library/asset/121 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Godot; | ||
|
||
public class Wall : Area2D | ||
{ | ||
|
||
[Export] | ||
private int yDirection = 1; | ||
public void OnWallAreaEntered(Area2D area) | ||
{ | ||
if (area.GetName().Equals("ball")) | ||
{ | ||
Ball ball = area as Ball; | ||
ball.currentDirection = new Vector2(ball.currentDirection.x, yDirection); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/ball.png-9a4ca347acb7532f6ae347744a6b04f7.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
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 | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
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 | ||
svg/scale=1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[gd_resource type="Environment" load_steps=2 format=2] | ||
|
||
[sub_resource type="ProceduralSky" id=1] | ||
|
||
[resource] | ||
background_mode = 2 | ||
background_sky = SubResource( 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
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 | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
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 | ||
svg/scale=1.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/left_pallete.png-bc33611074a0f886142e37c77bd2545a.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
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 | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
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 | ||
svg/scale=1.0 |
Oops, something went wrong.