Brick Breaker game
import pygame
from pygame.locals import *
pygame.init()
'''
Defining gaming window size and font
'''
Window_width = 500
Window_height = 500
window = pygame.display.set_mode((Window_width, Window_height))
pygame.display.set_caption('Brickstroy')
font = pygame.font.SysFont('Arial', 30)
'''
Defining Bricks colour
'''
O_brick = (255, 100, 10)
w_brick = (255, 255, 255)
g_brick = (0, 255, 0)
black = (0, 0, 0)
game_rows = 6
game_coloumns = 6
clock = pygame.time.Clock()
frame_rate = 60
my_ball = False
game_over = 0
score = 0
class Ball():
'''
Creating ball for the game
'''
def __init__(self, x, y):
self.radius = 10
self.x = x - self.radius
self.y = y - 50
self.rect = Rect(self.x, self.y, self.radius * 2, self.radius * 2)
self.x_speed = 4
self.y_speed = -4
self.max_speed = 5
self.game_over = 0
def motion(self):
collision_threshold = 5
block_object = Block.bricks
brick_destroyed = 1
count_row = 0
for row in block_object:
count_item = 0
for item in row:
# check collision with gaming window
if self.rect.colliderect(item[0]):
if abs(self.rect.bottom - item[0].top) < collision_threshold and self.y_speed > 0:
self.y_speed *= -1
if abs(self.rect.top - item[0].bottom) < collision_threshold and self.y_speed < 0:
self.y_speed *= -1
if abs(self.rect.right - item[0].left) < collision_threshold and self.x_speed > 0:
self.x_speed *= -1
if abs(self.rect.left - item[0].right) < collision_threshold and self.x_speed < 0:
self.x_speed *= -1
if block_object[count_row][count_item][1] > 1:
block_object[count_row][count_item][1] -= 1
else:
block_object[count_row][count_item][0] = (0, 0, 0, 0)
if block_object[count_row][count_item][0] != (0, 0, 0, 0):
brick_destroyed = 0
count_item += 1
count_row += 1
if brick_destroyed == 1:
self.game_over = 1
# check for collision with bricks
if self.rect.left < 0 or self.rect.right > Window_width:
self.x_speed *= -1
if self.rect.top < 0:
self.y_speed *= -1
if self.rect.bottom > Window_height:
self.game_over = -1
# check for collission with base
if self.rect.colliderect(user_basepad):
if abs(self.rect.bottom - user_basepad.rect.top) < collision_threshold and self.y_speed > 0:
self.y_speed *= -1
self.x_speed += user_basepad.direction
if self.x_speed > self.max_speed:
self.x_speed = self.max_speed
elif self.x_speed < 0 and self.x_speed < -self.max_speed:
self.x_speed = -self.max_speed
else:
self.x_speed *= -1
self.rect.x += self.x_speed
self.rect.y += self.y_speed
return self.game_over
def draw(self):
pygame.draw.circle(window, (0, 0, 255), (self.rect.x +
self.radius, self.rect.y + self.radius), self.radius)
pygame.draw.circle(window, (255, 255, 255), (self.rect.x +
self.radius, self.rect.y + self.radius), self.radius, 1)
def reset(self, x, y):
self.radius = 10
self.x = x - self.radius
self.y = y - 50
self.rect = Rect(self.x, self.y, self.radius * 2, self.radius * 2)
self.x_speed = 4
self.y_speed = -4
self.max_speed = 5
self.game_over = 0
class Block():
'''
This class will help me create Blocks/bricks of the game
'''
def __init__(self):
self.width = Window_width // game_coloumns
self.height = 40
def make_brick(self):
self.bricks = []
single_brick = []
for row in range(game_rows):
brick_row = []
for coloumn in range(game_coloumns):
x_brick = coloumn * self.width
y_brick = row * self.height
rect = pygame.Rect(x_brick, y_brick, self.width, self.height)
# assign power to the bricks based on row
if row < 2:
power = 3
elif row < 4:
power = 2
elif row < 6:
power = 1
single_brick = [rect, power]
brick_row.append(single_brick)
self.bricks.append(brick_row)
def draw_brick(self):
for row in self.bricks:
for brick in row:
if brick[1] == 3:
brick_colour = O_brick
elif brick[1] == 2:
brick_colour = w_brick
elif brick[1] == 1:
brick_colour = g_brick
pygame.draw.rect(window, brick_colour, brick[0])
pygame.draw.rect(window, black, (brick[0]), 1)
class base():
'''
This class is to create the base pad of the game
'''
def __init__(self):
self.height = 20
self.width = int(Window_width / game_coloumns)
self.x = int((Window_width / 2) - (self.width / 2))
self.y = Window_height - (self.height * 2)
self.speed = 8
self.rect = Rect(self.x, self.y, self.width, self.height)
self.direction = 0
def slide(self):
self.direction = 0
key = pygame.key.get_pressed()
if key[pygame.K_LEFT] and self.rect.left > 0:
self.rect.x -= self.speed
self.direction = -1
if key[pygame.K_RIGHT] and self.rect.right < Window_width:
self.rect.x += self.speed
self.direction = 1
def draw(self):
pygame.draw.rect(window, (0, 0, 255), self.rect)
pygame.draw.rect(window, (255, 255, 255), self.rect, 1)
def reset(self):
self.height = 20
self.width = int(Window_width / game_coloumns)
self.x = int((Window_width / 2) - (self.width / 2))
self.y = Window_height - (self.height * 2)
self.speed = 8
self.rect = Rect(self.x, self.y, self.width, self.height)
self.direction = 0
def draw_text(text, font, w_brick, x, y):
'''
Funtion for showing text in gaming window
'''
image = font.render(text, True, w_brick)
window.blit(image, (x, y))
Block = Block()
# Creating Brick
Block.make_brick()
# Defining base pad
user_basepad = base()
ball = Ball(user_basepad.x + (user_basepad.width // 2),
user_basepad.y - user_basepad.height) # Defining ball
game = True
while game:
clock.tick(frame_rate)
window.fill(black) # Gaming window Background
Block.draw_brick() # Drawing bricks
user_basepad.draw() # Drawing user basepad
ball.draw() # Drawing gaming ball
if my_ball:
user_basepad.slide()
game_over = ball.motion()
if game_over != 0:
my_ball = False
# Game Info on the gaming window
if not my_ball:
if game_over == 0:
draw_text('CLICK ANYWHERE TO START', font,
w_brick, 90, Window_height // 2 + 100)
elif game_over == 1:
draw_text('YOU WON!', font, w_brick, 180, Window_height // 2 + 50)
draw_text('CLICK ANYWHERE TO RESTART', font,
w_brick, 90, Window_height // 2 + 100)
elif game_over == -1:
draw_text('GAME OVER!', font, w_brick,
180, Window_height // 2 + 50)
draw_text('CLICK ANYWHERE TO RESTART', font,
w_brick, 90, Window_height // 2 + 100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
game = False
if event.type == pygame.MOUSEBUTTONDOWN and my_ball == False:
my_ball = True
ball.reset(user_basepad.x + (user_basepad.width // 2),
user_basepad.y - user_basepad.height)
user_basepad.reset()
Block.make_brick()
pygame.display.update()
pygame.quit()
Created: 7/9/2025
Keywords: text snippets, AI consulting, AI Cheat Tool, AI Cheat Tool for developers, AI Cheat Tool for AI, AI Cheat Tool for ChatGPT, AI Cheat Tool for email, AI Cheat Tool for text, AI Cheat Tool for keyboard shortcuts, AI Cheat Tool for text expansion, AI Cheat Tool for text snippets, AI Cheat Tool for text replacement, AI Cheating Tool, AI Cheating Tool for developers, AI Cheating Tool for AI, AI Cheating Tool for ChatGPT, AI Cheating Tool for email, AI Cheating Tool for text, AI Cheating Tool for keyboard shortcuts, prompt cheating, AI prompt engineering, AI context engineering, context engineering, ai prompt manager, AI prompt manager, AI prompt management, ai consulting, prompt engineering consulting, generative ai consulting, ai implementation services, llm integration consultants, ai strategy for enterprises, enterprise ai transformation, ai prompt optimization, large language model consulting, ai training for teams, ai workflow automation, build ai knowledge base, llm prompt management, ai prompt infrastructure, ai adoption consulting, enterprise ai onboarding, custom ai workflow design, ai integration for dev teams, ai productivity tools, team prompt collaboration, github gists, github snippets, github code snippets, github code snippets automation, github, text expansion, text automation, snippet manager, code snippets, team collaboration tools, shared snippets, snippet sharing, keyboard shortcuts, productivity tools, workflow automation, AI-powered productivity, snippet tool for teams, team knowledge base, AI text completion, text expander for teams, snippet collaboration, multi-platform productivity, custom keyboard shortcuts, snippet sharing platform, collaborative snippet management, knowledge base automation, team productivity software, business productivity tools, snippet management software, quick text input, macOS productivity apps, Windows productivity tools, Linux productivity tools, cloud-based snippets, cross-platform snippets, team workspace tools, workflow enhancement tools, automation tools for teams, text automation software, team knowledge sharing, task automation, integrated team tools, real-time collaboration, AI for team productivity, business text automation, time-saving tools, clipboard manager, multi-device clipboard, keyboard shortcut manager, team communication tools, project management integration, productivity boost AI, text snippet sharing, text replacement software, text management tools, efficient team collaboration, AI workspace tools, modern productivity apps, custom text automation, digital workspace tools, collaborative workspaces, cloud productivity tools, streamline team workflows, smart text management, snippets AI app, snippet management for teams, shared knowledge platforms, team-focused text automation, team productivity platform, AI text expansion tools, snippet taking app, note taking app, note taking software, note taking tools, note taking app for teams, note taking app for developers, note taking app for AI, note taking app for ChatGPT, snippet software, snippet tools, snippet app for teams, snippet app for developers, snippet app for AI, snippet app for ChatGPT, AI agent builder, AI agent snippets, AI agent prompts, prompt management, prompt engineering, ChatGPT snippets, ChatGPT prompts, AI prompt optimization, AI-powered prompts, prompt libraries for AI, prompt sharing for ChatGPT, GPT productivity tools, AI assistant snippets, ChatGPT integrations, custom AI prompts, AI agent workflows, machine learning snippets, automated AI prompts, AI workflow automation, collaborative AI prompts, personalized AI agents, text snippets for ChatGPT, AI prompt creation tools, AI code snippet manager, GPT-4 text automation, AI-powered writing assistants, AI tools for developers, AI agent integrations, developer prompt snippets, AI text generation workflows, AI-enhanced productivity, GPT prompt sharing tools, team collaboration for AI, openAI integrations, text automation for AI teams, AI-powered collaboration tools, GPT-4 team tools, AI-driven text expanders, AI-driven productivity solutions, AI agent for email writing, AI agent for text expansion, AI agent for text automation, AI agent for text snippets, AI agent for text replacement, AI agent for keyboard shortcuts, AI Agent Developer, Prompt engineering, Machine Learning Engineer, AI Engineer, Customer Support, Code snippets for developers, Recruiting, AI agent for automation, AI agent for AI automation, AI agent for ChatGPT automation, AI agent for email automation, electron app for snippets, desktop snippet manager, code snippet organization, AI prompt repository, intelligent text expansion, vibe coding, real-time prompt collaboration, developer workflow optimization, team prompt library, knowledge management for developers, code snippet search, searchable code library, reusable code blocks, prompt engineering tools, prompt template management, collaborative coding, cross-team knowledge sharing, code snippet versioning, AI prompt templates, technical documentation tools, developer productivity suite, team snippet repository, AI prompt history, snippet synchronization, cloud snippet backup, markdown snippet support, syntax highlighting for snippets, code categorization, programming language snippets, language-specific code templates, contextual code suggestions, snippets with AI integration, command palette for snippets, code snippet folder organization, team snippet discovery, private and public snippets, enterprise code management, team codebase documentation, prompt engineering best practices, Vibe Coding, Vibe Coding for developers, Vibe Coding for AI, Vibe Coding for ChatGPT, Vibe Coding for email, Vibe Coding for text, Vibe Coding for keyboard shortcuts, Vibe Coding for text expansion, Vibe Coding for text snippets, Vibe Coding for text replacement, api, python, go, django, postgresql, mysql, redis, rest, spa, cdn, logging, performance, security, testing, node, rust, vite, deployment, scaling, react, typescript, graphql, ssr, monitoring, express, mongodb, react native, ios, aws
AI Prompts, ChatGPT, Code Snippets, Prompt Engineering