Coder Social home page Coder Social logo

hello_pygame's Introduction

hello_pygame

ํŒŒ์ด์ฌ์˜ pygame์œผ๋กœ ๊ฒŒ์ž„์„ ๋งŒ๋“ค์–ด๋ณด์ž!

๐Ÿ’— ํ•˜ํŠธ๋ชจ์œผ๊ธฐ ๊ฒŒ์ž„

dd

  • ์„ค์ •ํ•ด์•ผ ๋  ๊ฒƒ

    • ๋ณด์ด์˜ ์›€์ง์ž„

      • pygame.KEYDOWN, pygame.K_LEFT๋“ฑ์œผ๋กœ ์„ค์ •
    • ํ™”๋ฉด์— ๋ณด์ผ ํ•˜ํŠธ์˜ ๊ฐœ์ˆ˜

      ##ํ•˜ํŠธ ์ด๋ฏธ์ง€
          love_image = pygame.image.load('image/love.png')
          loves = []
          for i in range(3): # ํ™”๋ฉด์— ์„ธ๊ฐœ๋งŒ
              love = love_image.get_rect(left=random.randint(0, 600 - love_image.get_width()), top=-100) # ๊ฐ€๋กœ ์œ„์น˜๋ฅผ 0~600 ์‚ฌ์ด์˜ ๋žœ๋ค์œผ๋กœ
              dy = random.randint(3, 9) # ๋น ๋ฅด๊ธฐ๋„ 3~9 ๋žœ๋ค์œผ๋กœ
              loves.append((love, dy))
    • ์ƒ๋ช… ๊ฐœ์ˆ˜

  • ํ™”๋ฉด์— ํ•˜ํŠธ ์„ธ๊ฐœ๊ฐ€ ์žˆ๋„๋ก ์„ค์ •, ๋žœ๋ค ์†๋„ ์„ค์ •, ํ™”๋ฉด์„ ๋ฒ—์–ด๋‚˜๊ฑฐ๋‚˜ ์—†์–ด์กŒ์„ ๋•Œ ๋‹ค์‹œ ํ•˜ํŠธ ๋ถ™์—ฌ์ฃผ๊ธฐ

    for love, dy in loves: # dy๋Š” ๋น ๋ฅด๊ธฐ
    	love.top += dy
        if love.top > 800: # ํ•˜ํŠธ๊ฐ€ ๋ฐ”๋‹ฅ์— ๋‹ฟ์ด๋ฉด ํ•˜ํŠธ ๋นผ๊ธฐ
           lifes.pop()
        if len(lifes) == 0 : # ์ƒ๋ช… ์—†์„ ๋•Œ๋Š” ๊ฒŒ์ž„์˜ค๋ฒ„
           game_over = True
        loves.remove((love, dy))
        love = love_image.get_rect(left=random.randint(0, 600 - love.width), top=-100)
        dy = random.randint(3, 9)
        loves.append((love, dy))
  • ํ•˜ํŠธ์— ๋‹ฟ์˜€์„ ๋•Œ

    if love.colliderect(boy_pos):
    	score += 1 # ์ ์ˆ˜ ์ถ”๊ฐ€
        loves.remove((love, dy)) # ํ•˜ํŠธ ์‚ญ์ œ (์ด ๋•Œ ์‚ญ์ œ ์•ˆํ•˜๋ฉด ์ ์ˆ˜๊ฐ€ ๊ณ„์† ์˜ฌ๋ผ๊ฐ)
    
        #ํ•˜ํŠธ ๋‹ค์‹œ ๋ถ™์—ฌ์„œ ๋‚ด๋ ค์ฃผ๊ธฐ
        love = love_image.get_rect(left=random.randint(0, 600 - love.width), top=-100)
        dy = random.randint(3, 9)
        loves.append((love, dy))

hello_pygame's People

Contributors

onethegarden avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.