Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Các phiên bản mới hoàn toàn của chiến xe tăng hiện có sẵn trong chapter11 \ \ tankwar trên đĩa CD-ROM, bạn có thể tải lên các dự án hoặc chỉ đơn giản là chạy các trò chơi từ vị trí đó nếu bạn muốn. Tôi khuyên bạn nên bạn làm theo theo và thực hiện những thay đổi chính mình vì nó là một kinh nghiệm học tập có giá trị. | Enhancing Tank War 415 Figure 11.8 Tank War now draws animated explosions in the game loop without pausing the game. Modifying the Tank War Project The complete new version of Tank War is available in chapter11 tankwar on the CD-ROM you can load up the project or simply run the game from that location if you want. I recommend you follow along and make the changes yourself because it is a valuable learning experience. To do so you ll want to open the Tank War project from Chapter 10 to make the following changes. Be sure to copy the tank1.bmp and tank2.bmp files off the CD-ROM so the new version of the game will work because these bitmap files contain the new animated tanks. Updating tankwar.h First you need to make a few minor changes to the tankwar.h header file. Look for the section of code that defines the sprites and add the new line of code shown in bold. SPRITE mytanks 2 SPRITE tanks 2 SPRITE mybulletS 2 SPRITE bullets 2 SPRITE explosions 2 Next modify the tank_bmp array which contains the bitmap images for the tanks. Scroll down in tankwar.h a little further to find the sprite bitmap definitions and make the change noted in bold. It s a small change to the tank_bmp array just add another dimension to the array as shown. 416 Chapter 11 Timers Interrupt Handlers and Multi-Threading sprite bitmaps BITMAP tank_bmp 2 8 8 BITMAP bullet_bmp BITMAP explode_bmp Now scroll down a little further in tankwar.h to the function prototypes and add the following three function definitions noted in bold function prototypes void animatetank int num void updateexplosion int num void loadsprites void drawtank int num void erasetank int num void movetank int num Updating tank.c Now you can make some changes to the tank.c source code file which contains all the code for loading moving and drawing the tanks. Add a new function to the top of tank.c to accommodate the new animated tanks. new function added in chapter 11 void animatetank int num if tanks num - framecount tanks num - .