cocoaTouch/overlayViewController.m
author koda
Thu, 18 Mar 2010 02:27:46 +0000
changeset 3017 4a52e0705011
parent 3015 20a9c8160e82
child 3025 01682ec58eb0
permissions -rw-r--r--
fix the glitch causing pass-through in land objects besides first game
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
     1
//
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
     2
//  overlayViewController.m
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
     3
//  HedgewarsMobile
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
     4
//
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
     5
//  Created by Vittorio on 16/03/10.
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
     7
//
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
     8
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
     9
#import "overlayViewController.h"
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    10
#import "PascalImports.h"
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    11
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    12
@implementation overlayViewController
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    13
@synthesize dimTimer;
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    14
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    15
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    16
-(void) didReceiveMemoryWarning {
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    17
	// Releases the view if it doesn't have a superview.
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    18
    [super didReceiveMemoryWarning];
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    19
	
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    20
	// Release any cached data, images, etc that aren't in use.
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    21
}
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    22
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    23
-(void) viewDidLoad {
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    24
    dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    25
                                        interval:1000
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    26
                                          target:self
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    27
                                        selector:@selector(dimOverlay)
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    28
                                        userInfo:nil
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    29
                                         repeats:YES];
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    30
    
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    31
    [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    32
}
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    33
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    34
-(void) viewDidUnload {
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    35
	[dimTimer invalidate];
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    36
}
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    37
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    38
-(void) dealloc {
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    39
    [dimTimer release];
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    40
    [super dealloc];
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    41
}
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    42
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    43
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    44
// dim the overlay when there's no more input for a certain amount of time
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    45
-(IBAction) buttonReleased:(id) sender {
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    46
	HW_allKeysUp();
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    47
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    48
}
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    49
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    50
// nice transition for dimming
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    51
-(void) dimOverlay {
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    52
    [UIView beginAnimations:@"overlay dim" context:NULL];
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    53
   	[UIView setAnimationDuration:0.6];
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    54
    self.view.alpha = 0.2;
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    55
	[UIView commitAnimations];
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    56
}
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    57
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    58
// set the overlay visible and put off the timer for enough time
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    59
-(void) activateOverlay {
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    60
    self.view.alpha = 1;
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    61
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]];
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    62
}
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    63
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    64
// issue certain action based on the tag of the button 
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    65
-(IBAction) buttonPressed:(id) sender {
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    66
    [self activateOverlay];
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    67
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    68
    UIButton *theButton = (UIButton*)sender;
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    69
    switch (theButton.tag) {
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    70
        case 0:
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    71
           	HW_walkLeft();
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    72
            break;
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    73
        case 1:
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    74
            HW_walkRight();
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    75
            break;
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    76
        case 2:
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    77
            HW_aimUp();
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    78
            break;
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    79
        case 3:
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    80
            HW_aimDown();
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    81
            break;
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    82
        case 4:
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    83
            HW_shoot();
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    84
            break;
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    85
        case 5:
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    86
            HW_jump();
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    87
            break;
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    88
        case 6:
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    89
            HW_backjump();
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    90
            break;
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    91
        default:
3015
20a9c8160e82 add jump and backjump controls
koda
parents: 3006
diff changeset
    92
            // HW_chat() HW_tab() HW_pause()
3006
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    93
            break;
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    94
    }
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    95
}
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    96
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    97
da6023c2745b restore compilation on simulator and device
koda
parents:
diff changeset
    98
@end