TAILIEUCHUNG - microsoft visual basic game programming for teens phần 9

Ngoài ra một thói quen chuyển động dựa trên trạng thái, tôi cũng đã sửa đổi các chương trình con DrawNPCs do đó, nó cũng dựa trên trạng thái của một NPC. Nhà nước lý do là kiểm tra ở cả những thói quen là bởi vì thói quen di chuyển xảy ra trước khi bất kỳ bản cập nhật màn hình, | 300 Chapter 17 Talking with NPCs State-Based Drawing In addition to a state-based movement routine I have also modified the DrawNPCs subroutine so it is also based on the state of an NPC. The reason state is checked in both of these routines is because the move routine occurs before any screen updates while the draw routine occurs inside the BeginScene and EndScene block of code. Public Sub DrawNPCs Dim n As Long loop through all of the NPCs and draw them For n 0 To NUMNPCS - 1 Select Case charStates n .state Case NPC_TALKING DrawNPC n charStates n .state NPC_WALKING If KEY_SPACE 0 Then TalkToPlayer n End If Case NPC_PAUSED DrawNPC n charStates n .state NPC_WALKING Case NPC_WALKING DrawNPC n Case NPC_STOPPED DrawNPC n charStates n .state NPC_WALKING End Select Next n End Sub Encountering the Player In order to accommodate the new state engine and in particular the encounter state that is to take place I wrote a new subroutine called CheckNPCCollisions that is called by the main game loop. The name is consistent with the last collision routine which is called Level Up 301 CheckTileCollisions. This routine looks for a close encounter between any one NPC and the player at which point the NPC s state is set to NPC_TALKING. Public Sub CheckNPCCollisions Dim n As Long check all NPCs for collisions For n 0 To NUMNPCS - 1 If Collision charSprites n heroSpr Then charStates n .state NPC_TALKING End If Next n End Sub Talking to the Player The DrawNPCs routine calls TalkToPlayer when the user chooses to talk to an NPC. To do this you press a certain key during an encounter to engage the NPC in dialog. I chose the spacebar in this example but you may feel free to use any key you wish and this is also a good time to add joystick support to the game in which case you could then use a joystick button to chat with an NPC . Public Sub TalkToPlayer ByVal num As Long Dim x As Long Dim y As Long x charSprites num .x charSprites num .width 4 y charSprites num .y PrintText .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.