2 u011933934 u011933934 于 2014.03.22 15:25 提问

MFC 横版 怎么使得怪物跟着地图滚动消失。

自己控制一个hero 然后人物走动会使得地图滚动,然后在屏幕上的怪物也随着地图的滚动而消失。就比如赛车超车了 被超的会落后到屏幕后面不见。贴上代码

lass Hero{

public:
int hero_x,hero_y,hero_vx,hero_vy,move_face,hero_face,step ;

Hero();
void run();

};
class Enemy{
public:

int enemy_x,enemy_y,enemy_vx,enemy_vy,face,step,life,lenght;
Enemy();
void enemy_move();
};
class Rollback
{
public: int rollback_x,rollback_vx;

    Rollback();
    void roll();

};
Hero Jianxiake;
Enemy Enemy[4];
Rollback rollback;
/////////////////////////////////////// 人物的动作 /////////////////////////////////////////////////
Hero::Hero()
{
hero_x=210,hero_y=370,hero_vy=0,hero_vx=0,hero_face=0;

}

void Hero::run()
{
hero_x=hero_x+hero_vx;
hero_y=hero_y+hero_vy;
step++;

if (hero_vy==0&&hero_vx==0)
{

  BufDC.TransparentBlt(hero_x,hero_y,56,91,&ManDC,(step%7)*56,hero_face*91,56,91,0x000000); 

}

else
BufDC.TransparentBlt(hero_x,hero_y,67,91,&MoveDC,(step%7)*67,move_face*91,67,91,0x000000);
}
///////////////////////////////////////人物动作////////////////////////////////////////////////////

//////////////////////////////////////背景滚动//////////////////////////////////////////////////////
Rollback::Rollback(){

rollback_x=0,rollback_vx=0;

}

void Rollback::roll()
{
rollback_x=rollback_x+rollback_vx;

if(Jianxiake.hero_x+67>400)
{
   Jianxiake.hero_vx=0;

   rollback_vx=10;
}
 BufDC.BitBlt(0,0,1024,760,&BackDC,rollback_x,0,SRCCOPY);

}
//////////////////////////////////////////////背景滚动////////////////////////////////////////////////////

//////////////////////////////////////怪物动作////////////////////////////////////////////////////
Enemy ::Enemy(){
enemy_x=600,enemy_y=370;
lenght=3;
life=1;
face=rand()%4;
switch(face)
{
case 0:
enemy_vx=lenght;
enemy_vy=0;
break;
case 1:
enemy_vx=-lenght;
enemy_vy=0;
break;
case 2:
enemy_vx=lenght;
enemy_vy=-lenght;
break;
case 3:
enemy_vy=-lenght;
enemy_vx=-lenght;
break;

  }

}
void Enemy::enemy_move(){
enemy_x+=enemy_vx;
enemy_y+=enemy_vy;
int q;

if (enemy_x<0)
{
    enemy_vx=lenght;
    //srand(time(0));
    q=rand()%3;
    switch(q)
    {
    case 0: 
        enemy_vy=-lenght;
        face=2;
        break;
    case 1:
        enemy_vy=lenght;
        face=0;
        break;
    case 2:
        enemy_vy=0;
        face=0;
        break;

    }
}
if (enemy_x>900-20)
{
    enemy_vx=-lenght;
    //srand(time(0));

    q= rand()%3;
    switch(q)
    {

    case 0:
        enemy_vy=-lenght;
        face=3;
        break;
    case 1:
        enemy_vy=lenght;
        face=1;
        break;
    case 2:
        enemy_vy=0;
        face=1;
        break;

    }
}
if (enemy_y>500)
{
    enemy_vy=-lenght;
    //srand(time(0));

    q= rand()%3;
    switch(q)
    {
    case 0:
        enemy_vx=-lenght;
        face=3;
        break;
    case 1:
        enemy_vx=lenght;
        face=2;
        break;
    case 2:
        enemy_vx=0;
        face=2;
        break;

    }
}

if (enemy_y<240)
{
    enemy_vy=lenght;
    //srand(time(0));

    q= rand()%3;
    switch(q)
    {
    case 0:
        enemy_vx=-lenght;
        face=1;
        break;
    case 1:
        enemy_vx=lenght;
        face=0;
        break;
    case 2:
        enemy_vx=0;
        face=0;
        break;

    }
}

        step++;
       BufDC.TransparentBlt(enemy_x+rollback.rollback_vx,enemy_y,204,176,&EnemyDC,(step%4)*204,face*176,204,176,0xffffff); 

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!