Initial commit

This commit is contained in:
2022-04-21 20:06:30 -04:00
parent 4aa6a5cabe
commit d422f172a1
41 changed files with 835 additions and 0 deletions

13
src/Actors/Actor.gd Normal file
View File

@ -0,0 +1,13 @@
extends KinematicBody2D
class_name Actor
export var speed: = Vector2(0, 0)
var _velocity: = Vector2.ZERO
var _direction: = Vector2.ZERO
func calculate_move_velocity(linear_velocity: Vector2, direction: Vector2, current_speed: Vector2) -> Vector2:
var move_velocity: = linear_velocity
move_velocity = current_speed * direction
return move_velocity

30
src/Actors/Ball.gd Normal file
View File

@ -0,0 +1,30 @@
extends Actor
export var top_speed: = 1000
func _ready() -> void:
randomize()
_direction.x = random_direction()
_direction.y = randf() * random_direction()
func _physics_process(_delta: float) -> void:
_velocity = calculate_move_velocity(_velocity, _direction, speed)
_velocity = move_and_slide(_velocity)
func _on_BounceCheck_body_entered(body: PhysicsBody2D) -> void:
bounce(body)
func bounce(object: PhysicsBody2D) -> void:
if speed.x <= top_speed:
speed.x *= 1.1
if object is Actor:
_direction.x = -_direction.x
$"SFX/BounceSound-2".play()
else:
_direction.y *= -1
$"SFX/BounceSound-1".play()
func random_direction() -> int:
var directions:= [-1, 1]
return directions[randi() % directions.size()]

42
src/Actors/Ball.tscn Normal file
View File

@ -0,0 +1,42 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://src/Actors/Ball.gd" type="Script" id=1]
[ext_resource path="res://assets/Ball.png" type="Texture" id=2]
[ext_resource path="res://assets/bounce_sfx-01.ogg" type="AudioStream" id=3]
[ext_resource path="res://assets/bounce_sfx-02.ogg" type="AudioStream" id=4]
[sub_resource type="RectangleShape2D" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 14.25, 15 )
[node name="Ball" type="KinematicBody2D"]
script = ExtResource( 1 )
speed = Vector2( 200, 100 )
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 2 )
disabled = true
[node name="BounceCheck" type="Area2D" parent="."]
position = Vector2( -1, 0 )
rotation = -3.14159
scale = Vector2( 1.40155, 1.3282 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="BounceCheck"]
modulate = Color( 0.815686, 0.854902, 0.113725, 1 )
position = Vector2( -0.75, 0 )
shape = SubResource( 1 )
[node name="SFX" type="Node" parent="."]
[node name="BounceSound-1" type="AudioStreamPlayer" parent="SFX"]
stream = ExtResource( 3 )
[node name="BounceSound-2" type="AudioStreamPlayer" parent="SFX"]
stream = ExtResource( 4 )
[connection signal="body_entered" from="BounceCheck" to="." method="_on_BounceCheck_body_entered"]

15
src/Actors/Paddle.gd Normal file
View File

@ -0,0 +1,15 @@
extends Actor
export var Player: = 1
func _physics_process(_delta: float) -> void:
_direction = get_direction()
_velocity = calculate_move_velocity(_velocity, _direction, speed)
_velocity = move_and_slide(_velocity)
func get_direction() -> Vector2:
return Vector2(
0,
Input.get_action_strength("P%s_Down" % Player) - Input.get_action_strength("P%s_Up" % Player)
)

17
src/Actors/Paddle.tscn Normal file
View File

@ -0,0 +1,17 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://assets/Paddle.png" type="Texture" id=1]
[ext_resource path="res://src/Actors/Paddle.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 20, 80 )
[node name="Paddle" type="KinematicBody2D"]
script = ExtResource( 2 )
speed = Vector2( 0, 250 )
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )