100-Days-Of-Code/PycharmProjects/Pong-Game/ball.py
Arcron ArchLinux 8e5462f8db 100Days
2024-10-26 14:55:49 +05:30

31 lines
637 B
Python

from turtle import Turtle
class Ball(Turtle):
def __init__(self):
super().__init__()
self.color("white")
self.shape("circle")
self.penup()
self.x_move = 10
self.y_move = 10
self.move_speed = 0.1
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
self.move_speed *= 0.9
def reset_position(self):
self.goto(0, 0)
self.move_speed = 0.1
self.bounce_x()