메뉴 건너뛰기

OBG

Programming

MoA
조회 수 516 추천 수 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 Views1973
    read more
  2. [첫게임 만들기] 4. 화살을 발사해보자

    Date2013.11.21 CategoryPython ByMoA Views710
    Read More
  3. Simple Add-On Wait Dialog in MFC

    Date2013.11.21 CategoryAPI/MFC ByMoA Views442
    Read More
  4. [첫게임 만들기] 5. 적을 생성하자

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

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

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

    Date2013.11.21 CategoryPython ByMoA Views438
    Read More
  8. [첫게임 만들기] 9. 사운드

    Date2013.11.21 CategoryPython ByMoA Views470
    Read More
  9. [GUI] Tkinter, wxPython

    Date2013.11.27 CategoryPython ByMoA Views667
    Read More
  10. [GUI] wxPython 기본 프로그램

    Date2013.11.30 CategoryPython ByMoA Views678
    Read More
  11. [GUI] wxPython에서 에러메시지 콘솔로 보는 법

    Date2013.12.03 CategoryPython ByMoA Views376
    Read More
  12. GetLastInputInfo 함수

    Date2013.12.06 CategoryAPI/MFC ByMoA Views453
    Read More
  13. WTL 정리

    Date2013.12.22 CategoryAPI/MFC ByMoA Views961
    Read More
  14. 다국어를 위한 StringTable, LoadString

    Date2013.12.22 CategoryAPI/MFC ByMoA Views2431
    Read More
  15. SciPy and NumPy

    Date2013.12.23 CategoryPython ByMoA Views631
    Read More
  16. Embedding Python in C/C++

    Date2013.12.23 CategoryPython ByMoA Views420
    Read More
  17. 유용한 라이브러리 소개

    Date2013.12.27 CategoryTool/etc ByMoA Views891
    Read More
  18. __FILE__ __LINE__ __FUNCTION__ 등 매크로

    Date2014.01.02 CategoryC/C++ ByMoA Views618
    Read More
  19. 화면 캡쳐 소스

    Date2014.01.14 CategoryPython ByMoA Views993
    Read More
  20. Quake 3 source code and review

    Date2014.01.15 CategoryTool/etc ByMoA Views415
    Read More
  21. OpenCV 이용한 템플릿 매칭

    Date2014.01.16 CategoryPython ByMoA Views1274
    Read More
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 15 Next
/ 15
위로