로그인

검색

MoA
조회 수 3716 추천 수 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 Views15452
    read more
  2. Windows 10 앱 개발(UWP)

    Date2015.10.13 CategoryAPI/MFC ByMoA Views3380
    Read More
  3. CString class

    Date2013.07.28 CategoryAPI/MFC ByMoA Views3379
    Read More
  4. 스레드 강좌 + CreateThread() 와 _beginthreadex() 함수의 차이

    Date2013.07.28 CategoryAPI/MFC ByMoA Views3378
    Read More
  5. [액션게임 만들기] 10. 캐릭터 기술 구현

    Date2014.05.07 CategoryPython ByMoA Views3361
    Read More
  6. What does set -e mean in a bash script?

    Date2021.04.29 CategoryTool/etc ByOBG Views3360
    Read More
  7. 에디트 플러스, VS 2008 컴파일 환경 설정

    Date2013.07.28 CategoryTool/etc ByMoA Views3354
    Read More
  8. GetLastInputInfo 함수

    Date2013.12.06 CategoryAPI/MFC ByMoA Views3337
    Read More
  9. Which Font is the default for MFC Dialog Controls

    Date2013.06.12 CategoryAPI/MFC ByMoA Views3335
    Read More
  10. MFC에서 생성,사용되는 파일 확장자

    Date2013.08.30 CategoryAPI/MFC ByMoA Views3335
    Read More
  11. Redmine 설치

    Date2013.07.28 CategoryTool/etc ByMoA Views3329
    Read More
  12. Simplified Logger Class

    Date2013.07.28 CategoryC/C++ ByMoA Views3324
    Read More
  13. [액션게임 만들기] 5. 장면 전환

    Date2014.05.07 CategoryPython ByMoA Views3321
    Read More
  14. extern "C" 에 관하여

    Date2013.07.28 CategoryC/C++ ByMoA Views3314
    Read More
  15. [액션게임 만들기] 6. 게임 화면 출력

    Date2014.05.07 CategoryPython ByMoA Views3308
    Read More
  16. 구글 검색 알고리즘의 원리

    Date2012.08.02 CategoryAlgorithm ByNaya Views3306
    Read More
  17. Simple Add-On Wait Dialog in MFC

    Date2013.11.21 CategoryAPI/MFC ByMoA Views3305
    Read More
  18. [농장게임 만들기] 4. 펜스를 그리자

    Date2014.04.30 CategoryPython ByMoA Views3304
    Read More
  19. 큰 수 구하기 알고리즘

    Date2012.08.02 CategoryAlgorithm ByNaya Views3299
    Read More
  20. Numpy의 axis 변경

    Date2023.06.09 CategoryPython ByOBG Views3293
    Read More
  21. 프로세스 - 생성과 종료 그리고 이것 저것

    Date2011.10.12 CategoryAPI/MFC By너울 Views3291
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15