메뉴 건너뛰기

OBG

Programming

MoA
조회 수 510 추천 수 0 댓글 1
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

이번엔 적을 없애는 단계이다. 드디어 게임 느낌 나는 작업을 하는 것이다.

코드부터 먼저 보자. 적이 성을 공격하는 코드 다음에 충돌 체크를 한다.

 

        #6.4.2.2 - 충돌 체크
        index1=0
        for bullet in arrows:
            bullrect=pygame.Rect(arrow.get_rect())
            bullrect.left=bullet[1]
            bullrect.top=bullet[2]
            if badrect.colliderect(bullrect):
                acc[0]+=1
                badguys.pop(index)
                arrows.pop(index1)
            index1+=1

간단하다. 화살들의 rect를 가져와서 충돌 검사 후 충돌이 되면 플레이어의 명중 횟수를 늘리고 적과 화살을 없애면 된다.

여기서 rect가 뭔지 궁금할 것이다. rect는 이미지의 상하좌우 좌표를 가지고 있는 정보이다. bullrect = pygame.Rect( arrow.get_rect() )를 하면 arrow의 rect를 가져온 후 이를 bullrect 에 저장한다. 충돌 체크를 하는 경우엔 rect끼리 colliderect함수를 통해 검사하면 된다. 즉, badrect.colliderect( bullrect )를 하면 badrect와 bullrect가 충돌했는지를 검사하는 것이다.

?
  • ?
    기모니머스 2014.04.11 13:02
    오오 신통방통한 기능이군요

  1. Programming 게시판 관련

    Date2014.11.01 CategoryTool/etc ByMoA Views1958
    read more
  2. 2048게임 높은 점수 얻기 위한 알고리즘

    Date2014.03.29 CategoryAlgorithm ByMoA Views574
    Read More
  3. Legacy MFC 어플리케이션을 MFC feature pack으로 포팅

    Date2013.07.30 CategoryAPI/MFC ByMoA Views560
    Read More
  4. [농장게임 만들기] 5. 플레이어를 추가하자

    Date2014.04.30 CategoryPython ByMoA Views550
    Read More
  5. 리스트 컨트롤 클릭 이벤트

    Date2013.06.12 CategoryAPI/MFC ByMoA Views550
    Read More
  6. [농장게임 만들기] 7. 농부 행동 추가

    Date2014.05.01 CategoryPython ByMoA Views548
    Read More
  7. [S/W 공학] 월-인원(man-month), LOC

    Date2013.09.23 CategoryTool/etc ByMoA Views547
    Read More
  8. UI Guidelines

    Date2014.03.11 CategoryTool/etc ByMoA Views537
    Read More
  9. ofstream ifstream

    Date2013.07.28 CategoryC/C++ ByMoA Views536
    Read More
  10. [액션게임 만들기] 8. 캐릭터 액션 구현 1

    Date2014.05.07 CategoryPython ByMoA Views525
    Read More
  11. 동적 프로그래밍

    Date2012.08.13 CategoryAlgorithm ByNaya Views524
    Read More
  12. CPaneDialog의 context menu 안뜨게 하기

    Date2013.06.12 CategoryAPI/MFC ByMoA Views523
    Read More
  13. 코드 실행 시간 계산

    Date2012.09.27 CategoryC/C++ ByNaya Views513
    Read More
  14. 텍스트 에디터 Sublime Text 2

    Date2012.03.30 CategoryTool/etc By너울 Views512
    Read More
  15. [첫게임 만들기] 6. 적을 해치우자

    Date2013.11.21 CategoryPython ByMoA Views510
    Read More
  16. 파일 입출력

    Date2013.07.28 CategoryC/C++ ByMoA Views510
    Read More
  17. Google의 C++ 라이브러리

    Date2013.07.28 CategoryC/C++ ByMoA Views503
    Read More
  18. 서비스중인 게임 DB 설계(쿠키런) 기초

    Date2016.07.12 CategoryDatabase ByMoA Views501
    Read More
  19. [액션게임 만들기] 7. 캐릭터 출력

    Date2014.05.07 CategoryPython ByMoA Views497
    Read More
  20. Property Sheet의 버튼 속성 변경하기

    Date2013.07.25 CategoryAPI/MFC ByMoA Views497
    Read More
  21. What to use instead of “addPreferencesFromResource” in a PreferenceActivity?

    Date2013.06.13 CategoryJAVA/Android ByMoA Views496
    Read More
Board Pagination Prev 1 ... 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15
위로