開発者のブログ

開発者のブログ

ブログの説明を入力します。

Amebaでブログを始めよう!
//移動と削除(タイマーの方が動く)
// [self moveMap:dir];
moveStat = dir;
moveCnt = 32;
moveFlag = YES;

}

-(void)checkMapPoint:(int)dir {
CGPoint nextPoint;
if (dir == 0) {
nextPoint = CGPointMake(nowMapBasePoint.x, nowMapBasePoint.y-1);
}else if (dir == 1) {
nextPoint = CGPointMake(nowMapBasePoint.x, nowMapBasePoint.y+1);
}else if (dir == 2) {
nextPoint = CGPointMake(nowMapBasePoint.x-1, nowMapBasePoint.y);
}else if (dir == 3) {
nextPoint = CGPointMake(nowMapBasePoint.x+1, nowMapBasePoint.y);
}

NSArray *array = [mapDataArray objectAtIndex:nextPoint.y+heroHoseiPoint.y];
MapPartsData *data = [array objectAtIndex:nextPoint.x+heroHoseiPoint.x];

if (data.imgNo == 1) {
keyFlag = NO;
}else {
nowMapBasePoint = nextPoint;
[self mapChangeImg:dir];
}
}


-(void)gameProcess:(NSTimer *)timer {
//キー入力
if (moveFlag) {
moveCnt -= 2;

if (moveStat == STAT_MOVE_UP) {
for (NSMutableArray *array in mapImgViewArray) {
for (UIImageView *imgView in array) {
imgView.frame = CGRectMake(imgView.frame.origin.x, imgView.frame.origin.y+2, 32, 32);
}
}
}else if (moveStat == STAT_MOVE_DOWN) {
for (NSMutableArray *array in mapImgViewArray) {
for (UIImageView *imgView in array) {
imgView.frame = CGRectMake(imgView.frame.origin.x, imgView.frame.origin.y-2, 32, 32);
}
}
}else if (moveStat == STAT_MOVE_LEFT) {
for (NSMutableArray *array in mapImgViewArray) {
for (UIImageView *imgView in array) {
imgView.frame = CGRectMake(imgView.frame.origin.x+2, imgView.frame.origin.y, 32, 32);
}
}
}else if (moveStat == STAT_MOVE_RIGHT) {
for (NSMutableArray *array in mapImgViewArray) {
for (UIImageView *imgView in array) {
imgView.frame = CGRectMake(imgView.frame.origin.x-2, imgView.frame.origin.y, 32, 32);
}
}
}

if (moveCnt <= 0) {
//削除
if (moveStat == STAT_MOVE_UP) {
NSMutableArray *chip_x_array = [mapImgViewArray lastObject];
for (UIImageView *imgView in chip_x_array) {
[imgView removeFromSuperview];
}
[mapImgViewArray removeLastObject];
}else if (moveStat == STAT_MOVE_DOWN) {
NSMutableArray *chip_x_array = [mapImgViewArray objectAtIndex:0];
for (UIImageView *imgView in chip_x_array) {
[imgView removeFromSuperview];
}
[mapImgViewArray removeObjectAtIndex:0];
}else if (moveStat == STAT_MOVE_LEFT) {
for (int i = 0; i < mapchip_y; i++) {
NSMutableArray *chip_x_array = [mapImgViewArray objectAtIndex:i];

UIImageView *imgView = [chip_x_array lastObject];
[imgView removeFromSuperview];

[chip_x_array removeLastObject];
}
}else if (moveStat == STAT_MOVE_RIGHT) {
for (int i = 0; i < mapchip_y; i++) {
NSMutableArray *chip_x_array = [mapImgViewArray objectAtIndex:i];

UIImageView *imgView = [chip_x_array objectAtIndex:0];
[imgView removeFromSuperview];

[chip_x_array removeObjectAtIndex:0];
}
}

moveFlag = NO;
keyFlag = NO;
}
}

float abs_input_x = fabs(key_input_point.x);
float abs_input_y = fabs(key_input_point.y);
if (abs_input_x - abs_input_y != 0) {
if (!keyFlag) {
keyFlag = YES;
if (abs_input_x > abs_input_y) {
//左右
if (key_input_point.x > 0) {
[self checkMapPoint:STAT_MOVE_RIGHT];
}else {
[self checkMapPoint:STAT_MOVE_LEFT];
}

}else {
//上下
if (key_input_point.y > 0) {
[self checkMapPoint:STAT_MOVE_DOWN];
}else {
[self checkMapPoint:STAT_MOVE_UP];
}
}
}
}


//時間経過
conma ++;
if (conma >= 60) {
conma = 0;
second ++;
}
}


- (void)panAction : (UIPanGestureRecognizer *)sender {

if (sender.state == UIGestureRecognizerStateBegan) {
CGPoint location = [sender locationInView:self.view];

if (keyImgView == nil) {
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"key" ofType:@"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath];
keyImgView = [[UIImageView alloc] initWithImage:image];
[image release];
keyImgView.center = location;
[self.view addSubview:keyImgView];
[keyImgView release];
}


// ドラッグで移動した距離を取得する
key_input_point = [sender translationInView:self.view];

}else if (sender.state == UIGestureRecognizerStateEnded) {
if (keyImgView != nil) {
[keyImgView removeFromSuperview];
keyImgView = nil;
}

key_input_point = CGPointMake(0, 0);

}else {

// ドラッグで移動した距離を取得する
key_input_point = [sender translationInView:self.view];

// NSLog(@"x_%f",beforeP.x);
// NSLog(@"y_%f",beforeP.y);


// ドラッグで移動した距離を初期化する
// これを行わないと、[sender translationInView:]が返す距離は、ドラッグが始まってからの蓄積値となるため、
// 今回のようなドラッグに合わせてImageを動かしたい場合には、蓄積値をゼロにする
//[sender setTranslation:CGPointZero inView:self.view];

}
}