pascalkk pascalkk
关注数: 27 粉丝数: 13 发帖数: 563 关注贴吧数: 11
【求助】我真不明白了。俄罗斯方块碰撞检测函数,求赐教。 我尽量把相关联的东西按我理解讲讲,代码全贴上来太烦了。 先上函数:bool collide(int dx,int dy,int roID=-1){ int i,j; for(i =0 ;i <bk.len;i++){ for (j =0;j< bk.len;j++){ if(bk.getUnit(j,i,roID)){ //获得填充单元【应该是即将填充的块的坐标,以及 // id???】 Point ptPos(j +x + dx, i + y +dy );//x和y分别是啥东西? if(Out(ptPos._x,ptPos._y) || //检测是否越边框 g_nGameBack[ptPos._y][ptPos._x] &&//游戏背景数组为真, ID != g_nGameBack[ptPos._y][ptPos._x] ) //ID为reset次 // 数???if语句中后两句表达式意思应该是检测是否和已经下落的方块碰撞的,但不知道ID究竟是干啥的,上文的ID好像是重置方块的次数 { return TRUE; } } } } return FALSE; }其中bk是一个表示七个方块的类,bk.len就是方块的边长(有6个3*3的,一个4*4的,就就是那个长条)。Point是个结构体,里头只有xy两个int量,表示坐标。 BOOL getUnit(int x, int y, int roID) { if(roID ==-1){ roID =nowRotateID;//这是选择id,代表方块的四种方向 } return mask[roID][y][x]; //返回一串01010,y在前面? }mask[][][]是个BOOL数组,按我理解返回一串1010,代表方块id 汉字都是我写的。求碰撞函数的意思。整小时整小时的搞,一个方块真这么难的么。。。目前这个游戏碰撞检测方面是有bug的。谢谢各位了哈。
c++习题,有点问题,没严格按照书上做,谢谢! #include <iostream> #include <string> #include <vector> #include <fstream> #include <algorithm> using namespace std; int main() { const char* msg_to_user(int try_num); { int try_num=0; const int rsp_cnt=5; static const char* usr_msg[rsp_cnt]={ "go on, make a guess.", "oops! nice guess but not quite it", "hmm,sorry,wrong again.", "ah,this is harder than it looks,no?", "it must be getting pretty frustrating by now!" }; if (try_num<0) try_num=0; else if(try_num>=rsp_cnt) try_num=rsp_cnt-1; return *usr_msg[try_num]; } int guess_num; string hi_to_usr; cout<<"enter a number:"<<endl; cin>>guess_num; hi_to_usr=*msg_to_user(guess_num); cout<<hi_to_usr<<endl; return 0; } ======================================== 1>------ 已启动生成: 项目: HelloWorld, 配置: Debug Win32 ------ 1>生成启动时间为 2011/11/22 20:54:09。 1>InitializeBuildStatus: 1> 正在对“Debug\HelloWorld.unsuccessfulbuild”执行 Touch 任务。 1>ClCompile: 1> Main.cpp 1>ManifestResourceCompile: 1> 所有输出均为最新。 1>Main.obj : error LNK2019: 无法解析的外部符号 "char const * __cdecl msg_to_user(int)" (?msg_to_user@@YAPBDH@Z),该符号在函数 _main 中被引用 1>E:\c++\4\HelloWorld\Debug\HelloWorld.exe : fatal error LNK1120: 1 个无法解析的外部命令 1> 1>生成失败。 1> 1>已用时间 00:00:01.16 ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ========== 无法解析外部符号是啥。。。。 书上是return usr_msg[try_num];,我写的是 return *usr_msg[try_num];,按照书上的写,说是返回类型有问题。谢谢指点啊。
1 下一页