Ios 为简单的迷宫游戏创建墙
我正在做一个单视图游戏演示,一个有墙的迷宫式游戏。玩家将使用UIButton控制角色 基本上,我已经设计好,我需要检查,如果在下一步中,角色将与墙相交,那么角色移动将返回false。但是,我似乎不能把它们放在一起 我现在有一个布尔函数来检查角色是否与墙相交Ios 为简单的迷宫游戏创建墙,ios,iphone,Ios,Iphone,我正在做一个单视图游戏演示,一个有墙的迷宫式游戏。玩家将使用UIButton控制角色 基本上,我已经设计好,我需要检查,如果在下一步中,角色将与墙相交,那么角色移动将返回false。但是,我似乎不能把它们放在一起 我现在有一个布尔函数来检查角色是否与墙相交 -(Boolean) checkCollision : (CGRect) newFrame{ CGRect frame = self.mainchar.frame; frame.origin.x = self.currentPoint.x;
-(Boolean) checkCollision : (CGRect) newFrame{
CGRect frame = self.mainchar.frame;
frame.origin.x = self.currentPoint.x;
frame.origin.y = self.currentPoint.y;
for (UIImageView *image in self.hardwalls) {
if (CGRectIntersectsRect(frame, image.frame)) {
return true;
}
}
return false;
}
我的移动按钮是
-(IBAction)CharMovingLeft:(id)sender; {
CGPointMake(mainchar.center.x -charmovement, mainchar.center.y);
我应该在按钮方法中添加什么,以便在交叉口即将发生时停止此移动
提前谢谢
-(IBAction)CharMovingLeft:(id)sender {
CGRect newFrame = YOUR_CHARACTERS_FRAME_IF_IT_MOVED;
if (![self checkCollision:newFrame];
//MOVE CHARACTER:
}
else
//DONT MOVE CHARACTER
}
这样行吗