sykwag7
@sykwag71248
Reviews Written
1
Average Rating
5.0
Posts
Q&A
๊ณต ์ชผ๊ฐ์ง๋ ๋ฌธ์
# install with : python3 -m pip install pygame==2.0.0.dev6 import os import pygame ############################################################ # ๊ธฐ๋ณธ ์ด๊ธฐํ ๋ถ๋ถ (๋ฐ๋์ ํด์ผ ํ๋ ๊ฒ๋ค) pygame.init() # ํ๋ฉด ํฌ๊ธฐ ์ค์ screen_width = 640 # ๊ฐ๋ก ํฌ๊ธฐ screen_height = 480 # ์ธ๋ก ํฌ๊ธฐ screen = pygame.display.set_mode((screen_width, screen_height)) # ํ๋ฉด ํ์ดํ ์ค์ pygame.display.set_caption("Nado Pang") # FPS clock = pygame.time.Clock() ############################################################ # 1. ์ฌ์ฉ์ ๊ฒ์ ์ด๊ธฐํ (๋ฐฐ๊ฒฝ ํ๋ฉด, ๊ฒ์ ์ด๋ฏธ์ง, ์ขํ, ์๋, ํฐํธ ๋ฑ) current_path = os.path.dirname(__file__) # ํ์ฌ ํ์ผ์ ์์น ๋ฐํ image_path = os.path.join(current_path, "images") # image ํด๋ ์์น ๋ฐํ # ๋ฐฐ๊ฒฝ ๋ง๋ค๊ธฐ background = pygame.image.load(os.path.join(image_path, "background.png")) # ์คํ ์ด์ง ๋ง๋ค๊ธฐ stage = pygame.image.load(os.path.join(image_path, "stage.png")) stage_size = stage.get_rect().size stage_height = stage_size[1] # ์คํ ์ด์ง์ ๋์ด ์์ ์บ๋ฆญํฐ๋ฅผ ๋๊ธฐ ์ํด ์ฌ์ฉ # ์บ๋ฆญํฐ ๋ง๋ค๊ธฐ character = pygame.image.load(os.path.join(image_path, "character.png")) character_size = character.get_rect().size character_width = character_size[0] character_height = character_size[1] character_x_pos = (screen_width / 2) - (character_width / 2) character_y_pos = screen_height - character_height - stage_height # ์บ๋ฆญํฐ ์ด๋ ๋ฐฉํฅ character_to_x = 0 # Y๋ ํ์์์ # ์บ๋ฆญํฐ ์ด๋ ์๋ character_speed = 5 # ๋ฌด๊ธฐ ๋ง๋ค๊ธฐ weapon = pygame.image.load(os.path.join(image_path, "weapon.png")) weapon_size = weapon.get_rect().size weapon_width = weapon_size[0] # width๋ง ๊ฐ์ ธ์ค๊ธฐ # ๋ฌด๊ธฐ๋ ํ ๋ฒ์ ์ฌ๋ฌ ๋ฐ ๋ฐ์ฌ ๊ฐ๋ฅ weapons = [] # ๋ฌด๊ธฐ ์ด๋ ์๋ weapon_speed = 10 # ๊ณต ๋ง๋ค๊ธฐ (4๊ฐ ํฌ๊ธฐ์ ๋ํด ๋ฐ๋ก ์ฒ๋ฆฌ) ball_images = [ pygame.image.load(os.path.join(image_path, "balloon1.png")), pygame.image.load(os.path.join(image_path, "balloon2.png")), pygame.image.load(os.path.join(image_path, "balloon3.png")), pygame.image.load(os.path.join(image_path, "balloon4.png"))] # ๊ณต ํฌ๊ธฐ์ ๋ฐ๋ฅธ ์ต์ด ์คํผ๋ ball_speed_y = [-18, -15, -12, -9] # index 0, 1, 2, 3์ ํด๋นํ๋ ๊ฐ # x๋ ์ข์ฐ์ธ๋ฐ ์ข์ฐ๋ ๋๊ฐ์ ์คํผ๋๋๊น # ๊ณต๋ค balls = [] # ์ต์ด ๋ฐ์ํ๋ ๊ณต ์ถ๊ฐ balls.append({ # ์ ๋ณด๊ฐ ๋ง์ผ๋ ๋์ ๋๋ฆฌ๋ก ๊ด๋ฆฌ, {} "pos_x" : 50, # ๊ณต์ x ์ขํ "pos_y" : 50, # ๊ณต์ y ์ขํ "img_idx" : 0, # ๋ช๋ฒ์งธ ๊ณต "to_x" : 3, # x์ถ ์ด๋ ๋ฐฉํฅ, -3 ์ด๋ฉด ์ผ์ชฝ์ผ๋ก, 3 ์ด๋ฉด ์ค๋ฅธ์ชฝ์ผ๋ก "to_y" : -6, # y์ถ ์ด๋๋ฐฉํฅ, "init_spd_y" : ball_speed_y[0] # y ์ต์ด ์๋, ๊ฐ ํฌ๊ธฐ์ ๊ณต๋ง๋ค ์คํผ๋๊ฐ ๋ค๋ฅด๋ }) # ์ฌ๋ผ์ง ๋ฌด๊ธฐ, ๊ณต ์ ๋ณด ์ ์ฅ ๋ณ์ weapon_to_remove = -1 # ์ฌ๊ธฐ์ ๋ค์ด๊ฐ๋ ๊ฐ์ ๊ทธ ๊ฐ์ ํด๋นํ๋ ๋ ์์ ์๋ฏธ๊ฐ ์์ผ๋ ๋ฆฌ์คํธ์์ ์ญ์ ํ ๊ฒ ball_to_remove = -1 running = True # ๊ฒ์์ด ์งํ์ค์ธ๊ฐ? ํ์ธํ๋ ๊ฑฐ while running: dt = clock.tick(30) # 2. ์ด๋ฒํธ ์ฒ๋ฆฌ (ํค๋ณด๋, ๋ง์ฐ์ค ๋ฑ) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: # ์บ๋ฆญํฐ๋ฅผ ์ผ์ชฝ์ผ๋ก character_to_x -= character_speed elif event.key == pygame.K_RIGHT: character_to_x += character_speed elif event.key == pygame.K_SPACE: # ๋ฌด๊ธฐ ๋ฐ์ฌ weapon_x_pos = character_x_pos + (character_width/2) - (weapon_width/2) # ๋ฐ์ฌํ ์์น๋ฅผ ์ ์ weapon_y_pos = character_y_pos weapons.append([weapon_x_pos, weapon_y_pos]) # ๋ฆฌ์คํธ ์์ ํ๋์ x,ywใ ํ ์ ๋ณด๊ฐ ์์. ์ฌ๋ฌ๋ฒ ์๋ฉด ์ด๋ฐ ๊ฐ์ด 2-3๊ฐ์ฉ ๋์ด๋จ if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: character_to_x = 0 # 3. ๊ฒ์ ์บ๋ฆญํฐ ์์น ์ ์ character_x_pos += character_to_x if character_x_pos screen_width - character_width: character_x_pos = screen_width - character_width # ๋ฌด๊ธฐ ์์น ์กฐ์ weapons = [ [w[0], w[1] - weapon_speed] for w in weapons] # ํ ์ค for, ๋ฌด๊ธฐ ์์น๋ฅผ ์๋ก # ์ด๋ฏธ weapons ๋ฆฌ์คํธ ์์ x, y์ขํ๊ฐ ์์ผ๋ ํธ์์ w[0], w[1]์ด๋ผ ํจ # weapons์์ ์๋ ๊ฐ๊ฐ ๋ฆฌ์คํธ๋ฅผ ๋ถ๋ฌ์์ w๋ผ ๋ถ๋ฅด๊ณ ๊ทธ ์์ ์๋ ๊ฐ์ ํตํด์ ์ฒ๋ฆฌ๋ฅผ ํจ. ๋ค์ weapons์ ๋ฃ์. ํ๋์ w๊ฐ x, y๊ฐ์ ๊ฐ์ง๋ ๋ ๋ค๋ฅธ ๋ฆฌ์คํธ. w ๋ฆฌ์คํธ์์ [0], [1] ๋ฅผ speed๋ก ๋นผ์ ๋ ๋ค์ ๋ฆฌ์คํธ๋ก ๊ฐ์ธ๋ ๊ฒ # ์ฒ์ฅ์ ๋ฟ์ ๋ฌด๊ธฐ ์์ ๊ธฐ weapons = [ [w[0], w[1]] for w in weapons if w[1] > 0] # y์ขํ๊ฐ 0๋ณด๋ค ํฐ๊ฑฐ๋ง ๋ค์ ๋ฆฌ์คํธ๋ก ๋ง๋ค์ด์ ์ ์ฅ # ๊ณต ์์น ์ ์ for ball_idx, ball_val in enumerate(balls): # ball๋ฆฌ์คํธ์ ์๋๊ฑธ ํ๋์ฉ ๊ฐ์ง๊ณ ์์ ํ์ฌ ๋ณผ ๋ฆฌ์คํธ์ ์๋ ๋ช๋ฒ์งธ ์ธ๋ฑ์ค์ธ์ง ๊ทธ๋ฆฌ๊ณ ๊ทธ ์ธ๋ฑ์ค ๋ฐธ๋ฅ๋ฅผ ์๋ ค์ค ball_pos_x = ball_val["pos_x"] # ์์ ๋์ ๋๋ฆฌ pos_x์ ํด๋นํ๋ ๊ฐdใ กใน ์ ๋ณ์์๋ค๊ฐ ์ ์ฅ ball_pos_y = ball_val["pos_y"] ball_img_idx = ball_val["img_idx"] ball_size = ball_images[ball_img_idx].get_rect().size ball_width = ball_size[0] ball_height = ball_size[1] # ๊ฐ๋ก๋ฒฝ์ ๋ฟ์์ ๋ ๊ณต ์ด๋ ์์น ๋ณ๊ฒฝ (ํ๊ฒจ ๋์ค๋ ํจ๊ณผ) if ball_pos_x screen_width - ball_width: ball_val["to_x"] = ball_val["to_x"] * -1 # ์ธ๋ก ์์น # ์คํ ์ด์ง์ ํ๊ฒจ์ ์ฌ๋ผ๊ฐ๋ ์ฒ๋ฆฌ if ball_pos_y >= screen_height - stage_height - ball_height: ball_val["to_y"] = ball_val["init_spd_y"] # ์คํ ์ด์ง์ ํ๊ฒผ์๋ ์ฌ๋ผ๊ฐ๋ ์ต์ด ์๋ ์ ์ else: # ์คํ ์ด์ง์ ํ๊ธฐ๋ ๊ฒฝ์ฐ๊ฐ ์๋๊ฒฝ์ฐ ์คํผ๋๋ฅผ ๊ณ์ ๋ฐ๊ฟ์ฃผ๋ฉด ๋จ (-5์์ 0.5์ฉ ๋ํ๋๊น ์คํผ๋ ๊ฐ์ํ๋ค๊ฐ 0์ด ๋๋ฉด ๋ค์ ๋ฐ์ผ๋ก ๋จ์ด์ง๋ ๊ฐ์) ball_val["to_y"] += 0.5 ball_val["pos_x"] += ball_val["to_x"] ball_val["pos_y"] += ball_val["to_y"] # 4. ์ถฉ๋ ์ฒ๋ฆฌ # ์บ๋ฆญํฐ rect ์ ๋ณด ์ ๋ฐ์ดํธ character_rect = character.get_rect() character_rect.left = character_x_pos character_rect.top = character_y_pos for ball_idx, ball_val in enumerate(balls): ball_pos_x = ball_val["pos_x"] ball_pos_y = ball_val["pos_y"] ball_img_idx = ball_val["img_idx"] # ๊ณต rect ์ ๋ณด ์ ๋ฐ์ดํธ ball_rect = ball_images[ball_img_idx].get_rect() ball_rect.left = ball_pos_x ball_rect.top = ball_pos_y # ๊ณต๊ณผ ์บ๋ฆญํฐ ์ถฉ๋ ์ฒ๋ฆฌ if character_rect.colliderect(ball_rect): running = False break # ๊ณต ์ฌ๋ฌ๊ฐ ์ค์ ํ๋๋ผ๋ ๋ฟ์ผ๋ฉด ๋ # ๋ฌด๊ธฐ ๊ฐ์ ๊ฒฝ์ฐ ํ๋ฒ์ ์ฌ๋ฌ๋ฐ. ๋ฌด๊ธฐ list๊ฐ์ ๋ํด ํด์ผํจ # ๊ณต๊ณผ ๋ฌด๊ธฐ๋ค ์ถฉ๋ ์ฒดํฌ for weapon_idx, weapon_val in enumerate(weapons): # enumerate๋ผ์ idx, val๋ก ์ ์ฅ๋์ด์์ weapon_x_pos = weapon_val[0] # weapons์๋ x์ y์ขํ๋ง ์์ weapon_y_pos - weapon_val[1] # ๋ฌด๊ธฐ rect ์ ๋ณด ์ ๋ฐ์ดํธ weapon_rect = weapon.get_rect() weapon_rect.left = weapon_x_pos weapon_rect.top = weapon_y_pos # ์ถฉ๋ ์ฒดํฌ if weapon_rect.colliderect(ball_rect): weapon_to_remove = weapon_idx # ํด๋น ๋ฌด๊ธฐ ์์ ๊ธฐ ์ํ ๊ฐ ์ค์ ball_to_remove = ball_idx # ๊ฐ์ฅ ์์ ํฌ๊ธฐ์ ๊ณต์ด ์๋๋ผ๋ฉด ๋ค์ ๋จ๊ณ์ ๊ณต์ผ๋ก ๋๋ ์ฃผ๊ธฐ if ball_img_idx -1: del balls[ball_to_remove] ball_to_remove = -1 # ๋ค์ ์ค์ if weapon_to_remove > -1: del weapons[weapon_to_remove] weapon_to_remove = -1 # 5. ํ๋ฉด์ ๊ทธ๋ฆฌ๊ธฐ screen.blit(background, (0,0)) for weapon_x_pos, weapon_y_pos in weapons: # weapon ๋ฆฌ์คํธ์ ์๋ ๋ชจ๋ ๋ฌด๊ธฐ ๊ทธ๋ฆฌ๊ธฐ screen.blit(weapon, (weapon_x_pos, weapon_y_pos)) # ๋ฆฌ์คํธ ์์ ์๋ ๋ชจ๋ x, y์ขํ๋ค for idx, val in enumerate(balls): # ๊ฐ๊ฐ์ ๊ณต ๊ทธ๋ฆฌ๋๊ฑฐ ball_pos_x = val["pos_x"] ball_pos_y = val["pos_y"] ball_img_idx = val["img_idx"] screen.blit(ball_images[ball_img_idx], (ball_pos_x, ball_pos_y)) screen.blit(stage, (0,screen_height - stage_height)) screen.blit(character, (character_x_pos, character_y_pos)) pygame.display.update() # ๊ฒ์ํ๋ฉด์ ๋ค์ ๊ทธ๋ฆฌ๊ธฐ (๋ฐ๋์ ํธ์ถ ๋งค๋ฒ ํญ์) pygame.quit()
- 0
- 3
- 277
Q&A
์ฌ๊ธฐ์ ํท๊ฐ๋ฆฌ๋๊ฒ ์ #pulse๊ฐ ์๋ .pulse๋ก css์ ์ ๋ ฅ์ ํ๋์?
์์ ์๋์์!! ํญ์ ์ ๋ณด๊ณ ์์ด์ ใ ใ ๊ทธ๋ฌ๋ฉด #์ .๋ ๋๊ฐ์ ๊ธฐ๋ฅ์ ํ๋๊ฑด๊ฐ์? ์๋๋ฉด ๊ตฌ๋ณํด์ ์ฌ์ฉํด์ผํ๋์? ๋ง์ฝ ๊ตฌ๋ณํ๋ค๋ฉด ์ด๋ค ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ณํ๋์?
- 1
- 4
- 447
Q&A
๋ง์ปค 2๊ฐ๋ฅผ ๋ง๋ค๊ธฐ ์ํด ์ธ๋ถํ์ผ์ ๋ง๋ค์๋๋ฐ ์์ฑ์ด ์๋ผ์
์ Latlng์ด ์๋ LatLng์ผ๋ก ๋ฐ๊ฟจ๋๋ ์คํ์ด ๋ฉ๋๋ค ใ ใ ใ ์ต๊ทผ์ ๋ง์ด ๋ฌผ์ด๋ณด๊ณ ์๋๋ฐ ํญ์ ๋ต๋ณ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค ๋ํ๋!!
- 1
- 5
- 324
Q&A
๋ง์ปค 2๊ฐ๋ฅผ ๋ง๋ค๊ธฐ ์ํด ์ธ๋ถํ์ผ์ ๋ง๋ค์๋๋ฐ ์์ฑ์ด ์๋ผ์
๋ต๋ต ์ ๊ฐ ๋ฐ์ดํฐ ํ์ผ์ ์ ์ฅํ๋๊ฑธ ๊น๋นกํ๋ค์ ใ ใ ๊ฐ์ฌํฉ๋๋น ๊ทธ๋ฆฌ๊ณ ํฌ๋กฌ์์ ์คํํ ๋ ์ด๋ ๊ฒ ๋น๋๋ค! (์ฌ์ง)
- 1
- 5
- 324
Q&A
๋งฅ์ผ๋ก ์งํ ๋์ค์ npm install -g nodemonํ๋ ค๋๊น ์๋ฌ๊ฐ ๋ ์
npm์ 6.14.6์ด๊ณ node๋ 2.0.4์ ๋๋ค! (npm์ ํฐ๋ฏธ๋์์ npm์น๋๊น ๋ง์ง๋ง์ npm@6.14.6์ด๋ผ ๋จ๋ค์)
- 1
- 5
- 1.3K
Q&A
๋งฅ์ผ๋ก ์งํ ๋์ค์ npm install -g nodemonํ๋ ค๋๊น ์๋ฌ๊ฐ ๋ ์
express-generator๋ฅผ sudo ์ ๋ ฅํ์ฌ ์ค์น๋ฅผ ์งํ ํ๋๋ฐ ๋ํ๋์ ๊ฒฐ๊ณผ๋ ๋ฌ๋ฆฌ ๋์์ ์ง๋ฌธ ๋๋ฆฝ๋๋ค Terrys-MacBook-Pro:nodemon Terry$ sudo npm install -g express-generator npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.) /usr/local/bin/express -> /usr/local/lib/node_modules/express-generator/bin/express-cli.js + express-generator@4.16.1 updated 1 package in 1.249s ์ด๋ ๊ฒ ๋์์ ๊ตฌ๊ธ์ mkdirp๋ฅผ ์ ๋ฐ์ดํธํ๋ ๋ฐฉ๋ฒ์ ์ฐพ์๋ดค๋๋ฐ ์ดํด๊ฐ ์๋ผ์ ์ง๋ฌธ ๋๋ฆฝ๋๋ค... ใ ใ ์ด๋ป๊ฒ ์ ๋ฐ์ดํธ๋ฅผ ํด์ผํ๋์? sudo npm install -g mkdirp๋ฅผ ์คํํด๋ ๋๊ฐ์ด legacy version์ด๋ผ๊ณ ๋์ค๋ค์ ใ ใ
- 1
- 5
- 1.3K




