Created
June 10, 2013 21:44
-
-
Save gregtemp/5752655 to your computer and use it in GitHub Desktop.
Match Game Scamble (ITP Version) same match game, but written differently so that it's possible to scramble the images easily.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// C4WorkSpace.m | |
// Examples | |
// | |
// Created by Greg Debicki. | |
// | |
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace { | |
BOOL s0Bool, s1Bool, s2Bool, s3Bool, s4Bool, s5Bool; | |
NSMutableArray *shapes, *images, *masks; | |
} | |
-(void)setup { | |
shapes = [@[] mutableCopy]; | |
images = [@[] mutableCopy]; | |
masks = [@[] mutableCopy]; | |
[self setupMasks]; | |
[self setupImages]; | |
[self placeImages]; | |
[self setupShapes]; | |
[self setupGestures]; | |
[self listenFor:@"touchesBegan" andRunMethod:@"test"]; | |
} | |
-(void) setupMasks { | |
CGRect rect = CGRectMake(0, 0, 150, 150); | |
for(int i = 0; i < 6; i ++) { | |
C4Shape *m = [C4Shape ellipse:rect]; | |
[masks addObject:m]; | |
} | |
} | |
-(void) setupImages { | |
C4Image *i0 = [C4Image imageNamed:@"C4Sky"]; | |
C4Image *i1 = [C4Image imageNamed:@"C4Sky"]; | |
C4Image *i2 = [C4Image imageNamed:@"C4Table"]; | |
C4Image *i3 = [C4Image imageNamed:@"C4Table"]; | |
C4Image *i4 = [C4Image imageNamed:@"C4Gradient"]; | |
C4Image *i5 = [C4Image imageNamed:@"C4Gradient"]; | |
[images addObject:i0]; | |
[images addObject:i1]; | |
[images addObject:i2]; | |
[images addObject:i3]; | |
[images addObject:i4]; | |
[images addObject:i5]; | |
for (int i = 0; i < 6; i++) { | |
C4Image *img = (C4Image *)images[i]; | |
img.width *= 0.5f; | |
C4Shape *m = (C4Shape *)masks[i]; | |
m.center = img.center; | |
img.mask = m; | |
} | |
} | |
-(void) placeImages { | |
NSInteger count = 0; | |
NSInteger order[6] = {2,3,5,0,4,1}; | |
for (int i = 0; i < 2; i++) { | |
for (int j = 0; j < 3; j++){ | |
CGPoint currentCenter = self.canvas.center; | |
currentCenter.x -= 200; | |
currentCenter.x += j * 200; | |
currentCenter.y += i * 200; | |
C4Image *img = (C4Image *)images[order[count]]; | |
img.center = currentCenter; | |
img.userInteractionEnabled = NO; | |
count++; | |
} | |
} | |
[self.canvas addObjects:images]; | |
} | |
-(void) setupShapes { | |
CGRect rect = CGRectMake(0, 0, 150, 150); | |
for(int i = 0; i < 6; i ++) { | |
C4Shape *s = [C4Shape ellipse:rect]; | |
C4Image *img = (C4Image *)images[i]; | |
s.center = img.center; | |
[shapes addObject:s]; | |
} | |
[self.canvas addObjects:shapes]; | |
} | |
-(void) setupGestures { | |
[self listenFor:@"touchesBegan" fromObject:shapes[0] andRunMethod:@"s0On"]; | |
[self listenFor:@"touchesBegan" fromObject:shapes[1] andRunMethod:@"s1On"]; | |
[self listenFor:@"touchesBegan" fromObject:shapes[2] andRunMethod:@"s2On"]; | |
[self listenFor:@"touchesBegan" fromObject:shapes[3] andRunMethod:@"s3On"]; | |
[self listenFor:@"touchesBegan" fromObject:shapes[4] andRunMethod:@"s4On"]; | |
[self listenFor:@"touchesBegan" fromObject:shapes[5] andRunMethod:@"s5On"]; | |
} | |
-(void) test { | |
C4Log(@"tsadlkfja"); | |
} | |
-(void) s0On { | |
C4Shape *s = (C4Shape *)shapes[0]; | |
s.animationDuration = 0.2f; | |
s.alpha = 0.0f; | |
s0Bool = YES; | |
[self runMethod:@"s0Off" afterDelay:1.0f]; | |
} | |
-(void) s0Off { | |
C4Shape *s = (C4Shape *)shapes[0]; | |
if(s1Bool != YES) { | |
s.alpha = 1.0f; | |
s0Bool = NO; | |
} | |
[self runMethod:@"didWin" afterDelay:2.0f]; | |
} | |
-(void) s1On { | |
C4Shape *s = (C4Shape *)shapes[1]; | |
s.animationDuration = 0.2f; | |
s.alpha = 0.0f; | |
s1Bool = YES; | |
[self runMethod:@"s1Off" afterDelay:1.0f]; | |
} | |
-(void) s1Off { | |
C4Shape *s = (C4Shape *)shapes[1]; | |
if(s0Bool != YES) { | |
s.alpha = 1.0f; | |
s1Bool = NO; | |
} | |
[self runMethod:@"didWin" afterDelay:2.0f]; | |
} | |
-(void) s2On { | |
C4Shape *s = (C4Shape *)shapes[2]; | |
s.animationDuration = 0.2f; | |
s.alpha = 0.0f; | |
s2Bool = YES; | |
[self runMethod:@"s2Off" afterDelay:1.0f]; | |
} | |
-(void) s2Off { | |
C4Shape *s = (C4Shape *)shapes[2]; | |
if(s3Bool != YES) { | |
s.alpha = 1.0f; | |
s2Bool = NO; | |
} | |
[self runMethod:@"didWin" afterDelay:2.0f]; | |
} | |
-(void) s3On { | |
C4Shape *s = (C4Shape *)shapes[3]; | |
s.animationDuration = 0.2f; | |
s.alpha = 0.0f; | |
s3Bool = YES; | |
[self runMethod:@"s3Off" afterDelay:1.0f]; | |
} | |
-(void) s3Off { | |
C4Shape *s = (C4Shape *)shapes[3]; | |
if(s2Bool != YES) { | |
s.alpha = 1.0f; | |
s3Bool = NO; | |
} | |
[self runMethod:@"didWin" afterDelay:2.0f]; | |
} | |
-(void) s4On { | |
C4Shape *s = (C4Shape *)shapes[4]; | |
s.animationDuration = 0.2f; | |
s.alpha = 0.0f; | |
s4Bool = YES; | |
[self runMethod:@"s4Off" afterDelay:1.0f]; | |
} | |
-(void) s4Off { | |
C4Shape *s = (C4Shape *)shapes[4]; | |
if(s5Bool != YES) { | |
s.alpha = 1.0f; | |
s4Bool = NO; | |
} | |
[self runMethod:@"didWin" afterDelay:2.0f]; | |
} | |
-(void) s5On { | |
C4Shape *s = (C4Shape *)shapes[5]; | |
s.animationDuration = 0.2f; | |
s.alpha = 0.0f; | |
s5Bool = YES; | |
[self runMethod:@"s5Off" afterDelay:1.0f]; | |
} | |
-(void) s5Off { | |
C4Shape *s = (C4Shape *)shapes[5]; | |
if(s4Bool != YES) { | |
s.alpha = 1.0f; | |
s5Bool = NO; | |
} | |
[self runMethod:@"didWin" afterDelay:2.0f]; | |
} | |
-(void) didWin { | |
if (s0Bool==YES && s1Bool==YES && s2Bool==YES && | |
s3Bool==YES && s4Bool==YES && s5Bool==YES) { | |
for (int i = 0; i < 6; i ++) { | |
C4Shape *s = (C4Shape *)shapes[i]; | |
s.animationDuration = 2.0f; | |
s.alpha = 1.0f; | |
[shapes replaceObjectAtIndex:i withObject:s]; | |
} | |
s0Bool = NO; | |
s1Bool = NO; | |
s2Bool = NO; | |
s3Bool = NO; | |
s4Bool = NO; | |
s5Bool = NO; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment