Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cranking business

  • Loading branch information...
commit 77884c59cea7bcff118308907f012d6b192fdf99 1 parent 91f7b61
@scoopr scoopr authored
View
BIN  FBDevStory.xcodeproj/project.xcworkspace/xcuserdata/scoopr.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
9 FacebookDevStory/AppDelegate.h
@@ -9,10 +9,16 @@
#import <UIKit/UIKit.h>
#import "FBConnect.h"
+#include <stdint.h>
+
@class ViewController;
+
@interface AppDelegate : UIResponder <UIApplicationDelegate, FBSessionDelegate, FBDialogDelegate, FBRequestDelegate> {
+
Facebook *facebook;
+ id whoamiRequest;
+ int64_t fbid;
}
@property (strong, nonatomic) UIWindow *window;
@@ -20,4 +26,7 @@
@property (strong, nonatomic) ViewController *viewController;
+
+-(int)itemType;
+
@end
View
27 FacebookDevStory/AppDelegate.m
@@ -19,6 +19,7 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
+ fbid=-1;
facebook = [[Facebook alloc] initWithAppId:@"359344330763412" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
@@ -26,6 +27,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
+ [self whoami];
}
if (![facebook isSessionValid]) {
@@ -40,6 +42,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
} else {
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
}
+ self.viewController.appDelegate = self;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
@@ -97,9 +100,15 @@ - (void)fbDidLogin {
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
-
+ [self whoami];
+}
+
+-(void)whoami
+{
+ whoamiRequest = [self.facebook requestWithGraphPath:@"/me" andDelegate:self];
}
+
- (void)fbDidNotLogin:(BOOL)cancelled {
}
@@ -163,6 +172,7 @@ - (void)applicationWillTerminate:(UIApplication *)application
*/
}
+
// Method that gets called when the request dialog button is pressed
- (void) requestDialogButtonClicked {
// The action links to be shown with the post in the feed
@@ -209,6 +219,14 @@ - (void) feedDialogButtonClicked {
*/
- (void)request:(FBRequest *)request didLoad:(id)result {
NSLog(@"received response");
+
+ if(request == whoamiRequest)
+ {
+
+ NSString* uid = [result objectForKey:@"id"];
+ fbid = [uid longLongValue];
+ return;
+ }
if (result != nil) {
NSArray *resultData = [result objectForKey:@"data"];
@@ -239,4 +257,11 @@ - (void) logoutButtonClicked {
[facebook logout];
}
+-(int)itemType
+{
+ return fbid%3;
+}
+
+
+
@end
View
7 FacebookDevStory/ViewController.h
@@ -9,6 +9,11 @@
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
-@interface ViewController : GLKViewController
+@class AppDelegate;
+@interface ViewController : GLKViewController
+{
+ AppDelegate* appDelegate;
+}
+@property (assign) AppDelegate* appDelegate;
@end
View
78 FacebookDevStory/ViewController.m
@@ -7,6 +7,7 @@
//
#import "ViewController.h"
+#import "AppDelegate.h"
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
@@ -147,11 +148,18 @@ @interface ViewController () {
double time;
double rotation;
+ double collectAnim;
+
+
+ float happiness;
+
+ int collectedItems;
}
@property (strong, nonatomic) EAGLContext *context;
@property (strong, nonatomic) GLKBaseEffect *effect;
+
- (void)setupGL;
- (void)tearDownGL;
@@ -165,6 +173,7 @@ @implementation ViewController
@synthesize context = _context;
@synthesize effect = _effect;
+@synthesize appDelegate;
- (void)dealloc
{
@@ -265,6 +274,8 @@ - (void)setupGL
time = 0;
rotation = 0;
+ happiness = 0;
+ collectAnim = 0;
redCube = [self loadTex:@"red"];
greenCube = [self loadTex:@"green"];
@@ -301,10 +312,6 @@ - (void)update
// float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
// GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0.1f, 100.0f);
-
-
-
-
screenWidth = self.view.frame.size.width;
screenHeight = self.view.frame.size.height;
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ||
@@ -338,6 +345,21 @@ - (void)update
// _rotation += self.timeSinceLastUpdate * 0.5f;
time += self.timeSinceLastUpdate;
+ happiness-= self.timeSinceLastUpdate;
+ collectAnim-= self.timeSinceLastUpdate;
+ if(collectAnim<0) collectAnim = 0;
+ if(rotation>2*M_PI)
+ {
+
+ collectedItems++;
+ if(collectedItems>3) collectedItems = 3;
+ else
+ {
+ collectAnim = 1;
+ happiness=1;
+ }
+ rotation-=2*M_PI;
+ }
}
-(void)rotateAroundX:(float)x Y:(float)y Rot:(float)rot
@@ -366,16 +388,42 @@ -(void)drawSadCreature
-(void)drawCrank:(double)rot
{
+ rot+=M_PI;
float x =screenWidth*.6f;
float y = screenHeight*.7f;
+
+ GLKTextureInfo* cube = [self cubeTex];
+ float pos = cube.width* (rotation/(2.0f*M_PI));
+ tex(cube, screenWidth+cube.width*.5f-pos, y, 1,1);
+
+
[self.effect prepareToDraw];
- tex(crank, x, y, 1, 1);
+ tex(crank, x, y, 1+sin(rot)*.1f, 1+cos(rot)*.1f);
[self rotateAroundX:x Y:(y-handle.height*.5f) Rot:rot];
- tex(handle, x-handle.width*.3f, y, 1, 1);
+ tex(handle, x-handle.width*.3f, y, 1,1);
[self rotateAroundX:0 Y:0 Rot:0];
+
+
+
}
+-(GLKTextureInfo*)cubeTex
+{
+ switch([self.appDelegate itemType])
+ {
+ case 0:
+ return redCube;
+ break;
+ case 1:
+ return greenCube;
+ break;
+ case 2:
+ return blueCube;
+ break;
+ }
+ return nil;
+}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
@@ -392,11 +440,25 @@ - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- [self drawSadCreature];
+ if(happiness>0)
+ {
+ [self drawHappyCreature];
+ } else
+ {
+ [self drawSadCreature];
+ }
[self drawCrank:rotation];
-// [self drawHappyCreature];
+
+ for(int i = 0; i < collectedItems; ++i)
+ {
+ GLKTextureInfo* cube = [self cubeTex];
+ float dropy = 0;
+ if(i == collectedItems-1) dropy = screenHeight*(1.0-collectAnim)-screenHeight;
+ tex(cube, screenWidth*.1, screenHeight-i*cube.height*.7f+dropy, 1,1);
+
+ }
#if 0
glDrawArrays(GL_TRIANGLES, 0, 36);
Please sign in to comment.
Something went wrong with that request. Please try again.