Breakout Paddle
Part of the Projects section of Coddy's Godot journey. Lesson 1 of 36.
In this chapter you build Breakout: a paddle, a ball, bricks, a score, lives and a way to win. The game runs after every step, so press Play often.
The game has three scripts, each in its own tab: paddle.gd, ball.gd and main.gd for the rest of the game. They start almost empty.
First, the paddle slides left and right on the keys. Input.get_axis gives -1 while Left is held, 1 for Right and 0 for neither.
func _physics_process(delta):
var direction = Input.get_axis("move_left", "move_right")
position.x += direction * SPEED * deltaMultiplying by delta makes SPEED a number of pixels per second.
Challenge
EasyMove the paddle with the keys.
- In
paddle.gd, addconst SPEED = 400at the top. - In
_physics_process, move the paddle withmove_leftandmove_right, atSPEEDpixels per second.
Press Play and hold Left or Right: the paddle slides along the bottom. Then Check.
Try it yourself
extends CharacterBody2D
func _physics_process(delta):
pass
All lessons in Projects
Practice on your own: Godot playground