forked from DocOtak/not_tanaka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TanakaGameController.m
59 lines (49 loc) · 1.22 KB
/
TanakaGameController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// TanakaGameController.m
// nottanaka
//
// Created by Alex Dodge on 8/3/10.
// Copyright 2010 Roke Foundries. All rights reserved.
//
#import "TanakaGameController.h"
@implementation TanakaGameController
@synthesize gameView;
-(void) awakeFromNib {
keys_left = keys_right = keys_up = NO;
player_rotation = player_distance = 0;
course = [[Course alloc] init];
[course circularTrackWithRadius:300 andSegments:500];
[gameView setKeyboardDelegate:self];
[gameView setCourse:course];
frameTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0/FPS) target:self selector:@selector(frame:) userInfo:nil repeats:YES];
}
-(void) frame: (NSTimer*)timer {
if(keys_left){
player_rotation += 90/(FPS);
}
if(keys_right){
player_rotation -= 90/(FPS);
}
if(!keys_up){
player_distance += 30/(FPS);
}
while(player_distance > [course totalDistance]) player_distance -= [course totalDistance]; // Loop track
[gameView setPlayerAngle:player_rotation Distance:player_distance];
}
-(void) key:(unichar) c value:(BOOL)v {
NSLog(@"%c is %s", c, v ? "down" : "up");
switch (c) {
case 'a':
keys_left = v;
break;
case 'd':
keys_right = v;
break;
case 'w':
keys_up = v;
break;
default:
break;
}
}
@end