Game Development 12 min read

Build an Arkanoid Clone Quickly with Python and PyGameZero

This tutorial walks you through creating a functional Arkanoid‑style game using Python and PyGameZero, covering installation, window setup, sprite handling, drawing and update loops, paddle control, ball physics, collision detection, and suggestions for adding game‑over logic and scoring.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Build an Arkanoid Clone Quickly with Python and PyGameZero

Introduction

We will use Python and PyGameZero to build an Arkanoid‑style clone, demonstrating how easy it is to create a simple game.

All source code is available at https://github.com/shantnu/arkanoid-clone . The graphics are taken from a free asset library.

Setup

pip install pgzero

Start with an empty window:

import pgzrun

TITLE = "Arkanoid clone"
WIDTH = 800
HEIGHT = 500

pgzrun.go()

The TITLE appears on the window, while WIDTH and HEIGHT define its size.

Loading Sprites

Images are loaded as Actor objects placed in an images folder next to the script.

paddle = Actor("paddleblue.png")
paddle.x = 120
paddle.y = 420

ball = Actor("ballblue.png")
ball.x = 30
ball.y = 300

Drawing

Initially the draw() function only renders the paddle and ball:

def draw():
    paddle.draw()
    ball.draw()

def update():
    pass

Later we add a background image:

def draw():
    screen.blit("background.png", (0, 0))
    paddle.draw()
    ball.draw()

Placing Bricks

Bricks are created with a loop. First a single brick:

bar = Actor("element_blue_rectangle_glossy.png")
bar.x = 120
bar.y = 100
bar.draw()

Then multiple bricks using a for loop:

def draw():
    bar_x = 120
    bar_y = 100
    for i in range(8):
        bar = Actor("element_blue_rectangle_glossy.png")
        bar.x = bar_x
        bar.y = bar_y
        bar.draw()
        bar_x += 70

A generic place_bars(x, y, image) function stores each created brick in a global bars_list for later collision checks.

bars_list = []

def place_bars(x, y, image):
    bar_x = x
    bar_y = y
    for i in range(8):
        bar = Actor(image)
        bar.x = bar_x
        bar.y = bar_y
        bars_list.append(bar)
        bar_x += 70

Three colour sets are placed by iterating over a list of image filenames and adjusting y for each row.

coloured_box_list = ["element_blue_rectangle_glossy.png",
                     "element_green_rectangle_glossy.png",
                     "element_red_rectangle_glossy.png"]
x = 120
y = 100
for coloured_box in coloured_box_list:
    place_bars(x, y, coloured_box)
    y += 50

Paddle Movement

def update():
    if keyboard.left:
        paddle.x -= 5
    if keyboard.right:
        paddle.x += 5

Ball Physics

Global speed variables control the ball’s motion.

ball_x_speed = 1
ball_y_speed = 1

Update the ball each frame and bounce off the screen edges:

def update_ball():
    global ball_x_speed, ball_y_speed
    ball.x -= ball_x_speed
    ball.y -= ball_y_speed
    if ball.x >= WIDTH or ball.x <= 0:
        ball_x_speed *= -1
    if ball.y >= HEIGHT or ball.y <= 0:
        ball_y_speed *= -1

Collision Detection

Check the ball against each brick and remove the brick on impact, also reversing the vertical direction:

def update():
    update_ball()
    for bar in bars_list:
        if ball.colliderect(bar):
            bars_list.remove(bar)
            ball_y_speed *= -1

Collision with the paddle similarly reverses the vertical speed and randomly flips the horizontal direction:

if paddle.colliderect(ball):
    ball_y_speed *= -1
    rand = random.randint(0, 1)
    if rand:
        ball_x_speed *= -1

Next Steps

Suggested extensions include adding game‑over logic when the ball falls below the paddle, implementing a scoring system (different scores for different coloured bricks), and refining the physics.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Pythoncollision detectionArkanoidPyGameZero
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.