๐Ÿ“’ [ TIL ] 2022.04.26_7์ผ์ฐจ # pygame ๊ณ ์ „๊ฒŒ์ž„๋งŒ๋“ค๊ธฐ(2)

๋ฌธ๋ช…์ฃผยท2022๋…„ 4์›” 26์ผ
0

[ 2022-04-26 (ํ™”) ์˜ค๋Š˜์˜ TIL ]

[ Today Project ]

  • pygame์œผ๋กœ ๊ณ ์ „๊ฒŒ์ž„๊ฐœ๋ฐœ
    : ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ๋Š” ๊ฐœ์ธํ”„๋กœ์ ํŠธ๋กœ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

[ Today Learn ]

  • pygame์œผ๋กœ ๊ฒŒ์ž„์„ ๋งŒ๋“ค๋ฉด์„œ python ๋ฌธ๋ฒ• ๊ณต๋ถ€

[ ๊ฐœ๋ฐœํ™˜๊ฒฝ ]

  • Pycharm

[ ์‚ฌ์šฉํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ]

  • pygame/sys/random/from math import sqrt, ceil

โœ๏ธ ๋‚ด๊ฐ€ ๋ฐฐ์šด๊ฒƒ, ๊ตฌํ˜„ํ•œ ๊ฒƒ

  • Stage๋ณ„๋กœ ๋‚œ์ด๋„ ์„ค์ • ( 0์  ์Œ“์ผ๋•Œ๋งˆ๋‹ค ๋‚œ์ด๋„ ์ƒ์Šน/ ์ตœ๋Œ€๋‚œ์ด๋„ 15)
    ๐Ÿงฉ ์ ์šฉ ์˜ˆ์‹œ
DIFFICULT = 1  # ๋‚œ๋„ ํ‘œํ˜„ ๋ณ€์ˆ˜

        else:  # ์‹œ๊ฐ„์ด ์ง€๋‚จ์— ๋”ฐ๋ผ ๋ธ”๋ก์„ ํ•œ์นธ์”ฉ ์•„๋ž˜๋กœ ๋‚ด๋ฆฌ๋Š” ์ฝ”๋“œ
            self.stop = self.stop + 1
            if self.stop > FPS / DIFFICULT:
                self.stop = 0
                self.ypos = self.ypos + 1
        return erased
        
        erased = BLOCK.update()
            if erased > 0:
                score = score + 2 ** erased
                DIFFICULT = min(ceil(score / 10), 15)  # 10์  ์Œ“์ผ๋•Œ๋งˆ๋‹ค ๋‚œ๋„ ์ƒ์Šน/ ์ตœ๋Œ€๋‚œ๋„ 15
            BLOCK.draw()
  • ๋ฐฐ๊ฒฝ์Œ, ํšจ๊ณผ์Œ ์„ค์ •

๐Ÿงฉ ์ ์šฉ ์˜ˆ์‹œ

pygame.mixer.init()
pygame.mixer.music.load('sound/tetris.mp3')
pygame.mixer.music.play(-1, 0)  # ๋ฌดํ•œ๋ฐ˜๋ณต
sound_line = pygame.mixer.Sound('sound/fall.mp3')
sound_fall = pygame.mixer.Sound('sound/drop.mp3')
  • ๊ฒŒ์ž„์˜ค๋ฒ„๋ฉ”์‹œ์ง€ ์„ค์ •

๐Ÿงฉ ์ ์šฉ ์˜ˆ์‹œ

largefont = pygame.font.SysFont(None, 72)  # ๊ฒŒ์ž„์˜ค๋ฒ„๊ธ€์”จ
    message_over = largefont.render('GAME OVER!!', True, (255, 255, 255))
  • ์Šคํฌ๋ฆฐ์ฐฝํฌ๊ฒŒ

๐Ÿงฉ ์ ์šฉ ์˜ˆ์‹œ

            elif event.type == KEYDOWN:
                if event.key == ord('f'):  # ํ‚ค๋ณด๋“œ f๋ฅผ ๋ˆŒ๋ €์„๋•Œ
                    user32 = ctypes.windll.user32
                    screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)  # ํ•ด์ƒ๋„ ๊ตฌํ•˜๊ธฐ
                    surface = pygame.display.set_mode((600, 600), pygame.FULLSCREEN)  # 600*600 ํ”ฝ์…€ ํ’€์Šคํฌ๋ฆฐ์กฐ์ ˆ

[๐Ÿ‘ ์˜ค๋Š˜์˜ ๊ฒฐ๊ณผ๋ฌผ ]

๐ŸŒฑ ๋Š๋‚€ ์ 

์ €๋…์„ ๋จน๊ณ ๋‚˜์„œ ๋‹ค๋ฅธํŒ€ ์‚ฌ๋žŒ๋“ค๊ณผ ๊ฒŒ๋”์—์„œ ๊ฐ์ž ๋งŒ๋“ ๊ฒŒ์ž„๊ณผ ๊ตฌํ˜„ํ•œ ๊ธฐ๋Šฅ์— ๋Œ€ํ•ด์„œ ๊ณต์œ ํ–ˆ๋‹ค.
๋‹ค์–‘ํ•œ ๊ฒŒ์ž„๋“ค์„ ์ง์ ‘ํ•ด๋ณด๋‹ˆ๊นŒ ๋‚˜๋„ ๊ฒŒ์ž„์„ ๋งŒ๋“ค์–ด์„œ ๊ทธ๋Ÿฐ์ง€, ์ง์ ‘ ๋งŒ๋“ ์‚ฌ๋žŒ์˜ ๋…ธ๋ ฅ์ด ๋„ˆ๋ฌด ๋ณด์˜€๋‹ค.
์ „์ฒด์ ์œผ๋กœ ๋‚ด๊ฐ€ ์ง  ์ฝ”๋“œ์— ๋Œ€ํ•ด์„œ ๋” ์„ธ์„ธํžˆ ์งš๊ณ  ๋„˜์–ด๊ฐ€๋ฉฐ ๊ณต๋ถ€ํ•ด์•ผ๊ฒ ๋‹ค.
python๋ฌธ๋ฒ•์„ ๋” ๊ณต๋ถ€ํ•ด์„œ ๋‹ค์Œ์—๋Š” ๊ณ ์ „๊ฒŒ์ž„๋ง๊ณ ๋„ ์ปดํ“จํ„ฐ๋กœํ• ์ˆ˜์žˆ๋Š” ๋ฐฉํƒˆ์ถœ๊ฒŒ์ž„์„ ๋งŒ๋“ค์–ด๋ณด๊ณ ์‹ถ๋‹ค.

๐ŸŽ ์ž์„ธํ•œ ์ฝ”๋“œ๋Š” Moonmoo ์— ๊ฒŒ์‹œํ–ˆ์Šต๋‹ˆ๋‹ค

profile
ํ•˜๋ฃจ ํ•œ๊ฑธ์Œ์”ฉ ๊พธ์ค€ํžˆ ๋‚˜์•„๊ฐ€๋Š” ๊ฐœ๋ฐœ์ž๐Ÿ™†โ€โ™€๏ธ https://github.com/Moonmooj

2๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2022๋…„ 4์›” 27์ผ

ํ€ด์ฆˆ...์–ด๋ ต์ง€ ์•Š์•˜์ฃ ,..??? ใ…Žใ…Žใ…Ž;;

1๊ฐœ์˜ ๋‹ต๊ธ€

๊ด€๋ จ ์ฑ„์šฉ ์ •๋ณด