tailieunhanh - Game Programming All in One 2 nd Edition phần 5

. Bạn sẽ tìm hiểu làm thế nào để nhìn vào màn hình video để xác định khi phóng một cuộc đình công một chiếc xe tăng hoặc đối tượng khác, làm thế nào để đọc bàn phím, và làm thế nào để xử lý một vòng lặp trò chơi. Mục tiêu của chương này là để cho bạn thấy rằng bạn có thể tạo ra một trò chơi toàn bộ bằng cách sử dụng | Enhancing Tank War 267 explode_bmp NULL draw the explosion bitmap several times for n 0 n 5 n rotate_sprite screen explode_bmp x rand 10 - 20 y rand 10 - 20 itofix rand 255 rest 30 clear the explosion circlefill screen x y 50 BLACK updatebullet function update the position of a bullet void updatebullet int num int x bullets num .x int y bullets num .y is the bullet active if bullets num .alive return erase bullet rectfill screen x y x 10 y 10 BLACK move bullet bullets num .x bullets num .xspd bullets num .y bullets num .yspd x bullets num .x y bullets num .y stay within the screen if x 6 x SCREEN_W-6 y 20 y SCREEN_H-6 bullets num .alive 0 268 Chapter 8 Basic Sprite Programming return look for a direct hit using basic collision tank is either 0 or 1 so negative num other tank int tx tanks num .x int ty tanks num .y if x tx-16 x tx 16 y ty-16 y ty 16 kill the bullet bullets num .alive 0 blow up the tank explode num x y score num else if no hit then draw the bullet draw bullet sprite draw_sprite screen bullet_bmp x y update the bullet positions for debugging textprintf screen font SCREEN_W 2-50 1 TAN B1 -3dx -3d B2 -3dx -3d bullets 0 .x bullets 0 .y bullets 1 .x bullets 1 .y fireweapon function set bullet direction and speed and activate it void fireweapon int num int x tanks num .x int y tanks num .y load bullet image if necessary if bullet_bmp NULL Enhancing Tank War 269 bullet_bmp NULL ready to fire again if bullets num .alive bullets num .alive 1 fire bullet in direction tank is facing switch tanks num .dir north case 0 bullets num .x x-2 bullets num .y y-22 bullets num .xspd 0 bullets num .yspd -BULLETSPEED break NE case 1 bullets num .x x 18 bullets num .y y-18 bullets num .xspd BULLETSPEED bullets num .yspd -BULLETSPEED break east case 2 bullets num .x x 22 bullets num .y y-2 bullets num .xspd BULLETSPEED bullets num .yspd 0 break SE case 3 bullets num .x x 18 bullets num .y y 18 bullets num .xspd BULLETSPEED .

crossorigin="anonymous">
Đã 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.