Breakout Paddle
Part of the Projects section of Coddy's Godot journey. Lesson 1 of 33.
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
EasyIn paddle.gd:
- Add
const SPEED = 400at the top. - In
_physics_process, move the paddle left and right withmove_leftandmove_right, atSPEEDpixels per second.
Try it yourself
extends CharacterBody2D
func _physics_process(delta):
pass
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Projects
Practice on your own: Godot playground