Skip to content

Commit

Permalink
Money money money!
Browse files Browse the repository at this point in the history
  • Loading branch information
scoopr committed Mar 5, 2012
1 parent da983d2 commit ca75361
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions FBDevStory.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
762F0575150502DD00C7319C /* FacebookDevStoryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 762F0574150502DD00C7319C /* FacebookDevStoryTests.m */; };
762F05921505042900C7319C /* FBDialog.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 762F05851505042900C7319C /* FBDialog.bundle */; };
762F05931505042900C7319C /* libfacebook_ios_sdk.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 762F058B1505042900C7319C /* libfacebook_ios_sdk.a */; };
BF075066150562A200001000 /* money.png in Resources */ = {isa = PBXBuildFile; fileRef = BF075065150562A200001000 /* money.png */; };
BF8CE278150512F2005E5D9D /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF8CE277150512F2005E5D9D /* OpenGLES.framework */; };
BF8CE27A1505137C005E5D9D /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF8CE2791505137C005E5D9D /* GLKit.framework */; };
BF8CE27F15051462005E5D9D /* ViewController_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = BF8CE27B15051462005E5D9D /* ViewController_iPad.xib */; };
Expand Down Expand Up @@ -78,6 +79,7 @@
762F058F1505042900C7319C /* SBJsonBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SBJsonBase.h; sourceTree = "<group>"; };
762F05901505042900C7319C /* SBJsonParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SBJsonParser.h; sourceTree = "<group>"; };
762F05911505042900C7319C /* SBJsonWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SBJsonWriter.h; sourceTree = "<group>"; };
BF075065150562A200001000 /* money.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = money.png; path = img/money.png; sourceTree = "<group>"; };
BF8CE274150512EE005E5D9D /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = System/Library/Frameworks/GameKit.framework; sourceTree = SDKROOT; };
BF8CE277150512F2005E5D9D /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
BF8CE2791505137C005E5D9D /* GLKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLKit.framework; path = System/Library/Frameworks/GLKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -225,6 +227,7 @@
children = (
BFB405FD15051B09008E58D8 /* blue.png */,
BFB4060B15053A8D008E58D8 /* crank.png */,
BF075065150562A200001000 /* money.png */,
BFB4060C15053A8D008E58D8 /* handle.png */,
BFB405FE15051B09008E58D8 /* green.png */,
BFB405FF15051B09008E58D8 /* happy.png */,
Expand Down Expand Up @@ -315,6 +318,7 @@
BFB4060615051B09008E58D8 /* sad.png in Resources */,
BFB4060D15053A8D008E58D8 /* crank.png in Resources */,
BFB4060E15053A8D008E58D8 /* handle.png in Resources */,
BF075066150562A200001000 /* money.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
49 changes: 49 additions & 0 deletions FacebookDevStory/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#define BUFFER_OFFSET(i) ((char *)NULL + (i))

const float MAX_HAPPINESS=60;

static float screenWidth, screenHeight;

// Uniform index.
Expand Down Expand Up @@ -145,13 +147,16 @@ @interface ViewController () {

GLKTextureInfo* handle;
GLKTextureInfo* crank;

GLKTextureInfo* money;

double time;
double rotation;
double collectAnim;


float happiness;
float moneyAnim;

int collectedItems;

Expand Down Expand Up @@ -277,6 +282,7 @@ - (void)setupGL
happiness = 0;
collectAnim = 0;
collectedItems = -1;
moneyAnim = 0;

redCube = [self loadTex:@"red"];
greenCube = [self loadTex:@"green"];
Expand All @@ -288,6 +294,8 @@ - (void)setupGL
handle = [self loadTex:@"handle"];
crank = [self loadTex:@"crank"];

money = [self loadTex:@"money"];

}

- (void)tearDownGL
Expand Down Expand Up @@ -315,6 +323,7 @@ - (void)update




int it = [self.appDelegate itemType];
if(it != -1)
{
Expand Down Expand Up @@ -357,6 +366,8 @@ - (void)update
time += self.timeSinceLastUpdate;
happiness-= self.timeSinceLastUpdate;
collectAnim-= self.timeSinceLastUpdate;
moneyAnim-= self.timeSinceLastUpdate;
if(moneyAnim<0) moneyAnim = 0;
if(collectAnim<0) collectAnim = 0;
if(rotation>2*M_PI && collectedItems != -1)
{
Expand All @@ -371,6 +382,27 @@ - (void)update
[self.appDelegate setItems:[self.appDelegate itemType] value:collectedItems];
rotation-=2*M_PI;
}


int reds = [self.appDelegate numItems:0];
int greens = [self.appDelegate numItems:1];
int blues = [self.appDelegate numItems:2];

if(reds>=1 && greens>=1 && blues>=1)
{
happiness=MAX_HAPPINESS;
moneyAnim = 1;
reds--;
greens--;
blues--;
[self.appDelegate setItems:0 value:reds];
[self.appDelegate setItems:1 value:greens];
[self.appDelegate setItems:2 value:blues];
}




}

-(void)rotateAroundX:(float)x Y:(float)y Rot:(float)rot
Expand Down Expand Up @@ -457,6 +489,21 @@ - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

int moneycount = happiness-1;
if(moneycount<0) moneycount = 0;
float moneyy = screenHeight*(1.0f-moneyAnim)-screenHeight;

for(size_t i = 0; i < moneycount; ++i)
{
float fun = happiness/(float)MAX_HAPPINESS;

tex(money, screenWidth*.5f + sin(i*342)*fun*screenWidth*.12, screenHeight*.5f-(i/fun)*screenHeight*.002f+moneyy, 1,1);
}






if(happiness>0)
{
Expand All @@ -482,6 +529,8 @@ - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
}
}



#if 0
glDrawArrays(GL_TRIANGLES, 0, 36);

Expand Down
Binary file added img/money.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ca75361

Please sign in to comment.