Godot Version
Godot 4.2.2
Question
Greetings everyone!
I currently have a school project where you have to select a topic or thing to research and develop your knowledge surrounding such. I have selected to learn basic GDScript to produce a basic clone of Breakout. While this has been successful, one core component of the assessment is to receive feedback from people with knowledge regarding said topic. I have attached my code which I have utilised within my game below, and was hoping to receive any possible feedback regarding the code from structure to functionality etc.
Thank you so much in advance!
The code:
Player Paddle
extends CharacterBody2D
@export var speed = 400
#Set up the speed of the player
func get_input():
var input_direction = Input.get_vector(“left”, “right”, “up”, “down”)
velocity = input_direction * speed
#Utilise speed to move the player in desired direction. Y-axis remains constant.
func _physics_process(delta):
get_input()
move_and_slide()
global_position.y = 120
Ball
extends StaticBody2D
#Cause ball to move in vector direction of (200,200).
var ball_speed = Vector2(200,200)
#Create the physics of the ball and cause the ball to speed up over time.
func _physics_process(delta):
var collision_info = move_and_collide(ball_speed * delta)
if collision_info:
ball_speed = ball_speed.bounce(collision_info.get_normal())
ball_speed.x *= 1.002
ball_speed.y *= 1.002
#If hitting block, activate hit.
if (collision_info.get_collider().name == ‘block’):
collision_info.get_collider().hit()
Bricks
extends StaticBody2D
#When the ball hits the block, delete the block.
func hit():
get_parent().queue_free()
Killzone
extends Area2D
#When ball goes into the killzone, activate a timer.
func _on_area_entered(body):
$Timer.start()
#When the timer ends, reset the game from the beginning.
func _on_timer_timeout():
get_tree().reload_current_scene()