2015-04-03 65 views
0

我将如何完成此功能,使子弹摧毁一块岩石(由#字符显示)?我正在考虑使用mvinch来检查* bullet字符==“#”,但这不起作用。如何检测子弹击中太空侵略者控制台游戏与lncurses

void update_bullet(int key_code) { 
    screen_position bullet_pos = get_sprite_screen_loc(bullet_id); 
    if (bullet_pos.x < 0 && key_code == ' ') { 
     screen_position ship_pos = get_sprite_screen_loc(ship_id); 
     move_sprite_to(bullet_id, ship_pos.x + 7, ship_pos.y + 3); 
    } else if (bullet_pos.x > 79) { 
     move_sprite_to(bullet_id, -1, 0); 
    } else if (bullet_pos.x > 0) { 
     move_sprite(bullet_id, 1, 0); 
    } 
} 

上面的代码是在整个屏幕上移动子弹。

我试图做的是,当它到达控制台屏幕的边缘外,它移回到(-1,0),并且当它与岩石#位于同一位置时, #和*字符移回(-1,0)。

回答

0

您不能将光标移出窗口,因此您的move_sprite函数(在问题中未给出)必须处理该方面。例如(缺少move_sprite的代码,它可能会做

int move_sprite(screen_position position, int dx, int dy) 
{ 
    int y, x; 
    getyx(stdscr, y, x); 
    if (dx > 0) { 
     ++x; 
    } 
    else if (dx < 0) { 
     x = -1;    /* this is incorrect, but matches the information given in the question */ 
    } 
    ... 
    move(y, x); 
} 

按照move手册页,将光标移到窗外,企图将返回ERR并没有任何效果。

+0

如何那回答这个问题? – 2015-04-03 10:33:27

+0

它回答了提供的信息给出的信息。 – 2015-04-03 10:43:36