from tkinter import*
import time
import random
WIDTH = 800
HEIGHT = 400
class Ball:
def __lnit__(self, canvas, color, size, x, y, xspeed, yspeed):
self.canvas = canvas
self.color = color
self.size = size
self.x = x
self.y = y
self.xspeed = xspeed
self.yspeed = yspeed
self.id = canvas.create_oval(x, y, x + size, y + size, fill=color)
def move(self):
self.canvas.move(self.id, self.xspeed, self.yspeed)
(x1, y1, x2, y2) = self.canvas.coords(self.id)
(self.x, self.y) = (x1, y1)
if y1 <= 0 or y2 >= HEIGHT:
self.yspeed = - self.yspeed
bullets = []
def fire(event):
bullets.append(Ball(canvas, "blue" , 10 , 150 , 250 , 10 , 0))
window = Tk()
canvas = Canvas(window, width=WIDTH, height=HEIGHT)
canvas.pack()
canvas.bind("<Button-1>", fire)
BallA =Ball(canvas, "red", 100, 100, 200, 0, 0)
BallB =Ball(canvas, "blue", 100, 500, 200, 0, 5)
while True:
for bullet in bullets:
bullet.move()
if (bullet.y) >= BallB.y and \
(bullet.y + bullet.size) <= BallB.y + BallB.size and \
(bullet.x) >= BallB.x and \
(bullet.x + bullet.size) <= BallB.x + BallB.size:
print("충돌했어요~")
canvas.delete(bullet.id)
bullets.remove(bullet)
BallB.move()
window.update()
time.sleep(0.03)
이렇게썼는데
BallA =Ball(canvas, "red", 100, 100, 200, 0, 0)
TypeError: Ball() takes no arguments
라는 에러코드가 계속남 이거뭐가문제임?
30분째보고있는데 틀린건없는거같은데..
에러는 매개변수 안받는다고 돼있는데 왜그럴까? 이상하네~ - dc Cpp
뭐가문젠지 잘모르겠어요ㅜ..
존나 개뻘짓해본결과 size 매개변수만 처받으면 이상해지는데 왠진모르겠음
그것만이 문제가 아니네 씹발뭐지ㅋㅋ
해당 댓글은 삭제되었습니다.
그러네
복붙해서 나도 안된거였군