├── README.md ├── .DS_Store ├── mahjong ├── Assets │ ├── Icon.png │ ├── error.wav │ ├── level1.png │ ├── level2.png │ ├── level3.png │ ├── level4.png │ ├── level5.png │ ├── level6.png │ ├── level7.png │ ├── level8.png │ ├── level9.png │ ├── opener.wav │ ├── select.wav │ ├── Default.png │ ├── deselect.wav │ ├── level10.png │ ├── level11.png │ ├── level12.png │ ├── mahjong.png │ ├── removeTile.wav │ └── instructions1.png ├── FlurryLib │ ├── libFlurry.a │ └── FlurryAPI.h ├── GoogleAdMobAdsSDK │ ├── libGoogleAdMobAds.a │ ├── GADRequestError.h │ ├── GADInterstitialDelegate.h │ ├── GADBannerViewDelegate.h │ ├── GADInterstitial.h │ ├── GADRequest.h │ └── GADBannerView.h ├── Mahjongg_Prefix.pch ├── Mahjongg.xcodeproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcuserdata │ │ └── manan19.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ ├── vorbis.xcscheme │ │ └── Mahjongg.xcscheme ├── main.m ├── Classes │ ├── MenuScene.h │ ├── MahjonggAppDelegate.h │ ├── AdManager.h │ ├── ScoreManager.h │ ├── PlayScene.h │ └── MahjonggAppDelegate.m ├── cocos2d │ ├── cocos2d.m │ ├── Support │ │ ├── TransformUtils.h │ │ ├── glu.h │ │ ├── FileUtils.h │ │ ├── base64.h │ │ ├── ZipUtils.h │ │ ├── TransformUtils.m │ │ ├── FileUtils.m │ │ ├── TGAlib.h │ │ ├── CGPointExtension.m │ │ ├── base64.c │ │ ├── glu.c │ │ ├── ZipUtils.m │ │ ├── PVRTexture.h │ │ └── OpenGL_Internal.h │ ├── Export.h │ ├── Scene.m │ ├── Grabber.h │ ├── Scene.h │ ├── ccExceptions.h │ ├── PointParticleSystem.h │ ├── ParallaxNode.h │ ├── QuadParticleSystem.h │ ├── ccMacros.h │ ├── TextureNode.h │ ├── ParticleExamples.h │ ├── LabelAtlas.h │ ├── CameraAction.h │ ├── Label.h │ ├── Grabber.m │ ├── TouchDispatcher.h │ ├── Camera.h │ ├── RenderTexture.h │ ├── MotionStreak.h │ ├── EaseAction.h │ ├── Menu.h │ ├── DrawingPrimitives.h │ ├── TileMapAtlas.h │ ├── AtlasNode.h │ ├── Label.m │ ├── TouchHandler.h │ ├── TouchDelegateProtocol.h │ ├── cocos2d.h │ ├── InstantAction.h │ ├── MotionStreak.m │ ├── CDConfig.h │ ├── TextureNode.m │ ├── Scheduler.h │ ├── AtlasSpriteManager.h │ ├── TMXXMLParser.h │ ├── ActionManager.h │ ├── Grid.h │ ├── Action.h │ ├── Camera.m │ ├── CDOpenALSupport.h │ ├── Ribbon.h │ ├── CameraAction.m │ ├── Sprite.h │ ├── LabelAtlas.m │ ├── SimpleAudioEngine_objc.h │ ├── BitmapFontAtlas.h │ ├── Layer.h │ ├── ParallaxNode.m │ ├── DrawingPrimitives.m │ ├── TextureMgr.h │ ├── TextureAtlas.h │ ├── AtlasNode.m │ ├── Action.m │ └── InstantAction.m ├── README.txt └── Mahjongg-Info.plist ├── promoArt ├── 512x512 Icon.png ├── screenshot1.png ├── screenshot2.png ├── screenshot3.png ├── screenshot4.png └── screenshot5.png └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | jong 2 | ==== 3 | 4 | just another game 5 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/.DS_Store -------------------------------------------------------------------------------- /mahjong/Assets/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/Icon.png -------------------------------------------------------------------------------- /mahjong/Assets/error.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/error.wav -------------------------------------------------------------------------------- /mahjong/Assets/level1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level1.png -------------------------------------------------------------------------------- /mahjong/Assets/level2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level2.png -------------------------------------------------------------------------------- /mahjong/Assets/level3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level3.png -------------------------------------------------------------------------------- /mahjong/Assets/level4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level4.png -------------------------------------------------------------------------------- /mahjong/Assets/level5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level5.png -------------------------------------------------------------------------------- /mahjong/Assets/level6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level6.png -------------------------------------------------------------------------------- /mahjong/Assets/level7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level7.png -------------------------------------------------------------------------------- /mahjong/Assets/level8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level8.png -------------------------------------------------------------------------------- /mahjong/Assets/level9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level9.png -------------------------------------------------------------------------------- /mahjong/Assets/opener.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/opener.wav -------------------------------------------------------------------------------- /mahjong/Assets/select.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/select.wav -------------------------------------------------------------------------------- /promoArt/512x512 Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/promoArt/512x512 Icon.png -------------------------------------------------------------------------------- /promoArt/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/promoArt/screenshot1.png -------------------------------------------------------------------------------- /promoArt/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/promoArt/screenshot2.png -------------------------------------------------------------------------------- /promoArt/screenshot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/promoArt/screenshot3.png -------------------------------------------------------------------------------- /promoArt/screenshot4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/promoArt/screenshot4.png -------------------------------------------------------------------------------- /promoArt/screenshot5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/promoArt/screenshot5.png -------------------------------------------------------------------------------- /mahjong/Assets/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/Default.png -------------------------------------------------------------------------------- /mahjong/Assets/deselect.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/deselect.wav -------------------------------------------------------------------------------- /mahjong/Assets/level10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level10.png -------------------------------------------------------------------------------- /mahjong/Assets/level11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level11.png -------------------------------------------------------------------------------- /mahjong/Assets/level12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/level12.png -------------------------------------------------------------------------------- /mahjong/Assets/mahjong.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/mahjong.png -------------------------------------------------------------------------------- /mahjong/Assets/removeTile.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/removeTile.wav -------------------------------------------------------------------------------- /mahjong/FlurryLib/libFlurry.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/FlurryLib/libFlurry.a -------------------------------------------------------------------------------- /mahjong/Assets/instructions1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/Assets/instructions1.png -------------------------------------------------------------------------------- /mahjong/GoogleAdMobAdsSDK/libGoogleAdMobAds.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manan19/jong/HEAD/mahjong/GoogleAdMobAdsSDK/libGoogleAdMobAds.a -------------------------------------------------------------------------------- /mahjong/Mahjongg_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Mahjongg' target in the 'Mahjongg' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /mahjong/Mahjongg.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mahjong/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Mahjongg 4 | // 5 | // Created by GamePipe Iphone Dev on 7/28/09. 6 | // Copyright USC 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, @"MahjonggAppDelegate"); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /mahjong/Classes/MenuScene.h: -------------------------------------------------------------------------------- 1 | // 2 | // MehuScene.h 3 | // Mahjongg 4 | // 5 | // Created by GamePipe Iphone Dev on 7/28/09. 6 | // Copyright 2009 USC. All rights reserved. 7 | // 8 | 9 | #import "cocos2d.h" 10 | 11 | 12 | 13 | @interface MenuScene : Scene 14 | { 15 | 16 | } 17 | 18 | @end 19 | 20 | 21 | @interface MenuLayer : ColorLayer { 22 | 23 | 24 | } 25 | @end 26 | 27 | @interface InstructionsLayer : ColorLayer { 28 | 29 | 30 | } 31 | @end -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build/ 3 | mahjong/Mahjongg.xcodeproj/project.xcworkspace/* 4 | mahjong/Mahjongg.xcodeproj/xcuserdata/shamikaga.xcuserdatad/xcschemes/Mahjongg.xcscheme 5 | mahjong/Mahjongg.xcodeproj/xcuserdata/shamikaga.xcuserdatad/xcschemes/vorbis.xcscheme 6 | mahjong/Mahjongg.xcodeproj/xcuserdata/shamikaga.xcuserdatad/xcschemes/xcschememanagement.plist 7 | mahjong/Mahjongg.xcodeproj/xcuserdata/manan19.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist 8 | mahjong/Mahjongg.xcodeproj/xcuserdata/shamikaga.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist 9 | -------------------------------------------------------------------------------- /mahjong/cocos2d/cocos2d.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | 17 | static NSString *version = @"cocos2d v0.8.1"; 18 | 19 | NSString *cocos2dVersion() 20 | { 21 | return version; 22 | } 23 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/TransformUtils.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 Valentin Milea 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | #import 17 | 18 | void CGAffineToGL(const CGAffineTransform *t, GLfloat *m); 19 | void GLToCGAffine(const GLfloat *m, CGAffineTransform *t); 20 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/glu.h: -------------------------------------------------------------------------------- 1 | // 2 | // cocos2d GLU implementation 3 | // 4 | // implementation of GLU functions 5 | // 6 | #ifndef __COCOS2D_GLU_H 7 | #define __COCOS2D_GLU_H 8 | 9 | #import 10 | 11 | /** 12 | @file 13 | cocos2d OpenGL GLU implementation 14 | */ 15 | 16 | /** OpenGL gluLookAt implementation */ 17 | void gluLookAt(float eyeX, float eyeY, float eyeZ, float lookAtX, float lookAtY, float lookAtZ, float upX, float upY, float upZ); 18 | /** OpenGL gluPerspective implementation */ 19 | void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar); 20 | 21 | #endif /* __COCOS2D_GLU_H */ 22 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Export.h: -------------------------------------------------------------------------------- 1 | #ifndef __EXPORT_COMMON__ 2 | #define __EXPORT_COMMON__ 3 | 4 | #if defined(_WIN32) 5 | #if defined(_EXPORT_DLL_) 6 | #define EXPORT_DLL __declspec(dllexport) 7 | #elif defined(IGNORE_EXPORT) 8 | #define EXPORT_DLL 9 | #else /* use a DLL library */ 10 | #define EXPORT_DLL __declspec(dllimport) 11 | #endif 12 | #else 13 | #if defined(_SHARED_) 14 | #define EXPORT_DLL __attribute__((visibility("default"))) 15 | #elif defined(IGNORE_EXPORT) 16 | #define EXPORT_DLL 17 | #else 18 | #define EXPORT_DLL 19 | #endif 20 | #endif 21 | 22 | #endif // end of __EXPORT_COMMON__ 23 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/FileUtils.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | 17 | 18 | /** Helper class to handle file operations */ 19 | @interface FileUtils : NSObject 20 | { 21 | } 22 | /** converts a relative path to a full path */ 23 | +(NSString*) fullPathFromRelativePath:(NSString*) relPath; 24 | @end 25 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | public domain BASE64 code 3 | 4 | modified for cocos2d-iphone 5 | http://www.cocos2d-iphone.org 6 | */ 7 | 8 | #ifndef __CC_BASE64_DECODE_H 9 | #define __CC_BASE64_DECODE_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | 16 | /** @file 17 | base64 helper functions 18 | */ 19 | 20 | /** 21 | * Decodes a 64base encoded memory. The decoded memory is 22 | * expected to be freed by the caller. 23 | * 24 | * @returns the length of the out buffer 25 | * 26 | @since v0.8.1 27 | */ 28 | int base64Decode(unsigned char *in, unsigned int inLength, unsigned char **out); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif // __CC_BASE64_DECODE_H 35 | -------------------------------------------------------------------------------- /mahjong/README.txt: -------------------------------------------------------------------------------- 1 | Instructions to set up a cocos2d-iPhone project 2 | 3 | 0. Download or check out the cocos2d library from http://code.google.com/p/cocos2d-iphone/ 4 | 5 | 1. Add the cocos2d subdirectory of the cocos2d library to this project. 6 | Do this by right clicking on the project and choosing Add / Existing Files... 7 | DON'T add the entire top level directory of the library, just the cocos2d subdirectory. 8 | 9 | 2. Add the fps_images.png from the cocos2d Resources/Images directory to the Resources group in this project. 10 | Do this by right clicking on the Resources folder and choosing Add / Existing Files... 11 | 12 | 3. In the main project AppDelegate file, import the cocos2d classes you need, set up the Director, create scenes, etc. -------------------------------------------------------------------------------- /mahjong/Classes/MahjonggAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MahjonggAppDelegate.h 3 | // Mahjongg 4 | // 5 | // Created by GamePipe Iphone Dev on 7/28/09. 6 | // Copyright USC 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AdManager.h" 11 | #import "ScoreManager.h" 12 | #import "FlurryAPI.h" 13 | 14 | @interface MahjonggAppDelegate : NSObject { 15 | UIWindow *window; 16 | UIViewController *placeHolderViewController; 17 | UIView *gameView; 18 | AdManager* adManager; 19 | @public ScoreManager* scoreManager; 20 | GKLeaderboardViewController *leaderboardController; 21 | BOOL soundOn; 22 | } 23 | 24 | - (void) showLeaderboard; 25 | - (ScoreManager*) getScoreMananger; 26 | 27 | @end 28 | 29 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Scene.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import "Scene.h" 17 | #import "Director.h" 18 | #import "Support/CGPointExtension.h" 19 | 20 | @implementation Scene 21 | -(id) init 22 | { 23 | if( (self=[super init]) ) { 24 | CGSize s = [[Director sharedDirector] winSize]; 25 | self.relativeAnchorPoint = NO; 26 | anchorPoint_ = ccp(0.5f, 0.5f); 27 | [self setContentSize:s]; 28 | } 29 | 30 | return self; 31 | } 32 | @end 33 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Grabber.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 On-Core 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | #import 17 | #import 18 | 19 | @class Texture2D; 20 | 21 | /** FBO class that grabs the the contents of the screen */ 22 | @interface Grabber : NSObject 23 | { 24 | GLuint fbo; 25 | GLint oldFBO; 26 | } 27 | 28 | -(void)grab:(Texture2D*)texture; 29 | -(void)beforeRender:(Texture2D*)texture; 30 | -(void)afterRender:(Texture2D*)texture; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /mahjong/Mahjongg.xcodeproj/xcuserdata/manan19.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Mahjongg.xcscheme 8 | 9 | orderHint 10 | 1 11 | 12 | vorbis.xcscheme 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | 1D6058900D05DD3D006BFB54 21 | 22 | primary 23 | 24 | 25 | 5A512F81105F7E2B00AD0ABC 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /mahjong/Classes/AdManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // AdManager.h 3 | // Cross Me Not 4 | // 5 | // Created by Manan Patel on 2/1/11. 6 | // Copyright 2011 ngmoco:). All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "GADBannerView.h" 12 | 13 | #define TOP_AD_FRAME CGRectMake(0, 0, 320, 50) 14 | #define BOTTOM_AD_FRAME CGRectMake(0, 430, 320, 50) 15 | 16 | @interface AdManager : NSObject { 17 | UIView *_adView; 18 | @public BOOL adFree,adViewVisible,adTop; 19 | UIView *_parentView; 20 | UIViewController *_parentViewController; 21 | NSString *countryCode; 22 | } 23 | 24 | - (UIView*) getAdView; 25 | -(void) setParentView:(UIView*)pView andPosition:(Boolean)Top; 26 | -(void) shutdown; 27 | 28 | -(id)init:(UIViewController*)pVC; 29 | - (void) _animate:(UIView*)adView up:(BOOL)up; 30 | 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/ZipUtils.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * 6 | * inflateMemory_ based on zlib example code 7 | * http://www.zlib.net 8 | * 9 | * Some ideas were taken from: 10 | * http://themanaworld.org/ 11 | * from the mapreader.cpp file 12 | * 13 | */ 14 | 15 | #ifndef __CC_ZIP_UTILS_H 16 | #define __CC_ZIP_UTILS_H 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** @file 23 | * Zip helper functions 24 | */ 25 | 26 | /** 27 | * Inflates either zlib or gzip deflated memory. The inflated memory is 28 | * expected to be freed by the caller. 29 | * 30 | * @returns the length of the deflated buffer 31 | * 32 | @since v0.8.1 33 | */ 34 | int inflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out); 35 | 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif // __CC_ZIP_UTILS_H 42 | -------------------------------------------------------------------------------- /mahjong/Classes/ScoreManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // ScoreManager.h 3 | // Cross Me Not 4 | // 5 | // Created by Manan Patel on 10/28/10. 6 | // Copyright 2010 ngmoco:). All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | 13 | @interface ScoreManager : NSObject { 14 | NSMutableDictionary *bestTimes; 15 | int temp; 16 | } 17 | 18 | - (void) newScore:(float)score forLevel:(int)level sendToGC:(BOOL)report; 19 | - (float) getBestScoreForLevel:(int)level; 20 | - (void) readBestTimes; 21 | 22 | 23 | - (void) _writeBestTimes; 24 | - (void) _setBestScore:(float)score forLevel:(int)level; 25 | - (void) _reportHighScore:(int64_t) score forCategory: (NSString*) category; 26 | - (void) _authenticateLocalPlayer; 27 | - (void) _registerForAuthenticationNotification; 28 | - (void) _authenticationChanged; 29 | + (BOOL) _isGameCenterAvailable; 30 | - (NSString*)_getFilePath; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Scene.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import 17 | 18 | #import "CocosNode.h" 19 | 20 | /** Scene is a subclass of CocosNode that is used only as an abstract concept. 21 | 22 | Scene an CocosNode are almost identical with the difference that Scene has it's 23 | anchor point (by default) at the center of the screen. 24 | 25 | For the moment Scene has no other logic than that, but in future releases it might have 26 | additional logic. 27 | 28 | It is a good practice to use and Scene as the parent of all your nodes. 29 | */ 30 | @interface Scene : CocosNode { 31 | 32 | } 33 | @end 34 | -------------------------------------------------------------------------------- /mahjong/cocos2d/ccExceptions.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | // cocos2d Exceptions 16 | // based on OC3D OC3DConstants.h file 17 | // 18 | 19 | static NSString *kccException_OpenGLViewAlreadyAttached = @"kccException_OpenGLViewAlreadyAttached"; 20 | static NSString *kccException_OpenGLViewNotAttached = @"kccException_OpenGLViewNotAttached"; 21 | static NSString *kccException_OpenGLViewCantDetach = @"kccException_OpenGLViewCantDetach"; 22 | static NSString *kccException_OpenGLViewCantAttach = @"kccException_OpenGLViewCantAttach"; 23 | static NSString *kccException_OpenGLViewCantInit = @"kccException_OpenGLViewCantInit"; 24 | -------------------------------------------------------------------------------- /mahjong/Mahjongg-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | Mahjong 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.mp.mahjongmania 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.01 25 | LSRequiresIPhoneOS 26 | 27 | UIStatusBarHidden 28 | 29 | UIPrerenderedIcon 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /mahjong/cocos2d/PointParticleSystem.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "ParticleSystem.h" 16 | 17 | /** PointParticleSystem is a subclass of ParticleSystem 18 | Attributes of a Particle System: 19 | * All the attributes of Particle System 20 | 21 | Features: 22 | * consumes small memory: uses 1 vertex (x,y) per particle, no need to assign tex coordinates 23 | * size can't be bigger than 64 24 | * the system can't be scaled since the particles are rendered using GL_POINT_SPRITE 25 | */ 26 | @interface PointParticleSystem : ParticleSystem 27 | { 28 | // Array of (x,y,size) 29 | ccPointSprite *vertices; 30 | // vertices buffer id 31 | GLuint verticesID; 32 | } 33 | @end 34 | 35 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/TransformUtils.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 Valentin Milea 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "TransformUtils.h" 16 | 17 | void CGAffineToGL(const CGAffineTransform *t, GLfloat *m) 18 | { 19 | // | m[0] m[4] m[8] m[12] | | m11 m21 m31 m41 | | a c 0 tx | 20 | // | m[1] m[5] m[9] m[13] | | m12 m22 m32 m42 | | b d 0 ty | 21 | // | m[2] m[6] m[10] m[14] | <=> | m13 m23 m33 m43 | <=> | 0 0 1 0 | 22 | // | m[3] m[7] m[11] m[15] | | m14 m24 m34 m44 | | 0 0 0 1 | 23 | 24 | m[2] = m[3] = m[6] = m[7] = m[8] = m[9] = m[11] = m[14] = 0.0f; 25 | m[10] = m[15] = 1.0f; 26 | m[0] = t->a; m[4] = t->c; m[12] = t->tx; 27 | m[1] = t->b; m[5] = t->d; m[13] = t->ty; 28 | } 29 | 30 | void GLToCGAffine(const GLfloat *m, CGAffineTransform *t) 31 | { 32 | t->a = m[0]; t->c = m[4]; t->tx = m[12]; 33 | t->b = m[1]; t->d = m[5]; t->ty = m[13]; 34 | } 35 | -------------------------------------------------------------------------------- /mahjong/cocos2d/ParallaxNode.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "CocosNode.h" 16 | #import "Support/ccArray.h" 17 | 18 | /** ParallaxNode: A node that simulates a parallax scroller 19 | 20 | The children will be moved faster / slower than the parent according the the parallax ratio. 21 | 22 | */ 23 | @interface ParallaxNode : CocosNode { 24 | ccArray *parallaxArray_; 25 | CGPoint lastPosition; 26 | } 27 | 28 | /** array that holds the offset / ratio of the children */ 29 | @property (nonatomic,readwrite) ccArray * parallaxArray; 30 | 31 | /** Adds a child to the container with a z-order, a parallax ratio and a position offset 32 | It returns self, so you can chain several addChilds. 33 | @since v0.8 34 | */ 35 | -(id) addChild: (CocosNode*)node z:(int)z parallaxRatio:(CGPoint)c positionOffset:(CGPoint)positionOffset; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /mahjong/GoogleAdMobAdsSDK/GADRequestError.h: -------------------------------------------------------------------------------- 1 | // 2 | // GADRequestError.h 3 | // Google AdMob Ads SDK 4 | // 5 | // Copyright 2011 Google Inc. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @class GADRequest; 11 | 12 | extern NSString *kGADErrorDomain; 13 | 14 | // NSError codes for GAD error domain. 15 | typedef enum { 16 | // The ad request is invalid. The localizedFailureReason error description 17 | // will have more details. Typically this is because the ad did not have the 18 | // ad unit ID or root view controller set. 19 | kGADErrorInvalidRequest, 20 | 21 | // The ad request was successful, but no ad was returned. 22 | kGADErrorNoFill, 23 | 24 | // There was an error loading data from the network. 25 | kGADErrorNetworkError, 26 | 27 | // The ad server experienced a failure processing the request. 28 | kGADErrorServerError, 29 | 30 | // The current device's OS is below the minimum required version. 31 | kGADErrorOSVersionTooLow, 32 | 33 | // The request was unable to be loaded before being timed out. 34 | kGADErrorTimeout, 35 | 36 | } GADErrorCode; 37 | 38 | // This class represents the error generated due to invalid request parameters. 39 | @interface GADRequestError : NSError 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /mahjong/cocos2d/QuadParticleSystem.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 Leonardo Kasperavičius 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "ParticleSystem.h" 16 | 17 | /** QuadParticleSystem is a subclass of ParticleSystem 18 | 19 | It includes all the features of ParticleSystem. 20 | 21 | Special features and Limitations: 22 | - Particle size can be any float number. 23 | - The system can be scaled 24 | - The particles can be rotated 25 | - It is a bit slower that PointParticleSystem 26 | - It consumes more RAM and more GPU memory than PointParticleSystem 27 | @since v0.8 28 | */ 29 | @interface QuadParticleSystem : ParticleSystem 30 | { 31 | ccV2F_C4F_T2F_Quad *quads; // quads to be rendered 32 | GLushort *indices; // indices 33 | GLuint quadsID; // VBO id 34 | } 35 | 36 | 37 | // initialices the indices for the vertices 38 | -(void) initIndices; 39 | // initilizes the text coords 40 | -(void) initTexCoords; 41 | 42 | 43 | @end 44 | 45 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/FileUtils.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "FileUtils.h" 16 | 17 | @implementation FileUtils 18 | +(NSString*) fullPathFromRelativePath:(NSString*) relPath 19 | { 20 | // do not convert an absolute path (starting with '/') 21 | if(([relPath length] > 0) && ([relPath characterAtIndex:0] == '/')) 22 | { 23 | return relPath; 24 | } 25 | 26 | NSMutableArray *imagePathComponents = [NSMutableArray arrayWithArray:[relPath pathComponents]]; 27 | NSString *file = [imagePathComponents lastObject]; 28 | 29 | [imagePathComponents removeLastObject]; 30 | NSString *imageDirectory = [NSString pathWithComponents:imagePathComponents]; 31 | 32 | NSString *fullpath = [[NSBundle mainBundle] pathForResource:file 33 | ofType:nil 34 | inDirectory:imageDirectory]; 35 | if (fullpath == nil) 36 | fullpath = relPath; 37 | 38 | return fullpath; 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/TGAlib.h: -------------------------------------------------------------------------------- 1 | // 2 | // TGA lib for cocos2d-iphone 3 | // 4 | // sources from: http://www.lighthouse3d.com/opengl/terrain/index.php3?tgasource 5 | // 6 | 7 | //#ifndef TGA_LIB 8 | //#define TGA_LIB 9 | 10 | /** 11 | @file 12 | TGA image support 13 | */ 14 | 15 | enum { 16 | TGA_OK, 17 | TGA_ERROR_FILE_OPEN, 18 | TGA_ERROR_READING_FILE, 19 | TGA_ERROR_INDEXED_COLOR, 20 | TGA_ERROR_MEMORY, 21 | TGA_ERROR_COMPRESSED_FILE, 22 | }; 23 | 24 | /** TGA format */ 25 | typedef struct sImageTGA { 26 | int status; 27 | unsigned char type, pixelDepth; 28 | 29 | /** map width */ 30 | short int width; 31 | 32 | /** map height */ 33 | short int height; 34 | 35 | /** raw data */ 36 | unsigned char *imageData; 37 | int flipped; 38 | } tImageTGA; 39 | 40 | /// load the image header fields. We only keep those that matter! 41 | void tgaLoadHeader(FILE *file, tImageTGA *info); 42 | 43 | /// loads the image pixels. You shouldn't call this function directly 44 | void tgaLoadImageData(FILE *file, tImageTGA *info); 45 | 46 | /// this is the function to call when we want to load an image 47 | tImageTGA * tgaLoad(const char *filename); 48 | 49 | // /converts RGB to greyscale 50 | void tgaRGBtogreyscale(tImageTGA *info); 51 | 52 | /// releases the memory used for the image 53 | void tgaDestroy(tImageTGA *info); 54 | 55 | //#endif // TGA_LIB 56 | -------------------------------------------------------------------------------- /mahjong/cocos2d/ccMacros.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | 17 | /** 18 | @file 19 | cocos2d helper macros 20 | */ 21 | 22 | #ifdef COCOS2D_DEBUG 23 | //#define CCLOG(s, …) NSLog((@”%s %s:%d ” s), __func__, basename(__FILE__), __LINE__, ## __VA_ARGS__); 24 | #define CCLOG(...) NSLog(__VA_ARGS__) 25 | #else 26 | #define CCLOG(...) do {} while (0) 27 | #endif 28 | 29 | //simple macro that swaps 2 variables 30 | #define CC_SWAP( x, y ) \ 31 | ({ __typeof__(x) temp = (x); \ 32 | x = y; y = temp; \ 33 | }) 34 | 35 | 36 | 37 | 38 | /// returns a random float between -1 and 1 39 | #define CCRANDOM_MINUS1_1() ((random() / (float)0x3fffffff )-1.0f) 40 | 41 | /// returns a random float between 0 and 1 42 | #define CCRANDOM_0_1() ((random() / (float)0x7fffffff )) 43 | 44 | /// converts degrees to radians 45 | #define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) / 180.0f * (float)M_PI) 46 | 47 | /// converts radians to degrees 48 | #define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) / (float)M_PI * 180.0f) 49 | 50 | /// default gl blend src function 51 | //#define CC_BLEND_SRC GL_SRC_ALPHA 52 | #define CC_BLEND_SRC GL_ONE 53 | /// default gl blend dst function 54 | #define CC_BLEND_DST GL_ONE_MINUS_SRC_ALPHA 55 | 56 | -------------------------------------------------------------------------------- /mahjong/cocos2d/TextureNode.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import 17 | 18 | #import "Support/Texture2D.h" 19 | 20 | #import "CocosNode.h" 21 | 22 | 23 | /** TextureNode is a subclass of CocosNode that implements the CocosNodeRGBA 24 | * and CocosNodeTexture protocol. 25 | * 26 | * As the name implies it, it knows how to render a textures. 27 | * 28 | * All features from CocosNode are valid, plus the following new features: 29 | * - opacity and RGB 30 | * - texture (can be Aliased or AntiAliased) 31 | */ 32 | @interface TextureNode : CocosNode { 33 | 34 | // texture 35 | Texture2D *texture_; 36 | 37 | // blend func 38 | ccBlendFunc blendFunc_; 39 | 40 | // texture RGBA 41 | GLubyte opacity_; 42 | ccColor3B color_; 43 | BOOL opacityModifyRGB_; 44 | 45 | } 46 | 47 | /** conforms to CocosNodeTexture protocol */ 48 | @property (nonatomic,readwrite,retain) Texture2D *texture; 49 | 50 | /** conforms to CocosNodeTexture protocol */ 51 | @property (nonatomic,readwrite) ccBlendFunc blendFunc; 52 | 53 | /** conforms to CocosNodeRGBA protocol */ 54 | @property (nonatomic,readonly) GLubyte opacity; 55 | /** conforms to CocosNodeRGBA protocol */ 56 | @property (nonatomic,readwrite) ccColor3B color; 57 | @end 58 | -------------------------------------------------------------------------------- /mahjong/cocos2d/ParticleExamples.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "PointParticleSystem.h" 16 | #import "QuadParticleSystem.h" 17 | 18 | //! Fire particle system 19 | @interface ParticleFire: PointParticleSystem 20 | { 21 | } 22 | @end 23 | 24 | //! Fireworks particle system 25 | @interface ParticleFireworks : PointParticleSystem 26 | { 27 | } 28 | @end 29 | 30 | //! Sun particle system 31 | @interface ParticleSun : PointParticleSystem 32 | { 33 | } 34 | @end 35 | 36 | //! Galaxy particle system 37 | @interface ParticleGalaxy : PointParticleSystem 38 | { 39 | } 40 | @end 41 | 42 | //! Flower particle system 43 | @interface ParticleFlower : PointParticleSystem 44 | { 45 | } 46 | @end 47 | 48 | //! Meteor particle system 49 | @interface ParticleMeteor : PointParticleSystem 50 | { 51 | } 52 | @end 53 | 54 | //! Spiral particle system 55 | @interface ParticleSpiral : PointParticleSystem 56 | { 57 | } 58 | @end 59 | 60 | //! Explosion particle system 61 | @interface ParticleExplosion : PointParticleSystem 62 | { 63 | } 64 | @end 65 | 66 | //! Smoke particle system 67 | @interface ParticleSmoke : PointParticleSystem 68 | { 69 | } 70 | @end 71 | 72 | //! Snow particle system 73 | @interface ParticleSnow : PointParticleSystem 74 | { 75 | } 76 | @end 77 | 78 | //! Rain particle system 79 | @interface ParticleRain : PointParticleSystem 80 | { 81 | } 82 | @end 83 | -------------------------------------------------------------------------------- /mahjong/cocos2d/LabelAtlas.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "AtlasNode.h" 16 | #import "TextureAtlas.h" 17 | 18 | /** LabelAtlas is a subclass of AtlasNode. 19 | 20 | It can be as a replacement of Label since it is MUCH faster. 21 | 22 | LabelAtlas versus Label: 23 | - LabelAtlas is MUCH faster than Label 24 | - LabelAtlas "characters" have a fixed height and width 25 | - LabelAtlas "characters" can be anything you want since they are taken from an image file 26 | 27 | A more flexible class is BitmapFontAtlas. It supports variable width characters and it also has a nice editor. 28 | */ 29 | @interface LabelAtlas : AtlasNode { 30 | 31 | // string to render 32 | NSString *string_; 33 | 34 | // the first char in the charmap 35 | char mapStartChar; 36 | } 37 | 38 | /** creates the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */ 39 | +(id) labelAtlasWithString:(NSString*) string charMapFile: (NSString*) charmapfile itemWidth:(int)w itemHeight:(int)h startCharMap:(char)c; 40 | 41 | /** initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */ 42 | -(id) initWithString:(NSString*) string charMapFile: (NSString*) charmapfile itemWidth:(int)w itemHeight:(int)h startCharMap:(char)c; 43 | @end 44 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/CGPointExtension.m: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007 Scott Lembcke 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | #include "stdio.h" 23 | #include "math.h" 24 | 25 | #include "CGPointExtension.h" 26 | 27 | CGFloat 28 | ccpLength(const CGPoint v) 29 | { 30 | return sqrtf(ccpLengthSQ(v)); 31 | } 32 | 33 | CGFloat 34 | ccpDistance(const CGPoint v1, const CGPoint v2) 35 | { 36 | return ccpLength(ccpSub(v1, v2)); 37 | } 38 | 39 | CGPoint 40 | ccpNormalize(const CGPoint v) 41 | { 42 | return ccpMult(v, 1.0f/ccpLength(v)); 43 | } 44 | 45 | CGPoint 46 | ccpForAngle(const CGFloat a) 47 | { 48 | return ccp(cosf(a), sinf(a)); 49 | } 50 | 51 | CGFloat 52 | ccpToAngle(const CGPoint v) 53 | { 54 | return atan2f(v.y, v.x); 55 | } 56 | -------------------------------------------------------------------------------- /mahjong/cocos2d/CameraAction.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "IntervalAction.h" 16 | 17 | /** Base class for Camera actions 18 | */ 19 | @interface CameraAction : IntervalAction { 20 | float centerXOrig; 21 | float centerYOrig; 22 | float centerZOrig; 23 | 24 | float eyeXOrig; 25 | float eyeYOrig; 26 | float eyeZOrig; 27 | 28 | float upXOrig; 29 | float upYOrig; 30 | float upZOrig; 31 | } 32 | @end 33 | 34 | /** Orbit Camera action 35 | Orbits the camera around the center of the screen using spherical coordinates 36 | */ 37 | @interface OrbitCamera : CameraAction { 38 | float radius; 39 | float deltaRadius; 40 | float angleZ; 41 | float deltaAngleZ; 42 | float angleX; 43 | float deltaAngleX; 44 | 45 | float radZ; 46 | float radDeltaZ; 47 | float radX; 48 | float radDeltaX; 49 | 50 | } 51 | /** creates an OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ 52 | +(id) actionWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx; 53 | /** initializes an OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ 54 | -(id) initWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx; 55 | /** positions the camera according to spherical coordinates */ 56 | -(void) sphericalRadius:(float*) r zenith:(float*) zenith azimuth:(float*) azimuth; 57 | @end 58 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Label.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import 17 | 18 | #import "Support/Texture2D.h" 19 | 20 | #import "TextureNode.h" 21 | 22 | /** Label is a subclass of TextureNode that knows how to render text labels 23 | * 24 | * All features from TextureNode are valid in Label 25 | * 26 | * Label are slow. Consider using LabelAtlas or BitmapFontAtlas instead. 27 | */ 28 | @interface Label : TextureNode 29 | { 30 | CGSize _dimensions; 31 | UITextAlignment _alignment; 32 | NSString * _fontName; 33 | CGFloat _fontSize; 34 | } 35 | 36 | /** creates a label from a fontname, alignment, dimension and font size */ 37 | + (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; 38 | /** creates a label from a fontname and font size */ 39 | + (id) labelWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; 40 | /** initializes the label with a font name, alignment, dimension and font size */ 41 | - (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; 42 | /** initializes the label with a font name and font size */ 43 | - (id) initWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; 44 | 45 | /** changes the string to render 46 | * @warning Changing the string is as expensive as creating a new Label. To obtain better performance use LabelAtlas 47 | */ 48 | - (void) setString:(NSString*)string; 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Grabber.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 On-Core 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "Grabber.h" 16 | #import "ccMacros.h" 17 | 18 | #import "Support/Texture2D.h" 19 | #import "Support/OpenGL_Internal.h" 20 | 21 | @implementation Grabber 22 | 23 | -(id) init 24 | { 25 | if(( self = [super init] )) { 26 | // generate FBO 27 | glGenFramebuffersOES(1, &fbo); 28 | } 29 | return self; 30 | } 31 | -(void)grab:(Texture2D*)texture 32 | { 33 | glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO); 34 | 35 | // bind 36 | glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo); 37 | 38 | // associate texture with FBO 39 | glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, texture.name, 0); 40 | 41 | // check if it worked (probably worth doing :) ) 42 | GLuint status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); 43 | if (status != GL_FRAMEBUFFER_COMPLETE_OES) 44 | { 45 | [NSException raise:@"Frame Grabber" format:@"Could not attach texture to framebuffer"]; 46 | } 47 | 48 | glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO); 49 | } 50 | 51 | -(void)beforeRender:(Texture2D*)texture 52 | { 53 | glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO); 54 | glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo); 55 | 56 | // BUG XXX: doesn't work with RGB565. 57 | glClearColor(0.0f,0.0f,0.0f,0.0f); 58 | 59 | glClear(GL_COLOR_BUFFER_BIT); 60 | } 61 | 62 | -(void)afterRender:(Texture2D*)texture 63 | { 64 | glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO); 65 | } 66 | 67 | - (void) dealloc 68 | { 69 | CCLOG( @"deallocing %@", self); 70 | glDeleteFramebuffersOES(1, &fbo); 71 | [super dealloc]; 72 | } 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /mahjong/Mahjongg.xcodeproj/xcuserdata/manan19.xcuserdatad/xcschemes/vorbis.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 13 | 14 | 16 | 22 | 23 | 24 | 25 | 26 | 34 | 35 | 36 | 37 | 44 | 45 | 47 | 48 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /mahjong/cocos2d/TouchDispatcher.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 Valentin Milea 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "TouchDelegateProtocol.h" 16 | #import "Support/EAGLView.h" 17 | 18 | 19 | /** TouchDispatcher. 20 | Singleton that handles all the touch events. 21 | The dispatcher dispatches events to the registered TouchHandlers. 22 | @since v0.8 23 | */ 24 | @interface TouchDispatcher : NSObject 25 | { 26 | NSMutableArray *touchHandlers; 27 | BOOL dispatchEvents; 28 | } 29 | 30 | /** singleton of the TouchDispatcher */ 31 | + (TouchDispatcher*)sharedDispatcher; 32 | 33 | /** Whether or not the events are going to be dispatched. Default: YES */ 34 | @property (nonatomic,readwrite, assign) BOOL dispatchEvents; 35 | 36 | /** Adds a standard touch delegate to the dispatcher's list. 37 | See StandardTouchDelegate description. 38 | IMPORTANT: The delegate will be retained. 39 | */ 40 | -(void) addStandardDelegate:(id) delegate priority:(int)priority; 41 | /** Adds a targeted touch delegate to the dispatcher's list. 42 | See TargetedTouchDelegate description. 43 | IMPORTANT: The delegate will be retained. 44 | */ 45 | -(void) addTargetedDelegate:(id) delegate priority:(int)priority swallowsTouches:(BOOL)swallowsTouches; 46 | /** Removes a touch delegate. 47 | The delegate will be released 48 | */ 49 | -(void) removeDelegate:(id) delegate; 50 | /** Removes all touch delegates, releasing all the delegates */ 51 | -(void) removeAllDelegates; 52 | /** Changes the priority of a previously added delegate. The lower the number, 53 | the higher the priority */ 54 | -(void) setPriority:(int) priority forDelegate:(id) delegate; 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Camera.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | 17 | #import "CocosNode.h" 18 | 19 | /** 20 | A Camera is used in every CocosNode. 21 | Useful to look at the object from different views. 22 | The OpenGL gluLookAt() function is used to locate the 23 | camera. 24 | 25 | If the object is transformed by any of the scale, rotation or 26 | position attributes, then they will override the camera. 27 | */ 28 | 29 | @interface Camera : NSObject { 30 | float eyeX; 31 | float eyeY; 32 | float eyeZ; 33 | 34 | float centerX; 35 | float centerY; 36 | float centerZ; 37 | 38 | float upX; 39 | float upY; 40 | float upZ; 41 | 42 | BOOL dirty; 43 | } 44 | 45 | /** whether of not the camera is dirty */ 46 | @property (nonatomic,readwrite) BOOL dirty; 47 | 48 | /** returns the Z eye */ 49 | +(float) getZEye; 50 | 51 | /** sets the camera in the defaul position */ 52 | -(void) restore; 53 | /** Sets the camera using gluLookAt using its eye, center and up_vector */ 54 | -(void) locate; 55 | /** sets the eye values */ 56 | -(void) setEyeX: (float)x eyeY:(float)y eyeZ:(float)z; 57 | /** sets the center values */ 58 | -(void) setCenterX: (float)x centerY:(float)y centerZ:(float)z; 59 | /** sets the up values */ 60 | -(void) setUpX: (float)x upY:(float)y upZ:(float)z; 61 | 62 | /** get the eye vector values */ 63 | -(void) eyeX:(float*)x eyeY:(float*)y eyeZ:(float*)z; 64 | /** get the center vector values */ 65 | -(void) centerX:(float*)x centerY:(float*)y centerZ:(float*)z; 66 | /** get the up vector values */ 67 | -(void) upX:(float*)x upY:(float*)y upZ:(float*)z; 68 | 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /mahjong/cocos2d/RenderTexture.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 Jason Booth 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | #import "CocosNode.h" 17 | #import "Sprite.h" 18 | #import "OpenGL_Internal.h" 19 | 20 | enum 21 | { 22 | kImageFormatJPG = 0, 23 | kImageFormatPNG = 1 24 | }; 25 | 26 | 27 | /** 28 | RenderTexture is a generic rendering target. To render things into it, 29 | simply construct a render target, call begin on it, call visit on any cocos 30 | scenes or objects to render them, and call end. For convienience, render texture 31 | adds a sprite as it's display child with the results, so you can simply add 32 | the render texture to your scene and treat it like any other CocosNode. 33 | There are also functions for saving the render texture to disk in PNG or JPG format. 34 | 35 | @since v0.8.1 36 | */ 37 | @interface RenderTexture : CocosNode 38 | { 39 | GLuint fbo; 40 | GLint oldFBO; 41 | Texture2D* texture; 42 | Sprite* sprite; 43 | } 44 | 45 | /** sprite being used */ 46 | @property (nonatomic,readwrite, assign) Sprite* sprite; 47 | 48 | /** creates a RenderTexture object with width and height */ 49 | +(id)renderTextureWithWidth:(int)width height:(int)height; 50 | /** initializes a RenderTexture object with width and height */ 51 | -(id)initWithWidth:(int)width height:(int)height; 52 | -(void)begin; 53 | -(void)end; 54 | /* get buffer as UIImage */ 55 | -(UIImage *)getUIImageFromBuffer; 56 | /** saves the texture into a file */ 57 | -(BOOL)saveBuffer:(NSString*)name; 58 | /** saves the texture into a file. The format can be JPG or PNG */ 59 | -(BOOL)saveBuffer:(NSString*)name format:(int)format; 60 | /** clears the texture with a color */ 61 | -(void)clear:(float)r g:(float)g b:(float)b a:(float)a; 62 | @end 63 | 64 | 65 | -------------------------------------------------------------------------------- /mahjong/GoogleAdMobAdsSDK/GADInterstitialDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // GADInterstitialDelegate.h 3 | // Google AdMob Ads SDK 4 | // 5 | // Copyright 2011 Google Inc. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @class GADInterstitial; 11 | @class GADRequestError; 12 | 13 | // Delegate for receiving state change messages from a GADInterstitial such as 14 | // interstitial ad requests succeeding/failing. 15 | @protocol GADInterstitialDelegate 16 | 17 | @optional 18 | 19 | #pragma mark Ad Request Lifecycle Notifications 20 | 21 | // Sent when an interstitial ad request succeeded. Show it at the next 22 | // transition point in your application such as when transitioning between view 23 | // controllers. 24 | - (void)interstitialDidReceiveAd:(GADInterstitial *)ad; 25 | 26 | // Sent when an interstitial ad request completed without an interstitial to 27 | // show. This is common since interstitials are shown sparingly to users. 28 | - (void)interstitial:(GADInterstitial *)ad 29 | didFailToReceiveAdWithError:(GADRequestError *)error; 30 | 31 | #pragma mark Display-Time Lifecycle Notifications 32 | 33 | // Sent just before presenting an interstitial. After this method finishes the 34 | // interstitial will animate onto the screen. Use this opportunity to stop 35 | // animations and save the state of your application in case the user leaves 36 | // while the interstitial is on screen (e.g. to visit the App Store from a link 37 | // on the interstitial). 38 | - (void)interstitialWillPresentScreen:(GADInterstitial *)ad; 39 | 40 | // Sent before the interstitial is to be animated off the screen. 41 | - (void)interstitialWillDismissScreen:(GADInterstitial *)ad; 42 | 43 | // Sent just after dismissing an interstitial and it has animated off the 44 | // screen. 45 | - (void)interstitialDidDismissScreen:(GADInterstitial *)ad; 46 | 47 | // Sent just before the application will background or terminate because the 48 | // user clicked on an ad that will launch another application (such as the App 49 | // Store). The normal UIApplicationDelegate methods, like 50 | // applicationDidEnterBackground:, will be called immediately before this. 51 | - (void)interstitialWillLeaveApplication:(GADInterstitial *)ad; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /mahjong/cocos2d/MotionStreak.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008, 2009 by Jason Booth 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | #import "CocosNode.h" 17 | #import "Ribbon.h" 18 | 19 | /** 20 | * Motion Streak manages a Ribbon based on it's motion in absolute space. 21 | * You construct it with a fadeTime, minimum segment size, texture path, texture 22 | * length and color. The fadeTime controls how long it takes each vertex in 23 | * the streak to fade out, the minimum segment size it how many pixels the 24 | * streak will move before adding a new ribbon segement, and the texture 25 | * length is the how many pixels the texture is stretched across. The texture 26 | * is vertically aligned along the streak segemnts. 27 | * 28 | * Limitations: 29 | * MotionStreak, by default, will use the GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA blending function. 30 | * This blending function might not be the correct one for certain textures. 31 | * But you can change it by using: 32 | * [obj setBlendFunc: (ccBlendfunc) {new_src_blend_func, new_dst_blend_func}]; 33 | * 34 | * @since v0.8.1 35 | */ 36 | @interface MotionStreak : CocosNode 37 | { 38 | Ribbon* ribbon_; 39 | float mSegThreshold; 40 | float mWidth; 41 | CGPoint mLastLocation; 42 | } 43 | 44 | /** Ribbon used by MotionStreak (weak reference) */ 45 | @property (nonatomic,readonly) Ribbon *ribbon; 46 | 47 | /** creates the a MotionStreak. The image will be loaded using the TextureMgr. */ 48 | +(id)streakWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color; 49 | 50 | /** initializes a MotionStreak. The file will be loaded using the TextureMgr. */ 51 | -(id)initWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color; 52 | 53 | /** polling function */ 54 | -(void)update:(ccTime)delta; 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /mahjong/cocos2d/EaseAction.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008, 2009 Jason Booth 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "IntervalAction.h" 16 | 17 | /** Base class for Easing actions 18 | */ 19 | @interface EaseAction : IntervalAction 20 | { 21 | IntervalAction * other; 22 | } 23 | /** creates the action */ 24 | +(id) actionWithAction: (IntervalAction*) action; 25 | /** initializes the action */ 26 | -(id) initWithAction: (IntervalAction*) action; 27 | @end 28 | 29 | /** Base class for Easing actions with rate parameters 30 | */ 31 | @interface EaseRateAction : EaseAction 32 | { 33 | float rate; 34 | } 35 | /** rate value for the actions */ 36 | @property (nonatomic,readwrite,assign) float rate; 37 | /** Creates the action with the inner action and the rate parameter */ 38 | +(id) actionWithAction: (IntervalAction*) action rate:(float)rate; 39 | /** Initializes the action with the inner action and the rate parameter */ 40 | -(id) initWithAction: (IntervalAction*) action rate:(float)rate; 41 | @end 42 | 43 | /** EaseIn action with a rate 44 | */ 45 | @interface EaseIn : EaseRateAction {} @end 46 | 47 | /** EaseOut action with a rate 48 | */ 49 | @interface EaseOut : EaseRateAction {} @end 50 | 51 | /** EaseInOut action with a rate 52 | */ 53 | @interface EaseInOut : EaseRateAction {} @end 54 | 55 | /** Ease Exponential In 56 | */ 57 | @interface EaseExponentialIn : EaseAction {} @end 58 | /** Ease Exponential Out 59 | */ 60 | @interface EaseExponentialOut : EaseAction {} @end 61 | /** Ease Exponential InOut 62 | */ 63 | @interface EaseExponentialInOut : EaseAction {} @end 64 | /** Ease Sine In 65 | */ 66 | @interface EaseSineIn : EaseAction {} @end 67 | /** Ease Sine Out 68 | */ 69 | @interface EaseSineOut : EaseAction {} @end 70 | /** Ease Sine InOut 71 | */ 72 | @interface EaseSineInOut : EaseAction {} @end 73 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Menu.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | 17 | #import "MenuItem.h" 18 | #import "Layer.h" 19 | 20 | typedef enum { 21 | kMenuStateWaiting, 22 | kMenuStateTrackingTouch 23 | } MenuState; 24 | 25 | /** A Menu 26 | * 27 | * Features and Limitation: 28 | * - You can add MenuItem objects in runtime using addChild: 29 | * - But the only accecpted children are MenuItem objects 30 | */ 31 | @interface Menu : Layer 32 | { 33 | MenuState state; 34 | MenuItem *selectedItem; 35 | GLubyte opacity_; 36 | ccColor3B color_; 37 | } 38 | 39 | /** creates a menu with it's items */ 40 | + (id) menuWithItems: (MenuItem*) item, ... NS_REQUIRES_NIL_TERMINATION; 41 | 42 | /** initializes a menu with it's items */ 43 | - (id) initWithItems: (MenuItem*) item vaList: (va_list) args; 44 | 45 | /** align items vertically */ 46 | -(void) alignItemsVertically; 47 | /** align items vertically with padding 48 | @since v0.7.2 49 | */ 50 | -(void) alignItemsVerticallyWithPadding:(float) padding; 51 | 52 | /** align items horizontally */ 53 | -(void) alignItemsHorizontally; 54 | /** align items horizontally with padding 55 | @since v0.7.2 56 | */ 57 | -(void) alignItemsHorizontallyWithPadding: (float) padding; 58 | 59 | 60 | /** align items in rows of columns */ 61 | -(void) alignItemsInColumns: (NSNumber *) columns, ... NS_REQUIRES_NIL_TERMINATION; 62 | -(void) alignItemsInColumns: (NSNumber *) columns vaList: (va_list) args; 63 | 64 | /** align items in columns of rows */ 65 | -(void) alignItemsInRows: (NSNumber *) rows, ... NS_REQUIRES_NIL_TERMINATION; 66 | -(void) alignItemsInRows: (NSNumber *) rows vaList: (va_list) args; 67 | 68 | 69 | /** conforms to CocosNodeRGBA protocol */ 70 | @property (nonatomic,readonly) GLubyte opacity; 71 | /** conforms to CocosNodeRGBA protocol */ 72 | @property (nonatomic,readonly) ccColor3B color; 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /mahjong/cocos2d/DrawingPrimitives.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #ifndef __CC_DRAWING_PRIMITIVES_H 16 | #define __CC_DRAWING_PRIMITIVES_H 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | @file 24 | Drawing OpenGL ES primitives. 25 | - drawPoint 26 | - drawLine 27 | - drawPoly 28 | - drawCircle 29 | 30 | You can change the color, width and other property by calling the 31 | glColor4ub(), glLineWitdh(), glPointSize(). 32 | 33 | @warning These functions draws the Line, Point, Polygon, immediately. They aren't batched. If you are going to make a game that depends on these primitives, I suggest creating a batch. 34 | */ 35 | 36 | #import // for CGPoint 37 | #import // for BOOL 38 | 39 | /** draws a point given x and y coordinate */ 40 | void drawPoint( CGPoint point ); 41 | 42 | /** draws an array of points. 43 | @since v0.7.2 44 | */ 45 | void drawPoints( CGPoint *points, unsigned int numberOfPoints ); 46 | 47 | /** draws a line given the origin and destination point */ 48 | void drawLine( CGPoint origin, CGPoint destination ); 49 | 50 | /** draws a poligon given a pointer to CGPoint coordiantes and the number of vertices. The polygon can be closed or open 51 | */ 52 | void drawPoly( CGPoint *vertices, int numOfVertices, BOOL closePolygon ); 53 | 54 | /** draws a circle given the center, radius and number of segments. */ 55 | void drawCircle( CGPoint center, float radius, float angle, int segments, BOOL drawLineToCenter); 56 | 57 | /** draws a quad bezier path 58 | @since v0.8 59 | */ 60 | void drawQuadBezier(CGPoint origin, CGPoint control, CGPoint destination, int segments); 61 | 62 | /** draws a cubic bezier path 63 | @since v0.8 64 | */ 65 | void drawCubicBezier(CGPoint origin, CGPoint control1, CGPoint control2, CGPoint destination, int segments); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif // __CC_DRAWING_PRIMITIVES_H 72 | -------------------------------------------------------------------------------- /mahjong/cocos2d/TileMapAtlas.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "TextureAtlas.h" 16 | #import "AtlasNode.h" 17 | #import "Support/TGAlib.h" 18 | 19 | /** TileMapAtlas is a subclass of AtlasNode. 20 | 21 | It knows how to render a map based of tiles. 22 | The tiles must be in a .PNG format while the map must be a .TGA file. 23 | 24 | For more information regarding the format, please see this post: 25 | http://blog.sapusmedia.com/2008/12/how-to-use-tilemap-editor-for-cocos2d.html 26 | 27 | All features from AtlasNode are valid in TileMapAtlas 28 | 29 | IMPORTANT: 30 | This class is deprecated. It is maintained for compatibility reasons only. 31 | You SHOULD not use this class. 32 | Instead, use the newer TMX file format: TMXTiledMap 33 | */ 34 | @interface TileMapAtlas : AtlasNode { 35 | 36 | /// info about the map file 37 | tImageTGA *tgaInfo; 38 | 39 | /// x,y to altas dicctionary 40 | NSMutableDictionary *posToAtlasIndex; 41 | 42 | /// numbers of tiles to render 43 | int itemsToRender; 44 | } 45 | 46 | /** TileMap info */ 47 | @property (nonatomic,readonly) tImageTGA *tgaInfo; 48 | 49 | /** creates the TileMap with a tile file (atlas) with a map file and the width and height of each tile. 50 | The tile file will be loaded using the TextureMgr. 51 | */ 52 | +(id) tileMapAtlasWithTileFile:(NSString*)tile mapFile:(NSString*)map tileWidth:(int)w tileHeight:(int)h; 53 | 54 | /** initializes the TileMap with a tile file (atlas) with a map file and the width and height of each tile. 55 | The file will be loaded using the TextureMgr. 56 | */ 57 | -(id) initWithTileFile:(NSString*)tile mapFile:(NSString*)map tileWidth:(int)w tileHeight:(int)h; 58 | 59 | /** returns a tile from position x,y. 60 | For the moment only channel R is used 61 | */ 62 | -(ccColor3B) tileAt: (ccGridSize) position; 63 | 64 | /** sets a tile at position x,y. 65 | For the moment only channel R is used 66 | */ 67 | -(void) setTile:(ccColor3B)tile at:(ccGridSize)position; 68 | /** dealloc the map from memory */ 69 | -(void) releaseMap; 70 | @end 71 | -------------------------------------------------------------------------------- /mahjong/Classes/PlayScene.h: -------------------------------------------------------------------------------- 1 | // 2 | // PlayScene.h 3 | // Mahjongg 4 | // 5 | // Created by GamePipe Iphone Dev on 7/28/09. 6 | // Copyright 2009 USC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "cocos2d.h" 11 | #import 12 | #import 13 | #import "MenuScene.h" 14 | 15 | 16 | #define numberOfRows 6 17 | #define numberOfColumns 6 18 | #define numberOfTiles 144 19 | #define numberOfLayers 5 20 | #define numberOfGames 12 21 | 22 | 23 | 24 | 25 | 26 | @interface tileSprite : AtlasSprite 27 | { 28 | @public 29 | int tileID; 30 | BOOL isEnabled; 31 | BOOL isRendered; 32 | CGPoint corner; 33 | int indexI , indexJ, indexK; 34 | AtlasSprite* tileShadow; 35 | } 36 | 37 | 38 | -(void) setProperties :(int)tileIdentity :(CGPoint)position :(BOOL) enable :(BOOL) rendered :(int)i :(int)j :(int)k ; 39 | 40 | @end 41 | 42 | 43 | @interface PlayScene : Scene 44 | { 45 | } 46 | 47 | -(void) finishGame; 48 | -(void) restartGame:(int)index; 49 | @end 50 | 51 | @interface BackgroundLayer : ColorLayer 52 | { 53 | @public 54 | BOOL bonusScheduler,timerScheduler; 55 | AtlasSpriteManager* manager; 56 | //AtlasSpriteManager* timerSprites; 57 | //AtlasSprite* timerBar; 58 | tileSprite* previousTile; 59 | float tileScale,layerOffset; 60 | int numCols,numRows,numLayers,numTiles,numTrials,tileCount,currentLayoutIndex; 61 | float timex; 62 | Label* timeLabel,*previousBestTime,*pauseLabel; 63 | float timeCount; 64 | int gameScore; 65 | Menu *menu; 66 | SystemSoundID shortSound; 67 | NSURL* audioFile; 68 | tileSprite* tileBoard[numberOfRows][numberOfColumns][numberOfLayers]; 69 | int layoutArray[numberOfGames][36]; 70 | BOOL tileIDtracker[numberOfTiles]; 71 | CGPoint previousTouch; 72 | int roundScore[(numberOfGames-1)]; 73 | BOOL enableTouch,endGame,gamePaused; 74 | Sprite* pauseCover; 75 | } 76 | 77 | -(void) checkWhichTileSelected:(CGPoint)currentPoint; 78 | -(void) checkIfMatch:(tileSprite*)currentTile; 79 | -(void) ridTile:(tileSprite*)currentTile; 80 | -(void) initGame; 81 | -(void) readyScreen:(int)roundNumber; 82 | -(void) gameFinished; 83 | -(void) beginRoundFunc; 84 | -(void) getTime; 85 | -(void) setTilesVisible:(BOOL)b; 86 | 87 | 88 | @end 89 | 90 | 91 | @interface LevelSelectLayer : ColorLayer 92 | { 93 | 94 | 95 | } 96 | 97 | @end 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/base64.c: -------------------------------------------------------------------------------- 1 | /* 2 | public domain BASE64 code 3 | 4 | modified for cocos2d-iphone 5 | http://www.cocos2d-iphone.org 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | unsigned char alphabet[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 12 | 13 | int _base64Decode( unsigned char *input, unsigned int input_len, unsigned char *output, unsigned int *output_len ) 14 | { 15 | static char inalphabet[256], decoder[256]; 16 | int i, bits, c, char_count, errors = 0; 17 | unsigned int input_idx = 0; 18 | unsigned int output_idx = 0; 19 | 20 | for (i = (sizeof alphabet) - 1; i >= 0 ; i--) { 21 | inalphabet[alphabet[i]] = 1; 22 | decoder[alphabet[i]] = i; 23 | } 24 | 25 | char_count = 0; 26 | bits = 0; 27 | for( input_idx=0; input_idx < input_len ; input_idx++ ) { 28 | c = input[ input_idx ]; 29 | if (c == '=') 30 | break; 31 | if (c > 255 || ! inalphabet[c]) 32 | continue; 33 | bits += decoder[c]; 34 | char_count++; 35 | if (char_count == 4) { 36 | output[ output_idx++ ] = (bits >> 16); 37 | output[ output_idx++ ] = ((bits >> 8) & 0xff); 38 | output[ output_idx++ ] = ( bits & 0xff); 39 | bits = 0; 40 | char_count = 0; 41 | } else { 42 | bits <<= 6; 43 | } 44 | } 45 | 46 | if( c == '=' ) { 47 | switch (char_count) { 48 | case 1: 49 | fprintf(stderr, "base64Decode: encoding incomplete: at least 2 bits missing"); 50 | errors++; 51 | break; 52 | case 2: 53 | output[ output_idx++ ] = ( bits >> 10 ); 54 | break; 55 | case 3: 56 | output[ output_idx++ ] = ( bits >> 16 ); 57 | output[ output_idx++ ] = (( bits >> 8 ) & 0xff); 58 | break; 59 | } 60 | } else if ( input_idx < input_len ) { 61 | if (char_count) { 62 | fprintf(stderr, "base64 encoding incomplete: at least %d bits truncated", 63 | ((4 - char_count) * 6)); 64 | errors++; 65 | } 66 | } 67 | 68 | *output_len = output_idx; 69 | return errors; 70 | } 71 | 72 | int base64Decode(unsigned char *in, unsigned int inLength, unsigned char **out) 73 | { 74 | unsigned int outLength = 0; 75 | 76 | //should be enough to store 6-bit buffers in 8-bit buffers 77 | *out = malloc( inLength * 3.0f / 4.0f + 1 ); 78 | if( *out ) { 79 | int ret = _base64Decode(in, inLength, *out, &outLength); 80 | 81 | if (ret > 0 ) 82 | { 83 | printf("Base64Utils: error decoding"); 84 | free(*out); 85 | *out = NULL; 86 | outLength = 0; 87 | } 88 | } 89 | return outLength; 90 | } 91 | -------------------------------------------------------------------------------- /mahjong/cocos2d/AtlasNode.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "TextureAtlas.h" 16 | #import "CocosNode.h" 17 | 18 | /** AtlasNode is a subclass of CocosNode that implements the CocosNodeRGBA and 19 | CocosNodeTexture protocol 20 | 21 | It knows how to render a TextureAtlas object. 22 | If you are going to render a TextureAtlas consider subclassing AtlasNode (or a subclass of AtlasNode) 23 | 24 | All features from CocosNode are valid, plus the following features: 25 | - opacity and RGB colors 26 | */ 27 | @interface AtlasNode : CocosNode { 28 | 29 | // texture atlas 30 | TextureAtlas *textureAtlas_; 31 | 32 | // chars per row 33 | int itemsPerRow; 34 | // chars per column 35 | int itemsPerColumn; 36 | 37 | // texture coordinate x increment 38 | float texStepX; 39 | // texture coordinate y increment 40 | float texStepY; 41 | 42 | // width of each char 43 | int itemWidth; 44 | // height of each char 45 | int itemHeight; 46 | 47 | // blend function 48 | ccBlendFunc blendFunc_; 49 | 50 | // texture RGBA. 51 | GLubyte opacity_; 52 | ccColor3B color_; 53 | BOOL opacityModifyRGB_; 54 | } 55 | 56 | /** conforms to CocosNodeTexture protocol */ 57 | @property (nonatomic,readwrite,retain) TextureAtlas *textureAtlas; 58 | 59 | /** conforms to CocosNodeTexture protocol */ 60 | @property (nonatomic,readwrite) ccBlendFunc blendFunc; 61 | 62 | /** conforms to CocosNodeRGBA protocol */ 63 | @property (nonatomic,readonly) GLubyte opacity; 64 | /** conforms to CocosNodeRGBA protocol */ 65 | @property (nonatomic,readwrite) ccColor3B color; 66 | 67 | 68 | /** creates an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/ 69 | +(id) atlasWithTileFile:(NSString*)tile tileWidth:(int)w tileHeight:(int)h itemsToRender: (int) c; 70 | 71 | /** initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/ 72 | -(id) initWithTileFile:(NSString*)tile tileWidth:(int)w tileHeight:(int)h itemsToRender: (int) c; 73 | 74 | /** updates the Atlas (indexed vertex array). 75 | * Shall be overriden in subclasses 76 | */ 77 | -(void) updateAtlasValues; 78 | @end 79 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Label.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import "Label.h" 17 | #import "Support/CGPointExtension.h" 18 | 19 | @implementation Label 20 | 21 | - (id) init 22 | { 23 | NSException* myException = [NSException 24 | exceptionWithName:@"LabelInit" 25 | reason:@"Use initWithString:dimensions:aligment:fontName:font instead" 26 | userInfo:nil]; 27 | @throw myException; 28 | } 29 | 30 | + (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size 31 | { 32 | return [[[self alloc] initWithString: string dimensions:dimensions alignment:alignment fontName:name fontSize:size]autorelease]; 33 | } 34 | 35 | + (id) labelWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size 36 | { 37 | return [[[self alloc] initWithString: string fontName:name fontSize:size]autorelease]; 38 | } 39 | 40 | 41 | - (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size; 42 | { 43 | if( (self=[super init]) ) { 44 | 45 | _dimensions = dimensions; 46 | _alignment = alignment; 47 | _fontName = [name retain]; 48 | _fontSize = size; 49 | 50 | [self setString:string]; 51 | } 52 | return self; 53 | } 54 | 55 | - (id) initWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size; 56 | { 57 | if( (self=[super init]) ) { 58 | 59 | _dimensions = CGSizeZero; 60 | _fontName = [name retain]; 61 | _fontSize = size; 62 | 63 | [self setString:string]; 64 | } 65 | return self; 66 | } 67 | 68 | - (void) setString:(NSString*)string 69 | { 70 | if( CGSizeEqualToSize( _dimensions, CGSizeZero ) ) 71 | // WARNING: double retain 72 | self.texture = [[Texture2D alloc] initWithString:string fontName:_fontName fontSize:_fontSize]; 73 | else 74 | // WARNING: double retain 75 | self.texture = [[Texture2D alloc] initWithString:string dimensions:_dimensions alignment:_alignment fontName:_fontName fontSize:_fontSize]; 76 | 77 | // end of warning. 1 retain only 78 | [self.texture release]; 79 | } 80 | 81 | - (void) dealloc 82 | { 83 | [_fontName release]; 84 | [super dealloc]; 85 | } 86 | @end 87 | -------------------------------------------------------------------------------- /mahjong/cocos2d/TouchHandler.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 Valentin Milea 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "TouchDelegateProtocol.h" 16 | 17 | /** 18 | TouchHandler 19 | Object than contains the delegate and priority of the event handler. 20 | */ 21 | @interface TouchHandler : NSObject { 22 | id delegate; 23 | int priority; 24 | } 25 | 26 | /** delegate */ 27 | @property(nonatomic, readwrite, retain) id delegate; 28 | /** priority */ 29 | @property(nonatomic, readwrite) int priority; // default 0 30 | 31 | /** allocates a TouchHandler with a delegate and a priority */ 32 | + (id)handlerWithDelegate:(id)aDelegate priority:(int)priority; 33 | /** initializes a TouchHandler with a delegate and a priority */ 34 | - (id)initWithDelegate:(id)aDelegate priority:(int)priority; 35 | 36 | - (BOOL)ccTouchesBegan:(NSMutableSet *)touches withEvent:(UIEvent *)event; 37 | - (BOOL)ccTouchesMoved:(NSMutableSet *)touches withEvent:(UIEvent *)event; 38 | - (BOOL)ccTouchesEnded:(NSMutableSet *)touches withEvent:(UIEvent *)event; 39 | - (BOOL)ccTouchesCancelled:(NSMutableSet *)touches withEvent:(UIEvent *)event; 40 | @end 41 | 42 | /** StandardTouchHandler 43 | It forwardes each event to the delegate until one delegate returns kEventHandled. 44 | */ 45 | @interface StandardTouchHandler : TouchHandler 46 | { 47 | } 48 | @end 49 | 50 | /** 51 | TargetedTouchHandler 52 | Object than contains the claimed touches and if it swallos touches. 53 | Used internally by TouchDispatcher 54 | */ 55 | @interface TargetedTouchHandler : TouchHandler { 56 | BOOL swallowsTouches; 57 | NSMutableSet *claimedTouches; 58 | } 59 | /** whether or not the touches are swallowed */ 60 | @property(nonatomic, readwrite) BOOL swallowsTouches; // default NO 61 | /** MutableSet that contains the claimed touches */ 62 | @property(nonatomic, readonly) NSMutableSet *claimedTouches; 63 | 64 | /** allocates a TargetedTouchHandler with a delegate, a priority and whether or not it swallows touches or not */ 65 | + (id)handlerWithDelegate:(id) aDelegate priority:(int)priority swallowsTouches:(BOOL)swallowsTouches; 66 | /** initializes a TargetedTouchHandler with a delegate, a priority and whether or not it swallows touches or not */ 67 | - (id)initWithDelegate:(id) aDelegate priority:(int)priority swallowsTouches:(BOOL)swallowsTouches; 68 | 69 | @end 70 | 71 | -------------------------------------------------------------------------------- /mahjong/cocos2d/TouchDelegateProtocol.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 Valentin Milea 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | #import 15 | 16 | /** 17 | TargetedTouchDelegate. 18 | 19 | Using this type of delegate results in two benefits: 20 | 1. You don't need to deal with NSSets, the dispatcher does the job of splitting 21 | them. You get exactly one UITouch per call. 22 | 2. You can *claim* a UITouch by returning YES in ccTouchBegan. Updates of claimed 23 | touches are sent only to the delegate(s) that claimed them. So if you get a move/ 24 | ended/cancelled update you're sure it's your touch. This frees you from doing a 25 | lot of checks when doing multi-touch. 26 | 27 | (The name TargetedTouchDelegate relates to updates "targeting" their specific 28 | handler, without bothering the other handlers.) 29 | @since v0.8 30 | */ 31 | @protocol TargetedTouchDelegate 32 | 33 | /** Return YES to claim the touch. 34 | @since v0.8 35 | */ 36 | - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event; 37 | @optional 38 | // touch updates: 39 | - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event; 40 | - (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event; 41 | - (void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event; 42 | @end 43 | 44 | /** 45 | StandardTouchDelegate. 46 | Each event that is received will be propagated to the delegate, 47 | unless a previous delegate consumes the event. 48 | To consume the event (prevent propagation) the delegate should return kEventHandled. 49 | To ignore the event (the event will be forwarded to the next delegate in the chain) the delegate should return kEventIgnored. 50 | @since v0.8 51 | */ 52 | @protocol StandardTouchDelegate 53 | @optional 54 | - (BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 55 | - (BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; 56 | - (BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 57 | - (BOOL)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; 58 | @end 59 | 60 | enum { 61 | /// return kEventHandled if the event should NOT be forwarded to the next handler in the chain 62 | kEventHandled = YES, 63 | /// return kEventIgnored if the event should be forwarded to the next handler in the chain 64 | kEventIgnored = NO, 65 | }; 66 | -------------------------------------------------------------------------------- /mahjong/cocos2d/cocos2d.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | /** @mainpage cocos2d for iPhone API reference 17 | * 18 | * @image html Icon.png 19 | * 20 | * @section intro Introduction 21 | * This is cocos2d API reference 22 | * 23 | * The programming guide is hosted here: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index 24 | * 25 | *
26 | * 27 | * @todo A native english speaker should check the grammar. We need your help! 28 | * 29 | */ 30 | 31 | // 0x00 HI ME LO 32 | // 00 00 08 01 33 | #define COCOS2D_VERSION 0x00000801 34 | 35 | // 36 | // all cocos2d include files 37 | // 38 | #import "Action.h" 39 | #import "Camera.h" 40 | #import "CameraAction.h" 41 | #import "CocosNode.h" 42 | #import "Director.h" 43 | #import "TouchDispatcher.h" 44 | #import "TouchDelegateProtocol.h" 45 | #import "InstantAction.h" 46 | #import "IntervalAction.h" 47 | #import "EaseAction.h" 48 | #import "Label.h" 49 | #import "Layer.h" 50 | #import "Menu.h" 51 | #import "MenuItem.h" 52 | #import "ParticleSystem.h" 53 | #import "PointParticleSystem.h" 54 | #import "QuadParticleSystem.h" 55 | #import "ParticleExamples.h" 56 | #import "DrawingPrimitives.h" 57 | #import "Scene.h" 58 | #import "Scheduler.h" 59 | #import "Sprite.h" 60 | #import "TextureMgr.h" 61 | #import "TextureNode.h" 62 | #import "Transition.h" 63 | #import "TextureAtlas.h" 64 | #import "LabelAtlas.h" 65 | #import "TileMapAtlas.h" 66 | #import "AtlasNode.h" 67 | #import "EaseAction.h" 68 | #import "TiledGridAction.h" 69 | #import "Grabber.h" 70 | #import "Grid.h" 71 | #import "Grid3DAction.h" 72 | #import "GridAction.h" 73 | #import "AtlasSprite.h" 74 | #import "AtlasSpriteManager.h" 75 | #import "BitmapFontAtlas.h" 76 | #import "ParallaxNode.h" 77 | #import "ActionManager.h" 78 | #import "TMXTiledMap.h" 79 | #import "RenderTexture.h" 80 | #import "MotionStreak.h" 81 | 82 | // 83 | // cocos2d macros 84 | // 85 | #import "ccTypes.h" 86 | #import "ccMacros.h" 87 | 88 | // 89 | // cocos2d helper files 90 | // 91 | #import "Support/OpenGL_Internal.h" 92 | #import "Support/Texture2D.h" 93 | #import "Support/EAGLView.h" 94 | #import "Support/FileUtils.h" 95 | #import "Support/CGPointExtension.h" 96 | 97 | 98 | // free functions 99 | NSString * cocos2dVersion(void); 100 | -------------------------------------------------------------------------------- /mahjong/FlurryLib/FlurryAPI.h: -------------------------------------------------------------------------------- 1 | // 2 | // FlurryAPI.h 3 | // Flurry iOS Analytics Agent 2.8.3 ver 45 4 | // 5 | // Copyright 2009 Flurry, Inc. All rights reserved. 6 | // 7 | // Methods in this header file are for use with Flurry Analytics 8 | 9 | #import 10 | 11 | @interface FlurryAPI : NSObject { 12 | } 13 | 14 | /* 15 | optional sdk settings that should be called before start session 16 | */ 17 | + (void)setAppVersion:(NSString *)version; // override the app version 18 | + (NSString *)getFlurryAgentVersion; // get the Flurry Agent version number 19 | + (void)setShowErrorInLogEnabled:(BOOL)value; // default is NO 20 | + (void)setDebugLogEnabled:(BOOL)value; // generate debug logs for Flurry support, default is NO 21 | + (void)setSessionContinueSeconds:(int)seconds; // default is 10 seconds 22 | 23 | /* 24 | start session, attempt to send saved sessions to server 25 | */ 26 | + (void)startSession:(NSString *)apiKey; 27 | 28 | /* 29 | log events or errors after session has started 30 | */ 31 | + (void)logEvent:(NSString *)eventName; 32 | + (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters; 33 | + (void)logError:(NSString *)errorID message:(NSString *)message exception:(NSException *)exception; 34 | + (void)logError:(NSString *)errorID message:(NSString *)message error:(NSError *)error; 35 | 36 | /* 37 | start or end timed events 38 | */ 39 | + (void)logEvent:(NSString *)eventName timed:(BOOL)timed; 40 | + (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters timed:(BOOL)timed; 41 | + (void)endTimedEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters; // non-nil parameters will update the parameters 42 | 43 | /* 44 | count page views 45 | */ 46 | + (void)logAllPageViews:(id)target; // automatically track page view on UINavigationController or UITabBarController 47 | + (void)logPageView; // manually increment page view by 1 48 | 49 | /* 50 | set user info 51 | */ 52 | + (void)setUserID:(NSString *)userID; // user's id in your system 53 | + (void)setAge:(int)age; // user's age in years 54 | + (void)setGender:(NSString *)gender; // user's gender m or f 55 | 56 | /* 57 | set location information 58 | */ 59 | + (void)setLatitude:(double)latitude longitude:(double)longitude horizontalAccuracy:(float)horizontalAccuracy verticalAccuracy:(float)verticalAccuracy; 60 | 61 | /* 62 | optional session settings that can be changed after start session 63 | */ 64 | + (void)setSessionReportsOnCloseEnabled:(BOOL)sendSessionReportsOnClose; // default is YES 65 | + (void)setSessionReportsOnPauseEnabled:(BOOL)setSessionReportsOnPauseEnabled; // default is YES 66 | + (void)setEventLoggingEnabled:(BOOL)value; // default is YES 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /mahjong/cocos2d/InstantAction.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import 17 | 18 | #import "Action.h" 19 | 20 | /** Instant actions are immediate actions. They don't have a duration like 21 | the Interval Actions. 22 | */ 23 | @interface InstantAction : FiniteTimeAction 24 | {} 25 | @end 26 | 27 | /** Show the node 28 | */ 29 | @interface Show : InstantAction 30 | { 31 | } 32 | @end 33 | 34 | /** Hide the node 35 | */ 36 | @interface Hide : InstantAction 37 | { 38 | } 39 | @end 40 | 41 | /** Toggles the visibility of a node 42 | */ 43 | @interface ToggleVisibility : InstantAction 44 | { 45 | } 46 | @end 47 | 48 | /** Places the node in a certain position 49 | */ 50 | @interface Place : InstantAction 51 | { 52 | CGPoint position; 53 | } 54 | /** creates a Place action with a position */ 55 | +(id) actionWithPosition: (CGPoint) pos; 56 | /** Initializes a Place action with a position */ 57 | -(id) initWithPosition: (CGPoint) pos; 58 | @end 59 | 60 | /** Calls a 'callback' 61 | */ 62 | @interface CallFunc : InstantAction 63 | { 64 | id targetCallback; 65 | SEL selector; 66 | } 67 | /** creates the action with the callback */ 68 | +(id) actionWithTarget: (id) t selector:(SEL) s; 69 | /** initializes the action with the callback */ 70 | -(id) initWithTarget: (id) t selector:(SEL) s; 71 | /** exeuctes the callback */ 72 | -(void) execute; 73 | @end 74 | 75 | /** Calls a 'callback' with the node as the first argument 76 | N means Node 77 | */ 78 | @interface CallFuncN : CallFunc 79 | { 80 | } 81 | @end 82 | 83 | /** Calls a 'callback' with the node as the first argument and the 2nd argument is data 84 | * ND means: Node Data 85 | */ 86 | @interface CallFuncND : CallFuncN 87 | { 88 | void *data; 89 | NSInvocation *invocation_; 90 | } 91 | 92 | /** Invocation object that has the target#selector and the parameters */ 93 | @property (nonatomic,readwrite,retain) NSInvocation *invocation; 94 | 95 | /** creates the action with the callback and the data to pass as an argument */ 96 | +(id) actionWithTarget: (id) t selector:(SEL) s data:(void*)d; 97 | /** initializes the action with the callback and the data to pass as an argument */ 98 | -(id) initWithTarget:(id) t selector:(SEL) s data:(void*) d; 99 | @end 100 | -------------------------------------------------------------------------------- /mahjong/GoogleAdMobAdsSDK/GADBannerViewDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // GADBannerViewDelegate.h 3 | // Google AdMob Ads SDK 4 | // 5 | // Copyright 2011 Google Inc. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @class GADRequestError; 11 | @class GADBannerView; 12 | 13 | // Delegate for receiving state change messages from a GADBannerView such as ad 14 | // requests succeeding/failing or when an ad has been clicked. 15 | @protocol GADBannerViewDelegate 16 | 17 | @optional 18 | 19 | #pragma mark Ad Request Lifecycle Notifications 20 | 21 | // Sent when an ad request loaded an ad. This is a good opportunity to add this 22 | // view to the hierarchy if it has not yet been added. If the ad was received 23 | // as a part of the server-side auto refreshing, you can examine the 24 | // hasAutoRefreshed property of the view. 25 | - (void)adViewDidReceiveAd:(GADBannerView *)view; 26 | 27 | // Sent when an ad request failed. Normally this is because no network 28 | // connection was available or no ads were available (i.e. no fill). If the 29 | // error was received as a part of the server-side auto refreshing, you can 30 | // examine the hasAutoRefreshed property of the view. 31 | - (void)adView:(GADBannerView *)view 32 | didFailToReceiveAdWithError:(GADRequestError *)error; 33 | 34 | #pragma mark Click-Time Lifecycle Notifications 35 | 36 | // Sent just before presenting the user a full screen view, such as a browser, 37 | // in response to clicking on an ad. Use this opportunity to stop animations, 38 | // time sensitive interactions, etc. 39 | // 40 | // Normally the user looks at the ad, dismisses it, and control returns to your 41 | // application by calling adViewDidDismissScreen:. However if the user hits the 42 | // Home button or clicks on an App Store link your application will end. On iOS 43 | // 4.0+ the next method called will be applicationWillResignActive: of your 44 | // UIViewController (UIApplicationWillResignActiveNotification). Immediately 45 | // after that adViewWillLeaveApplication: is called. 46 | - (void)adViewWillPresentScreen:(GADBannerView *)adView; 47 | 48 | // Sent just before dismissing a full screen view. 49 | - (void)adViewWillDismissScreen:(GADBannerView *)adView; 50 | 51 | // Sent just after dismissing a full screen view. Use this opportunity to 52 | // restart anything you may have stopped as part of adViewWillPresentScreen:. 53 | - (void)adViewDidDismissScreen:(GADBannerView *)adView; 54 | 55 | // Sent just before the application will background or terminate because the 56 | // user clicked on an ad that will launch another application (such as the App 57 | // Store). The normal UIApplicationDelegate methods, like 58 | // applicationDidEnterBackground:, will be called immediately before this. 59 | - (void)adViewWillLeaveApplication:(GADBannerView *)adView; 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /mahjong/cocos2d/MotionStreak.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008, 2009 Jason Booth 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | ********************************************************* 14 | * 15 | * Motion Streak manages a Ribbon based on it's motion in absolute space. 16 | * You construct it with a fadeTime, minimum segment size, texture path, texture 17 | * length and color. The fadeTime controls how long it takes each vertex in 18 | * the streak to fade out, the minimum segment size it how many pixels the 19 | * streak will move before adding a new ribbon segement, and the texture 20 | * length is the how many pixels the texture is stretched across. The texture 21 | * is vertically aligned along the streak segemnts. 22 | */ 23 | 24 | #import "MotionStreak.h" 25 | #import "Support/CGPointExtension.h" 26 | 27 | @implementation MotionStreak 28 | 29 | @synthesize ribbon=ribbon_; 30 | 31 | +(id)streakWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color 32 | { 33 | return [[[MotionStreak alloc] initWithFade:(float)fade minSeg:seg image:path width:width length:length color:color] autorelease]; 34 | } 35 | 36 | -(id)initWithFade:(float)fade minSeg:(float)seg image:(NSString*)path width:(float)width length:(float)length color:(ccColor4B)color 37 | { 38 | if( (self=[super init])) { 39 | mSegThreshold = seg; 40 | mWidth = width; 41 | mLastLocation = CGPointZero; 42 | ribbon_ = [Ribbon ribbonWithWidth: mWidth image:path length:length color:color fade:fade]; 43 | [self addChild:ribbon_]; 44 | 45 | // update ribbon position 46 | [self schedule:@selector(update:) interval:0]; 47 | } 48 | return self; 49 | } 50 | 51 | -(void)update:(ccTime)delta 52 | { 53 | CGPoint location = [self convertToWorldSpace:CGPointZero]; 54 | [ribbon_ setPosition:ccp(-1*location.x, -1*location.y)]; 55 | float len = sqrtf(powf(mLastLocation.x - location.x, 2) + powf(mLastLocation.y - location.y, 2)); 56 | if (len > mSegThreshold) 57 | { 58 | [ribbon_ addPointAt:location width:mWidth]; 59 | mLastLocation = location; 60 | } 61 | [ribbon_ update:delta]; 62 | } 63 | 64 | 65 | -(void)dealloc 66 | { 67 | [super dealloc]; 68 | } 69 | 70 | #pragma mark MotionStreak - CocosNodeTexture protocol 71 | 72 | -(void) setTexture:(Texture2D*) texture 73 | { 74 | [ribbon_ setTexture: texture]; 75 | } 76 | 77 | -(Texture2D*) texture 78 | { 79 | return [ribbon_ texture]; 80 | } 81 | 82 | -(ccBlendFunc) blendFunc 83 | { 84 | return [ribbon_ blendFunc]; 85 | } 86 | 87 | -(void) setBlendFunc:(ccBlendFunc)blendFunc 88 | { 89 | [ribbon_ setBlendFunc:blendFunc]; 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /mahjong/cocos2d/CDConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010 Steve Oldmeadow 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | $Id$ 23 | */ 24 | #define COCOSDENSHION_VERSION "Aphex.rc" 25 | 26 | 27 | /** 28 | If enabled code useful for debugging such as parameter check assertions will be performed. 29 | If you experience any problems you should enable this and test your code with a debug build. 30 | */ 31 | //#define CD_DEBUG 1 32 | 33 | /** 34 | The total number of sounds/buffers that can be loaded assuming memory is sufficient 35 | */ 36 | //Number of buffers slots that will be initially created 37 | #define CD_BUFFERS_START 64 38 | //Number of buffers that will be added 39 | #define CD_BUFFERS_INCREMENT 16 40 | 41 | /** 42 | If enabled, OpenAL code will use static buffers. When static buffers are used the audio 43 | data is managed outside of OpenAL, this eliminates a memcpy operation which leads to 44 | higher performance when loading sounds. 45 | 46 | However, the downside is that when the audio data is freed you must 47 | be certain that it is no longer being accessed otherwise your app will crash. Testing on OS 2.2.1 48 | and 3.1.2 has shown that this may occur if a buffer is being used by a source with state = AL_PLAYING 49 | when the buffer is deleted. If the data is freed too quickly after the source is stopped then 50 | a crash will occur. The implemented workaround is that when static buffers are used the unloadBuffer code will wait for 51 | any playing sources to finish playing before the associated buffer and data are deleted, however, this delay may negate any 52 | performance gains that are achieved during loading. 53 | 54 | Performance tests on a 1st gen iPod running OS 2.2.1 loading the CocosDenshionDemo sounds were ~0.14 seconds without 55 | static buffers and ~0.12 seconds when using static buffers. 56 | 57 | */ 58 | //#define CD_USE_STATIC_BUFFERS 1 59 | 60 | 61 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/glu.c: -------------------------------------------------------------------------------- 1 | // 2 | // cocos2d (incomplete) GLU implementation 3 | // 4 | // gluLookAt and gluPerspective from: 5 | // http://jet.ro/creations (San Angeles Observation) 6 | // 7 | // 8 | 9 | #import 10 | #import 11 | #import "OpenGL_Internal.h" 12 | #include "glu.h" 13 | 14 | void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar) 15 | { 16 | GLfloat xmin, xmax, ymin, ymax; 17 | 18 | ymax = zNear * (GLfloat)tanf(fovy * (float)M_PI / 360); 19 | ymin = -ymax; 20 | xmin = ymin * aspect; 21 | xmax = ymax * aspect; 22 | 23 | glFrustumf(xmin, xmax, 24 | ymin, ymax, 25 | zNear, zFar); 26 | } 27 | 28 | void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, 29 | GLfloat centerx, GLfloat centery, GLfloat centerz, 30 | GLfloat upx, GLfloat upy, GLfloat upz) 31 | { 32 | GLfloat m[16]; 33 | GLfloat x[3], y[3], z[3]; 34 | GLfloat mag; 35 | 36 | /* Make rotation matrix */ 37 | 38 | /* Z vector */ 39 | z[0] = eyex - centerx; 40 | z[1] = eyey - centery; 41 | z[2] = eyez - centerz; 42 | mag = (float)sqrtf(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]); 43 | if (mag) { 44 | z[0] /= mag; 45 | z[1] /= mag; 46 | z[2] /= mag; 47 | } 48 | 49 | /* Y vector */ 50 | y[0] = upx; 51 | y[1] = upy; 52 | y[2] = upz; 53 | 54 | /* X vector = Y cross Z */ 55 | x[0] = y[1] * z[2] - y[2] * z[1]; 56 | x[1] = -y[0] * z[2] + y[2] * z[0]; 57 | x[2] = y[0] * z[1] - y[1] * z[0]; 58 | 59 | /* Recompute Y = Z cross X */ 60 | y[0] = z[1] * x[2] - z[2] * x[1]; 61 | y[1] = -z[0] * x[2] + z[2] * x[0]; 62 | y[2] = z[0] * x[1] - z[1] * x[0]; 63 | 64 | /* cross product gives area of parallelogram, which is < 1.0 for 65 | * non-perpendicular unit-length vectors; so normalize x, y here 66 | */ 67 | 68 | mag = (float)sqrtf(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]); 69 | if (mag) { 70 | x[0] /= mag; 71 | x[1] /= mag; 72 | x[2] /= mag; 73 | } 74 | 75 | mag = (float)sqrtf(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]); 76 | if (mag) { 77 | y[0] /= mag; 78 | y[1] /= mag; 79 | y[2] /= mag; 80 | } 81 | 82 | #define M(row,col) m[col*4+row] 83 | M(0, 0) = x[0]; 84 | M(0, 1) = x[1]; 85 | M(0, 2) = x[2]; 86 | M(0, 3) = 0.0f; 87 | M(1, 0) = y[0]; 88 | M(1, 1) = y[1]; 89 | M(1, 2) = y[2]; 90 | M(1, 3) = 0.0f; 91 | M(2, 0) = z[0]; 92 | M(2, 1) = z[1]; 93 | M(2, 2) = z[2]; 94 | M(2, 3) = 0.0f; 95 | M(3, 0) = 0.0f; 96 | M(3, 1) = 0.0f; 97 | M(3, 2) = 0.0f; 98 | M(3, 3) = 1.0f; 99 | #undef M 100 | { 101 | int a; 102 | GLfloat fixedM[16]; 103 | for (a = 0; a < 16; ++a) 104 | fixedM[a] = m[a]; 105 | glMultMatrixf(fixedM); 106 | } 107 | 108 | /* Translate Eye to Origin */ 109 | glTranslatef(-eyex, -eyey, -eyez); 110 | } 111 | 112 | 113 | -------------------------------------------------------------------------------- /mahjong/cocos2d/TextureNode.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | #import 17 | #import 18 | 19 | #import "TextureMgr.h" 20 | #import "TextureNode.h" 21 | #import "ccMacros.h" 22 | #import "Support/CGPointExtension.h" 23 | 24 | @implementation TextureNode 25 | 26 | @synthesize opacity=opacity_; 27 | @synthesize color=color_; 28 | @synthesize blendFunc = blendFunc_; 29 | 30 | - (id) init 31 | { 32 | if( (self=[super init]) ) { 33 | opacity_ = 255; 34 | color_ = ccWHITE; 35 | anchorPoint_ = ccp(0.5f, 0.5f); 36 | blendFunc_.src = CC_BLEND_SRC; 37 | blendFunc_.dst = CC_BLEND_DST; 38 | } 39 | 40 | return self; 41 | } 42 | 43 | -(void) dealloc 44 | { 45 | [texture_ release]; 46 | [super dealloc]; 47 | } 48 | 49 | -(void) setTexture:(Texture2D*) texture 50 | { 51 | [texture_ release]; 52 | texture_ = [texture retain]; 53 | [self setContentSize: texture.contentSize]; 54 | if( ! [texture hasPremultipliedAlpha] ) { 55 | blendFunc_.src = GL_SRC_ALPHA; 56 | blendFunc_.dst = GL_ONE_MINUS_SRC_ALPHA; 57 | } 58 | opacityModifyRGB_ = [texture hasPremultipliedAlpha]; 59 | } 60 | 61 | -(Texture2D*) texture 62 | { 63 | return texture_; 64 | } 65 | 66 | #pragma mark TextureNode - RGBA protocol 67 | -(void) setRGB: (GLubyte)r :(GLubyte)g :(GLubyte)b 68 | { 69 | [self setColor:ccc3(r,g,b)]; 70 | } 71 | 72 | -(void) setOpacity:(GLubyte)opacity 73 | { 74 | // special opacity for premultiplied textures 75 | opacity_ = opacity; 76 | if( opacityModifyRGB_ ) 77 | color_.r = color_.g = color_.b = opacity_; 78 | } 79 | -(void) setOpacityModifyRGB:(BOOL)modify 80 | { 81 | opacityModifyRGB_ = modify; 82 | } 83 | -(BOOL) doesOpacityModifyRGB 84 | { 85 | return opacityModifyRGB_; 86 | } 87 | 88 | #pragma mark TextureNode - draw 89 | - (void) draw 90 | { 91 | glEnableClientState( GL_VERTEX_ARRAY); 92 | glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 93 | 94 | glEnable( GL_TEXTURE_2D); 95 | 96 | glColor4ub( color_.r, color_.g, color_.b, opacity_); 97 | 98 | BOOL newBlend = NO; 99 | if( blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST ) { 100 | newBlend = YES; 101 | glBlendFunc( blendFunc_.src, blendFunc_.dst ); 102 | } 103 | 104 | [texture_ drawAtPoint: CGPointZero]; 105 | 106 | if( newBlend ) 107 | glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); 108 | 109 | // is this chepear than saving/restoring color state ? 110 | glColor4ub( 255, 255, 255, 255); 111 | 112 | glDisable( GL_TEXTURE_2D); 113 | 114 | glDisableClientState(GL_VERTEX_ARRAY ); 115 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); 116 | } 117 | @end 118 | -------------------------------------------------------------------------------- /mahjong/Mahjongg.xcodeproj/xcuserdata/manan19.xcuserdatad/xcschemes/Mahjongg.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 40 | 41 | 47 | 48 | 49 | 50 | 51 | 52 | 59 | 60 | 66 | 67 | 68 | 69 | 71 | 72 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Scheduler.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | // cocoa related 17 | #import 18 | 19 | #import "ccTypes.h" 20 | 21 | typedef void (*TICK_IMP)(id, SEL, ccTime); 22 | 23 | // 24 | // Timer 25 | // 26 | /** Light weight timer */ 27 | @interface Timer : NSObject 28 | { 29 | id target; 30 | SEL selector; 31 | TICK_IMP impMethod; 32 | 33 | ccTime interval; 34 | ccTime elapsed; 35 | } 36 | 37 | /** interval in seconds */ 38 | @property (nonatomic,readwrite,assign) ccTime interval; 39 | 40 | /** Allocates a timer with a target and a selector. 41 | */ 42 | +(id) timerWithTarget:(id) t selector:(SEL)s; 43 | 44 | /** Allocates a timer with a target, a selector and an interval in seconds. 45 | */ 46 | +(id) timerWithTarget:(id) t selector:(SEL)s interval:(ccTime)seconds; 47 | 48 | /** Initializes a timer with a target and a selector. 49 | */ 50 | -(id) initWithTarget:(id) t selector:(SEL)s; 51 | 52 | /** Initializes a timer with a target, a selector and an interval in seconds. 53 | */ 54 | -(id) initWithTarget:(id) t selector:(SEL)s interval:(ccTime)seconds; 55 | 56 | 57 | /** triggers the timer */ 58 | -(void) fire: (ccTime) dt; 59 | @end 60 | 61 | // 62 | // Scheduler 63 | // 64 | /** Scheduler is responsible of triggering the scheduled callbacks. 65 | You should not use NSTimer. Instead use this class. 66 | */ 67 | @interface Scheduler : NSObject 68 | { 69 | NSMutableArray *scheduledMethods; 70 | NSMutableArray *methodsToRemove; 71 | NSMutableArray *methodsToAdd; 72 | 73 | ccTime timeScale_; 74 | } 75 | 76 | /** Modifies the time of all scheduled callbacks. 77 | You can use this property to create a 'slow motion' or 'fast fordward' effect. 78 | Default is 1.0. To create a 'slow motion' effect, use values below 1.0. 79 | To create a 'fast fordward' effect, use values higher than 1.0. 80 | @since v0.8 81 | @warning It will affect EVERY scheduled selector / action. 82 | */ 83 | @property (nonatomic,readwrite) ccTime timeScale; 84 | 85 | /** returns a shared instance of the Scheduler */ 86 | +(Scheduler *)sharedScheduler; 87 | 88 | /** 'tick' the scheduler. 89 | You should NEVER call this method, unless you know what you are doing. 90 | */ 91 | -(void) tick:(ccTime)dt; 92 | 93 | /** schedules a Timer. 94 | It will be fired in every frame. 95 | */ 96 | -(void) scheduleTimer: (Timer*) t; 97 | 98 | /** unschedules an already scheduled Timer */ 99 | -(void) unscheduleTimer: (Timer*) t; 100 | 101 | /** unschedule all timers. 102 | You should NEVER call this method, unless you know what you are doing. 103 | @since v0.8 104 | */ 105 | -(void) unscheduleAllTimers; 106 | @end 107 | -------------------------------------------------------------------------------- /mahjong/cocos2d/AtlasSpriteManager.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 Matt Oswald 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "CocosNode.h" 16 | #import "TextureAtlas.h" 17 | #import "ccMacros.h" 18 | 19 | #pragma mark AtlasSpriteManager 20 | 21 | @class AtlasSprite; 22 | 23 | /** AtlasSpriteManager is the object that draws all the AtlasSprite objects 24 | * that belongs to this Manager. Use 1 AtlasSpriteManager per TextureAtlas 25 | * 26 | * Limitations: 27 | * - The only object that is accepted as child is AtlasSprite 28 | * - It's children are all Aliased or all Antialiased. 29 | * 30 | * @since v0.7.1 31 | */ 32 | @interface AtlasSpriteManager : CocosNode 33 | { 34 | unsigned int totalSprites_; 35 | TextureAtlas *textureAtlas_; 36 | ccBlendFunc blendFunc_; 37 | } 38 | 39 | /** returns the TextureAtlas that is used */ 40 | @property (nonatomic,readwrite,retain) TextureAtlas * textureAtlas; 41 | 42 | /** conforms to CocosNodeTexture protocol */ 43 | @property (nonatomic,readwrite) ccBlendFunc blendFunc; 44 | 45 | /** creates an AtlasSpriteManager with a texture2d */ 46 | +(id)spriteManagerWithTexture:(Texture2D *)tex; 47 | /** creates an AtlasSpriteManager with a texture2d and capacity */ 48 | +(id)spriteManagerWithTexture:(Texture2D *)tex capacity:(NSUInteger)capacity; 49 | /** creates an AtlasSpriteManager with a file image (.png, .jpeg, .pvr, etc). 50 | The file will be loaded using the TextureMgr. 51 | */ 52 | +(id)spriteManagerWithFile:(NSString*) fileImage; 53 | /** creates an AtlasSpriteManager with a file image (.png, .jpeg, .pvr, etc) and capacity. 54 | The file will be loaded using the TextureMgr. 55 | */ 56 | +(id)spriteManagerWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity; 57 | 58 | /** initializes an AtlasSpriteManager with a texture2d and capacity */ 59 | -(id)initWithTexture:(Texture2D *)tex capacity:(NSUInteger)capacity; 60 | /** initializes an AtlasSpriteManager with a file image (.png, .jpeg, .pvr, etc). 61 | The file will be loaded using the TextureMgr. 62 | */ 63 | -(id)initWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity; 64 | 65 | -(NSUInteger)indexForNewChildAtZ:(int)z; 66 | 67 | /** creates an sprite with a rect in the AtlasSpriteManage */ 68 | -(AtlasSprite*) createSpriteWithRect:(CGRect)rect; 69 | 70 | /** removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter. 71 | @warning Removing a child from an AtlasSpriteManager is very slow 72 | */ 73 | -(void)removeChildAtIndex:(NSUInteger)index cleanup:(BOOL)doCleanup; 74 | 75 | /** removes a child given a reference. It will also cleanup the running actions depending on the cleanup parameter. 76 | @warning Removing a child from an AtlasSpriteManager is very slow 77 | */ 78 | -(void)removeChild: (AtlasSprite *)sprite cleanup:(BOOL)doCleanup; 79 | @end 80 | -------------------------------------------------------------------------------- /mahjong/cocos2d/TMXXMLParser.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | * TMX Tiled Map support: 14 | * http://www.mapeditor.org 15 | * 16 | */ 17 | 18 | /* 19 | * Internal TMX parser 20 | * 21 | * IMPORTANT: These classed should not be documented using doxygen strings 22 | * since the user should not use them. 23 | * 24 | */ 25 | 26 | 27 | enum { 28 | TMXLayerAttribNone = 1 << 0, 29 | TMXLayerAttribBase64 = 1 << 1, 30 | TMXLayerAttribGzip = 1 << 2, 31 | }; 32 | 33 | /* TMXLayerInfo contains the information about the layers like: 34 | - Layer name 35 | - Layer size 36 | - Layer opacity at creation time (it can be modified at runtime) 37 | - Whether the layer is visible (if it's not visible, then the CocosNode won't be created) 38 | 39 | This information is obtained from the TMX file. 40 | */ 41 | @interface TMXLayerInfo : NSObject 42 | { 43 | @public 44 | NSString *name; 45 | CGSize layerSize; 46 | unsigned int *tiles; 47 | BOOL visible; 48 | unsigned char opacity; 49 | BOOL ownTiles; 50 | } 51 | @end 52 | 53 | /* TMXTilesetInfo contains the information about the tilesets like: 54 | - Tileset name 55 | - Tilset spacing 56 | - Tileset margin 57 | - size of the tiles 58 | - Image used for the tiles 59 | - Image size 60 | 61 | This information is obtained from the TMX file. 62 | */ 63 | @interface TMXTilesetInfo : NSObject 64 | { 65 | @public 66 | NSString *name; 67 | int firstGid; 68 | CGSize tileSize; 69 | int spacing; 70 | int margin; 71 | 72 | // filename containing the tiles (should be spritesheet / texture atlas) 73 | NSString *sourceImage; 74 | 75 | // size in pixels of the image 76 | CGSize imageSize; 77 | } 78 | -(CGRect) tileForGID:(unsigned int)gid; 79 | @end 80 | 81 | /* TMXMapInfo contains the information about the map like: 82 | - Map orientation (hexagonal, isometric or orthogonal) 83 | - Tile size 84 | - Map size 85 | 86 | And it also contains: 87 | - Layers (an array of TMXLayerInfo objects) 88 | - Tilesets (an array of TMXTilesetInfo objects) 89 | 90 | This information is obtained from the TMX file. 91 | 92 | */ 93 | @interface TMXMapInfo : NSObject 94 | { 95 | 96 | NSMutableString *currentLayer; 97 | NSMutableString *currentString; 98 | BOOL storingCharacters; 99 | int layerAttribs; 100 | 101 | @public 102 | int orientation; 103 | 104 | 105 | // map width & height 106 | CGSize mapSize; 107 | 108 | // tiles width & height 109 | CGSize tileSize; 110 | 111 | // Layers 112 | NSMutableArray *layers; 113 | 114 | // tilesets 115 | NSMutableArray *tilesets; 116 | } 117 | 118 | /** creates a TMX Format with a tmx file */ 119 | +(id) formatWithTMXFile:(NSString*)tmxFile; 120 | /** initializes a TMX format witha tmx file */ 121 | -(id) initWithTMXFile:(NSString*)tmxFile; 122 | @end 123 | 124 | -------------------------------------------------------------------------------- /mahjong/cocos2d/ActionManager.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * Copyright (C) 2009 Valentin Milea 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the 'cocos2d for iPhone' license. 10 | * 11 | * You will find a copy of this license within the cocos2d for iPhone 12 | * distribution inside the "LICENSE" file. 13 | * 14 | */ 15 | 16 | #import "Action.h" 17 | #import "Support/ccArray.h" 18 | #import "Support/ccHashSet.h" 19 | 20 | typedef struct _hashElement 21 | { 22 | struct ccArray *actions; 23 | id target; 24 | unsigned int actionIndex; 25 | Action *currentAction; 26 | BOOL currentActionSalvaged; 27 | BOOL paused; 28 | } tHashElement; 29 | 30 | 31 | /** ActionManager is a singleton that manages all the actions. 32 | Normally you won't need to use this singleton directly. 99% of the cases you will use the CocosNode interface, 33 | which uses this singleton. 34 | But there are some cases where you might need to use this singleton. 35 | Examples: 36 | - When you want to run an action where the target is different from a CocosNode. 37 | - When you want to pause / resume the actions 38 | 39 | @since v0.8 40 | */ 41 | @interface ActionManager : NSObject { 42 | 43 | ccHashSet * targets; 44 | tHashElement * currentTarget; 45 | BOOL currentTargetSalvaged; 46 | } 47 | 48 | /** returns a shared instance of the ActionManager */ 49 | + (ActionManager *)sharedManager; 50 | 51 | // actions 52 | 53 | /** Adds an action with a target. The action can be added paused or unpaused. 54 | The action will be run "against" the target. 55 | If the action is added paused, then it will be queued, but it won't be "ticked" until it is resumed. 56 | If the action is added unpaused, then it will be queued, and it will be "ticked" in every frame. 57 | */ 58 | -(void) addAction: (Action*) action target:(id)target paused:(BOOL)paused; 59 | /** Removes all actions from all the targers. 60 | */ 61 | -(void) removeAllActions; 62 | 63 | /** Removes all actions from a certain target. 64 | All the actions that belongs to the target will be removed. 65 | */ 66 | -(void) removeAllActionsFromTarget:(id)target; 67 | /** Removes an action given an action reference. 68 | */ 69 | -(void) removeAction: (Action*) action; 70 | /** Removes an action given its tag and the target */ 71 | -(void) removeActionByTag:(int)tag target:(id)target; 72 | /** Gets an action given its tag an a target 73 | @return the Action the with the given tag 74 | */ 75 | -(Action*) getActionByTag:(int) tag target:(id)target; 76 | /** Returns the numbers of actions that are running in a certain target 77 | * Composable actions are counted as 1 action. Example: 78 | * If you are running 1 Sequence of 7 actions, it will return 1. 79 | * If you are running 7 Sequences of 2 actions, it will return 7. 80 | */ 81 | -(int) numberOfRunningActionsInTarget:(id)target; 82 | /** Pauses all actions for a certain target. 83 | When the actions are paused, they won't be "ticked". 84 | */ 85 | -(void) pauseAllActionsForTarget:(id)target; 86 | /** Resumes all actions for a certain target. 87 | Once the actions are resumed, they will be "ticked" in every frame. 88 | */ 89 | -(void) resumeAllActionsForTarget:(id)target; 90 | 91 | @end 92 | 93 | -------------------------------------------------------------------------------- /mahjong/GoogleAdMobAdsSDK/GADInterstitial.h: -------------------------------------------------------------------------------- 1 | // 2 | // GADInterstitial.h 3 | // Google AdMob Ads SDK 4 | // 5 | // Copyright 2011 Google Inc. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | #import "GADInterstitialDelegate.h" 11 | #import "GADRequest.h" 12 | #import "GADRequestError.h" 13 | 14 | // An interstitial ad. This is a full-screen advertisement shown at natural 15 | // transition points in your application such as between game levels or news 16 | // stories. 17 | // 18 | // Interstitials are shown sparingly. Expect low to no fill. 19 | @interface GADInterstitial : NSObject 20 | 21 | #pragma mark Pre-Request 22 | 23 | // Required value created in the AdSense website. Create a new ad unit for 24 | // every unique placement of an ad in your application. Set this to the ID 25 | // assigned for this placement. Ad units are important for targeting and stats. 26 | // Example values for different request types: 27 | // AdMob: a0123456789ABCD 28 | // DFP: /0123/ca-pub-0123456789012345/my-ad-identifier 29 | // AdSense: ca-mb-app-pub-0123456789012345/my-ad-identifier 30 | @property (nonatomic, copy) NSString *adUnitID; 31 | 32 | // Optional delegate object that receives state change notifications from this 33 | // GADInterstitalAd. Remember to nil the delegate before deallocating this 34 | // object. 35 | @property (nonatomic, assign) NSObject *delegate; 36 | 37 | #pragma mark Making an Ad Request 38 | 39 | // Makes an interstitial ad request. Additional targeting options can be 40 | // supplied with a request object. Only one interstitial request is allowed at 41 | // a time. 42 | // 43 | // This is best to do several seconds before the interstitial is needed to 44 | // preload its content. Then when transitioning between view controllers show 45 | // the interstital with presentFromViewController. 46 | - (void)loadRequest:(GADRequest *)request; 47 | 48 | #pragma mark Request at Application Launch 49 | 50 | // The |window| will be shown with the |image| displayed until either the 51 | // |request| interstitial is shown or a timeout occurs. The delegate will 52 | // receive an interstitialDidDismissScreen: callback to indicate that your app 53 | // should continue when the interstitial has finished. 54 | - (void)loadAndDisplayRequest:(GADRequest *)request 55 | usingWindow:(UIWindow *)window 56 | initialImage:(UIImage *)image; 57 | 58 | #pragma mark Post-Request 59 | 60 | // Returns YES if the interstitial is ready to be displayed. The delegate's 61 | // interstitialAdDidReceiveAd: will be called when this switches from NO to YES. 62 | @property (nonatomic, readonly) BOOL isReady; 63 | 64 | // Presents the interstitial ad which takes over the entire screen until the 65 | // user dismisses it. This has no effect unless isReady returns YES and/or the 66 | // delegate's interstitialDidReceiveAd: has been received. 67 | // 68 | // Set rootViewController to the current view controller at the time this method 69 | // is called. If your application does not use view controllers pass in nil and 70 | // your views will be removed from the window to show the interstitial and 71 | // restored when done. After the interstitial has been removed, the delegate's 72 | // interstitialDidDismissScreen: will be called. 73 | - (void)presentFromRootViewController:(UIViewController *)rootViewController; 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Grid.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 On-Core 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | 17 | #import "CocosNode.h" 18 | #import "Camera.h" 19 | #import "ccTypes.h" 20 | 21 | @class Texture2D; 22 | @class Grabber; 23 | 24 | /** Base class for other 25 | */ 26 | @interface GridBase : NSObject 27 | { 28 | BOOL active; 29 | int reuseGrid; 30 | ccGridSize gridSize; 31 | Texture2D * texture; 32 | CGPoint step; 33 | Grabber * grabber; 34 | } 35 | 36 | /** wheter or not the grid is active */ 37 | @property (nonatomic,readwrite) BOOL active; 38 | /** number of times that the grid will be reused */ 39 | @property (nonatomic,readwrite) int reuseGrid; 40 | /** size of the grid */ 41 | @property (nonatomic,readonly) ccGridSize gridSize; 42 | /** pixels between the grids */ 43 | @property (nonatomic,readwrite) CGPoint step; 44 | /** texture used */ 45 | @property (nonatomic, retain) Texture2D *texture; 46 | /** grabber used */ 47 | @property (nonatomic, retain) Grabber *grabber; 48 | 49 | -(id)initWithSize:(ccGridSize)gridSize; 50 | -(void)beforeDraw; 51 | -(void)afterDraw:(Camera*)camera; 52 | -(void)blit; 53 | -(void)reuse; 54 | 55 | @end 56 | 57 | //////////////////////////////////////////////////////////// 58 | 59 | /** 60 | Grid3D is a 3D grid implementation. Each vertex has 3 dimensions: x,y,z 61 | */ 62 | @interface Grid3D : GridBase 63 | { 64 | GLvoid *texCoordinates; 65 | GLvoid *vertices; 66 | GLvoid *originalVertices; 67 | GLushort *indices; 68 | } 69 | 70 | /** creates a Grid3D (non-tiled) grid with a grid size */ 71 | +(id)gridWithSize:(ccGridSize)gridSize; 72 | /** initizlies a Grid3D (non-tiled) grid with a grid size */ 73 | -(id)initWithSize:(ccGridSize)gridSize; 74 | 75 | /** returns the vertex at a given position */ 76 | -(ccVertex3F)vertex:(ccGridSize)pos; 77 | /** returns the original (non-transformed) vertex at a given position */ 78 | -(ccVertex3F)originalVertex:(ccGridSize)pos; 79 | /** sets a new vertex at a given position */ 80 | -(void)setVertex:(ccGridSize)pos vertex:(ccVertex3F)vertex; 81 | 82 | -(void)calculateVertexPoints; 83 | 84 | @end 85 | 86 | //////////////////////////////////////////////////////////// 87 | 88 | /** 89 | TiledGrid3D is a 3D grid implementation. It differs from Grid3D in that 90 | the tiles can be separated from the grid. 91 | */ 92 | @interface TiledGrid3D : GridBase 93 | { 94 | GLvoid *texCoordinates; 95 | GLvoid *vertices; 96 | GLvoid *originalVertices; 97 | GLushort *indices; 98 | } 99 | 100 | /** creates a TiledGrid3D with a grid size */ 101 | +(id)gridWithSize:(ccGridSize)gridSize; 102 | /** initializes a TiledGrid3D with a grid size */ 103 | -(id)initWithSize:(ccGridSize)gridSize; 104 | 105 | /** returns the tile at the given position */ 106 | -(ccQuad3)tile:(ccGridSize)pos; 107 | /** returns the original tile (untransformed) at the given position */ 108 | -(ccQuad3)originalTile:(ccGridSize)pos; 109 | /** sets a new tile */ 110 | -(void)setTile:(ccGridSize)pos coords:(ccQuad3)coords; 111 | 112 | -(void)calculateVertexPoints; 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Action.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | #include 17 | 18 | #import "ccTypes.h" 19 | 20 | enum { 21 | //! Default tag 22 | kActionTagInvalid = -1, 23 | }; 24 | 25 | /** Base class for actions 26 | */ 27 | @interface Action : NSObject { 28 | id target; 29 | int tag; 30 | } 31 | 32 | /** The "target". The action will modify the target properties */ 33 | @property (nonatomic,readwrite,assign) id target; 34 | /** The action tag. An identifier of the action */ 35 | @property (nonatomic,readwrite,assign) int tag; 36 | 37 | +(id) action; 38 | -(id) init; 39 | 40 | -(id) copyWithZone: (NSZone*) zone; 41 | 42 | //! called before the action start 43 | -(void) start; 44 | //! return YES if the action has finished 45 | -(BOOL) isDone; 46 | //! called after the action has finished 47 | -(void) stop; 48 | //! called every frame with it's delta time. DON'T override unless you know what you are doing. 49 | -(void) step: (ccTime) dt; 50 | //! called once per frame. time a value between 0 and 1 51 | //! For example: 52 | //! * 0 means that the action just started 53 | //! * 0.5 means that the action is in the middle 54 | //! * 1 means that the action is over 55 | -(void) update: (ccTime) time; 56 | 57 | @end 58 | 59 | /** Base class actions that do have a finite time duration. 60 | Possible actions: 61 | - An action with a duration of 0 seconds 62 | - An action with a duration of 35.5 seconds 63 | Infitite time actions are valid 64 | */ 65 | @interface FiniteTimeAction : Action 66 | { 67 | //! duration in seconds 68 | ccTime duration; 69 | } 70 | //! duration in seconds of the action 71 | @property (nonatomic,readwrite) ccTime duration; 72 | 73 | /** returns a reversed action */ 74 | - (FiniteTimeAction*) reverse; 75 | @end 76 | 77 | 78 | @class IntervalAction; 79 | /** Repeats an action for ever. 80 | To repeat the an action for a limited number of times use the Repeat action. 81 | @warning This action can't be Sequenceable because it is not an IntervalAction 82 | */ 83 | @interface RepeatForever : Action 84 | { 85 | IntervalAction *other; 86 | } 87 | /** creates the action */ 88 | +(id) actionWithAction: (IntervalAction*) action; 89 | /** initializes the action */ 90 | -(id) initWithAction: (IntervalAction*) action; 91 | @end 92 | 93 | /** Changes the speed of an action, making it take longer (speed>1) 94 | or less (speed<1) time. 95 | Useful to simulate 'slow motion' or 'fast forward' effect. 96 | @warning This action can't be Sequenceable because it is not an IntervalAction 97 | */ 98 | @interface Speed : Action 99 | { 100 | IntervalAction *other; 101 | float speed; 102 | } 103 | /** alter the speed of the inner function in runtime */ 104 | @property (nonatomic,readwrite) float speed; 105 | /** creates the action */ 106 | +(id) actionWithAction: (IntervalAction*) action speed:(float)rate; 107 | /** initializes the action */ 108 | -(id) initWithAction: (IntervalAction*) action speed:(float)rate; 109 | @end 110 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/ZipUtils.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * 6 | * Inflates either zlib or gzip deflated memory. The inflated memory is 7 | * expected to be freed by the caller. 8 | * 9 | * inflateMemory_ based on zlib example code 10 | * http://www.zlib.net 11 | * 12 | * Some ideas were taken from: 13 | * http://themanaworld.org/ 14 | * from the mapreader.cpp file 15 | */ 16 | 17 | #import 18 | #import 19 | #import 20 | #import 21 | #import 22 | 23 | #import "ZipUtils.h" 24 | #import "ccMacros.h" 25 | 26 | int inflateMemory_(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLength) 27 | { 28 | #if 1 29 | /* ret value */ 30 | int err = Z_OK; 31 | 32 | /* 256k initial decompress buffer */ 33 | int bufferSize = 256 * 1024; 34 | *out = (unsigned char*) malloc(bufferSize); 35 | 36 | z_stream d_stream; /* decompression stream */ 37 | d_stream.zalloc = (alloc_func)0; 38 | d_stream.zfree = (free_func)0; 39 | d_stream.opaque = (voidpf)0; 40 | 41 | d_stream.next_in = in; 42 | d_stream.avail_in = inLength; 43 | d_stream.next_out = *out; 44 | d_stream.avail_out = bufferSize; 45 | 46 | /* window size to hold 256k */ 47 | if( (err = inflateInit2(&d_stream, 15 + 32)) != Z_OK ) 48 | return err; 49 | 50 | for (;;) { 51 | err = inflate(&d_stream, Z_NO_FLUSH); 52 | 53 | if (err == Z_STREAM_END) 54 | break; 55 | 56 | switch (err) { 57 | case Z_NEED_DICT: 58 | err = Z_DATA_ERROR; 59 | case Z_DATA_ERROR: 60 | case Z_MEM_ERROR: 61 | inflateEnd(&d_stream); 62 | return err; 63 | } 64 | 65 | // not enough memory ? 66 | if (err != Z_STREAM_END) { 67 | 68 | // memory in iPhone is precious 69 | // Should buffer factor be 1.5 instead of 2 ? 70 | #define BUFFER_INC_FACTOR (2) 71 | unsigned char *tmp = realloc(*out, bufferSize * BUFFER_INC_FACTOR); 72 | 73 | /* not enough memory, ouch */ 74 | if (! tmp ) { 75 | CCLOG(@"ZipUtils: realloc failed"); 76 | inflateEnd(&d_stream); 77 | return Z_MEM_ERROR; 78 | } 79 | /* only assign to *out if tmp is valid. it's not guaranteed that realloc will reuse the memory */ 80 | *out = tmp; 81 | 82 | d_stream.next_out = *out + bufferSize; 83 | d_stream.avail_out = bufferSize; 84 | bufferSize *= BUFFER_INC_FACTOR; 85 | } 86 | } 87 | 88 | 89 | *outLength = bufferSize - d_stream.avail_out; 90 | err = inflateEnd(&d_stream); 91 | return err; 92 | #else 93 | return 0; 94 | #endif 95 | } 96 | 97 | int inflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out) 98 | { 99 | #if 1 100 | unsigned int outLength = 0; 101 | int err = inflateMemory_(in, inLength, out, &outLength); 102 | 103 | if (err != Z_OK || *out == NULL) { 104 | if (err == Z_MEM_ERROR) 105 | CCLOG(@"ZipUtils: Out of memory while decompressing map data!"); 106 | 107 | else if (err == Z_VERSION_ERROR) 108 | CCLOG(@"ZipUtils: Incompatible zlib version!"); 109 | 110 | else if (err == Z_DATA_ERROR) 111 | CCLOG(@"ZipUtils: Incorrect zlib compressed data!"); 112 | 113 | else 114 | CCLOG(@"ZipUtils: Unknown error while decompressing map data!"); 115 | 116 | free(*out); 117 | *out = NULL; 118 | outLength = 0; 119 | } 120 | 121 | return outLength; 122 | #else 123 | return 0; 124 | #endif 125 | } 126 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Camera.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import "Director.h" 17 | #import "Camera.h" 18 | #import "ccMacros.h" 19 | 20 | #import "Support/glu.h" 21 | 22 | @implementation Camera 23 | 24 | @synthesize dirty; 25 | 26 | -(id) init 27 | { 28 | if( (self=[super init]) ) 29 | [self restore]; 30 | 31 | return self; 32 | } 33 | 34 | - (NSString*) description 35 | { 36 | return [NSString stringWithFormat:@"<%@ = %08X | center = (%.2f,%.2f,%.2f)>", [self class], self, centerX, centerY, centerZ]; 37 | } 38 | 39 | 40 | - (void) dealloc 41 | { 42 | CCLOG(@"deallocing %@", self); 43 | [super dealloc]; 44 | } 45 | 46 | -(void) restore 47 | { 48 | CGSize s = [[Director sharedDirector] displaySize]; 49 | 50 | eyeX = s.width/2; 51 | eyeY = s.height/2; 52 | eyeZ = [Camera getZEye]; 53 | 54 | centerX = s.width/2; 55 | centerY = s.height/2; 56 | centerZ = 0.0f; 57 | 58 | upX = 0.0f; 59 | upY = 1.0f; 60 | upZ = 0.0f; 61 | 62 | dirty = NO; 63 | } 64 | 65 | -(void) locate 66 | { 67 | if( dirty ) { 68 | ccDeviceOrientation orientation = [[Director sharedDirector] deviceOrientation]; 69 | 70 | glLoadIdentity(); 71 | 72 | switch( orientation ) { 73 | case CCDeviceOrientationPortrait: 74 | break; 75 | case CCDeviceOrientationPortraitUpsideDown: 76 | glRotatef(-180,0,0,1); 77 | break; 78 | case CCDeviceOrientationLandscapeLeft: 79 | glRotatef(-90,0,0,1); 80 | break; 81 | case CCDeviceOrientationLandscapeRight: 82 | glRotatef(90,0,0,1); 83 | break; 84 | } 85 | 86 | gluLookAt( eyeX, eyeY, eyeZ, 87 | centerX, centerY, centerZ, 88 | upX, upY, upZ 89 | ); 90 | 91 | switch( orientation ) { 92 | case CCDeviceOrientationPortrait: 93 | case CCDeviceOrientationPortraitUpsideDown: 94 | // none 95 | break; 96 | case CCDeviceOrientationLandscapeLeft: 97 | glTranslatef(-80,80,0); 98 | break; 99 | case CCDeviceOrientationLandscapeRight: 100 | glTranslatef(-80,80,0); 101 | break; 102 | } 103 | } 104 | } 105 | 106 | +(float) getZEye 107 | { 108 | CGSize s = [[Director sharedDirector] displaySize]; 109 | return ( s.height / 1.1566f ); 110 | } 111 | 112 | -(void) setEyeX: (float)x eyeY:(float)y eyeZ:(float)z 113 | { 114 | eyeX = x; 115 | eyeY = y; 116 | eyeZ = z; 117 | dirty = YES; 118 | } 119 | 120 | -(void) setCenterX: (float)x centerY:(float)y centerZ:(float)z 121 | { 122 | centerX = x; 123 | centerY = y; 124 | centerZ = z; 125 | dirty = YES; 126 | } 127 | 128 | -(void) setUpX: (float)x upY:(float)y upZ:(float)z 129 | { 130 | upX = x; 131 | upY = y; 132 | upZ = z; 133 | dirty = YES; 134 | } 135 | 136 | -(void) eyeX: (float*)x eyeY:(float*)y eyeZ:(float*)z 137 | { 138 | *x = eyeX; 139 | *y = eyeY; 140 | *z = eyeZ; 141 | } 142 | 143 | -(void) centerX: (float*)x centerY:(float*)y centerZ:(float*)z 144 | { 145 | *x = centerX; 146 | *y = centerY; 147 | *z = centerZ; 148 | } 149 | 150 | -(void) upX: (float*)x upY:(float*)y upZ:(float*)z 151 | { 152 | *x = upX; 153 | *y = upY; 154 | *z = upZ; 155 | } 156 | 157 | @end 158 | -------------------------------------------------------------------------------- /mahjong/GoogleAdMobAdsSDK/GADRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // GADRequest.h 3 | // Google AdMob Ads SDK 4 | // 5 | // Copyright 2011 Google Inc. All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | // Constant for getting test ads on the simulator using the testDevices method. 12 | #define GAD_SIMULATOR_ID @"Simulator" 13 | 14 | // Genders to help deliver more relevant ads. 15 | typedef enum { 16 | kGADGenderUnknown, 17 | kGADGenderMale, 18 | kGADGenderFemale 19 | } GADGender; 20 | 21 | // Specifies optional parameters for ad requests. 22 | @interface GADRequest : NSObject 23 | 24 | // Creates an autoreleased GADRequest. 25 | + (GADRequest *)request; 26 | 27 | // Reserved for future use. 28 | @property (nonatomic, retain) NSDictionary *additionalParameters; 29 | 30 | #pragma mark Collecting SDK Information 31 | 32 | // Returns the version of the SDK. 33 | + (NSString *)sdkVersion; 34 | 35 | #pragma mark Testing 36 | 37 | // Test ads are returned to these devices. Device identifiers are the same used 38 | // to register as a development device with Apple. To obtain a value open the 39 | // Organizer (Window -> Organizer from Xcode), control-click or right-click on 40 | // the device's name, and choose "Copy Device Identifier". Alternatively you 41 | // can obtain it through code using [[UIDevice currentDevice] uniqueIdentifier]. 42 | // 43 | // For example: 44 | // request.testDevices = [NSArray arrayWithObjects: 45 | // GAD_SIMULATOR_ID, // Simulator 46 | // //@"28ab37c3902621dd572509110745071f0101b124", // Test iPhone 3G 3.0.1 47 | // @"8cf09e81ef3ec5418c3450f7954e0e95db8ab200", // Test iPod 4.3.1 48 | // nil]; 49 | @property (nonatomic, retain) NSArray *testDevices; 50 | 51 | #pragma mark User Information 52 | 53 | // The user's gender may be used to deliver more relevant ads. 54 | @property (nonatomic, assign) GADGender gender; 55 | 56 | // The user's birthday may be used to deliver more relevant ads. 57 | @property (nonatomic, retain) NSDate *birthday; 58 | - (void)setBirthdayWithMonth:(NSInteger)m day:(NSInteger)d year:(NSInteger)y; 59 | 60 | // The user's current location may be used to deliver more relevant ads. 61 | // However do not use Core Location just for advertising, make sure it is used 62 | // for more beneficial reasons as well. It is both a good idea and part of 63 | // Apple's guidelines. 64 | - (void)setLocationWithLatitude:(CGFloat)latitude longitude:(CGFloat)longitude 65 | accuracy:(CGFloat)accuracyInMeters; 66 | 67 | // When Core Location isn't available but the user's location is known supplying 68 | // it here may deliver more relevant ads. It can be any free-form text such as 69 | // @"Champs-Elysees Paris" or @"94041 US". 70 | - (void)setLocationWithDescription:(NSString *)locationDescription; 71 | 72 | #pragma mark Contextual Information 73 | 74 | // A keyword is a word or phrase describing the current activity of the user 75 | // such as @"Sports Scores". Each keyword is an NSString in the NSArray. To 76 | // clear the keywords set this to nil. 77 | @property (nonatomic, retain) NSMutableArray *keywords; 78 | 79 | // Convenience method for adding keywords one at a time such as @"Sports Scores" 80 | // and then @"Football". 81 | - (void)addKeyword:(NSString *)keyword; 82 | 83 | #pragma mark - 84 | #pragma mark Deprecated Methods 85 | 86 | // Please use testDevices instead. 87 | @property (nonatomic, getter=isTesting) BOOL testing; 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/PVRTexture.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: PVRTexture.h 4 | Abstract: The PVRTexture class is responsible for loading .pvr files. 5 | 6 | Version: 1.0 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. 9 | ("Apple") in consideration of your agreement to the following terms, and your 10 | use, installation, modification or redistribution of this Apple software 11 | constitutes acceptance of these terms. If you do not agree with these terms, 12 | please do not use, install, modify or redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and subject 15 | to these terms, Apple grants you a personal, non-exclusive license, under 16 | Apple's copyrights in this original Apple software (the "Apple Software"), to 17 | use, reproduce, modify and redistribute the Apple Software, with or without 18 | modifications, in source and/or binary forms; provided that if you redistribute 19 | the Apple Software in its entirety and without modifications, you must retain 20 | this notice and the following text and disclaimers in all such redistributions 21 | of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used 23 | to endorse or promote products derived from the Apple Software without specific 24 | prior written permission from Apple. Except as expressly stated in this notice, 25 | no other rights or licenses, express or implied, are granted by Apple herein, 26 | including but not limited to any patent rights that may be infringed by your 27 | derivative works or by other works in which the Apple Software may be 28 | incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO 31 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED 32 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 33 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN 34 | COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR 37 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 38 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR 40 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF 41 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF 42 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2008 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | #import 50 | #import 51 | 52 | @interface PVRTexture : NSObject 53 | { 54 | NSMutableArray *_imageData; 55 | 56 | GLuint _name; 57 | uint32_t _width, _height; 58 | GLenum _internalFormat; 59 | BOOL _hasAlpha; 60 | 61 | // cocos2d integration 62 | BOOL _retainName; 63 | } 64 | 65 | - (id)initWithContentsOfFile:(NSString *)path; 66 | - (id)initWithContentsOfURL:(NSURL *)url; 67 | + (id)pvrTextureWithContentsOfFile:(NSString *)path; 68 | + (id)pvrTextureWithContentsOfURL:(NSURL *)url; 69 | 70 | @property (nonatomic,readonly) GLuint name; 71 | @property (nonatomic,readonly) uint32_t width; 72 | @property (nonatomic,readonly) uint32_t height; 73 | @property (nonatomic,readonly) GLenum internalFormat; 74 | @property (nonatomic,readonly) BOOL hasAlpha; 75 | 76 | // cocos2d integration 77 | @property (nonatomic,readwrite) BOOL retainName; 78 | 79 | @end 80 | 81 | 82 | -------------------------------------------------------------------------------- /mahjong/cocos2d/CDOpenALSupport.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Disclaimer: IMPORTANT: This Apple software is supplied to you by 4 | Apple Inc. ("Apple") in consideration of your agreement to the 5 | following terms, and your use, installation, modification or 6 | redistribution of this Apple software constitutes acceptance of these 7 | terms. If you do not agree with these terms, please do not use, 8 | install, modify or redistribute this Apple software. 9 | 10 | In consideration of your agreement to abide by the following terms, and 11 | subject to these terms, Apple grants you a personal, non-exclusive 12 | license, under Apple's copyrights in this original Apple software (the 13 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 14 | Software, with or without modifications, in source and/or binary forms; 15 | provided that if you redistribute the Apple Software in its entirety and 16 | without modifications, you must retain this notice and the following 17 | text and disclaimers in all such redistributions of the Apple Software. 18 | Neither the name, trademarks, service marks or logos of Apple Inc. 19 | may be used to endorse or promote products derived from the Apple 20 | Software without specific prior written permission from Apple. Except 21 | as expressly stated in this notice, no other rights or licenses, express 22 | or implied, are granted by Apple herein, including but not limited to 23 | any patent rights that may be infringed by your derivative works or by 24 | other works in which the Apple Software may be incorporated. 25 | 26 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 27 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 28 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 29 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 30 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 31 | 32 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 33 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 36 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 37 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 38 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 39 | POSSIBILITY OF SUCH DAMAGE. 40 | 41 | Copyright (C) 2009 Apple Inc. All Rights Reserved. 42 | 43 | $Id$ 44 | */ 45 | 46 | /* 47 | This file contains code from version 1.1 and 1.4 of MyOpenALSupport.h taken from Apple's oalTouch version. 48 | The 1.4 version code is used for loading IMA4 files, however, this code causes very noticeable clicking 49 | when used to load wave files that are looped so the 1.1 version code is used specifically for loading 50 | wav files. 51 | */ 52 | 53 | #ifndef __CD_OPENAL_H 54 | #define __CD_OPENAL_H 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | 61 | #import 62 | #import 63 | #import 64 | 65 | 66 | //Taken from oalTouch MyOpenALSupport 1.1 67 | void* CDloadWaveAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei* outSampleRate); 68 | void* CDloadCafAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei* outSampleRate); 69 | void* CDGetOpenALAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei* outSampleRate); 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif 76 | 77 | 78 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Ribbon.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008, 2009 Jason Booth 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | * 14 | */ 15 | 16 | #import "CocosNode.h" 17 | #import "Texture2D.h" 18 | #import 19 | 20 | /** 21 | * A ribbon is a dynamically generated list of polygons drawn as a single or series 22 | * of triangle strips. The primary use of Ribbon is as the drawing class of Motion Streak, 23 | * but it is quite useful on it's own. When manually drawing a ribbon, you can call addPointAt 24 | * and pass in the parameters for the next location in the ribbon. The system will automatically 25 | * generate new polygons, texture them accourding to your texture width, etc, etc. 26 | * 27 | * Ribbon data is stored in a RibbonSegment class. This class statically allocates enough verticies and 28 | * texture coordinates for 50 locations (100 verts or 48 triangles). The ribbon class will allocate 29 | * new segments when they are needed, and reuse old ones if available. The idea is to avoid constantly 30 | * allocating new memory and prefer a more static method. However, since there is no way to determine 31 | * the maximum size of some ribbons (motion streaks), a truely static allocation is not possible. 32 | * 33 | * @since v0.8.1 34 | */ 35 | @interface Ribbon : CocosNode 36 | { 37 | NSMutableArray* mSegments; 38 | NSMutableArray* dSegments; 39 | 40 | CGPoint mLastPoint1; 41 | CGPoint mLastPoint2; 42 | CGPoint mLastLocation; 43 | int mVertCount; 44 | float mTexVPos; 45 | float mCurTime; 46 | float mFadeTime; 47 | float mDelta; 48 | float mLastWidth; 49 | float mLastSign; 50 | BOOL mPastFirstPoint; 51 | 52 | // Texture used 53 | Texture2D* texture_; 54 | 55 | // texture lenght 56 | float textureLength_; 57 | 58 | // RGBA protocol 59 | ccColor4B color_; 60 | 61 | // blend func 62 | ccBlendFunc blendFunc_; 63 | } 64 | 65 | /** Texture used by the ribbon. Conforms to CocosNodeTexture protocol */ 66 | @property (nonatomic,readwrite,retain) Texture2D* texture; 67 | 68 | /** Texture lenghts in pixels */ 69 | @property (nonatomic,readwrite) float textureLength; 70 | 71 | /** GL blendind function */ 72 | @property (nonatomic,readwrite,assign) ccBlendFunc blendFunc; 73 | 74 | /** color used by the Ribbon (RGBA) */ 75 | @property (nonatomic,readwrite) ccColor4B color; 76 | 77 | /** creates the ribbon */ 78 | +(id)ribbonWithWidth:(float)w image:(NSString*)path length:(float)l color:(ccColor4B)color fade:(float)fade; 79 | /** init the ribbon */ 80 | -(id)initWithWidth:(float)w image:(NSString*)path length:(float)l color:(ccColor4B)color fade:(float)fade; 81 | /** add a point to the ribbon */ 82 | -(void)addPointAt:(CGPoint)location width:(float)w; 83 | /** polling function */ 84 | -(void)update:(ccTime)delta; 85 | /** determine side of line */ 86 | -(float)sideOfLine:(CGPoint)p l1:(CGPoint)l1 l2:(CGPoint)l2; 87 | 88 | @end 89 | 90 | /** object to hold ribbon segment data */ 91 | @interface RibbonSegment : NSObject 92 | { 93 | @public 94 | GLfloat verts[50*6]; 95 | GLfloat coords[50*4]; 96 | GLubyte colors[50*8]; 97 | float creationTime[50]; 98 | bool finished; 99 | uint end; 100 | uint begin; 101 | } 102 | -(id)init; 103 | -(void)reset; 104 | -(void)draw:(float)curTime fadeTime:(float)fadeTime color:(ccColor4B)color; 105 | @end 106 | -------------------------------------------------------------------------------- /mahjong/cocos2d/CameraAction.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import "CameraAction.h" 17 | #import "CocosNode.h" 18 | #import "Camera.h" 19 | #import "ccMacros.h" 20 | 21 | // 22 | // CameraAction 23 | // 24 | @implementation CameraAction 25 | -(void) start 26 | { 27 | [super start]; 28 | [[target camera] centerX:¢erXOrig centerY:¢erYOrig centerZ: ¢erZOrig]; 29 | [[target camera] eyeX:&eyeXOrig eyeY:&eyeYOrig eyeZ: &eyeZOrig]; 30 | [[target camera] upX:&upXOrig upY:&upYOrig upZ: &upZOrig]; 31 | } 32 | 33 | -(id) reverse 34 | { 35 | return [ReverseTime actionWithAction:self]; 36 | } 37 | @end 38 | 39 | @implementation OrbitCamera 40 | +(id) actionWithDuration:(float)t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx 41 | { 42 | return [[[self alloc] initWithDuration:t radius:r deltaRadius:dr angleZ:z deltaAngleZ:dz angleX:x deltaAngleX:dx] autorelease]; 43 | } 44 | 45 | -(id) copyWithZone: (NSZone*) zone 46 | { 47 | return [[[self class] allocWithZone: zone] initWithDuration:duration radius:radius deltaRadius:deltaRadius angleZ:angleZ deltaAngleZ:deltaAngleZ angleX:angleX deltaAngleX:deltaAngleX]; 48 | } 49 | 50 | 51 | -(id) initWithDuration:(float)t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx 52 | { 53 | if(!(self=[super initWithDuration:t]) ) 54 | return nil; 55 | 56 | radius = r; 57 | deltaRadius = dr; 58 | angleZ = z; 59 | deltaAngleZ = dz; 60 | angleX = x; 61 | deltaAngleX = dx; 62 | 63 | radDeltaZ = (CGFloat)CC_DEGREES_TO_RADIANS(dz); 64 | radDeltaX = (CGFloat)CC_DEGREES_TO_RADIANS(dx); 65 | 66 | return self; 67 | } 68 | 69 | -(void) start 70 | { 71 | [super start]; 72 | float r, zenith, azimuth; 73 | 74 | [self sphericalRadius: &r zenith:&zenith azimuth:&azimuth]; 75 | if( isnan(radius) ) 76 | radius = r; 77 | if( isnan(angleZ) ) 78 | angleZ = (CGFloat)CC_RADIANS_TO_DEGREES(zenith); 79 | if( isnan(angleX) ) 80 | angleX = (CGFloat)CC_RADIANS_TO_DEGREES(azimuth); 81 | 82 | radZ = (CGFloat)CC_DEGREES_TO_RADIANS(angleZ); 83 | radX = (CGFloat)CC_DEGREES_TO_RADIANS(angleX); 84 | } 85 | 86 | -(void) update: (ccTime) t 87 | { 88 | float r = (radius + deltaRadius * t) *[Camera getZEye]; 89 | float za = radZ + radDeltaZ * t; 90 | float xa = radX + radDeltaX * t; 91 | 92 | float i = sinf(za) * cosf(xa) * r + centerXOrig; 93 | float j = sinf(za) * sinf(xa) * r + centerYOrig; 94 | float k = cosf(za) * r + centerZOrig; 95 | 96 | [[target camera] setEyeX:i eyeY:j eyeZ:k]; 97 | } 98 | 99 | -(void) sphericalRadius:(float*) newRadius zenith:(float*) zenith azimuth:(float*) azimuth 100 | { 101 | float ex, ey, ez, cx, cy, cz, x, y, z; 102 | float r; // radius 103 | float s; 104 | 105 | [[target camera] eyeX:&ex eyeY:&ey eyeZ:&ez]; 106 | [[target camera] centerX:&cx centerY:&cy centerZ:&cz]; 107 | 108 | x = ex-cx; 109 | y = ey-cy; 110 | z = ez-cz; 111 | 112 | r = sqrtf( powf(x,2) + powf(y,2) + powf(z,2)); 113 | s = sqrtf( powf(x,2) + powf(y,2)); 114 | if(s==0.0f) 115 | s=0.00000001f; 116 | if(r==0.0f) 117 | r=0.00000001f; 118 | 119 | *zenith = acosf( z/r); 120 | if( x < 0 ) 121 | *azimuth= (CGFloat)M_PI - asinf(y/s); 122 | else 123 | *azimuth = asinf(y/s); 124 | 125 | *newRadius = r / [Camera getZEye]; 126 | } 127 | @end 128 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Sprite.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import 17 | 18 | #import "Support/Texture2D.h" 19 | 20 | #import "TextureNode.h" 21 | 22 | #pragma mark Sprite 23 | 24 | @class Animation; 25 | /** Sprite is a subclass of TextureNode that implements the CocosNodeFrames protocol. 26 | * 27 | * Sprite supports ALL CocosNode transformations, but in contrast to AtlasSprite it is much slower. 28 | * ONLY use Sprite if you can't achieve the same with effect with AtlasSprite, otherwise the use of 29 | * AtlasSprite is recommended. 30 | * 31 | * All features from TextureNode are valid, plus the following new features: 32 | * - it supports animations (frames) 33 | * 34 | * Limitations of Sprite: 35 | * - It doesn't perform as well as AtlasSprite 36 | */ 37 | @interface Sprite : TextureNode 38 | { 39 | NSMutableDictionary *animations; 40 | } 41 | 42 | /** creates an sprite with an image file. The file will be loaded using the TextureMgr */ 43 | + (id) spriteWithFile:(NSString *)imageFile; 44 | /** creates an sprite from a CGImageRef image */ 45 | + (id) spriteWithCGImage:(CGImageRef)image; 46 | 47 | /** initializes the sprite with an image file. The file will be loaded using the TextureMg */ 48 | - (id) initWithFile:(NSString *) imageFile; 49 | /** creates an sprite from a CGImageRef image */ 50 | - (id) initWithCGImage:(CGImageRef)image; 51 | /** creates an sprite with a Texture2D instance */ 52 | +(id) spriteWithTexture:(Texture2D*) tex; 53 | /** initializes the sprite with a Texture2D instance */ 54 | -(id) initWithTexture:(Texture2D*) tex; 55 | @end 56 | 57 | #pragma mark Animation 58 | 59 | /** an Animation object used within Sprites to perform animations */ 60 | @interface Animation : NSObject 61 | { 62 | NSString *name; 63 | float delay; 64 | NSMutableArray *frames; 65 | } 66 | 67 | @property (nonatomic,readwrite,copy) NSString * name; 68 | 69 | // CocosAnimation 70 | @property (nonatomic,readwrite,assign) float delay; 71 | @property (nonatomic,readwrite,retain) NSMutableArray *frames; 72 | 73 | /** creates an Animation with name, delay and frames from image files */ 74 | +(id) animationWithName: (NSString*) name delay:(float)delay; 75 | 76 | /** creates an Animation with name, delay and frames from image files */ 77 | +(id) animationWithName: (NSString*) name delay:(float)delay images:image1,... NS_REQUIRES_NIL_TERMINATION; 78 | 79 | /** creates an Animation with name, delay and frames from Texture2D objects */ 80 | +(id) animationWithName: (NSString*) name delay:(float)delay textures:tex1,... NS_REQUIRES_NIL_TERMINATION; 81 | 82 | /** initializes an Animation with name, delay and frames from Texture2D objects */ 83 | -(id) initWithName: (NSString*) name delay:(float)delay firstTexture:(Texture2D*)tex vaList:(va_list) args; 84 | 85 | 86 | 87 | /** initializes an Animation with name and delay 88 | */ 89 | -(id) initWithName: (NSString*) name delay:(float)delay; 90 | 91 | /** initializes an Animation with name, delay and frames from image files 92 | */ 93 | -(id) initWithName: (NSString*) name delay:(float)delay firstImage:(NSString*)filename vaList:(va_list) args; 94 | 95 | /** adds a frame to an Animation */ 96 | -(void) addFrameWithFilename: (NSString*) filename; 97 | 98 | /** adds a frame from a Texture2D object to an Animation */ 99 | -(void) addFrameWithTexture: (Texture2D*) tex; 100 | @end 101 | -------------------------------------------------------------------------------- /mahjong/Classes/MahjonggAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // MahjonggAppDelegate.m 3 | // Mahjongg 4 | // 5 | // Created by GamePipe Iphone Dev on 7/28/09. 6 | // Copyright USC 2009. All rights reserved. 7 | // 8 | 9 | #import "MahjonggAppDelegate.h" 10 | #import "MenuScene.h" 11 | #include "SimpleAudioEngine_objc.h" 12 | 13 | 14 | void uncaughtExceptionHandler(NSException *exception) { 15 | [FlurryAPI logError:@"Uncaught" message:@"Crash!" exception:exception]; 16 | } 17 | 18 | @implementation MahjonggAppDelegate 19 | 20 | - (void)applicationDidFinishLaunching:(UIApplication *)application { 21 | // Analytics 22 | NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); 23 | [FlurryAPI setAppVersion:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]]; 24 | [FlurryAPI startSession:@"Z5QYWFGYXY6B2ZTANRZV"]; 25 | 26 | // View heirarchy setup 27 | window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 28 | [window setUserInteractionEnabled:YES]; 29 | [window setMultipleTouchEnabled:YES]; 30 | [window makeKeyAndVisible]; 31 | 32 | placeHolderViewController = [[UIViewController alloc] init]; 33 | [window addSubview:placeHolderViewController.view]; 34 | 35 | [[SimpleAudioEngine sharedEngine] preloadEffect:@"opener.wav"]; 36 | 37 | gameView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 38 | [placeHolderViewController.view addSubview:gameView]; 39 | 40 | 41 | soundOn = true; 42 | // Setup for high scores 43 | scoreManager = [[ScoreManager alloc] init]; 44 | [scoreManager readBestTimes]; 45 | if([ScoreManager _isGameCenterAvailable]) 46 | { 47 | leaderboardController = [[GKLeaderboardViewController alloc] init]; 48 | } 49 | else 50 | { 51 | //[gameCenterButton removeFromSuperview]; 52 | } 53 | 54 | //[[Director sharedDirector] setLandscape:YES]; 55 | [[Director sharedDirector] setDeviceOrientation:CCDeviceOrientationPortrait]; 56 | [[Director sharedDirector] attachInView:gameView]; 57 | 58 | MenuScene *scene = [MenuScene node]; 59 | [[Director sharedDirector] runWithScene:scene]; 60 | 61 | // Setup Ads if NOT Ad Free 62 | adManager = [[AdManager alloc] init:placeHolderViewController]; 63 | 64 | [[SimpleAudioEngine sharedEngine] preloadEffect:@"deselect.wav"]; 65 | [[SimpleAudioEngine sharedEngine] preloadEffect:@"select.wav"]; 66 | [[SimpleAudioEngine sharedEngine] preloadEffect:@"error.wav"]; 67 | [[SimpleAudioEngine sharedEngine] preloadEffect:@"opener.wav"]; 68 | [[SimpleAudioEngine sharedEngine] preloadEffect:@"removeTile.wav"]; 69 | } 70 | 71 | 72 | - (void)applicationWillResignActive:(UIApplication *)application 73 | { 74 | } 75 | 76 | - (void)applicationDidBecomeActive:(UIApplication *)application 77 | { 78 | } 79 | 80 | - (void)applicationWillTerminate:(UIApplication *)application 81 | { 82 | } 83 | 84 | - (void)applicationDidEnterBackground:(UIApplication *)application 85 | { 86 | } 87 | 88 | - (void)applicationWillEnterForeground:(UIApplication *)application 89 | { 90 | } 91 | 92 | - (ScoreManager*) getScoreMananger 93 | { 94 | return scoreManager; 95 | } 96 | 97 | - (void) showLeaderboard 98 | { 99 | if (leaderboardController != nil) 100 | { 101 | leaderboardController.leaderboardDelegate = self; 102 | [placeHolderViewController presentModalViewController: leaderboardController animated: YES]; 103 | } 104 | } 105 | 106 | - (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController 107 | { 108 | [placeHolderViewController dismissModalViewControllerAnimated:YES]; 109 | } 110 | 111 | - (void)dealloc { 112 | [adManager release]; 113 | [gameView release]; 114 | [placeHolderViewController release]; 115 | [scoreManager release]; 116 | [leaderboardController release]; 117 | [window release]; 118 | [super dealloc]; 119 | } 120 | 121 | 122 | @end 123 | -------------------------------------------------------------------------------- /mahjong/GoogleAdMobAdsSDK/GADBannerView.h: -------------------------------------------------------------------------------- 1 | // 2 | // GADBannerView.h 3 | // Google AdMob Ads SDK 4 | // 5 | // Copyright 2011 Google Inc. All rights reserved. 6 | // 7 | 8 | #import 9 | #import "GADRequest.h" 10 | #import "GADRequestError.h" 11 | #import "GADBannerViewDelegate.h" 12 | 13 | #pragma mark - 14 | #pragma mark Ad Sizes 15 | 16 | // iPhone and iPod Touch ad size. 17 | #define GAD_SIZE_320x50 CGSizeMake(320, 50) 18 | 19 | // Medium Rectangle size for the iPad (especially in a UISplitView's left pane). 20 | #define GAD_SIZE_300x250 CGSizeMake(300, 250) 21 | 22 | // Full Banner size for the iPad (especially in a UIPopoverController or in 23 | // UIModalPresentationFormSheet). 24 | #define GAD_SIZE_468x60 CGSizeMake(468, 60) 25 | 26 | // Leaderboard size for the iPad. 27 | #define GAD_SIZE_728x90 CGSizeMake(728, 90) 28 | 29 | #pragma mark - 30 | #pragma mark Banner Ad View 31 | 32 | // The view that displays banner ads. A minimum implementation to get an ad 33 | // from within a UIViewController class is: 34 | // 35 | // // Place an ad at the top of the screen of an iPhone/iPod Touch. 36 | // CGRect adFrame = CGRectZero; 37 | // adFrame.size = GAD_SIZE_320x50; 38 | // 39 | // // Create and setup the ad view. 40 | // GADBannerView *adView = [[GADBannerView alloc] initWithFrame:adFrame]; 41 | // adView.rootViewController = self; 42 | // adView.adUnitID = @"ID created when registering my app"; 43 | // 44 | // // Place the ad view onto the screen. 45 | // [self.view addSubview:adView]; 46 | // [adView release]; 47 | // 48 | // // Request an ad without any additional targeting information. 49 | // [adView loadRequest:nil]; 50 | // 51 | @interface GADBannerView : UIView 52 | 53 | #pragma mark Pre-Request 54 | 55 | // Required value created in the AdSense website. Create a new ad unit for 56 | // every unique placement of an ad in your application. Set this to the ID 57 | // assigned for this placement. Ad units are important for targeting and stats. 58 | // Example values for different request types: 59 | // AdMob: a0123456789ABCD 60 | // DFP: /0123/ca-pub-0123456789012345/my-ad-identifier 61 | // AdSense: ca-mb-app-pub-0123456789012345/my-ad-identifier 62 | @property (nonatomic, copy) NSString *adUnitID; 63 | 64 | // Required reference to the current root view controller. For example the root 65 | // view controller in tab-based application would be the UITabViewController. 66 | @property (nonatomic, assign) UIViewController *rootViewController; 67 | 68 | // Optional delegate object that receives state change notifications from this 69 | // GADBannerView. Typically this is a UIViewController, however, if you are 70 | // unfamiliar with the delegate pattern it is recommended you subclass this 71 | // GADBannerView and make it the delegate. That avoids any chance of your 72 | // application crashing if you forget to nil out the delegate. For example: 73 | // 74 | // @interface MyAdView : GADBannerView 75 | // @end 76 | // 77 | // @implementation MyAdView 78 | // - (id)initWithFrame:(CGRect)frame { 79 | // if ((self = [super initWithFrame:frame])) { 80 | // self.delegate = self; 81 | // } 82 | // return self; 83 | // } 84 | // 85 | // - (void)dealloc { 86 | // self.delegate = nil; 87 | // [super dealloc]; 88 | // } 89 | // 90 | // @end 91 | // 92 | @property (nonatomic, assign) NSObject *delegate; 93 | 94 | #pragma mark Making an Ad Request 95 | 96 | // Makes an ad request. Additional targeting options can be supplied with a 97 | // request object. Refresh the ad by calling this method again. 98 | - (void)loadRequest:(GADRequest *)request; 99 | 100 | #pragma mark Ad Request 101 | 102 | // YES, if the currently displayed ad (or most recent failure) was a result of 103 | // auto refreshing as specified on server. This will be set to NO after each 104 | // loadRequest: method. 105 | @property (nonatomic, readonly) BOOL hasAutoRefreshed; 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /mahjong/cocos2d/LabelAtlas.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "LabelAtlas.h" 16 | #import "ccMacros.h" 17 | 18 | 19 | @implementation LabelAtlas 20 | 21 | #pragma mark LabelAtlas - Creation & Init 22 | +(id) labelAtlasWithString:(NSString*)string charMapFile:(NSString*)charmapfile itemWidth:(int)w itemHeight:(int)h startCharMap:(char)c 23 | { 24 | return [[[self alloc] initWithString:string charMapFile:charmapfile itemWidth:w itemHeight:h startCharMap:c] autorelease]; 25 | } 26 | 27 | 28 | -(id) initWithString:(NSString*) theString charMapFile: (NSString*) charmapfile itemWidth:(int)w itemHeight:(int)h startCharMap:(char)c 29 | { 30 | 31 | if ((self=[super initWithTileFile:charmapfile tileWidth:w tileHeight:h itemsToRender:[theString length] ]) ) { 32 | 33 | mapStartChar = c; 34 | [self setString: theString]; 35 | } 36 | 37 | return self; 38 | } 39 | 40 | -(void) dealloc 41 | { 42 | [string_ release]; 43 | 44 | [super dealloc]; 45 | } 46 | 47 | #pragma mark LabelAtlas - Atlas generation 48 | 49 | -(void) updateAtlasValues 50 | { 51 | int n = [string_ length]; 52 | 53 | ccV3F_C4B_T2F_Quad quad; 54 | 55 | const char *s = [string_ UTF8String]; 56 | 57 | for( int i=0; i textureAtlas_.totalQuads ) 93 | [textureAtlas_ resizeCapacity: newString.length]; 94 | 95 | [string_ release]; 96 | string_ = [newString retain]; 97 | [self updateAtlasValues]; 98 | 99 | CGSize s; 100 | s.width = [string_ length] * itemWidth; 101 | s.height = itemHeight; 102 | [self setContentSize:s]; 103 | } 104 | 105 | #pragma mark LabelAtlas - draw 106 | 107 | // XXX: overriding draw from AtlasNode 108 | - (void) draw 109 | { 110 | glEnableClientState( GL_VERTEX_ARRAY); 111 | glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 112 | 113 | glEnable( GL_TEXTURE_2D); 114 | 115 | glColor4ub( color_.r, color_.g, color_.b, opacity_); 116 | 117 | BOOL newBlend = NO; 118 | if( blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST ) { 119 | newBlend = YES; 120 | glBlendFunc( blendFunc_.src, blendFunc_.dst ); 121 | } 122 | 123 | [textureAtlas_ drawNumberOfQuads: string_.length]; 124 | 125 | if( newBlend ) 126 | glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); 127 | 128 | // is this chepear than saving/restoring color state ? 129 | glColor4ub( 255, 255, 255, 255); 130 | 131 | glDisable( GL_TEXTURE_2D); 132 | 133 | glDisableClientState(GL_VERTEX_ARRAY ); 134 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); 135 | } 136 | @end 137 | -------------------------------------------------------------------------------- /mahjong/cocos2d/SimpleAudioEngine_objc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010 Steve Oldmeadow 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | $Id$ 23 | */ 24 | 25 | 26 | #import "CDAudioManager.h" 27 | 28 | /** 29 | A wrapper to the CDAudioManager object. 30 | This is recommended for basic audio requirements. If you just want to play some sound fx 31 | and some background music and have no interest in learning the lower level workings then 32 | this is the interface to use. 33 | 34 | Requirements: 35 | - Firmware: OS 2.2 or greater 36 | - Files: SimpleAudioEngine.*, CocosDenshion.* 37 | - Frameworks: OpenAL, AudioToolbox, AVFoundation 38 | @since v0.8 39 | */ 40 | @interface SimpleAudioEngine : NSObject { 41 | 42 | BOOL mute_; 43 | BOOL enabled_; 44 | } 45 | 46 | /** Background music volume. Range is 0.0f to 1.0f. This will only have an effect if willPlayBackgroundMusic returns YES */ 47 | @property (readwrite) float backgroundMusicVolume; 48 | /** Effects volume. Range is 0.0f to 1.0f */ 49 | @property (readwrite) float effectsVolume; 50 | /** If NO it indicates background music will not be played either because no background music is loaded or the audio session does not permit it.*/ 51 | @property (readonly) BOOL willPlayBackgroundMusic; 52 | 53 | /** returns the shared instance of the SimpleAudioEngine object */ 54 | + (SimpleAudioEngine*) sharedEngine; 55 | 56 | /** Preloads a music file so it will be ready to play as background music */ 57 | -(void) preloadBackgroundMusic:(NSString*) filePath; 58 | 59 | /** plays background music in a loop*/ 60 | -(void) playBackgroundMusic:(NSString*) filePath; 61 | /** plays background music, if loop is true the music will repeat otherwise it will be played once */ 62 | -(void) playBackgroundMusic:(NSString*) filePath loop:(BOOL) loop; 63 | /** stops playing background music */ 64 | -(void) stopBackgroundMusic; 65 | /** pauses the background music */ 66 | -(void) pauseBackgroundMusic; 67 | /** resume background music that has been paused */ 68 | -(void) resumeBackgroundMusic; 69 | /** rewind the background music */ 70 | -(void) rewindBackgroundMusic; 71 | /** returns whether or not the background music is playing */ 72 | -(BOOL) isBackgroundMusicPlaying; 73 | 74 | /** plays an audio effect with a file path*/ 75 | -(ALuint) playEffect:(NSString*) filePath; 76 | /** stop a sound that is playing, note you must pass in the soundId that is returned when you started playing the sound with playEffect */ 77 | -(void) stopEffect:(ALuint) soundId; 78 | /** plays an audio effect with a file path, pitch, pan and gain */ 79 | -(ALuint) playEffect:(NSString*) filePath pitch:(Float32) pitch pan:(Float32) pan gain:(Float32) gain; 80 | /** preloads an audio effect */ 81 | -(void) preloadEffect:(NSString*) filePath; 82 | /** unloads an audio effect from memory */ 83 | -(void) unloadEffect:(NSString*) filePath; 84 | /** Gets a CDSoundSource object set up to play the specified file. */ 85 | -(CDSoundSource *) soundSourceForFile:(NSString*) filePath; 86 | 87 | /** Shuts down the shared audio engine instance so that it can be reinitialised */ 88 | +(void) end; 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /mahjong/cocos2d/BitmapFontAtlas.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | * Portions of this code are based and inspired on: 14 | * http://www.71squared.co.uk/2009/04/iphone-game-programming-tutorial-4-bitmap-font-class 15 | * by Michael Daley 16 | * 17 | */ 18 | 19 | #import "AtlasNode.h" 20 | #import "AtlasSpriteManager.h" 21 | 22 | /** bitmap font definition */ 23 | typedef struct _bitmapFontDef { 24 | //! ID of the character 25 | unsigned char charID; 26 | //! origin and size of the font 27 | CGRect rect; 28 | //! The X amount the image should be offset when drawing the image (in pixels) 29 | int xOffset; 30 | //! The Y amount the image should be offset when drawing the image (in pixels) 31 | int yOffset; 32 | //! The amount to move the current position after drawing the character (in pixels) 33 | int xAdvance; 34 | } ccBitmapFontDef; 35 | 36 | enum { 37 | kBitmapFontAtlasMaxChars = 256, 38 | }; 39 | 40 | /** BitmapFontConfiguration has parsed configuration of the the .fnt file 41 | @since v0.8 42 | */ 43 | @interface BitmapFontConfiguration : NSObject 44 | { 45 | // XXX: Creating a public interface so that the bitmapFontArray[] is accesible 46 | @public 47 | // The characters building up the font 48 | ccBitmapFontDef bitmapFontArray[kBitmapFontAtlasMaxChars]; 49 | 50 | // FNTConfig: Common Height 51 | NSUInteger commonHeight; 52 | 53 | // values for kerning 54 | NSMutableDictionary *kerningDictionary; 55 | } 56 | 57 | /** allocates a BitmapFontConfiguration with a FNT file */ 58 | +(id) configurationWithFNTFile:(NSString*)FNTfile; 59 | /** initializes a BitmapFontConfiguration with a FNT file */ 60 | -(id) initWithFNTfile:(NSString*)FNTfile; 61 | @end 62 | 63 | 64 | /** BitmapFontAtlas is a subclass of AtlasSpriteManger. 65 | 66 | Features: 67 | - Treats each character like an AtlasSprite. This means that each individual character can be: 68 | - rotated 69 | - scaled 70 | - translated 71 | - tinted 72 | - chage the opacity 73 | - It can be used as part of a menu item. 74 | - anchorPoint can be used to align the "label" 75 | - Supports Hiero format (http://slick.cokeandcode.com/demos/hiero.jnlp) 76 | 77 | Limitations: 78 | - All inner characters are using an anchorPoint of (0.5f, 0.5f) and it is not recommend to change it 79 | because it might affect the rendering 80 | 81 | BitmapFontAtlas implements the protocol CocosNodeLabel, like Label and LabelAtlas. 82 | BitmapFontAtlas has the flexibility of Label, the speed of LabelAtlas and all the features of AtlasSprite. 83 | If in doubt, use BitmapFontAtlas instead of LabelAtlas / Label. 84 | 85 | @since v0.8 86 | */ 87 | 88 | @interface BitmapFontAtlas : AtlasSpriteManager 89 | { 90 | // string to render 91 | NSString *string_; 92 | 93 | BitmapFontConfiguration *configuration; 94 | 95 | // texture RGBA 96 | GLubyte opacity_; 97 | ccColor3B color_; 98 | BOOL opacityModifyRGB_; 99 | } 100 | 101 | /** conforms to CocosNodeRGBA protocol */ 102 | @property (nonatomic,readonly) GLubyte opacity; 103 | /** conforms to CocosNodeRGBA protocol */ 104 | @property (nonatomic,readonly) ccColor3B color; 105 | 106 | 107 | /** creates a bitmap font altas with an initial string and the FNT file */ 108 | +(id) bitmapFontAtlasWithString:(NSString*)string fntFile:(NSString*)fntFile; 109 | 110 | /** init a bitmap font altas with an initial string and the FNT file */ 111 | -(id) initWithString:(NSString*)string fntFile:(NSString*)fntFile; 112 | 113 | /** updates the font chars based on the string to render */ 114 | -(void) createFontChars; 115 | @end 116 | 117 | /** Free function that parses a FNT file a place it on the cache 118 | */ 119 | BitmapFontConfiguration * FNTConfigLoadFile( NSString *file ); 120 | /** Purges the FNT config cache 121 | */ 122 | void FNTConfigRemoveCache( void ); 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Layer.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import 17 | 18 | #import "CocosNode.h" 19 | #import "TouchDelegateProtocol.h" 20 | 21 | // 22 | // Layer 23 | // 24 | /** Layer is a subclass of CocosNode that implements the TouchEventsDelegate protocol. 25 | 26 | All features from CocosNode are valid, plus the following new features: 27 | - It can receive iPhone Touches 28 | - It can receive Accelerometer input 29 | */ 30 | @interface Layer : CocosNode 31 | { 32 | BOOL isTouchEnabled; 33 | BOOL isAccelerometerEnabled; 34 | } 35 | 36 | /** If isTouchEnabled, this method is called onEnter. Override it to change the 37 | way Layer receives touch events. 38 | ( Default: [[TouchDispatcher sharedDispatcher] addStandardDelegate:self priority:0] ) 39 | Example: 40 | -(void) registerWithTouchDispatcher 41 | { 42 | [[TouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:YES]; 43 | } 44 | */ 45 | -(void) registerWithTouchDispatcher; 46 | 47 | // whether or not it will receive Touch events 48 | @property(nonatomic,assign) BOOL isTouchEnabled; 49 | // whether or not it will receive Accelerometer events 50 | @property(nonatomic,assign) BOOL isAccelerometerEnabled; 51 | 52 | @end 53 | 54 | // 55 | // ColorLayer 56 | // 57 | /** ColorLayer is a subclass of Layer that implements the CocosNodeRGBA protocol. 58 | 59 | All features from Layer are valid, plus the following new features: 60 | - opacity 61 | - RGB colors 62 | */ 63 | @interface ColorLayer : Layer 64 | { 65 | GLubyte opacity_; 66 | ccColor3B color_; 67 | GLfloat squareVertices[4 * 2]; 68 | GLubyte squareColors[4 * 4]; 69 | } 70 | 71 | /** creates the Layer with color, width and height */ 72 | + (id) layerWithColor: (ccColor4B)color width:(GLfloat)w height:(GLfloat)h; 73 | /** creates the layer with color. Width and height are the window size. */ 74 | + (id) layerWithColor: (ccColor4B)color; 75 | 76 | /** initializes a Layer with color, width and height */ 77 | - (id) initWithColor:(ccColor4B)color width:(GLfloat)w height:(GLfloat)h; 78 | /** initializes a Layer with color. Width and height are the window size. */ 79 | - (id) initWithColor:(ccColor4B)color; 80 | 81 | /** change width */ 82 | -(void) changeWidth: (GLfloat)w; 83 | /** change height */ 84 | -(void) changeHeight: (GLfloat)h; 85 | /** change width and height 86 | @since v0.8 87 | */ 88 | -(void) changeWidth:(GLfloat)w height:(GLfloat)h; 89 | 90 | /** Opacity: conforms to CocosNodeRGBA protocol */ 91 | @property (nonatomic,readonly) GLubyte opacity; 92 | /** Opacity: conforms to CocosNodeRGBA protocol */ 93 | @property (nonatomic,readonly) ccColor3B color; 94 | 95 | @end 96 | 97 | /** A Layer with the ability to multiplex it's children. 98 | Features: 99 | - It supports one or more children 100 | - Only one children will be active a time 101 | */ 102 | @interface MultiplexLayer : Layer 103 | { 104 | unsigned int enabledLayer; 105 | NSMutableArray *layers; 106 | } 107 | 108 | /** creates a MultiplexLayer with one or more layers using a variable argument list. */ 109 | +(id) layerWithLayers: (Layer*) layer, ... NS_REQUIRES_NIL_TERMINATION; 110 | /** initializes a MultiplexLayer with one or more layers using a variable argument list. */ 111 | -(id) initWithLayers: (Layer*) layer vaList:(va_list) params; 112 | /** switches to a certain layer indexed by n. 113 | The current (old) layer will be removed from it's parent with 'cleanup:YES'. 114 | */ 115 | -(void) switchTo: (unsigned int) n; 116 | /** release the current layer and switches to another layer indexed by n. 117 | The current (old) layer will be removed from it's parent with 'cleanup:YES'. 118 | */ 119 | -(void) switchToAndReleaseMe: (unsigned int) n; 120 | @end 121 | -------------------------------------------------------------------------------- /mahjong/cocos2d/ParallaxNode.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "ParallaxNode.h" 16 | #import "Support/CGPointExtension.h" 17 | #import "Support/ccArray.h" 18 | 19 | @interface CGPointObject : NSObject 20 | { 21 | CGPoint ratio_; 22 | CGPoint offset_; 23 | CocosNode *child_; // weak ref 24 | } 25 | @property (readwrite) CGPoint ratio; 26 | @property (readwrite) CGPoint offset; 27 | @property (readwrite,assign) CocosNode *child; 28 | +(id) pointWithCGPoint:(CGPoint)point offset:(CGPoint)offset; 29 | -(id) initWithCGPoint:(CGPoint)point offset:(CGPoint)offset; 30 | @end 31 | @implementation CGPointObject 32 | @synthesize ratio = ratio_; 33 | @synthesize offset = offset_; 34 | @synthesize child=child_; 35 | 36 | +(id) pointWithCGPoint:(CGPoint)ratio offset:(CGPoint)offset 37 | { 38 | return [[[self alloc] initWithCGPoint:ratio offset:offset] autorelease]; 39 | } 40 | -(id) initWithCGPoint:(CGPoint)ratio offset:(CGPoint)offset 41 | { 42 | if( (self=[super init])) { 43 | ratio_ = ratio; 44 | offset_ = offset; 45 | } 46 | return self; 47 | } 48 | @end 49 | 50 | 51 | @implementation ParallaxNode 52 | 53 | @synthesize parallaxArray=parallaxArray_; 54 | 55 | -(id) init 56 | { 57 | if( (self=[super init]) ) { 58 | parallaxArray_ = ccArrayNew(5); 59 | 60 | // [self schedule:@selector(updateCoords:)]; 61 | lastPosition = CGPointMake(-100,-100); 62 | } 63 | return self; 64 | } 65 | 66 | - (void) dealloc 67 | { 68 | if( parallaxArray_ ) { 69 | ccArrayFree(parallaxArray_); 70 | parallaxArray_ = nil; 71 | } 72 | [super dealloc]; 73 | } 74 | 75 | -(id) addChild:(CocosNode*)child z:(int)z tag:(int)tag 76 | { 77 | NSAssert(NO,@"ParallaxNode: use addChild:z:parallaxRatio:positionOffset instead"); 78 | return nil; 79 | } 80 | 81 | -(id) addChild: (CocosNode*) child z:(int)z parallaxRatio:(CGPoint)ratio positionOffset:(CGPoint)offset 82 | { 83 | NSAssert( child != nil, @"Argument must be non-nil"); 84 | CGPointObject *obj = [CGPointObject pointWithCGPoint:ratio offset:offset]; 85 | obj.child = child; 86 | ccArrayAppendObject(parallaxArray_, obj); 87 | 88 | CGPoint pos = self.position; 89 | float x = pos.x * ratio.x + offset.x; 90 | float y = pos.y * ratio.y + offset.y; 91 | child.position = ccp(x,y); 92 | 93 | return [super addChild: child z:z tag:child.tag]; 94 | } 95 | 96 | -(void) removeChild:(CocosNode*)node cleanup:(BOOL)cleanup 97 | { 98 | for( unsigned int i=0;i < parallaxArray_->num;i++) { 99 | CGPointObject *point = parallaxArray_->arr[i]; 100 | if( [point.child isEqual:node] ) { 101 | ccArrayRemoveObjectAtIndex(parallaxArray_, i); 102 | break; 103 | } 104 | } 105 | [super removeChild:node cleanup:cleanup]; 106 | } 107 | 108 | -(void) removeAllChildrenWithCleanup:(BOOL)cleanup 109 | { 110 | ccArrayRemoveAllObjects(parallaxArray_); 111 | [super removeAllChildrenWithCleanup:cleanup]; 112 | } 113 | 114 | -(CGPoint) absolutePosition_ 115 | { 116 | CGPoint ret = position_; 117 | 118 | CocosNode *cn = self; 119 | 120 | while (cn.parent != nil) { 121 | cn = cn.parent; 122 | ret = ccpAdd( ret, cn.position ); 123 | } 124 | 125 | return ret; 126 | } 127 | 128 | /* 129 | The positions are updated at visit because: 130 | - using a timer is not guaranteed that it will called after all the positions were updated 131 | - overriding "draw" will only precise if the children have a z > 0 132 | */ 133 | -(void) visit 134 | { 135 | // CGPoint pos = position_; 136 | // CGPoint pos = [self convertToWorldSpace:CGPointZero]; 137 | CGPoint pos = [self absolutePosition_]; 138 | if( ! CGPointEqualToPoint(pos, lastPosition) ) { 139 | 140 | for(unsigned int i=0; i < parallaxArray_->num; i++ ) { 141 | 142 | CGPointObject *point = parallaxArray_->arr[i]; 143 | float x = -pos.x + pos.x * point.ratio.x + point.offset.x; 144 | float y = -pos.y + pos.y * point.ratio.y + point.offset.y; 145 | point.child.position = ccp(x,y); 146 | } 147 | 148 | lastPosition = pos; 149 | } 150 | 151 | [super visit]; 152 | } 153 | @end 154 | -------------------------------------------------------------------------------- /mahjong/cocos2d/DrawingPrimitives.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | #import 17 | #import 18 | #import 19 | 20 | #import "DrawingPrimitives.h" 21 | 22 | void drawPoint( CGPoint point ) 23 | { 24 | glVertexPointer(2, GL_FLOAT, 0, &point); 25 | glEnableClientState(GL_VERTEX_ARRAY); 26 | 27 | glDrawArrays(GL_POINTS, 0, 1); 28 | 29 | glDisableClientState(GL_VERTEX_ARRAY); 30 | } 31 | 32 | void drawPoints( CGPoint *points, unsigned int numberOfPoints ) 33 | { 34 | glVertexPointer(2, GL_FLOAT, 0, points); 35 | glEnableClientState(GL_VERTEX_ARRAY); 36 | 37 | glDrawArrays(GL_POINTS, 0, numberOfPoints); 38 | 39 | glDisableClientState(GL_VERTEX_ARRAY); 40 | } 41 | 42 | 43 | void drawLine( CGPoint origin, CGPoint destination ) 44 | { 45 | CGPoint vertices[2]; 46 | 47 | vertices[0] = origin; 48 | vertices[1] = destination; 49 | 50 | glVertexPointer(2, GL_FLOAT, 0, vertices); 51 | glEnableClientState(GL_VERTEX_ARRAY); 52 | 53 | glDrawArrays(GL_LINES, 0, 2); 54 | 55 | glDisableClientState(GL_VERTEX_ARRAY); 56 | } 57 | 58 | 59 | void drawPoly( CGPoint *poli, int points, BOOL closePolygon ) 60 | { 61 | glVertexPointer(2, GL_FLOAT, 0, poli); 62 | glEnableClientState(GL_VERTEX_ARRAY); 63 | 64 | if( closePolygon ) 65 | glDrawArrays(GL_LINE_LOOP, 0, points); 66 | else 67 | glDrawArrays(GL_LINE_STRIP, 0, points); 68 | 69 | glDisableClientState(GL_VERTEX_ARRAY); 70 | } 71 | 72 | void drawCircle( CGPoint center, float r, float a, int segs, BOOL drawLineToCenter) 73 | { 74 | int additionalSegment = 1; 75 | if (drawLineToCenter) 76 | additionalSegment++; 77 | 78 | const float coef = 2.0f * (float)M_PI/segs; 79 | 80 | float *vertices = malloc( sizeof(float)*2*(segs+2)); 81 | if( ! vertices ) 82 | return; 83 | 84 | memset( vertices,0, sizeof(float)*2*(segs+2)); 85 | 86 | for(int i=0;i<=segs;i++) 87 | { 88 | float rads = i*coef; 89 | float j = r * cosf(rads + a) + center.x; 90 | float k = r * sinf(rads + a) + center.y; 91 | 92 | vertices[i*2] = j; 93 | vertices[i*2+1] =k; 94 | } 95 | vertices[(segs+1)*2] = center.x; 96 | vertices[(segs+1)*2+1] = center.y; 97 | 98 | glVertexPointer(2, GL_FLOAT, 0, vertices); 99 | glEnableClientState(GL_VERTEX_ARRAY); 100 | 101 | glDrawArrays(GL_LINE_STRIP, 0, segs+additionalSegment); 102 | 103 | glDisableClientState(GL_VERTEX_ARRAY); 104 | 105 | free( vertices ); 106 | } 107 | 108 | void drawQuadBezier(CGPoint origin, CGPoint control, CGPoint destination, int segments) 109 | { 110 | CGPoint vertices[segments + 1]; 111 | 112 | float t = 0.0f; 113 | for(int i = 0; i < segments; i++) 114 | { 115 | float x = powf(1 - t, 2) * origin.x + 2.0f * (1 - t) * t * control.x + t * t * destination.x; 116 | float y = powf(1 - t, 2) * origin.y + 2.0f * (1 - t) * t * control.y + t * t * destination.y; 117 | vertices[i] = CGPointMake(x, y); 118 | t += 1.0f / segments; 119 | } 120 | vertices[segments] = destination; 121 | 122 | glVertexPointer(2, GL_FLOAT, 0, vertices); 123 | glEnableClientState(GL_VERTEX_ARRAY); 124 | 125 | glDrawArrays(GL_LINE_STRIP, 0, segments + 1); 126 | 127 | glDisableClientState(GL_VERTEX_ARRAY); 128 | } 129 | 130 | void drawCubicBezier(CGPoint origin, CGPoint control1, CGPoint control2, CGPoint destination, int segments) 131 | { 132 | CGPoint vertices[segments + 1]; 133 | 134 | float t = 0; 135 | for(int i = 0; i < segments; i++) 136 | { 137 | float x = powf(1 - t, 3) * origin.x + 3.0f * powf(1 - t, 2) * t * control1.x + 3.0f * (1 - t) * t * t * control2.x + t * t * t * destination.x; 138 | float y = powf(1 - t, 3) * origin.y + 3.0f * powf(1 - t, 2) * t * control1.y + 3.0f * (1 - t) * t * t * control2.y + t * t * t * destination.y; 139 | vertices[i] = CGPointMake(x, y); 140 | t += 1.0f / segments; 141 | } 142 | vertices[segments] = destination; 143 | 144 | glVertexPointer(2, GL_FLOAT, 0, vertices); 145 | glEnableClientState(GL_VERTEX_ARRAY); 146 | 147 | glDrawArrays(GL_LINE_STRIP, 0, segments + 1); 148 | 149 | glDisableClientState(GL_VERTEX_ARRAY); 150 | } 151 | -------------------------------------------------------------------------------- /mahjong/cocos2d/TextureMgr.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import 16 | 17 | #import "Support/Texture2D.h" 18 | 19 | /** Singleton that handles the loading of textures 20 | * Once the texture is loaded, the next time it will return 21 | * a reference of the previously loaded texture reducing GPU & CPU memory 22 | */ 23 | @interface TextureMgr : NSObject 24 | { 25 | NSMutableDictionary *textures; 26 | NSLock *dictLock; 27 | NSLock *contextLock; 28 | } 29 | 30 | /** Retruns ths shared instance of the Texture Manager */ 31 | + (TextureMgr *) sharedTextureMgr; 32 | 33 | /** Returns a Texture2D object given an file image 34 | * If the file image was not previously loaded, it will create a new Texture2D 35 | * object and it will return it. 36 | * Otherwise it will return a reference of a previosly loaded image. 37 | * Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif 38 | */ 39 | -(Texture2D*) addImage: (NSString*) fileimage; 40 | 41 | /** Returns a Texture2D object given an file image 42 | * If the file image was not previously loaded, it will create a new Texture2D object and it will return it. 43 | * Otherwise it will load a texture in a new thread, and when the image is loaded, the callback will be called with the Texture2D as a parameter. 44 | * The callback will be called from the main thread, so it is safe to create any cocos2d object from the callback. 45 | * Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif 46 | * @since v0.8 47 | */ 48 | -(void) addImageAsync:(NSString*) filename target:(id)target selector:(SEL)selector; 49 | 50 | /** Returns a Texture2D object given an PVRTC RAW filename 51 | * If the file image was not previously loaded, it will create a new Texture2D 52 | * object and it will return it. Otherwise it will return a reference of a previosly loaded image 53 | * 54 | * It can only load square images: width == height, and it must be a power of 2 (128,256,512...) 55 | * bpp can only be 2 or 4. 2 means more compression but lower quality. 56 | * hasAlpha: whether or not the image contains alpha channel 57 | */ 58 | -(Texture2D*) addPVRTCImage: (NSString*) fileimage bpp:(int)bpp hasAlpha:(BOOL)alpha width:(int)w; 59 | 60 | /** Returns a Texture2D object given an PVRTC filename 61 | * If the file image was not previously loaded, it will create a new Texture2D 62 | * object and it will return it. Otherwise it will return a reference of a previosly loaded image 63 | */ 64 | -(Texture2D*) addPVRTCImage: (NSString*) filename; 65 | 66 | /** Returns a Texture2D object given an CGImageRef image 67 | * If the image was not previously loaded, it will create a new Texture2D object and it will return it. 68 | * Otherwise it will return a reference of a previously loaded image. 69 | * The CGImageRef (a memory pointer) will be used as the "key" for the cache. 70 | * @deprecated Use addCGImage:forKey: instead 71 | */ 72 | -(Texture2D*) addCGImage: (CGImageRef) image __attribute__((deprecated)); 73 | /** Returns a Texture2D object given an CGImageRef image 74 | * If the image was not previously loaded, it will create a new Texture2D object and it will return it. 75 | * Otherwise it will return a reference of a previously loaded image 76 | * The "key" parameter will be used as the "key" for the cache. 77 | * @since v0.8 78 | */ 79 | -(Texture2D*) addCGImage: (CGImageRef) image forKey: (NSString *)key; 80 | 81 | /** Purges the dictionary of loaded textures. 82 | * Call this method if you receive the "Memory Warning" 83 | * In the short term: it will free some resources preventing your app from being killed 84 | * In the medium term: it will allocate more resources 85 | * In the long term: it will be the same 86 | */ 87 | -(void) removeAllTextures; 88 | 89 | /** Removes unused textures 90 | * Textures that have a retain count of 1 will be deleted 91 | * It is convinient to call this method after when starting a new Scene 92 | * @since v0.8 93 | */ 94 | -(void) removeUnusedTextures; 95 | 96 | /** Deletes a texture from the Texture Manager 97 | */ 98 | -(void) removeTexture: (Texture2D*) tex; 99 | @end 100 | -------------------------------------------------------------------------------- /mahjong/cocos2d/TextureAtlas.h: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "Texture2D.h" 16 | #import "ccTypes.h" 17 | 18 | /** A class that implements a Texture Atlas. 19 | Supported features: 20 | * The atlas file can be a PVRTC, PNG or any other fomrat supported by Texture2D 21 | * Quads can be udpated in runtime 22 | * Quads can be added in runtime 23 | * Quads can be removed in runtime 24 | * Quads can be re-ordered in runtime 25 | * The TextureAtlas capacity can be increased or decreased in runtime 26 | * OpenGL component: V3F, C4B, T2F. 27 | The quads are rendered using an OpenGL ES an interleaved vertex array list 28 | */ 29 | @interface TextureAtlas : NSObject { 30 | NSUInteger totalQuads_; 31 | NSUInteger capacity_; 32 | ccV3F_C4B_T2F_Quad *quads_; // quads to be rendered 33 | GLushort *indices; 34 | Texture2D *texture_; 35 | } 36 | 37 | /** quantity of quads that are going to be drawn */ 38 | @property (nonatomic,readonly) NSUInteger totalQuads; 39 | /** quantity of quads that can be stored with the current texture atlas size */ 40 | @property (nonatomic,readonly) NSUInteger capacity; 41 | /** Texture of the texture atlas */ 42 | @property (nonatomic,retain) Texture2D *texture; 43 | /** Quads that are going to be rendered */ 44 | @property (nonatomic,readwrite) ccV3F_C4B_T2F_Quad *quads; 45 | 46 | /** creates a TextureAtlas with an filename and with an initial capacity for Quads. 47 | * The TextureAtlas capacity can be increased in runtime. 48 | */ 49 | +(id) textureAtlasWithFile:(NSString*)file capacity:(NSUInteger)capacity; 50 | 51 | /** initializes a TextureAtlas with a filename and with a certain capacity for Quads. 52 | * The TextureAtlas capacity can be increased in runtime. 53 | */ 54 | -(id) initWithFile: (NSString*) file capacity:(NSUInteger)capacity; 55 | 56 | /** creates a TextureAtlas with a previously initialized Texture2D object, and 57 | * with an initial capacity for n Quads. 58 | * The TextureAtlas capacity can be increased in runtime. 59 | */ 60 | +(id) textureAtlasWithTexture:(Texture2D *)tex capacity:(NSUInteger)capacity; 61 | 62 | /** initializes a TextureAtlas with a previously initialized Texture2D object, and 63 | * with an initial capacity for Quads. 64 | * The TextureAtlas capacity can be increased in runtime. 65 | */ 66 | -(id) initWithTexture:(Texture2D *)tex capacity:(NSUInteger)capacity; 67 | 68 | /** updates a Quad (texture, vertex and color) at a certain index 69 | * index must be between 0 and the atlas capacity - 1 70 | @since v0.8 71 | */ 72 | -(void) updateQuad:(ccV3F_C4B_T2F_Quad*)quad atIndex:(NSUInteger)index; 73 | 74 | /** Inserts a Quad (texture, vertex and color) at a certain index 75 | index must be between 0 and the atlas capacity - 1 76 | @since v0.8 77 | */ 78 | -(void) insertQuad:(ccV3F_C4B_T2F_Quad*)quad atIndex:(NSUInteger)index; 79 | 80 | /** Removes the quad that is located at a certain index and inserts it at a new index 81 | This operation is faster than remove and insert in 2 different steps. 82 | @since v0.7.2 83 | */ 84 | -(void) insertQuadFromIndex:(NSUInteger)fromIndex atIndex:(NSUInteger)newIndex; 85 | 86 | /** removes a quad at a given index number. 87 | The capacity remains the same, but the total number of quads to be drawn is reduced in 1 88 | @since v0.7.2 89 | */ 90 | -(void) removeQuadAtIndex:(NSUInteger) index; 91 | 92 | /** removes all Quads. 93 | The TextureAtlas capacity remains untouched. No memory is freed. 94 | The total number of quads to be drawn will be 0 95 | @since v0.7.2 96 | */ 97 | -(void) removeAllQuads; 98 | 99 | 100 | /** resize the capacity of the Texture Atlas. 101 | * The new capacity can be lower or higher than the current one 102 | * It returns YES if the resize was successful. 103 | * If it fails to resize the capacity it will return NO with a new capacity of 0. 104 | */ 105 | -(BOOL) resizeCapacity: (NSUInteger) n; 106 | 107 | 108 | /** draws n quads 109 | * n can't be greater than the capacity of the Atlas 110 | */ 111 | -(void) drawNumberOfQuads: (NSUInteger) n; 112 | 113 | /** draws all the Atlas's Quads 114 | */ 115 | -(void) drawQuads; 116 | 117 | @end 118 | -------------------------------------------------------------------------------- /mahjong/cocos2d/AtlasNode.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | #import "AtlasNode.h" 16 | #import "ccMacros.h" 17 | 18 | 19 | @interface AtlasNode (Private) 20 | -(void) calculateMaxItems; 21 | -(void) calculateTexCoordsSteps; 22 | -(void) updateBlendFunc; 23 | -(void) updateOpacityModifyRGB; 24 | @end 25 | 26 | @implementation AtlasNode 27 | 28 | @synthesize opacity=opacity_, color=color_; 29 | @synthesize textureAtlas = textureAtlas_; 30 | @synthesize blendFunc = blendFunc_; 31 | 32 | #pragma mark AtlasNode - Creation & Init 33 | +(id) atlasWithTileFile:(NSString*)tile tileWidth:(int)w tileHeight:(int)h itemsToRender: (int) c 34 | { 35 | return [[[self alloc] initWithTileFile:tile tileWidth:w tileHeight:h itemsToRender:c] autorelease]; 36 | } 37 | 38 | 39 | -(id) initWithTileFile:(NSString*)tile tileWidth:(int)w tileHeight:(int)h itemsToRender: (int) c 40 | { 41 | if( (self=[super init]) ) { 42 | 43 | itemWidth = w; 44 | itemHeight = h; 45 | 46 | opacity_ = 255; 47 | color_ = ccWHITE; 48 | opacityModifyRGB_ = NO; 49 | 50 | blendFunc_.src = CC_BLEND_SRC; 51 | blendFunc_.dst = CC_BLEND_DST; 52 | 53 | // retained 54 | self.textureAtlas = [TextureAtlas textureAtlasWithFile:tile capacity:c]; 55 | 56 | [self updateBlendFunc]; 57 | [self updateOpacityModifyRGB]; 58 | 59 | [self calculateMaxItems]; 60 | [self calculateTexCoordsSteps]; 61 | } 62 | 63 | return self; 64 | } 65 | 66 | -(void) dealloc 67 | { 68 | [textureAtlas_ release]; 69 | 70 | [super dealloc]; 71 | } 72 | 73 | #pragma mark AtlasNode - Atlas generation 74 | 75 | -(void) calculateMaxItems 76 | { 77 | CGSize s = [[textureAtlas_ texture] contentSize]; 78 | itemsPerColumn = s.height / itemHeight; 79 | itemsPerRow = s.width / itemWidth; 80 | } 81 | 82 | -(void) calculateTexCoordsSteps 83 | { 84 | texStepX = itemWidth / (float) [[textureAtlas_ texture] pixelsWide]; 85 | texStepY = itemHeight / (float) [[textureAtlas_ texture] pixelsHigh]; 86 | } 87 | 88 | -(void) updateAtlasValues 89 | { 90 | [NSException raise:@"AtlasNode:Abstract" format:@"updateAtlasValue not overriden"]; 91 | } 92 | 93 | #pragma mark AtlasNode - draw 94 | - (void) draw 95 | { 96 | glEnableClientState( GL_VERTEX_ARRAY); 97 | glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 98 | 99 | glEnable( GL_TEXTURE_2D); 100 | 101 | glColor4ub( color_.r, color_.g, color_.b, opacity_); 102 | 103 | BOOL newBlend = NO; 104 | if( blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST ) { 105 | newBlend = YES; 106 | glBlendFunc( blendFunc_.src, blendFunc_.dst ); 107 | } 108 | 109 | [textureAtlas_ drawQuads]; 110 | 111 | if( newBlend ) 112 | glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); 113 | 114 | // is this chepear than saving/restoring color state ? 115 | glColor4ub( 255, 255, 255, 255); 116 | 117 | glDisable( GL_TEXTURE_2D); 118 | 119 | glDisableClientState(GL_VERTEX_ARRAY ); 120 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); 121 | } 122 | 123 | #pragma mark AtlasNode - RGBA protocol 124 | 125 | -(void) setRGB: (GLubyte)r :(GLubyte)g :(GLubyte)b 126 | { 127 | [self setColor:ccc3(r,g,b)]; 128 | } 129 | 130 | -(void) setOpacity:(GLubyte)opacity 131 | { 132 | // special opacity for premultiplied textures 133 | opacity_ = opacity; 134 | if( opacityModifyRGB_ ) 135 | color_.r = color_.g = color_.b = opacity_; 136 | } 137 | -(void) updateOpacityModifyRGB 138 | { 139 | opacityModifyRGB_ = [textureAtlas_.texture hasPremultipliedAlpha]; 140 | } 141 | -(void) setOpacityModifyRGB:(BOOL)modify 142 | { 143 | opacityModifyRGB_ = modify; 144 | } 145 | -(BOOL) doesOpacityModifyRGB 146 | { 147 | return opacityModifyRGB_; 148 | } 149 | 150 | #pragma mark AtlasNode - CocosNodeTexture protocol 151 | 152 | -(void) updateBlendFunc 153 | { 154 | if( ! [textureAtlas_.texture hasPremultipliedAlpha] ) { 155 | blendFunc_.src = GL_SRC_ALPHA; 156 | blendFunc_.dst = GL_ONE_MINUS_SRC_ALPHA; 157 | } 158 | } 159 | 160 | -(void) setTexture:(Texture2D*)texture 161 | { 162 | textureAtlas_.texture = texture; 163 | [self updateBlendFunc]; 164 | [self updateOpacityModifyRGB]; 165 | } 166 | 167 | -(Texture2D*) texture 168 | { 169 | return textureAtlas_.texture; 170 | } 171 | 172 | 173 | @end 174 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Action.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import "Action.h" 17 | #import "ccMacros.h" 18 | 19 | #import "IntervalAction.h" 20 | 21 | // 22 | // Action Base Class 23 | // 24 | #pragma mark - 25 | #pragma mark Action 26 | @implementation Action 27 | 28 | @synthesize target; 29 | @synthesize tag; 30 | 31 | +(id) action 32 | { 33 | return [[[self alloc] init] autorelease]; 34 | } 35 | 36 | -(id) init 37 | { 38 | if( !(self=[super init]) ) 39 | return nil; 40 | 41 | target = nil; 42 | tag = kActionTagInvalid; 43 | return self; 44 | } 45 | 46 | -(void) dealloc 47 | { 48 | CCLOG(@"deallocing %@", self); 49 | [super dealloc]; 50 | } 51 | 52 | -(NSString*) description 53 | { 54 | return [NSString stringWithFormat:@"<%@ = %08X | Tag = %i>", [self class], self, tag]; 55 | } 56 | 57 | -(id) copyWithZone: (NSZone*) zone 58 | { 59 | Action *copy = [[[self class] allocWithZone: zone] init]; 60 | [copy setTarget: target]; 61 | copy.tag = tag; 62 | return copy; 63 | } 64 | 65 | -(void) start 66 | { 67 | // override me 68 | } 69 | 70 | -(void) stop 71 | { 72 | // override me 73 | } 74 | 75 | -(BOOL) isDone 76 | { 77 | return YES; 78 | } 79 | 80 | -(void) step: (ccTime) dt 81 | { 82 | NSLog(@"[Action step]. override me"); 83 | } 84 | 85 | -(void) update: (ccTime) time 86 | { 87 | NSLog(@"[Action update]. override me"); 88 | } 89 | @end 90 | 91 | // 92 | // FiniteTimeAction 93 | // 94 | #pragma mark - 95 | #pragma mark FiniteTimeAction 96 | @implementation FiniteTimeAction 97 | @synthesize duration; 98 | 99 | - (FiniteTimeAction*) reverse 100 | { 101 | CCLOG(@"FiniteTimeAction#reverse: Implement me"); 102 | return nil; 103 | } 104 | @end 105 | 106 | 107 | // 108 | // RepeatForever 109 | // 110 | #pragma mark - 111 | #pragma mark RepeatForever 112 | @implementation RepeatForever 113 | +(id) actionWithAction: (IntervalAction*) action 114 | { 115 | return [[[self alloc] initWithAction: action] autorelease]; 116 | } 117 | 118 | -(id) initWithAction: (IntervalAction*) action 119 | { 120 | if( !(self=[super init]) ) 121 | return nil; 122 | 123 | other = [action retain]; 124 | return self; 125 | } 126 | 127 | -(id) copyWithZone: (NSZone*) zone 128 | { 129 | Action *copy = [[[self class] allocWithZone: zone] initWithAction:[[other copy] autorelease] ]; 130 | return copy; 131 | } 132 | 133 | -(void) dealloc 134 | { 135 | [other release]; 136 | [super dealloc]; 137 | } 138 | 139 | -(void) start 140 | { 141 | [super start]; 142 | [other setTarget: target]; 143 | [other start]; 144 | } 145 | 146 | -(void) step:(ccTime) dt 147 | { 148 | [other step: dt]; 149 | if( [other isDone] ) { 150 | [other start]; 151 | } 152 | } 153 | 154 | 155 | -(BOOL) isDone 156 | { 157 | return NO; 158 | } 159 | 160 | - (IntervalAction *) reverse 161 | { 162 | return [RepeatForever actionWithAction:[other reverse]]; 163 | } 164 | 165 | @end 166 | 167 | // 168 | // Speed 169 | // 170 | #pragma mark - 171 | #pragma mark Speed 172 | @implementation Speed 173 | @synthesize speed; 174 | 175 | +(id) actionWithAction: (IntervalAction*) action speed:(float)r 176 | { 177 | return [[[self alloc] initWithAction: action speed:r] autorelease]; 178 | } 179 | 180 | -(id) initWithAction: (IntervalAction*) action speed:(float)r 181 | { 182 | if( !(self=[super init]) ) 183 | return nil; 184 | 185 | other = [action retain]; 186 | speed = r; 187 | return self; 188 | } 189 | 190 | -(id) copyWithZone: (NSZone*) zone 191 | { 192 | Action *copy = [[[self class] allocWithZone: zone] initWithAction:[[other copy] autorelease] speed:speed]; 193 | return copy; 194 | } 195 | 196 | -(void) dealloc 197 | { 198 | [other release]; 199 | [super dealloc]; 200 | } 201 | 202 | -(void) start 203 | { 204 | [super start]; 205 | [other setTarget: target]; 206 | [other start]; 207 | } 208 | 209 | -(void) stop 210 | { 211 | [other stop]; 212 | [super stop]; 213 | } 214 | 215 | -(void) step:(ccTime) dt 216 | { 217 | [other step: dt * speed]; 218 | } 219 | 220 | -(BOOL) isDone 221 | { 222 | return [other isDone]; 223 | } 224 | 225 | - (IntervalAction *) reverse 226 | { 227 | return [Speed actionWithAction:[other reverse] speed:speed]; 228 | } 229 | @end 230 | 231 | 232 | 233 | -------------------------------------------------------------------------------- /mahjong/cocos2d/Support/OpenGL_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ===== IMPORTANT ===== 4 | 5 | This is sample code demonstrating API, technology or techniques in development. 6 | Although this sample code has been reviewed for technical accuracy, it is not 7 | final. Apple is supplying this information to help you plan for the adoption of 8 | the technologies and programming interfaces described herein. This information 9 | is subject to change, and software implemented based on this sample code should 10 | be tested with final operating system software and final documentation. Newer 11 | versions of this sample code may be provided with future seeds of the API or 12 | technology. For information about updates to this and other developer 13 | documentation, view the New & Updated sidebars in subsequent documentation 14 | seeds. 15 | 16 | ===================== 17 | 18 | File: OpenGL_Internal.h 19 | Abstract: This file is included for support purposes and isn't necessary for 20 | understanding this sample. 21 | 22 | Version: 1.0 23 | 24 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. 25 | ("Apple") in consideration of your agreement to the following terms, and your 26 | use, installation, modification or redistribution of this Apple software 27 | constitutes acceptance of these terms. If you do not agree with these terms, 28 | please do not use, install, modify or redistribute this Apple software. 29 | 30 | In consideration of your agreement to abide by the following terms, and subject 31 | to these terms, Apple grants you a personal, non-exclusive license, under 32 | Apple's copyrights in this original Apple software (the "Apple Software"), to 33 | use, reproduce, modify and redistribute the Apple Software, with or without 34 | modifications, in source and/or binary forms; provided that if you redistribute 35 | the Apple Software in its entirety and without modifications, you must retain 36 | this notice and the following text and disclaimers in all such redistributions 37 | of the Apple Software. 38 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used 39 | to endorse or promote products derived from the Apple Software without specific 40 | prior written permission from Apple. Except as expressly stated in this notice, 41 | no other rights or licenses, express or implied, are granted by Apple herein, 42 | including but not limited to any patent rights that may be infringed by your 43 | derivative works or by other works in which the Apple Software may be 44 | incorporated. 45 | 46 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO 47 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED 48 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 49 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN 50 | COMBINATION WITH YOUR PRODUCTS. 51 | 52 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR 53 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 54 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR 56 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF 57 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF 58 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 59 | 60 | Copyright (C) 2008 Apple Inc. All Rights Reserved. 61 | 62 | */ 63 | 64 | /* Generic error reporting */ 65 | #define REPORT_ERROR(__FORMAT__, ...) printf("%s: %s\n", __FUNCTION__, [[NSString stringWithFormat:__FORMAT__, __VA_ARGS__] UTF8String]) 66 | 67 | /* EAGL and GL functions calling wrappers that log on error */ 68 | #define CALL_EAGL_FUNCTION(__FUNC__, ...) ({ EAGLError __error = __FUNC__( __VA_ARGS__ ); if(__error != kEAGLErrorSuccess) printf("%s() called from %s returned error %i\n", #__FUNC__, __FUNCTION__, __error); (__error ? NO : YES); }) 69 | #define CHECK_GL_ERROR() ({ GLenum __error = glGetError(); if(__error) printf("OpenGL error 0x%04X in %s\n", __error, __FUNCTION__); (__error ? NO : YES); }) 70 | 71 | /* Optional delegate methods support */ 72 | #ifndef __DELEGATE_IVAR__ 73 | #define __DELEGATE_IVAR__ _delegate 74 | #endif 75 | #ifndef __DELEGATE_METHODS_IVAR__ 76 | #define __DELEGATE_METHODS_IVAR__ _delegateMethods 77 | #endif 78 | #define TEST_DELEGATE_METHOD_BIT(__BIT__) (self->__DELEGATE_METHODS_IVAR__ & (1 << __BIT__)) 79 | #define SET_DELEGATE_METHOD_BIT(__BIT__, __NAME__) { if([self->__DELEGATE_IVAR__ respondsToSelector:@selector(__NAME__)]) self->__DELEGATE_METHODS_IVAR__ |= (1 << __BIT__); else self->__DELEGATE_METHODS_IVAR__ &= ~(1 << __BIT__); } 80 | -------------------------------------------------------------------------------- /mahjong/cocos2d/InstantAction.m: -------------------------------------------------------------------------------- 1 | /* cocos2d for iPhone 2 | * 3 | * http://www.cocos2d-iphone.org 4 | * 5 | * Copyright (C) 2008,2009 Ricardo Quesada 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the 'cocos2d for iPhone' license. 9 | * 10 | * You will find a copy of this license within the cocos2d for iPhone 11 | * distribution inside the "LICENSE" file. 12 | * 13 | */ 14 | 15 | 16 | #import "InstantAction.h" 17 | #import "CocosNode.h" 18 | 19 | // 20 | // InstantAction 21 | // 22 | @implementation InstantAction 23 | 24 | -(id) init 25 | { 26 | if( (self=[super init]) ) 27 | duration = 0; 28 | return self; 29 | } 30 | 31 | -(id) copyWithZone: (NSZone*) zone 32 | { 33 | InstantAction *copy = [[[self class] allocWithZone: zone] init]; 34 | return copy; 35 | } 36 | 37 | - (BOOL) isDone 38 | { 39 | return YES; 40 | } 41 | -(void) step: (ccTime) dt 42 | { 43 | [self update: 1]; 44 | } 45 | -(void) update: (ccTime) t 46 | { 47 | // ignore 48 | } 49 | -(FiniteTimeAction*) reverse 50 | { 51 | return [[self copy] autorelease]; 52 | } 53 | @end 54 | 55 | // 56 | // Show 57 | // 58 | @implementation Show 59 | -(void) start 60 | { 61 | [super start]; 62 | [target setVisible: YES]; 63 | } 64 | -(FiniteTimeAction*) reverse 65 | { 66 | return [Hide action]; 67 | } 68 | @end 69 | 70 | // 71 | // Hide 72 | // 73 | @implementation Hide 74 | -(void) start 75 | { 76 | [super start]; 77 | [target setVisible: NO]; 78 | } 79 | -(FiniteTimeAction*) reverse 80 | { 81 | return [Show action]; 82 | } 83 | @end 84 | 85 | // 86 | // ToggleVisibility 87 | // 88 | @implementation ToggleVisibility 89 | -(void) start 90 | { 91 | [super start]; 92 | BOOL v = [target visible]; 93 | [target setVisible: !v]; 94 | } 95 | @end 96 | 97 | // 98 | // Place 99 | // 100 | @implementation Place 101 | +(id) actionWithPosition: (CGPoint) pos 102 | { 103 | return [[[self alloc]initWithPosition:pos]autorelease]; 104 | } 105 | 106 | -(id) initWithPosition: (CGPoint) pos 107 | { 108 | if( (self=[super init]) ) 109 | position = pos; 110 | return self; 111 | } 112 | 113 | -(id) copyWithZone: (NSZone*) zone 114 | { 115 | InstantAction *copy = [[[self class] allocWithZone: zone] initWithPosition: position]; 116 | return copy; 117 | } 118 | 119 | -(void) start 120 | { 121 | [super start]; 122 | [target setPosition: position]; 123 | } 124 | @end 125 | 126 | // 127 | // CallFunc 128 | // 129 | @implementation CallFunc 130 | +(id) actionWithTarget: (id) t selector:(SEL) s 131 | { 132 | return [[[self alloc] initWithTarget: t selector: s] autorelease]; 133 | } 134 | 135 | -(id) initWithTarget: (id) t selector:(SEL) s 136 | { 137 | if( (self=[super init]) ) { 138 | targetCallback = [t retain]; 139 | selector = s; 140 | } 141 | return self; 142 | } 143 | 144 | -(void) dealloc 145 | { 146 | [targetCallback release]; 147 | [super dealloc]; 148 | } 149 | 150 | -(id) copyWithZone: (NSZone*) zone 151 | { 152 | InstantAction *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback selector:selector]; 153 | return copy; 154 | } 155 | 156 | 157 | -(void) start 158 | { 159 | [super start]; 160 | [self execute]; 161 | } 162 | 163 | -(void) execute 164 | { 165 | [targetCallback performSelector:selector]; 166 | } 167 | @end 168 | 169 | // 170 | // CallFuncN 171 | // 172 | @implementation CallFuncN 173 | 174 | -(void) execute 175 | { 176 | [targetCallback performSelector:selector withObject:target]; 177 | } 178 | @end 179 | 180 | // 181 | // CallFuncND 182 | // 183 | @implementation CallFuncND 184 | 185 | @synthesize invocation = invocation_; 186 | 187 | +(id) actionWithTarget: (id) t selector:(SEL) s data:(void*) d 188 | { 189 | return [[[self alloc] initWithTarget: t selector: s data:d] autorelease]; 190 | } 191 | 192 | -(id) initWithTarget:(id) t selector:(SEL) s data:(void*) d 193 | { 194 | if( (self=[super initWithTarget:t selector:s]) ) { 195 | data = d; 196 | NSMethodSignature * sig = [[t class] instanceMethodSignatureForSelector:s]; 197 | self.invocation = [NSInvocation invocationWithMethodSignature:sig]; 198 | [invocation_ setTarget:t]; 199 | [invocation_ setSelector:s]; 200 | } 201 | return self; 202 | } 203 | 204 | -(id) copyWithZone: (NSZone*) zone 205 | { 206 | InstantAction *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback selector:selector data:data]; 207 | return copy; 208 | } 209 | 210 | 211 | -(void) dealloc 212 | { 213 | [invocation_ release]; 214 | [super dealloc]; 215 | } 216 | 217 | -(void) execute 218 | { 219 | [invocation_ setArgument:&target atIndex:2]; 220 | [invocation_ setArgument:&data atIndex:3]; 221 | [invocation_ invoke]; 222 | } 223 | @end 224 | --------------------------------------------------------------------------------