python3.x pong game paddle width reduce
youtube 2016. 6. 1. 10:10원본 출처 : http://cafe.naver.com/toolsinfo/11044
[질문] : 게임을 진행하면서 점수 5점이상이면
패달의 길이를 반으로 줄게 하고 싶음.
[해결방법]
1.파이썬 버전 선택
원본 소스코드에서 from tkinter 로 tkinter 소문자 이면 python 3.x
(from Tkinter 처럼 T가 대문자이면 python 2.x) 로 판단
2. 스코어 점수 받아오기
class Score : 에 아래 함수 추가
def getJumsu(self):
return self.score;
3.Paddle 크기 조정
class Paddle: 의 draw 함수 수정
def draw(self, jumsu): # jumsu 파라미터 추가
#----------------------------------------
w1=100
w2=w1/2
h=10
w=w1
if jumsu>=5:
w=w2
(x0,y0,x1,y1)=self.canvas.coords(self.id)
x1=x0+w
y1=y0+h
self.canvas.coords(self.id, x0,y0,x1,y1)
#----------------------------------------
참고 : 아래 코드 중 일부 참고
http://stackoverflow.com/questions/12254995/tkinter-resizable-objects-python-canvas
def do_scale(self, tag):
factor = int(self.spinbox[tag].get())
(width, height) = self.default[tag]
(x0,y0,x1,y1) = self.canvas.coords(tag)
width = factor * width
height = factor * height
x1 = x0 + width
y1 = y0 + height
self.canvas.coords(tag, x0,y0,x1,y1)
4. paddle.draw()를 paddle.draw(score.getJumsu()) 이렇게 수정
'youtube' 카테고리의 다른 글
python34 poly_1 inputPoly function (0) | 2016.06.12 |
---|---|
python34 A variable number of arguments (0) | 2016.06.12 |
python27 pygame install (0) | 2016.06.12 |
python sorted (0) | 2016.06.12 |
fortran if test (0) | 2016.06.05 |