ブロック崩しの素

# ブロック崩しの素 # https://news.mynavi.jp/article/zeropython- […]

# ブロック崩しの素 # https://news.mynavi.jp/article/zeropython- […]

  • タグ:
  • タグはありません
#
# https://news.mynavi.jp/article/zeropython-10/
# URL
#
from tkinter import *
#
win = Tk()
cv = Canvas(win, width = 600, height = 400)
cv.pack()
#
class Ball:
def __init__(self):
self.dirx=8 # X
self.diry=-8 # Y
x=350 #
y=300
self.w=10
self.ball=cv.create_oval(
x - self.w, y - self.w,
x + self.w, y + self.w,
fill="green"
)
def left(self):
return cv.coords(self.ball)[0]
def top(self):
return cv.coords(self.ball)[1]
def right(self):
return cv.coords(self.ball)[2]
def bottom(self):
return cv.coords(self.ball)[3]
ball=Ball()
#
def draw_objects():
pass
#
def move_ball():
#
if ball.left() < 0 or ball.right() > 600: ball.dirx *= -1
if ball.bottom() < 0 or ball.top() > 400: ball.diry *= -1
#
cv.move(ball.ball,ball.dirx,ball.diry)
#
def game_loop():
draw_objects()
move_ball()
win.after(33,game_loop)
game_loop()
win.mainloop()
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX