로그인

검색

MoA
조회 수 12471 추천 수 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 Views108251
    read more
  2. OpenCV 이용한 템플릿 매칭

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

    Date2014.01.15 CategoryTool/etc ByMoA Views21250
    Read More
  4. 화면 캡쳐 소스

    Date2014.01.14 CategoryPython ByMoA Views12636
    Read More
  5. __FILE__ __LINE__ __FUNCTION__ 등 매크로

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

    Date2013.12.27 CategoryTool/etc ByMoA Views12485
    Read More
  7. Embedding Python in C/C++

    Date2013.12.23 CategoryPython ByMoA Views20620
    Read More
  8. SciPy and NumPy

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

    Date2013.12.22 CategoryAPI/MFC ByMoA Views23224
    Read More
  10. WTL 정리

    Date2013.12.22 CategoryAPI/MFC ByMoA Views13568
    Read More
  11. GetLastInputInfo 함수

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

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

    Date2013.11.30 CategoryPython ByMoA Views12015
    Read More
  14. [GUI] Tkinter, wxPython

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

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

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

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

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

    Date2013.11.21 CategoryPython ByMoA Views11074
    Read More
  20. Simple Add-On Wait Dialog in MFC

    Date2013.11.21 CategoryAPI/MFC ByMoA Views21767
    Read More
  21. [첫게임 만들기] 4. 화살을 발사해보자

    Date2013.11.21 CategoryPython ByMoA Views11882
    Read More
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 17 Next
/ 17