로그인

검색

MoA
조회 수 3717 추천 수 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 Views15455
    read more
  2. 모달리스 대화상자

    Date2012.08.02 CategoryAPI/MFC ByNaya Views3207
    Read More
  3. [첫게임 만들기] 8. Win or Lose

    Date2013.11.21 CategoryPython ByMoA Views3209
    Read More
  4. 리스트뷰에 체크박스 추가 예제

    Date2013.05.24 CategoryJAVA/Android ByMoA Views3211
    Read More
  5. [S/W 공학] 월-인원(man-month), LOC

    Date2013.09.23 CategoryTool/etc ByMoA Views3215
    Read More
  6. fwrite(), fread()

    Date2013.07.28 CategoryC/C++ ByMoA Views3221
    Read More
  7. 추천 시스템

    Date2023.03.30 CategoryDeeplearning ByOBG Views3226
    Read More
  8. 정적 배열과 STL vector 속도 비교

    Date2013.07.28 CategorySTL/Boost ByMoA Views3232
    Read More
  9. CSS, 자바스크립트 강좌

    Date2013.11.05 CategorySite ByMoA Views3233
    Read More
  10. Deploying a Visual C++ Application (배포 방법)

    Date2012.08.02 CategoryAPI/MFC ByNaya Views3235
    Read More
  11. 동적 프로그래밍

    Date2012.08.13 CategoryAlgorithm ByNaya Views3241
    Read More
  12. ChartFX 7.0 MFC에서 사용하기

    Date2013.07.28 CategoryLibrary ByMoA Views3243
    Read More
  13. Property Sheet의 버튼 속성 변경하기

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

    Date2014.04.30 CategoryPython ByMoA Views3262
    Read More
  15. 작업자 스레드(Worker Thread) 와 사용자 인터페이스 스레드(User Interface Thread)

    Date2013.07.28 CategoryAPI/MFC ByMoA Views3283
    Read More
  16. Quake 3 source code and review

    Date2014.01.15 CategoryTool/etc ByMoA Views3284
    Read More
  17. Stable Diffusion

    Date2022.09.27 CategoryDeeplearning ByOBG Views3287
    Read More
  18. [액션게임 만들기] 4. 캐릭터 선택 화면

    Date2014.05.07 CategoryPython ByOBG Views3290
    Read More
  19. 잡담) AWS에 서버 띄워 놓으니 벼라별 리퀘스트가 다 날아 오네요

    Date2023.03.11 CategoryTool/etc ByOBG Views3291
    Read More
  20. Numpy의 axis 변경

    Date2023.06.09 CategoryPython ByOBG Views3301
    Read More
  21. 큰 수 구하기 알고리즘

    Date2012.08.02 CategoryAlgorithm ByNaya Views3303
    Read More
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 15 Next
/ 15