Skip to content

Commit

Permalink
Added motion detection code and sounds from Warren.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Burks committed Apr 17, 2010
1 parent f543d76 commit c24663d
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Prefix.pch
Expand Up @@ -2,4 +2,7 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <GameKit/GameKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <CoreAudio/CoreAudioTypes.h>
#import <AVFoundation/AVFoundation.h>
#endif
Binary file added Sounds/LittleFlips6.wav
Binary file not shown.
Binary file added Sounds/StartingGate.wav
Binary file not shown.
4 changes: 4 additions & 0 deletions Source/ApplicationDelegate.h
Expand Up @@ -17,11 +17,14 @@ typedef enum {
SlotMachineApplicationRoleMax
} SlotMachineApplicationRoleType;

@class Motion;

@interface ApplicationDelegate : NSObject {
UIWindow *window;
int applicationRole;
BOOL is_iPad;

Motion *motion;
GKSession *session;

// Peer IDs
Expand All @@ -34,6 +37,7 @@ typedef enum {
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, assign) int applicationRole;
@property (nonatomic, assign) BOOL is_iPad;
@property (nonatomic, retain) Motion *motion;

@property (nonatomic, retain) GKSession *session;

Expand Down
24 changes: 21 additions & 3 deletions Source/ApplicationDelegate.m
Expand Up @@ -6,6 +6,7 @@
//

#import "ApplicationDelegate.h"
#import "Motion.h"

ApplicationDelegate *DELEGATE;

Expand All @@ -14,10 +15,12 @@

@implementation ApplicationDelegate
@synthesize window, applicationRole, is_iPad;
@synthesize motion;
@synthesize session;
@synthesize masterID, slaveHandleID, slaveHopperID, slaveReels;

UIAlertView *roleChooserAlert;
AVAudioPlayer *soundPlayer;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Expand All @@ -36,6 +39,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window = [[[UIWindow alloc] initWithFrame:mainBounds] autorelease];
self.window.backgroundColor = [UIColor blueColor]; // confirm we've got it

self.motion = [[[Motion alloc] init] retain];
[window addSubview:motion];
[self.motion becomeFirstResponder];

// display role chooser
roleChooserAlert = [[[UIAlertView alloc]
initWithTitle:@"iPad Slot Machine"
Expand All @@ -47,8 +54,19 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[roleChooserAlert show];

[self.window makeKeyAndVisible];

// play a sound on startup
NSURL *fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"StartingGate" ofType:@"wav"]];
NSError *error;
if (!soundPlayer) {
soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
}
[soundPlayer play];
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);

return YES;
}
}


- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
Expand Down Expand Up @@ -79,8 +97,8 @@ - (void)session:(GKSession *)session didReceiveConnectionRequestFromPeer:(NSStri
autorelease];
[alert show];

NSError *perror;
[session acceptConnectionFromPeer:peerID error:perror];
NSError *error;
[session acceptConnectionFromPeer:peerID error:&error];
}

- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state
Expand Down
6 changes: 6 additions & 0 deletions Source/Motion.h
@@ -0,0 +1,6 @@

@interface Motion : UIView {

}

@end
34 changes: 34 additions & 0 deletions Source/Motion.m
@@ -0,0 +1,34 @@
//
// Motion.m
// AcceleratorTest
//
// Created by Warren Stringer on 4/16/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "Motion.h"


@implementation Motion

// must add [motion becomeFirstResponder] *after* adding this view to view hierarchy
// see MotionAppDelegate

-(BOOL) canBecomeFirstResponder {
return YES;
}

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { //__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)

NSLog(@"%s",_cmd);
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {//__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)

NSLog(@"%s",_cmd);
}
-(void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {//__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);

NSLog(@"%s",_cmd);
}

@end
34 changes: 34 additions & 0 deletions iPadSlotMachine.xcodeproj/project.pbxproj
Expand Up @@ -11,6 +11,12 @@
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
2235A27711797E5D0099FE99 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2235A27611797E5D0099FE99 /* main.m */; };
2235A28211797E980099FE99 /* ApplicationDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2235A28111797E980099FE99 /* ApplicationDelegate.m */; };
225D17811179A8B70085D2A4 /* Motion.m in Sources */ = {isa = PBXBuildFile; fileRef = 225D17801179A8B70085D2A4 /* Motion.m */; };
225D17AD1179AA530085D2A4 /* LittleFlips6.wav in Resources */ = {isa = PBXBuildFile; fileRef = 225D17AC1179AA530085D2A4 /* LittleFlips6.wav */; };
225D17AF1179AA5A0085D2A4 /* StartingGate.wav in Resources */ = {isa = PBXBuildFile; fileRef = 225D17AE1179AA5A0085D2A4 /* StartingGate.wav */; };
225D17CE1179AB9A0085D2A4 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 225D17CD1179AB9A0085D2A4 /* CoreAudio.framework */; };
225D17D81179ABF10085D2A4 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 225D17D71179ABF10085D2A4 /* AVFoundation.framework */; };
225D17DE1179AC040085D2A4 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 225D17DD1179AC030085D2A4 /* AudioToolbox.framework */; };
22C1CC491179855B003D1424 /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22C1CC481179855B003D1424 /* GameKit.framework */; };
288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765FC0DF74451002DB57D /* CoreGraphics.framework */; };
/* End PBXBuildFile section */
Expand All @@ -22,6 +28,13 @@
2235A27611797E5D0099FE99 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
2235A28011797E980099FE99 /* ApplicationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplicationDelegate.h; sourceTree = "<group>"; };
2235A28111797E980099FE99 /* ApplicationDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ApplicationDelegate.m; sourceTree = "<group>"; };
225D177F1179A8B70085D2A4 /* Motion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Motion.h; sourceTree = "<group>"; };
225D17801179A8B70085D2A4 /* Motion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Motion.m; sourceTree = "<group>"; };
225D17AC1179AA530085D2A4 /* LittleFlips6.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = LittleFlips6.wav; sourceTree = "<group>"; };
225D17AE1179AA5A0085D2A4 /* StartingGate.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = StartingGate.wav; sourceTree = "<group>"; };
225D17CD1179AB9A0085D2A4 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
225D17D71179ABF10085D2A4 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
225D17DD1179AC030085D2A4 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
22C1CC481179855B003D1424 /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = System/Library/Frameworks/GameKit.framework; sourceTree = SDKROOT; };
288765FC0DF74451002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
32CA4F630368D1EE00C91783 /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = "<group>"; };
Expand All @@ -37,6 +50,9 @@
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */,
288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */,
22C1CC491179855B003D1424 /* GameKit.framework in Frameworks */,
225D17CE1179AB9A0085D2A4 /* CoreAudio.framework in Frameworks */,
225D17D81179ABF10085D2A4 /* AVFoundation.framework in Frameworks */,
225D17DE1179AC040085D2A4 /* AudioToolbox.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -57,16 +73,28 @@
2235A27611797E5D0099FE99 /* main.m */,
2235A28011797E980099FE99 /* ApplicationDelegate.h */,
2235A28111797E980099FE99 /* ApplicationDelegate.m */,
225D177F1179A8B70085D2A4 /* Motion.h */,
225D17801179A8B70085D2A4 /* Motion.m */,
);
path = Source;
sourceTree = "<group>";
};
225D17A91179AA130085D2A4 /* Sounds */ = {
isa = PBXGroup;
children = (
225D17AC1179AA530085D2A4 /* LittleFlips6.wav */,
225D17AE1179AA5A0085D2A4 /* StartingGate.wav */,
);
path = Sounds;
sourceTree = "<group>";
};
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
8D1107310486CEB800E47090 /* Info.plist */,
2235A27011797DD70099FE99 /* Source */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
225D17A91179AA130085D2A4 /* Sounds */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
);
Expand All @@ -88,6 +116,9 @@
1D30AB110D05D00D00671497 /* Foundation.framework */,
288765FC0DF74451002DB57D /* CoreGraphics.framework */,
22C1CC481179855B003D1424 /* GameKit.framework */,
225D17CD1179AB9A0085D2A4 /* CoreAudio.framework */,
225D17D71179ABF10085D2A4 /* AVFoundation.framework */,
225D17DD1179AC030085D2A4 /* AudioToolbox.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -134,6 +165,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
225D17AD1179AA530085D2A4 /* LittleFlips6.wav in Resources */,
225D17AF1179AA5A0085D2A4 /* StartingGate.wav in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -146,6 +179,7 @@
files = (
2235A27711797E5D0099FE99 /* main.m in Sources */,
2235A28211797E980099FE99 /* ApplicationDelegate.m in Sources */,
225D17811179A8B70085D2A4 /* Motion.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit c24663d

Please sign in to comment.