diff --git a/Breakout/LICENSE.md b/Breakout/LICENSE.md new file mode 100644 index 00000000..adfbeeeb --- /dev/null +++ b/Breakout/LICENSE.md @@ -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. diff --git a/Breakout/README.md b/Breakout/README.md new file mode 100644 index 00000000..bf896524 --- /dev/null +++ b/Breakout/README.md @@ -0,0 +1,67 @@ +
+ Breakout + +   + + +
+ +

Breakout

+ +

+ Github top language + + Github language count + + Repository size + + License + + Github issues + + Github forks + + Github stars +

+ + + + + +

+ About   |   + + Starting   |   + License   |   + Author +

+ +
+ +## :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 Antonio Rodriguez + +  + +Back to top diff --git a/Breakout/logo/breakout.jpg b/Breakout/logo/breakout.jpg new file mode 100644 index 00000000..0f51f703 Binary files /dev/null and b/Breakout/logo/breakout.jpg differ diff --git a/Breakout/main.py b/Breakout/main.py new file mode 100644 index 00000000..61424298 --- /dev/null +++ b/Breakout/main.py @@ -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() \ No newline at end of file diff --git a/Breakout/paddle.py b/Breakout/paddle.py new file mode 100644 index 00000000..d6ddbccf --- /dev/null +++ b/Breakout/paddle.py @@ -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() \ No newline at end of file