로그인

검색

MoA
조회 수 3920 추천 수 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 Views17643
    read more
  2. RAND_MAX

    Date2014.01.19 CategoryC/C++ ByMoA Views3244
    Read More
  3. OpenCV 이용한 템플릿 매칭

    Date2014.01.16 CategoryPython ByMoA Views4101
    Read More
  4. Quake 3 source code and review

    Date2014.01.15 CategoryTool/etc ByMoA Views3596
    Read More
  5. 화면 캡쳐 소스

    Date2014.01.14 CategoryPython ByMoA Views3790
    Read More
  6. __FILE__ __LINE__ __FUNCTION__ 등 매크로

    Date2014.01.02 CategoryC/C++ ByMoA Views4020
    Read More
  7. 유용한 라이브러리 소개

    Date2013.12.27 CategoryTool/etc ByMoA Views3773
    Read More
  8. Embedding Python in C/C++

    Date2013.12.23 CategoryPython ByMoA Views3222
    Read More
  9. SciPy and NumPy

    Date2013.12.23 CategoryPython ByMoA Views3286
    Read More
  10. 다국어를 위한 StringTable, LoadString

    Date2013.12.22 CategoryAPI/MFC ByMoA Views5416
    Read More
  11. WTL 정리

    Date2013.12.22 CategoryAPI/MFC ByMoA Views3891
    Read More
  12. GetLastInputInfo 함수

    Date2013.12.06 CategoryAPI/MFC ByMoA Views3750
    Read More
  13. [GUI] wxPython에서 에러메시지 콘솔로 보는 법

    Date2013.12.03 CategoryPython ByMoA Views4105
    Read More
  14. [GUI] wxPython 기본 프로그램

    Date2013.11.30 CategoryPython ByMoA Views3654
    Read More
  15. [GUI] Tkinter, wxPython

    Date2013.11.27 CategoryPython ByMoA Views3632
    Read More
  16. [첫게임 만들기] 9. 사운드

    Date2013.11.21 CategoryPython ByMoA Views3735
    Read More
  17. [첫게임 만들기] 8. Win or Lose

    Date2013.11.21 CategoryPython ByMoA Views3419
    Read More
  18. [첫게임 만들기] 7. 게임 정보 표시

    Date2013.11.21 CategoryPython ByMoA Views4135
    Read More
  19. [첫게임 만들기] 6. 적을 해치우자

    Date2013.11.21 CategoryPython ByMoA Views3920
    Read More
  20. [첫게임 만들기] 5. 적을 생성하자

    Date2013.11.21 CategoryPython ByMoA Views3260
    Read More
  21. Simple Add-On Wait Dialog in MFC

    Date2013.11.21 CategoryAPI/MFC ByMoA Views3496
    Read More
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 17 Next
/ 17