微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

难度设置和测试对象属性

如何解决难度设置和测试对象属性

所以我正在使用 VS2010 使用 Allegro 4.4 开发基于图块的地图游戏

稍后会涉及寻路,所以我有代表地图上图块的节点结构。节点结构包含在我为该程序称为“地图”的图形结构中。游戏以一个空的 16x16 网格开始。这个想法是玩家可以通过在菜单上选择地形类型,然后单击网格图块来使该网格图块成为选定的地形类型,从而自己创建地图布局。一旦玩家选择了一个地图图块,代表该地图图块的节点对象的“set”布尔值就会设置为 true,并将地形信息和节点位置写入节点对象属性中。

为了将选定的瓷砖地形绘制到屏幕上,我有一个 drawMap() 函数,它循环遍历地图中的每个节点,如果节点的布尔属性“set”为真,则应绘制相应的瓷砖。请参阅下面的代码

void getInput(Menu option,Graph map)   {
    float x = 0;
    float y = 0;
    int tile = 0; 
    int enumStore = 0;
    bool inputFlag = false;

    //retrieve mouse position when clicked
    if(mouse_b & 1)
    {
        inputFlag = true;
        x = mouse_x;
        y = mouse_y;
    }
    if(inputFlag)
    {
        //set index node cost attribute to currently selected terrain
        x = floor(x/tileSize);
        y = floor(y/tileSize);
        tile = (16*y)+x;    //16 because grid is 16x16
        map.nodes[tile].terrain = option.current;
        map.nodes[tile].nodex = x*tileSize; //store position of top left corner of tile with node attributes
        map.nodes[tile].nodey = y*tileSize;
        map.nodes[tile].set = true;
        textprintf_ex(screen,font,15,WHITE,"Current Menu Selection: %i",option.current);
        textprintf_ex(screen,25,"tile %i is Now set",tile);
    }
}

void drawMap(BITMAP *buffer,BITMAP *tiles[],Graph map)    {
    for(int i=0; i<map.tiles; i++)
    {
        if(map.nodes[i].set)
        {
            blit(tiles[map.nodes[i].terrain],buffer,map.nodes[i].nodex,map.nodes[i].nodey,tiles[map.nodes[i].terrain]->w,tiles[map.nodes[i].terrain]->h);
            textprintf_ex(screen,35,"blit executed");
        }
    }   
}
//main game loop
    while (!key[KEY_ESC])
    {
        //see if mouse needs polled before using mouse position functions
        if(mouse_needs_poll())
        {
            poll_mouse();
        }
        //change menu selection
        option.ChangeSelection(buffer);
        //get and apply player input
        getInput(option,map);

        //draw the menu and the tile grid
        option.DrawMenu(buffer);
        drawMap(buffer,tiles,map);
        drawGrid(buffer);

        show_mouse(buffer);

        //update the screen
        blit(buffer,screen,640,480);

        //game timer 
        rest(10);
    }

我的文本输出语句确认玩家输入被注册到正确的节点索引。但由于某种原因,drawMap() 函数中的 blit 似乎从未被执行过。我不明白这是怎么可能的,因为我单击的节点的“设置”属性肯定被设置为 true?我弄乱了一个标志来验证我的 drawMap() 函数中的 if 语句从未被输入,甚至没有在单个循环中短暂输入。

我刚刚开始学习 OOP 和不同的游戏设计方法,所以请随时建设性地指出我代码中的效率问题或其他问题。

先谢谢你!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。