2d汽车转向算法左右?

时间:2014-02-24 12:43:20

标签: iphone objective-c game-engine game-physics

我对编程很陌生,之前在游戏创建者Gamesalad中只有“编程”应用程序。我在Appstore上有一个我想要更新的游戏,因为它真的很快且很慢。如果有人能帮我把这段代码放在一起,我会很高兴的。汽车基本上不断前进,他们没有休息按钮。这个问题我似乎无法弄清楚它需要在汽车行驶的任何方向上工作。

// User pressed start game button
- (IBAction)Begin:(id)sender {
        timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(movement1) userInfo:nil repeats:YES];
        Hide.hidden = YES;
    }

// BOOL for left or right
- (IBAction)Leftdown1:(id)sender {
    NSLog(@"%hhd",left1);
    left1 = YES;
}

- (IBAction)Left1up:(id)sender {
     NSLog(@"%hhd",left1);
    left1 = NO;
}

- (IBAction)Right1down:(id)sender {
    right1 = YES;
}

- (IBAction)Right1up:(id)sender {
    right1 = NO;
}

    // movement1 getting called every 0.01 seconds
    -(void)movement1{
    if (left1) {
        //here i don't know what to do. I suppose i need to use cosines. The code below is just me testing.
        point1 = CGPointMake(point1.x-1, point1.y-1);
    } else {
        point1 = CGPointMake(point1.x+1, point1.y+1);
    }

      if (right1) {
        point1 = CGPointMake(point1.x-1, point1.y-1);
    } else {
        point1 = CGPointMake(point1.x+1, point1.y+1);
    }

    car.center = point1;
}

0 个答案:

没有答案