Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Game Development 6 min read

Python Fruit Ninja Game Tutorial with Pygame

This tutorial walks through building a simple Fruit Ninja‑style game in Python using Pygame, covering imports, window setup, random fruit generation, drawing text and lives, handling game over screens, and implementing the main loop with event processing and scoring.

This article provides a step‑by‑step tutorial for creating a simple Fruit Ninja‑style game in Python using the Pygame library.

It begins by importing the required packages ( import pygame, sys, os, random) and setting up the game window with a fixed width of 800, height of 500, and a frame rate of 15 FPS.

Colors, fonts, and background images are defined, and a generate_random_fruits function creates a dictionary for each fruit containing its image, position, speed, and state flags.

The draw_text function renders text on the screen, while draw_lives and hide_cross_lives display and update the player's remaining lives using a life‑icon image.

A show_gameover_screen function displays the start screen and the game‑over screen, waiting for a key press to begin or restart the game.

The main game loop manages the game state, processes events, moves fruits according to their speed vectors, detects mouse clicks to slice fruits or bombs, updates the score, and reduces lives when a bomb is hit; when lives reach zero the game‑over screen is shown.

Throughout the code the article explains how pygame.display.update(), clock.tick(FPS), and event handling keep the game running smoothly at the intended speed.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Pythongame-developmentPygameFruit Ninja

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion