Skip to content

Instantly share code, notes, and snippets.

Created January 25, 2013 12:40
Show Gist options
  • Save anonymous/4634157 to your computer and use it in GitHub Desktop.
Save anonymous/4634157 to your computer and use it in GitHub Desktop.
/*
* DANGER! Copy-paste that going to hurt your eyes.
*/
#import "Cat.h"
@interface Cat ()
@property (strong, nonatomic) CCSprite *catBody;
@property (strong, nonatomic) CCSprite *catShadeLight;
@property (strong, nonatomic) CCSprite *catShadeMid;
@property (strong, nonatomic) CCSprite *catShadeDarkest;
@property (strong, nonatomic) CCSprite *catOutlineBottom;
@property (strong, nonatomic) CCSprite *catOutlineTop;
@property (strong, nonatomic) CCSprite *catColour;
- (void)paintYellow;
- (void)paintRed;
- (void)paintGreen;
- (void)paintBlue;
- (void)paintViolet;
- (void)paintYellow;
- (void)paintOrange;
@property (strong, nonatomic) CCSpriteFrame *catBodyFrame;
@property (strong, nonatomic) CCSpriteFrame *catShadeLightFrame;
@property (strong, nonatomic) CCSpriteFrame *catShadeMidFrame;
@property (strong, nonatomic) CCSpriteFrame *catShadeDarkestFrame;
@property (strong, nonatomic) CCSpriteFrame *catOutlineBottomFrame;
@property (strong, nonatomic) CCSpriteFrame *catOutlineTopFrame;
@property (strong, nonatomic) CCSpriteFrame *catColourFrame;
@property (strong, nonatomic) CCSpriteFrame *catBodyZoomedFrame;
@property (strong, nonatomic) CCSpriteFrame *catShadeLightZoomedFrame;
@property (strong, nonatomic) CCSpriteFrame *catShadeMidZoomedFrame;
@property (strong, nonatomic) CCSpriteFrame *catShadeDarkestZoomedFrame;
@property (strong, nonatomic) CCSpriteFrame *catOutlineBottomZoomedFrame;
@property (strong, nonatomic) CCSpriteFrame *catOutlineTopZoomedFrame;
@property (strong, nonatomic) CCSpriteFrame *catColourZoomedFrame;
@end
@implementation Cat
- (id)init {
self = [super init];
if (self) {
CGSize size = [[CCDirector sharedDirector] winSize];
{
UIImage *textureImage = [UIImage imageNamed:@"cat-body.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catBody = [CCSprite spriteWithSpriteFrame:frame];
self.catBody.zOrder = 1;
self.catBody.position = ccp( size.width /2 , size.height/2 );
self.catBodyFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-shade-light.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catShadeLight = [CCSprite spriteWithSpriteFrame:frame];
self.catShadeLight.zOrder = 2;
self.catShadeLight.position = ccp( size.width /2 , size.height/2 );
self.catShadeLightFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-shade-mid.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catShadeMid = [CCSprite spriteWithSpriteFrame:frame];
self.catShadeMid.zOrder = 3;
self.catShadeMid.position = ccp( size.width /2 , size.height/2 );
self.catShadeMidFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-shade-darkest.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catShadeDarkest = [CCSprite spriteWithSpriteFrame:frame];
self.catShadeDarkest.zOrder = 4;
self.catShadeDarkest.position = ccp( size.width /2 , size.height/2 );
self.catShadeDarkestFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-outline-bottom.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catOutlineBottom = [CCSprite spriteWithSpriteFrame:frame];
self.catOutlineBottom.zOrder = 5;
self.catOutlineBottom.position = ccp( size.width /2 , size.height/2 );
self.catOutlineBottomFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-outline-top.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catOutlineTop = [CCSprite spriteWithSpriteFrame:frame];
self.catOutlineTop.zOrder = 6;
self.catOutlineTop.position = ccp( size.width /2 , size.height/2 );
self.catOutlineTopFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-colour.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catColour = [CCSprite spriteWithSpriteFrame:frame];
self.catColour.zOrder = 7;
self.catColour.position = ccp( size.width /2 , size.height/2 );
self.catColourFrame = frame;
}
self.color = CatColorYellow;
[self addChild:self.catBody];
[self addChild:self.catShadeLight];
[self addChild:self.catShadeMid];
[self addChild:self.catShadeDarkest];
[self addChild:self.catOutlineBottom];
[self addChild:self.catOutlineTop];
[self addChild:self.catColour];
{
UIImage *textureImage = [UIImage imageNamed:@"cat-body-zoomed.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catBodyZoomedFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-shade-light-zoomed.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catShadeLightZoomedFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-shade-mid-zoomed.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catShadeMidZoomedFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-shade-darkest-zoomed.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catShadeDarkestZoomedFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-outline-bottom-zoomed.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catOutlineBottomZoomedFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-outline-top-zoomed.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catOutlineTopZoomedFrame = frame;
}
{
UIImage *textureImage = [UIImage imageNamed:@"cat-colour-zoomed.png"];
CCTexture2D *texture = [[CCTexture2D alloc] initWithCGImage:textureImage.CGImage resolutionType:kCCResolutioniPhone];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
self.catColourZoomedFrame = frame;
}
}
return self;
}
- (void)setColor:(MyCatColor)color {
_color = color;
switch (color) {
case CatColorBlue:
[self paintBlue];
break;
case CatColorGreen:
[self paintGreen];
break;
case CatColorOrange:
[self paintOrange];
break;
case CatColorRed:
[self paintRed];
break;
case CatColorViolet:
[self paintViolet];
break;
case CatColorYellow:
[self paintYellow];
break;
default:
break;
}
}
static ccColor3B catBodyColorRed = {228, 41, 46};
static ccColor3B catShadeLightColorRed = {204, 38, 43};
static ccColor3B catShadeMidColorRed = {177, 33, 36};
static ccColor3B catShadeDarkestColorRed = {154, 35, 38};
static ccColor3B catOutlineBottomColorRed = {77, 6, 22};
static ccColor3B catOutlineTopColorRed = {142, 0, 47};
static ccColor3B catColourColorRed = {217, 125, 23};
- (void)paintRed {
self.catBody.color = catBodyColorRed;
self.catShadeLight.color = catShadeLightColorRed;
self.catShadeMid.color = catShadeMidColorRed;
self.catShadeDarkest.color = catShadeDarkestColorRed;
self.catOutlineBottom.color = catOutlineBottomColorRed;
self.catOutlineTop.color = catOutlineTopColorRed;
self.catColour.color = catColourColorRed;
}
static ccColor3B catBodyColorYellow = {255, 231, 62};
static ccColor3B catShadeLightColorYellow = {255, 194, 14};
static ccColor3B catShadeMidColorYellow = {217, 125, 23};
static ccColor3B catShadeDarkestColorYellow = {169, 82, 29};
static ccColor3B catOutlineBottomColorYellow = {77, 6, 22};
static ccColor3B catOutlineTopColorYellow = {153, 0, 48};
static ccColor3B catColourColorYellow = {255, 163, 77};
- (void)paintYellow {
self.catBody.color = catBodyColorYellow;
self.catShadeLight.color = catShadeLightColorYellow;
self.catShadeMid.color = catShadeMidColorYellow;
self.catShadeDarkest.color = catShadeDarkestColorYellow;
self.catOutlineBottom.color = catOutlineBottomColorYellow;
self.catOutlineTop.color = catOutlineTopColorYellow;
self.catColour.color = catColourColorYellow;
}
static ccColor3B catBodyColorBlue = {0, 183, 239};
static ccColor3B catShadeLightColorBlue = {6, 125, 234};
static ccColor3B catShadeMidColorBlue = {16, 13, 209};
static ccColor3B catShadeDarkestColorBlue = {22, 85, 188};
static ccColor3B catOutlineBottomColorBlue = {77, 6, 22};
static ccColor3B catOutlineTopColorBlue = {53, 63, 100};
static ccColor3B catColourColorBlue = {255, 163, 77};
- (void)paintBlue {
self.catBody.color = catBodyColorBlue;
self.catShadeLight.color = catShadeLightColorBlue;
self.catShadeMid.color = catShadeMidColorBlue;
self.catShadeDarkest.color = catShadeDarkestColorBlue;
self.catOutlineBottom.color = catOutlineBottomColorBlue;
self.catOutlineTop.color = catOutlineTopColorBlue;
self.catColour.color = catColourColorBlue;
}
static ccColor3B catBodyColorGreen = {91, 196, 77};
static ccColor3B catShadeLightColorGreen = {62, 179, 68};
static ccColor3B catShadeMidColorGreen = {53, 147, 7};
static ccColor3B catShadeDarkestColorGreen = {50, 112, 56};
static ccColor3B catOutlineBottomColorGreen = {77, 6, 22};
static ccColor3B catOutlineTopColorGreen = {30, 69, 34};
static ccColor3B catColourColorGreen = {255, 163, 77};
- (void)paintGreen {
self.catBody.color = catBodyColorGreen;
self.catShadeLight.color = catShadeLightColorGreen;
self.catShadeMid.color = catShadeMidColorGreen;
self.catShadeDarkest.color = catShadeDarkestColorGreen;
self.catOutlineBottom.color = catOutlineBottomColorGreen;
self.catOutlineTop.color = catOutlineTopColorGreen;
self.catColour.color = catColourColorGreen;
}
static ccColor3B catBodyColorOrange = {232, 123, 26};
static ccColor3B catShadeLightColorOrange = {219, 104, 28};
static ccColor3B catShadeMidColorOrange = {197, 91, 29};
static ccColor3B catShadeDarkestColorOrange = {169, 72, 31};
static ccColor3B catOutlineBottomColorOrange = {77, 6, 22};
static ccColor3B catOutlineTopColorOrange = {153, 0, 38};
static ccColor3B catColourColorOrange = {255, 163, 77};
- (void)paintOrange {
self.catBody.color = catBodyColorOrange;
self.catShadeLight.color = catShadeLightColorOrange;
self.catShadeMid.color = catShadeMidColorOrange;
self.catShadeDarkest.color = catShadeDarkestColorOrange;
self.catOutlineBottom.color = catOutlineBottomColorOrange;
self.catOutlineTop.color = catOutlineTopColorOrange;
self.catColour.color = catColourColorOrange;
}
static ccColor3B catBodyColorViolet = {132, 78, 199};
static ccColor3B catShadeLightColorViolet = {116, 66, 191};
static ccColor3B catShadeMidColorViolet = {91, 61, 136};
static ccColor3B catShadeDarkestColorViolet = {80, 56, 133};
static ccColor3B catOutlineBottomColorViolet = {77, 6, 22};
static ccColor3B catOutlineTopColorViolet = {40, 49, 77};
static ccColor3B catColourColorViolet = {220, 69, 88};
- (void)paintViolet {
self.catBody.color = catBodyColorViolet;
self.catShadeLight.color = catShadeLightColorViolet;
self.catShadeMid.color = catShadeMidColorViolet;
self.catShadeDarkest.color = catShadeDarkestColorViolet;
self.catOutlineBottom.color = catOutlineBottomColorViolet;
self.catOutlineTop.color = catOutlineTopColorViolet;
self.catColour.color = catColourColorViolet;
}
- (void)paintNextColor {
int nextColor = 0;
int currentColor = (int)self.color;
if (currentColor == 5) {
nextColor = 0;
}
else {
nextColor = currentColor + 1;
}
self.color = (MyCatColor)nextColor;
}
- (void)setIsZoomed:(BOOL)isZoomed {
_isZoomed = isZoomed;
if (isZoomed) {
[self.catBody setDisplayFrame:self.catBodyZoomedFrame];
[self.catShadeLight setDisplayFrame:self.catShadeLightZoomedFrame];
[self.catShadeMid setDisplayFrame:self.catShadeMidZoomedFrame];
[self.catShadeDarkest setDisplayFrame:self.catShadeDarkestZoomedFrame];
[self.catOutlineBottom setDisplayFrame:self.catOutlineBottomZoomedFrame];
[self.catOutlineTop setDisplayFrame:self.catOutlineTopZoomedFrame];
[self.catColour setDisplayFrame:self.catColourZoomedFrame];
}
else {
[self.catBody setDisplayFrame:self.catBodyFrame];
[self.catShadeLight setDisplayFrame:self.catShadeLightFrame];
[self.catShadeMid setDisplayFrame:self.catShadeMidFrame];
[self.catShadeDarkest setDisplayFrame:self.catShadeDarkestFrame];
[self.catOutlineBottom setDisplayFrame:self.catOutlineBottomFrame];
[self.catOutlineTop setDisplayFrame:self.catOutlineTopFrame];
[self.catColour setDisplayFrame:self.catColourFrame];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment