【发布时间】:2014-12-23 15:36:51
【问题描述】:
我正在开发 Microsoft Visual Studio 2010,尝试使用 Allegro.h 库编写游戏。
重点是
- 我正在使用缓冲区通过 draw_sprite(screen,buf1,0,0); 绘制到建筑物;
- 之后我想在该屏幕中移动位图球图像
- 当我移动 .bmp 图像时,我再次使用 buf1(同一个缓冲区),但我应该清理 buf1 以创建移动图像
- 当我自然而然地这样做时,我会错过缓冲区中的所有内容,但我想要在我的游戏中使用建筑物背景。
- 如何在一个屏幕中使用两个缓冲区?
这是我的代码:
void BinaCizdir1(BITMAP *buf1){
int r;
int renk;
int say=0;
BITMAP *turuncu_beton=load_bitmap("turuncu.bmp",NULL);
BITMAP *sari_beton=load_bitmap("sari.bmp",NULL);
BITMAP *pembe_beton=load_bitmap("pink.bmp",NULL);
BITMAP *oyunu1_resmi=load_bitmap("topbu.bmp",NULL);
//Birinci oyuncunun x koordinatını belirledik.Random olarak!
int oyuncu1_y_koor=0;
int oyuncu1_x_koor1= (1+rand()%4);
if (oyuncu1_x_koor1==1){
oyuncu1_x_koor1=30;
}
if (oyuncu1_x_koor1==2){
oyuncu1_x_koor1=150;
}if (oyuncu1_x_koor1==3){
oyuncu1_x_koor1=270;
}if (oyuncu1_x_koor1==4){
oyuncu1_x_koor1=390;
}
if(kontrol==0){
renk=(rand()%3);r= (1+rand()%6)*30;
for(int x=0;x<1080;x=x+30){
for(int y=600;y>450-r;y=y-30){
if(oyuncu1_x_koor1==x){
oyuncu1_y_koor=390-r;
draw_sprite(buf1,oyunu1_resmi,oyuncu1_x_koor1,oyuncu1_y_koor);
}
if(renk==0){
draw_sprite(buf1,turuncu_beton,x,y);
}
if(renk==1){
draw_sprite(buf1,sari_beton,x,y);
}
if(renk==2){
draw_sprite(buf1,pembe_beton,x,y);
}
}
if( say%3==2 && x!=1020){
renk=(rand()%3);
r= (1+rand()%6)*30;
x=x+30;
}
say++;
/*
velocityY = velocityY +acc*dt; // updating the y component of the velocity
x = x + (velocityX*dt); // updating the x position
y = y + (velocityY*dt) + 0.5*acc*(dt*dt);// updating the y position.
rest(5);
draw_sprite(buf1,oyunu1_resmi,x,y);
*/
}
kontrol=1;
}
draw_sprite(screen,buf1,0,0);
}
这是我的移动 bmp 图像代码:
velocityY = velocityY +acc*dt; // updating the y component of the velocity
x = x + (velocityX*dt); // updating the x position
y = y + (velocityY*dt) + 0.5*acc*(dt*dt);// updating the y position.
rest(5);
draw_sprite(buf1,oyunu1_resmi,x,y);
【问题讨论】: