Chủ nhiệm Bộ môn Ngô Hữu Phúc ĐỀ CƯƠng chi tiết bài giảNG


Figure 6.5 A single sprite is flipped both vertically and horizontally



tải về 3.11 Mb.
trang13/21
Chuyển đổi dữ liệu24.11.2017
Kích3.11 Mb.
#34506
1   ...   9   10   11   12   13   14   15   16   ...   21

Figure 6.5

A single sprite is flipped both vertically and horizontally.

6.5 Drawing Rotated Sprites

Figure 8.7



The tank sprite (courtesy of Ari Feldman) rotated in eight directions.

Figure 8.8

The tank sprite (courtesy of Ari Feldman) rotated in 16 directions.

#include

#include

#define WHITE makecol(255,255,255)

int main(void)

{

int x, y;

float angle = 0;

//initialize program

allegro init();

install keyboard();

set color depth(32);

set gfx mode(GFX AUTODETECT WINDOWED, 640, 480, 0, 0);

textout ex(screen, font, "Rotate: LEFT / RIGHT arrow keys",

0, 0, WHITE, 0);

//load tank sprite

BITMAP *tank = load bitmap("tank.bmp", NULL);

//calculate center of screen

x = SCREEN W/2 - tank->w/2;

y = SCREEN H/2 - tank->h/2;

//draw tank at starting location

rotate sprite(screen, tank, x, y, 0);

//main loop

while(!key[KEY ESC])

{

//wait for keypress

if (keypressed())

{

//left arrow rotates left

if (key[KEY LEFT])

{

angle -= 0.1;

if (angle < 0) angle = 256;

rotate sprite(screen, tank, x, y, itofix(angle));

}

//right arrow rotates right

if (key[KEY RIGHT])

{

angle þ= 0.1;

if (angle > 256) angle = 0;

rotate sprite(screen, tank, x, y, itofix(angle));

}

Basic Sprite Handling 285

//display angle

textprintf ex(screen,font,0,10,WHITE,0,"Angle = %f", angle);

}

}

allegro exit();

return 0;

}

END OF MAIN()

Additional Rotation Functions



void rotate sprite v flip(BITMAP *bmp, BITMAP *sprite,

int x, int y, fixed angle)

The preceding function rotates and also flips the image vertically. To flip

horizontally, add itofix(128) to the angle. To flip in both directions, use

rotate sprite() and add itofix(128) to its angle.



void rotate scaled sprite(BITMAP *bmp, BITMAP *sprite,

int x, int y, fixed angle, fixed scale)

The preceding function rotates an image and scales (stretches to fit) the image at

the same time.

void rotate scaled sprite v flip(BITMAP *bmp, BITMAP *sprite,

int x, int y, fixed angle, fixed scale)

The preceding function rotates the image while also scaling and flipping it

vertically, simply combining the functionality of the previous two functions.


Каталог: files -> FileMonHoc
FileMonHoc -> NGÂn hàng câu hỏi lập trình cơ BẢn nhóm câu hỏI 2 ĐIỂM
FileMonHoc -> CHƯƠng 2 giới thiệu về LÝ thuyết số
FileMonHoc -> CÁc hệ MẬt khoá CÔng khai kháC
FileMonHoc -> BỘ MÔn duyệt chủ nhiệm Bộ môn
FileMonHoc -> Khoa công nghệ thông tin cộng hòa xã HỘi chủ nghĩa việt nam
FileMonHoc -> Chủ nhiệm Bộ môn Ngô Thành Long ĐỀ CƯƠng chi tiết bài giảNG
FileMonHoc -> Chủ nhiệm Bộ môn Phan Nguyên Hải ĐỀ CƯƠng chi tiết bài giảNG
FileMonHoc -> Khoa: CÔng nghệ thông tin cộng hòa xã HỘi chủ nghĩa việt nam
FileMonHoc -> MẬt mã khóA ĐỐi xứng lý thuyết cơ bản của Shannon
FileMonHoc -> Khoa công nghệ thông tin bài giảng LẬp trình cơ BẢn biên soạn

tải về 3.11 Mb.

Chia sẻ với bạn bè của bạn:
1   ...   9   10   11   12   13   14   15   16   ...   21




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương