똑같이 했는데 왜안되죠?
289
finalcut02
작성한 질문수 10
0
다 작성하고 실행 해봤더니 공이 끝가지 올라가길래 질문 남깁니다. 왜이러는 거죠?1시간 동안 동영상이랑 계속 돌려서 찾아도 안보이네요 왜이러죠??
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("공 쪼개기 게임")
# FPS
clock = pygame.time.Clock()
#########################################################
# 1. 사용자 게임 초기화 (배경 화면, 게임 이미지, 좌표, 속도, 폰트 등)
# 배경 만들기
background = pygame.image.load("C:\\Users\\c\\Desktop\\서지율\\pythonworkspace\\파이썬.활용편\\pygame_project\\images\\background.png")
# 스테이지 만들기
stage = pygame.image.load("C:\\Users\\c\\Desktop\\서지율\\pythonworkspace\\파이썬.활용편\\pygame_project\\images\\stage.png")
stage_size = stage.get_rect().size
stage_height = stage_size[1] # 스테이지의 높이 위에 캐릭터를 두기 위해 사용
# 캐릭터 만들기
character = pygame.image.load("C:\\Users\\c\\Desktop\\서지율\\pythonworkspace\\파이썬.활용편\\pygame_project\\images\\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
character_speed = 5
# 무기 만들기
weapon = pygame.image.load("C:\\Users\\c\\Desktop\\서지율\\pythonworkspace\\파이썬.활용편\\pygame_project\\images\\weapon.png")
weapon_size = weapon.get_rect().size
weapon_width = weapon_size[0]
weapon_speed = 10
# 무기는 한 번에 여러 발 발사 가능
weapons = []
# 공 만들기 (4개 크기에 대해 따로 처리)
ball_images = [
pygame.image.load("C:\\Users\\c\\Desktop\\서지율\\pythonworkspace\\파이썬.활용편\\pygame_project\\images\\balloon1.png"),
pygame.image.load("C:\\Users\\c\\Desktop\\서지율\\pythonworkspace\\파이썬.활용편\\pygame_project\\images\\balloon2.png"),
pygame.image.load("C:\\Users\\c\\Desktop\\서지율\\pythonworkspace\\파이썬.활용편\\pygame_project\\images\\balloon4.png"),
pygame.image.load("C:\\Users\\c\\Desktop\\서지율\\pythonworkspace\\파이썬.활용편\\pygame_project\\images\\balloon4.png")]
# 공 속도
ball_speed_y = [-18, -15, -12, -9]
# 공들
balls = []
balls.append({
"pos_x" : 50, # 공의 x 좌표
"pos_y" : 50, # 공의 y 좌표
"img_idx" : 0, # 공의 이미지 인덱스
"to_x" : 3, # x축 이동 방향
"to_y" : -6, # y축 이동 방향
"init_spd_y" : ball_speed_y[0]}) # y 최초 속도
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])
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 < 0:
character_x_pos = 0
elif 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] # 무기 위치를 위로
# 천장에 닿은 무기 없애기
weapons = [ [w[0], w[1]] for w in weapons if w[1] > 0]
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"]
ball_size = ball_images[ball_img_idx].get_rect().size
ball_width = ball_size[0]
ball_height = ball_size[1]
# 가로벽에 닿았을 떄 공 이동 위치 번경 (튕겨 나오는 효과)
if ball_pos_x < 0 or 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:
ball_val["to_y"] += 0.5
ball_val["pos_x"] += ball_val["to_x"]
ball_val["pos_y"] += ball_val["to_y"]
# 4. 충돌 처리
# 5. 화면에 그리기
screen.blit(background, (0, 0))
for weapon_x_pos, weapon_y_pos in weapons:
screen.blit(weapon, (weapon_x_pos, weapon_y_pos))
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()
pygame 설치오류
0
119
1
pip install pygame 이 실패합니다
0
204
1
pip install pygame 이 안되요
0
881
1
(4:00) linting enabled 항목이 보이지 않습니다
0
155
1
마지막 프로젝트 그림 파일들을 올려주실 수는 없을까요?
0
202
1
import pygame에서 계속 오류가 발생해요
0
3577
2
무기 Y포지션 speed 감소
0
294
1
pygame 공부
0
504
0
마지막 부분 스프라이트가 맨 왼쪽에 위치해있습니다
0
264
1
공 쪼개기 문제
0
305
0
실행시 글자가 깨집니다.
0
309
1
키보드 이벤트 오류
0
569
1
스크린의 높이를 680으로 설정했을 때 오류?
0
294
1
pygame.time.get_ticks() 질문있습니다.
0
534
0
캐릭터의 이동
0
328
0
적(똥)과 케릭터가 충돌했을 때 게임 오버가 뜨게 만들려고..
0
298
1
시작을 하기에 앞서...
0
388
0
이미지 배경을 투명하게 하려면?
0
374
0
파이게임이 실행은 되는데....
0
227
0
실행이 안됩니다.
0
320
0
똑같이 따라 쳤는데 오류가 생겨요
0
302
0
배경색이 안 나와요
0
328
0
import pygame 실행이 안 돼요
0
2697
1
Error
0
151
0





