Skip to content

Breakout game #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Breakout/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Antonio Rodriguez

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
67 changes: 67 additions & 0 deletions Breakout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<div align="center" id="top">
<img src="logo/breakout.jpg" alt="Breakout" />

&#xa0;

<!-- <a href="https://breakout.netlify.app">Demo</a> -->
</div>

<h1 align="center">Breakout</h1>

<p align="center">
<img alt="Github top language" src="https://img.shields.io/github/languages/top/antoniorodr/breakout?color=56BEB8">

<img alt="Github language count" src="https://img.shields.io/github/languages/count/antoniorodr/breakout?color=56BEB8">

<img alt="Repository size" src="https://img.shields.io/github/repo-size/antoniorodr/breakout?color=56BEB8">

<img alt="License" src="https://img.shields.io/github/license/antoniorodr/breakout?color=56BEB8">

<img alt="Github issues" src="https://img.shields.io/github/issues/antoniorodr/breakout?color=56BEB8" />

<img alt="Github forks" src="https://img.shields.io/github/forks/antoniorodr/breakout?color=56BEB8" />

<img alt="Github stars" src="https://img.shields.io/github/stars/antoniorodr/breakout?color=56BEB8" />
</p>

<!-- Status -->

<!-- <h4 align="center">
🚧 Breakout 🚀 Under construction... 🚧
</h4>

<hr> -->

<p align="center">
<a href="#dart-about">About</a> &#xa0; | &#xa0;
<!-- <a href="#sparkles-features">Features</a> &#xa0; | &#xa0;
<a href="#rocket-technologies">Technologies</a> &#xa0; | &#xa0;
<a href="#white_check_mark-requirements">Requirements</a> &#xa0; | &#xa0; -->
<a href="#checkered_flag-starting">Starting</a> &#xa0; | &#xa0;
<a href="#memo-license">License</a> &#xa0; | &#xa0;
<a href="https://github.com/antoniorodr" target="_blank">Author</a>
</p>

<br>

## :dart: About ##

A scaled-down version of the famous Breakout game, created using Python.

## :checkered_flag: Starting ##

```bash
# Clone this project
$ git clone https://github.com/antoniorodr/breakout
```

## :memo: License ##

This project is under license from MIT. For more details, see the [LICENSE](LICENSE.md) file.


Made with :heart: by <a href="https://github.com/antoniorodr" target="_blank">Antonio Rodriguez</a>

&#xa0;

<a href="#top">Back to top</a>
Binary file added Breakout/logo/breakout.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions Breakout/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from turtle import Screen, Turtle
from paddle import Paddle, Ball, Scoreboard, Brick
from tkinter import messagebox
import time

BRICK_COLORS = ["IndianRed1", "LightSalmon1", "LightGoldenrod1", "LightGreen", "DodgerBlue1", "LightPink1"]
game_on = True
bricks = []

CURSOR_SIZE = 20
FONT_SIZE = 12
FONT = ('Arial', FONT_SIZE, 'bold')

screen = Screen()
screen.bgcolor("gray20")
screen.setup(width = 1300, height = 800)
screen.title("Breakout")
screen.tracer(0)

paddle = Paddle((0, -320))
ball = Ball()
scoreboard = Scoreboard()

for n in range(len(BRICK_COLORS)):
y_position = 300 - n * (30 + 10)
color = BRICK_COLORS[n % len(BRICK_COLORS)]
for x in range(-610, 650, 100):
brick = Brick((x, y_position), color)
bricks.append(brick)

screen.listen()
screen.onkey(paddle.go_right, "Right")
screen.onkey(paddle.go_left, "Left")

while game_on:
time.sleep(ball.move_speed)
screen.update()
ball.move()

if scoreboard.lives == 0:
messagebox.showinfo(message = f"Game Over. Final score: {scoreboard.score}. Thanks for playing!")
screen.exitonclick()

if scoreboard.score == 468:
messagebox.showinfo(message = f"You won!. Final score: {scoreboard.score}. Thanks for playing!")
screen.exitonclick()

if ball.xcor() > 620 or ball.xcor() < - 620:
ball.bounce_x()

if (ball.ycor() > -320 and ball.ycor() < -320 + 24) and \
(ball.xcor() > paddle.xcor() - 100/ 2 and ball.xcor() < paddle.xcor() + 100 / 2):
ball.bounce_y()

for index, brick in enumerate(bricks):
if ball.distance(brick) < 40:
row_index = index // 13
score_increment = 2 * (5 - row_index) + 1
scoreboard.scoring(score_increment)
ball.bounce_y()
bricks.remove(brick)
brick.hideturtle()
break

if ball.ycor() > 300:
ball.bounce_y()

if ball.ycor() <= - 350:
ball.reset_position()
scoreboard.lose()
paddle.start_position((0, -320))
time.sleep(1)

screen.exitonclick()
89 changes: 89 additions & 0 deletions Breakout/paddle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from turtle import Turtle

class Paddle(Turtle):
def __init__(self, position: tuple):
super().__init__()
self.shape("square")
self.color("white")
self.shapesize(stretch_wid = 1.2, stretch_len =5)
self.penup()
self.goto(position)

def go_right(self):
new_x = self.xcor() + 40
self.goto(new_x, self.ycor())

def go_left(self):
new_x = self.xcor() - 40
self.goto(new_x, self.ycor())

def start_position(self, position: tuple):
self.goto(position)

class Brick(Turtle):
def __init__(self, position: tuple, color: str):
super().__init__()
self.shape("square")
self.color(color)
self.shapesize(stretch_wid = 1.5, stretch_len =4)
self.penup()
self.goto(position)
class Ball(Turtle):
def __init__(self):
super().__init__()
self.shape("circle")
self.color("white")
self.penup()
self.x_move = 10
self.y_move = 10
self.move_speed = 0.05

def move(self):
new_x = self.xcor() - self.x_move
new_y = self.ycor() - self.y_move
self.goto(new_x, new_y)

def bounce_y(self):
self.y_move *= -1

def bounce_x(self):
self.x_move *= -1

def reset_position(self):
self.goto(0, 0)
self.move_speed = 0.05
self.bounce_x()

class Scoreboard(Turtle):
def __init__(self):
super().__init__()
self.hideturtle()
self.color("white")
self.penup()
self.lives = 5
self.score = 0
self.update_scoreboard()

def update_scoreboard(self):
self.clear()
self.goto(-300, 340)
lives_text = f"Lives: {self.lives}"
self.write(lives_text, align="center", font=("Courier", 30, "normal"))

self.goto(300, 340)
score_text = f"Your score: {self.score}"
self.write(score_text, align="center", font=("Courier", 30, "normal"))

def lose(self):
self.lives -= 1
self.update_scoreboard()

def scoring(self, points):
self.score += points
self.update_scoreboard()




if __name__ == "__main__":
paddle = Paddle()