본문 바로가기

moving circle every 2 secs (using class)

by 머니해커_개발자 2016. 7. 28.

import pygame

import time

import sys


black = [0,0,0]

white = [255, 255, 255]


class Ball () :

    x = 0

    y = 0

    spd = 10

    size = 2

    color = white

    def move(self) :

        self.x += self.spd

        self.y += self.spd

    def draw(self, screen) :

        pygame.draw.circle(screen, self.color, [self.x, self.y], self.size)


sizeX = 400

sizeY = 500

size = [sizeX, sizeY]


pygame.init()

screen = pygame.display.set_mode(size)

pygame.display.set_caption('hell ball,?')


ball1 = Ball()

ball1.size = 3

ball1.x = 50

ball1.y = 50

ball1.color = black

for i in range(0, 200) :

    screen.fill(white)

    ball1.draw(screen)

    pygame.display.update()

    ball1.move()

    time.sleep(1)


while True :

    for event in pygame.event.get():

        if event.type == pygame.QUIT :

            pygame.quit()

            sys.exit()




'Python > 학습' 카테고리의 다른 글

ghost gets coins  (0) 2016.07.31
remove black blocks with mouse(sprite)  (0) 2016.07.28
load image and set transparency  (0) 2016.07.27
falling snows  (0) 2016.07.27
fix the code moving a rect  (0) 2016.07.27

댓글

최신글 전체

이미지
제목
글쓴이
등록일