Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

migrated to github

  • Loading branch information...
commit cda95fb6fd327a306a8b1e7ffe9357a8775af9a7 0 parents
Kaspars authored
Showing with 38,399 additions and 0 deletions.
  1. +60 −0 Classes/AppController.h
  2. +365 −0 Classes/AppController.m
  3. +31 −0 Classes/BonusAction.h
  4. +107 −0 Classes/BonusAction.m
  5. +27 −0 Classes/Common.h
  6. +25 −0 Classes/Common.m
  7. +50 −0 Classes/ComputerPlayer.h
  8. +123 −0 Classes/ComputerPlayer.m
  9. +34 −0 Classes/ComputerPlayer1.h
  10. +53 −0 Classes/ComputerPlayer1.m
  11. +35 −0 Classes/ComputerPlayer2.h
  12. +54 −0 Classes/ComputerPlayer2.m
  13. +34 −0 Classes/ComputerPlayer3.h
  14. +54 −0 Classes/ComputerPlayer3.m
  15. +35 −0 Classes/ComputerPlayer4.h
  16. +55 −0 Classes/ComputerPlayer4.m
  17. +35 −0 Classes/ComputerPlayer5.h
  18. +54 −0 Classes/ComputerPlayer5.m
  19. +71 −0 Classes/Config.h
  20. +25 −0 Classes/Empty.h
  21. +26 −0 Classes/Empty.m
  22. +44 −0 Classes/EnterName.h
  23. +103 −0 Classes/EnterName.m
  24. +103 −0 Classes/Game.h
  25. +450 −0 Classes/Game.m
  26. +37 −0 Classes/GameObject.h
  27. +45 −0 Classes/GameObject.m
  28. +51 −0 Classes/GameOver.h
  29. +135 −0 Classes/GameOver.m
  30. +47 −0 Classes/Gestures.h
  31. +111 −0 Classes/Gestures.m
  32. +19 −0 Classes/HeadGloveJoint.h
  33. +151 −0 Classes/HeadGloveJoint.m
  34. +35 −0 Classes/HeadParticle.h
  35. +106 −0 Classes/HeadParticle.m
  36. +28 −0 Classes/HitEffect.h
  37. +168 −0 Classes/HitEffect.m
  38. +37 −0 Classes/JSONLoader.h
  39. +116 −0 Classes/JSONLoader.m
  40. +44 −0 Classes/LeagueLeaderboard.h
  41. +188 −0 Classes/LeagueLeaderboard.m
  42. +42 −0 Classes/LeaguePlayers.h
  43. +128 −0 Classes/LeaguePlayers.m
  44. +95 −0 Classes/Link.h
  45. +332 −0 Classes/Link.m
  46. +36 −0 Classes/MainMenu.h
  47. +77 −0 Classes/MainMenu.m
  48. +56 −0 Classes/MultiPlayerGame.h
  49. +238 −0 Classes/MultiPlayerGame.m
  50. +20 −0 Classes/NSDataExtensions.h
  51. +128 −0 Classes/NSDataExtensions.m
  52. +34 −0 Classes/Opponent.h
  53. +96 −0 Classes/Opponent.m
  54. +176 −0 Classes/Player.h
  55. +711 −0 Classes/Player.m
  56. +42 −0 Classes/PunchAction.h
  57. +115 −0 Classes/PunchAction.m
  58. +40 −0 Classes/ReplaceLayerAction.h
  59. +100 −0 Classes/ReplaceLayerAction.m
  60. +32 −0 Classes/RotateAction.h
  61. +71 −0 Classes/RotateAction.m
  62. +25 −0 Classes/SinglePlayerGame.h
  63. +131 −0 Classes/SinglePlayerGame.m
  64. +25 −0 Classes/Splash.h
  65. +38 −0 Classes/Splash.m
  66. +27 −0 Classes/State.h
  67. +46 −0 Classes/State.m
  68. +74 −0 Classes/TwiztLeague.h
  69. +301 −0 Classes/TwiztLeague.m
  70. +5 −0 README
  71. BIN  Resources/Default.png
  72. +32 −0 Resources/Info.plist
  73. +15 −0 Resources/fonts/numbers.fnt
  74. BIN  Resources/fonts/numbers.png
  75. BIN  Resources/fps_images.png
  76. BIN  Resources/grossini_dance_atlas.png
  77. BIN  Resources/images/b_back.png
  78. BIN  Resources/images/b_back_s.png
  79. BIN  Resources/images/b_go.png
  80. BIN  Resources/images/b_go_s.png
  81. BIN  Resources/images/b_human.png
  82. BIN  Resources/images/b_human_s.png
  83. BIN  Resources/images/b_league.png
  84. BIN  Resources/images/b_league_s.png
  85. BIN  Resources/images/b_machine.png
  86. BIN  Resources/images/b_machine_s.png
  87. BIN  Resources/images/b_menu.png
  88. BIN  Resources/images/b_menu_s.png
  89. BIN  Resources/images/b_more.png
  90. BIN  Resources/images/b_more_s.png
  91. BIN  Resources/images/b_replay.png
  92. BIN  Resources/images/b_replay_s.png
  93. BIN  Resources/images/bg.png
  94. BIN  Resources/images/bonuses.png
  95. BIN  Resources/images/energy.png
  96. BIN  Resources/images/flake.png
  97. BIN  Resources/images/game_over_f.png
  98. BIN  Resources/images/game_over_s.png
  99. BIN  Resources/images/glove.png
  100. BIN  Resources/images/head.png
  101. BIN  Resources/images/head_p.png
  102. BIN  Resources/images/icon.png
  103. BIN  Resources/images/league.png
  104. BIN  Resources/images/menu.png
  105. BIN  Resources/images/name.png
  106. BIN  Resources/images/name_bg.png
  107. BIN  Resources/images/opponent.png
  108. BIN  Resources/images/spring.png
  109. BIN  Resources/images/twizt.png
  110. BIN  Resources/sounds/hit.wav
  111. BIN  Resources/sounds/punch.wav
  112. +7 −0 libs/Chipmunk/CMakeLists.txt
  113. +63 −0 libs/Chipmunk/Demo/CMakeLists.txt
  114. +124 −0 libs/Chipmunk/Demo/Demo1.m
  115. +100 −0 libs/Chipmunk/Demo/Demo2.m
  116. +108 −0 libs/Chipmunk/Demo/Demo3.m
  117. +114 −0 libs/Chipmunk/Demo/Demo4.m
  118. +124 −0 libs/Chipmunk/Demo/Demo5.m
  119. +143 −0 libs/Chipmunk/Demo/Demo6.m
  120. +262 −0 libs/Chipmunk/Demo/Demo7.m
  121. +1 −0  libs/Chipmunk/Demo/build.sh
  122. +14 −0 libs/Chipmunk/Demo/main.h
  123. +333 −0 libs/Chipmunk/Demo/main.m
  124. +20 −0 libs/Chipmunk/LICENSE.txt
  125. +47 −0 libs/Chipmunk/README.txt
  126. +944 −0 libs/Chipmunk/chipmunk-docs.html
  127. +58 −0 libs/Chipmunk/src/CMakeLists.txt
  128. +69 −0 libs/Chipmunk/src/chipmunk.c
  129. +91 −0 libs/Chipmunk/src/chipmunk.h
  130. +263 −0 libs/Chipmunk/src/cpArbiter.c
  131. +85 −0 libs/Chipmunk/src/cpArbiter.h
  132. +114 −0 libs/Chipmunk/src/cpArray.c
  133. +45 −0 libs/Chipmunk/src/cpArray.h
  134. +46 −0 libs/Chipmunk/src/cpBB.c
  135. +53 −0 libs/Chipmunk/src/cpBB.h
  136. +180 −0 libs/Chipmunk/src/cpBody.c
  137. +132 −0 libs/Chipmunk/src/cpBody.h
  138. +390 −0 libs/Chipmunk/src/cpCollision.c
  139. +23 −0 libs/Chipmunk/src/cpCollision.h
  140. +219 −0 libs/Chipmunk/src/cpHashSet.c
  141. +79 −0 libs/Chipmunk/src/cpHashSet.h
  142. +553 −0 libs/Chipmunk/src/cpJoint.c
  143. +122 −0 libs/Chipmunk/src/cpJoint.h
  144. +139 −0 libs/Chipmunk/src/cpPolyShape.c
  145. +92 −0 libs/Chipmunk/src/cpPolyShape.h
  146. +244 −0 libs/Chipmunk/src/cpShape.c
  147. +141 −0 libs/Chipmunk/src/cpShape.h
  148. +530 −0 libs/Chipmunk/src/cpSpace.c
  149. +120 −0 libs/Chipmunk/src/cpSpace.h
  150. +455 −0 libs/Chipmunk/src/cpSpaceHash.c
  151. +100 −0 libs/Chipmunk/src/cpSpaceHash.h
  152. +63 −0 libs/Chipmunk/src/cpVect.c
  153. +108 −0 libs/Chipmunk/src/cpVect.h
  154. +68 −0 libs/Chipmunk/src/prime.h
  155. +1 −0  libs/README
  156. +68 −0 libs/TouchJSON/CDataScanner.h
  157. +270 −0 libs/TouchJSON/CDataScanner.m
  158. +37 −0 libs/TouchJSON/Extensions/CDataScanner_Extensions.h
  159. +80 −0 libs/TouchJSON/Extensions/CDataScanner_Extensions.m
  160. +36 −0 libs/TouchJSON/Extensions/NSCharacterSet_Extensions.h
  161. +48 −0 libs/TouchJSON/Extensions/NSCharacterSet_Extensions.m
  162. +36 −0 libs/TouchJSON/Extensions/NSDictionary_JSONExtensions.h
  163. +41 −0 libs/TouchJSON/Extensions/NSDictionary_JSONExtensions.m
  164. +44 −0 libs/TouchJSON/Extensions/NSScanner_Extensions.h
  165. +118 −0 libs/TouchJSON/Extensions/NSScanner_Extensions.m
  166. +59 −0 libs/TouchJSON/JSON/CJSONDeserializer.h
  167. +84 −0 libs/TouchJSON/JSON/CJSONDeserializer.m
  168. +43 −0 libs/TouchJSON/JSON/CJSONScanner.h
  169. +536 −0 libs/TouchJSON/JSON/CJSONScanner.m
  170. +45 −0 libs/TouchJSON/JSON/CJSONSerializer.h
  171. +184 −0 libs/TouchJSON/JSON/CJSONSerializer.m
  172. +19 −0 libs/Tremor/CHANGELOG
  173. +28 −0 libs/Tremor/COPYING
  174. +38 −0 libs/Tremor/Makefile.am
  175. +46 −0 libs/Tremor/README
  176. +49 −0 libs/Tremor/Version_script.in
  177. +243 −0 libs/Tremor/asm_arm.h
  178. +120 −0 libs/Tremor/autogen.sh
  179. +130 −0 libs/Tremor/backends.h
  180. +265 −0 libs/Tremor/bitwise.c
  181. +453 −0 libs/Tremor/block.c
  182. +24 −0 libs/Tremor/block.h
  183. +371 −0 libs/Tremor/codebook.c
  184. +102 −0 libs/Tremor/codebook.h
  185. +92 −0 libs/Tremor/codec_internal.h
  186. +25 −0 libs/Tremor/config_types.h
  187. +131 −0 libs/Tremor/configure.in
  188. +435 −0 libs/Tremor/floor0.c
  189. +441 −0 libs/Tremor/floor1.c
  190. +1,126 −0 libs/Tremor/framing.c
  191. +356 −0 libs/Tremor/info.c
  192. +202 −0 libs/Tremor/ivorbiscodec.h
  193. +130 −0 libs/Tremor/ivorbisfile.h
  194. +136 −0 libs/Tremor/lsp_lookup.h
  195. +322 −0 libs/Tremor/mapping0.c
  196. +510 −0 libs/Tremor/mdct.c
  197. +52 −0 libs/Tremor/mdct.h
  198. +540 −0 libs/Tremor/mdct_lookup.h
  199. +244 −0 libs/Tremor/misc.h
  200. +206 −0 libs/Tremor/ogg.h
  201. +64 −0 libs/Tremor/os.h
  202. +88 −0 libs/Tremor/os_types.h
  203. +50 −0 libs/Tremor/registry.c
  204. +40 −0 libs/Tremor/registry.h
  205. +342 −0 libs/Tremor/res012.c
  206. +439 −0 libs/Tremor/sharedbook.c
  207. +113 −0 libs/Tremor/synthesis.c
  208. +1,586 −0 libs/Tremor/vorbisfile.c
  209. +83 −0 libs/Tremor/window.c
  210. +27 −0 libs/Tremor/window.h
  211. +2,084 −0 libs/Tremor/window_lookup.h
  212. +109 −0 libs/cocos2d/Action.h
  213. +232 −0 libs/cocos2d/Action.m
  214. +92 −0 libs/cocos2d/ActionManager.h
  215. +352 −0 libs/cocos2d/ActionManager.m
  216. +78 −0 libs/cocos2d/AtlasNode.h
  217. +173 −0 libs/cocos2d/AtlasNode.m
  218. +149 −0 libs/cocos2d/AtlasSprite.h
  219. +525 −0 libs/cocos2d/AtlasSprite.m
  220. +73 −0 libs/cocos2d/AtlasSpriteManager.h
  221. +339 −0 libs/cocos2d/AtlasSpriteManager.m
  222. +125 −0 libs/cocos2d/BitmapFontAtlas.h
  223. +461 −0 libs/cocos2d/BitmapFontAtlas.m
  224. +69 −0 libs/cocos2d/Camera.h
  225. +158 −0 libs/cocos2d/Camera.m
  226. +57 −0 libs/cocos2d/CameraAction.h
  227. +127 −0 libs/cocos2d/CameraAction.m
  228. +484 −0 libs/cocos2d/CocosNode.h
  229. +718 −0 libs/cocos2d/CocosNode.m
  230. +277 −0 libs/cocos2d/Director.h
  231. +908 −0 libs/cocos2d/Director.m
  232. +58 −0 libs/cocos2d/DrawingPrimitives.h
  233. +150 −0 libs/cocos2d/DrawingPrimitives.m
  234. +72 −0 libs/cocos2d/EaseAction.h
  235. +230 −0 libs/cocos2d/EaseAction.m
  236. +32 −0 libs/cocos2d/Grabber.h
  237. +74 −0 libs/cocos2d/Grabber.m
  238. +108 −0 libs/cocos2d/Grid.h
  239. +480 −0 libs/cocos2d/Grid.m
  240. +191 −0 libs/cocos2d/Grid3DAction.h
  241. +522 −0 libs/cocos2d/Grid3DAction.m
  242. +156 −0 libs/cocos2d/GridAction.h
  243. +348 −0 libs/cocos2d/GridAction.m
  244. +99 −0 libs/cocos2d/InstantAction.h
  245. +223 −0 libs/cocos2d/InstantAction.m
  246. +356 −0 libs/cocos2d/IntervalAction.h
  247. +1,124 −0 libs/cocos2d/IntervalAction.m
  248. +50 −0 libs/cocos2d/Label.h
  249. +86 −0 libs/cocos2d/Label.m
  250. +43 −0 libs/cocos2d/LabelAtlas.h
  251. +136 −0 libs/cocos2d/LabelAtlas.m
  252. +112 −0 libs/cocos2d/Layer.h
  253. +337 −0 libs/cocos2d/Layer.m
  254. +74 −0 libs/cocos2d/Menu.h
  255. +456 −0 libs/cocos2d/Menu.m
  256. +249 −0 libs/cocos2d/MenuItem.h
Sorry, we could not display the entire diff because too many files (324) changed.
60 Classes/AppController.h
@@ -0,0 +1,60 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "GameOver.h"
+#import "MainMenu.h"
+#import "Game.h"
+#import "Link.h"
+#import "State.h"
+#import "Opponent.h"
+#import "EnterName.h"
+#import "TwiztLeague.h"
+#import "LeaguePlayers.h"
+#import "LeagueLeaderboard.h"
+
+@interface AppController : NSObject
+ <
+ UIApplicationDelegate,
+ GameDelegate,
+ GameOverDelegate,
+ MainMenuDelegate,
+ LinkDelegate,
+ OpponentDelegate,
+ EnterNameDelegate,
+ LeaguePlayersDelegate,
+ LeagueLeaderboardDelegate
+ >
+{
+ UIWindow *window;
+ Scene *scene;
+ Layer *currentLayer;
+ Link *link;
+ State *state;
+ TwiztLeague *league;
+ int gameState;
+ int opponent;
+
+ bool youWin;
+ int score;
+ NSString *opponentName;
+ NSString *opponentID;
+}
+
+- (void) mainMenu;
+- (void) enterName;
+
+@end
+
365 Classes/AppController.m
@@ -0,0 +1,365 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "AppController.h"
+#import "ReplaceLayerAction.h"
+#import "SinglePlayerGame.h"
+#import "MultiPlayerGame.h"
+#import "PASoundMgr.h"
+#import "Empty.h"
+#import "Splash.h"
+
+typedef enum {
+ StateNone,
+ StateMenu,
+ StateControls,
+ StateSingleOpponent,
+ StateSingle,
+ StateMultiPick,
+ StateMulti,
+ StateSingleOver,
+ StateMultiOver,
+ StateLeaguePlayers,
+} AppState;
+
+
+@implementation AppController
+
+- (void) applicationDidFinishLaunching:(UIApplication*)application
+{
+ application.idleTimerDisabled = YES; // we don't want the screen to sleep during our game
+
+
+ window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ [window setMultipleTouchEnabled:YES];
+
+ //[Director useFastDirector]; // causing prblems with GKPeerPicker
+
+ // before creating any layer, set the landscape mode
+ [[Director sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];
+
+ [[Director sharedDirector] attachInView:window];
+
+ // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
+ // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
+ // You can change anytime.
+ [Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
+
+
+ // add layer
+ scene = [Scene node];
+
+ Sprite *bg = [Sprite spriteWithFile:@"bg.png"];
+ bg.anchorPoint = cpvzero;
+ [scene addChild:bg z:0];
+
+ currentLayer = nil;
+
+ [MenuItemFont setFontSize:40];
+
+ [PASoundMgr sharedSoundManager];
+
+ link = nil;
+
+ [window makeKeyAndVisible];
+
+ [[Director sharedDirector] runWithScene: scene];
+
+ Splash *splash = [Splash node];
+ [scene addChild:splash z:1];
+ currentLayer = splash;
+
+ gameState = StateNone;
+
+ state = [[State alloc] init];
+
+ league = [[TwiztLeague alloc] initWithAppID:[NSString stringWithCString:APP_ID] secret:[NSString stringWithCString:SECRET]];
+ [league setPlayerName:state.name];
+
+ [self mainMenu];
+}
+
+
+
+- (void) dealloc
+{
+ [opponentID release];
+ [opponentName release];
+ [league release];
+ [state release];
+ [link release];
+ [window release];
+ [super dealloc];
+}
+
+
+
+// getting a call, pause the game
+-(void) applicationWillResignActive:(UIApplication *)application
+{
+ [[Director sharedDirector] pause];
+}
+
+
+
+// call got rejected
+-(void) applicationDidBecomeActive:(UIApplication *)application
+{
+ [[Director sharedDirector] resume];
+}
+
+
+
+// purge memroy
+- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
+ [[TextureMgr sharedTextureMgr] removeAllTextures];
+}
+
+
+
+// next delta time will be zero
+-(void) applicationSignificantTimeChange:(UIApplication *)application
+{
+ [[Director sharedDirector] setNextDeltaTimeZero:YES];
+}
+
+
+
+- (void) mainMenu {
+ if (gameState != StateMenu) {
+ gameState = StateMenu;
+
+ MainMenu *menu = [[[MainMenu alloc] init:self] autorelease];
+ ReplaceLayerAction *replaceScreen = [[[ReplaceLayerAction alloc] initWithScene:scene layer:menu replaceLayer:currentLayer] autorelease];
+ replaceScreen.reverse = true;
+ [scene runAction: replaceScreen];
+ currentLayer = menu;
+ }
+}
+
+
+
+- (void) opponentSelected:(int)_opponent {
+ opponent = _opponent;
+
+ gameState = StateSingle;
+
+ SinglePlayerGame *game = [[[SinglePlayerGame alloc] initWithDelegate:self opponent:_opponent] autorelease];
+ if ([league getTotalGames] > 3) game.showHint = false;
+ ReplaceLayerAction *replaceScreen = [[[ReplaceLayerAction alloc] initWithScene: scene layer:game replaceLayer:currentLayer] autorelease];
+ [scene runAction: replaceScreen];
+ currentLayer = game;
+}
+
+
+
+- (void) startSinglePlayer {
+ gameState = StateSingleOpponent;
+
+ Opponent *o = [[[Opponent alloc] init:self] autorelease];
+ ReplaceLayerAction *replaceScreen = [[[ReplaceLayerAction alloc] initWithScene: scene layer:o replaceLayer:currentLayer] autorelease];
+ [scene runAction: replaceScreen];
+ currentLayer = o;
+}
+
+
+
+- (void) startMultiPlayer {
+ gameState = StateMultiPick;
+
+ if (!state.name) {
+ [self enterName];
+ return;
+ }
+
+ if (!link) {
+ link = [[Link alloc] initWithID:@"Punchball" name:state.name delegate:self];
+ }
+
+ Empty *l = [[[Empty alloc] init] autorelease];
+ ReplaceLayerAction *replaceScreen = [[[ReplaceLayerAction alloc] initWithScene: scene layer:l replaceLayer:currentLayer] autorelease];
+ [scene runAction: replaceScreen];
+ currentLayer = l;
+
+ [link startPicker];
+}
+
+
+
+-(void) linkConnected: (LinkRole) role {
+
+ gameState = StateMulti;
+
+ MultiPlayerGame *game;
+ if (role == RoleServer) {
+ game = [[[MultiPlayerGame alloc] initWithDelegate:self link:link left:true] autorelease];
+ } else {
+ game = [[[MultiPlayerGame alloc] initWithDelegate:self link:link left:false] autorelease];
+ }
+ if ([league getTotalGames] > 3) game.showHint = false;
+
+ ReplaceLayerAction *replaceScreen = [[[ReplaceLayerAction alloc] initWithScene: scene layer:game replaceLayer:currentLayer] autorelease];
+ [scene runAction: replaceScreen];
+ currentLayer = game;
+}
+
+
+
+-(void) linkDisconnected {
+ NSLog(@">>> linkDisconnected");
+ [self mainMenu];
+}
+
+
+
+- (void) gameOver: (bool)_youWin score:(int)_score opponentName:(NSString*)_opponentName
+{
+ youWin = _youWin;
+ score = _score;
+ opponentName = [_opponentName copy];
+
+ if (!state.name) {
+ [self enterName];
+ return;
+ } else {
+ [league setPlayerName:state.name];
+ }
+
+ bool submitBoth;
+ if (gameState == StateMulti) {
+ opponentID = [[NSString stringWithFormat:@"ID_%d_%@", link.peerUniqueID, opponentName] retain];
+ submitBoth = false;
+ gameState = StateMultiOver;
+ [link reset];
+ } else { // if (gameState == StateSingle) {
+ opponentID = [[NSString stringWithFormat:@"ID_0_%@", opponentName] retain];
+ submitBoth = true;
+ gameState = StateSingleOver;
+ }
+
+ GameOver *go = [[[GameOver alloc] initWithDelegate:self youWin:youWin score:score opponentName:opponentName] autorelease];
+ league.delegate = go;
+ [go setBestScore: [league addGame:opponentID opponentName:opponentName score:score submitBoth:false]];
+
+ ReplaceLayerAction *replaceScreen = [[[ReplaceLayerAction alloc] initWithScene:scene layer:go replaceLayer:currentLayer] autorelease];
+ [scene runAction: replaceScreen];
+ currentLayer = go;
+}
+
+
+
+-(void) onGameOverReplay {
+ league.delegate = nil;
+
+ if (gameState == StateMultiOver) {
+ [link resync];
+
+ } else if (gameState == StateSingleOver) {
+ [self opponentSelected:opponent];
+
+ }
+}
+
+
+
+-(void) onGameOverMenu {
+ league.delegate = nil;
+
+ if (gameState == StateMultiOver) {
+ [link invalidateSession];
+ }
+
+ [self mainMenu];
+}
+
+
+
+- (void) leaderboard {
+ league.delegate = nil;
+
+ [self onLeaguePlayer:opponentID];
+}
+
+
+
+- (void) league {
+ gameState = StateLeaguePlayers;
+ LeaguePlayers *l = [[[LeaguePlayers alloc] init:self league:league window:window] autorelease];
+ ReplaceLayerAction *replaceScreen = [[[ReplaceLayerAction alloc] initWithScene:scene layer:l replaceLayer:currentLayer] autorelease];
+ [scene runAction: replaceScreen];
+ currentLayer = l;
+}
+
+
+
+- (void) enterName {
+ EnterName *l = [[[EnterName alloc] initWithDelegate:self window:window] autorelease];
+ ReplaceLayerAction *replaceScreen = [[[ReplaceLayerAction alloc] initWithScene:scene layer:l replaceLayer:currentLayer] autorelease];
+ [scene runAction: replaceScreen];
+ currentLayer = l;
+}
+
+
+
+- (void) nameEntered: (NSString*)name {
+ state.name = name;
+ if (gameState == StateSingle) {
+ [self gameOver:youWin score:score opponentName:opponentName];
+ } else { // StateMultiPick
+ [self startMultiPlayer];
+ }
+}
+
+
+
+-(void) onLeagueMenu {
+ [self mainMenu];
+}
+
+
+
+-(void) onLeaguePlayer:(NSString*)playerID {
+ NSLog(@"onLeaguePlayer=%@", playerID);
+ LeagueLeaderboard *l = [[[LeagueLeaderboard alloc] init:self league:league window:window playerID:playerID] autorelease];
+ ReplaceLayerAction *replaceScreen = [[[ReplaceLayerAction alloc] initWithScene:scene layer:l replaceLayer:currentLayer] autorelease];
+ [scene runAction: replaceScreen];
+ currentLayer = l;
+}
+
+
+
+-(void) onLeagueBack {
+ if (gameState == StateLeaguePlayers) {
+ LeaguePlayers *l = [[[LeaguePlayers alloc] init:self league:league window:window] autorelease];
+ ReplaceLayerAction *replaceScreen = [[[ReplaceLayerAction alloc] initWithScene:scene layer:l replaceLayer:currentLayer] autorelease];
+ replaceScreen.reverse = true;
+ [scene runAction: replaceScreen];
+ currentLayer = l;
+
+ } else {
+ GameOver *go = [[[GameOver alloc] initWithDelegate:self youWin:youWin score:score opponentName:opponentName] autorelease];
+ [go setBestScore: [league getBestScore:opponentID]];
+ [go setRank: [league getRank:opponentID]];
+
+ ReplaceLayerAction *replaceScreen = [[[ReplaceLayerAction alloc] initWithScene:scene layer:go replaceLayer:currentLayer] autorelease];
+ replaceScreen.reverse = true;
+ [scene runAction: replaceScreen];
+ currentLayer = go;
+
+ }
+}
+
+@end
31 Classes/BonusAction.h
@@ -0,0 +1,31 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "cocos2d.h"
+#import "chipmunk.h"
+
+@interface BonusAction : IntervalAction {
+ cpVect startPosition;
+ cpVect delta;
+ AtlasSpriteManager *sm;
+ AtlasSprite *sprite;
+}
+
++(id) actionWithType:(int)type pos:(cpVect)pos sm:(AtlasSpriteManager*)_sm;
+
+-(id) initWithType:(int)type pos:(cpVect)pos sm:(AtlasSpriteManager*)_sm;
+
+@end
107 Classes/BonusAction.m
@@ -0,0 +1,107 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "BonusAction.h"
+#import "Config.h"
+#import "Common.h"
+
+@implementation BonusAction
+
++(id) actionWithType:(int)type pos:(cpVect)pos sm:(AtlasSpriteManager*)_sm;
+{
+ return [[[self alloc] initWithType:type pos:pos sm:_sm] autorelease];
+}
+
+-(id) initWithType:(int)type pos:(cpVect)pos sm:(AtlasSpriteManager*)_sm {
+ if (type > 10) {
+ [super initWithDuration:BONUS_LONG_TIP_TIME];
+ } else {
+ [super initWithDuration:BONUS_TIP_TIME];
+ }
+
+ startPosition = pos;
+
+ float a = fmod(arc4random(), D_PI);
+ delta = cpvmult(cpvforangle(a), BONUS_TIP_DIST);
+
+ sm = _sm;
+
+ if (type < 0) {
+ sprite = [AtlasSprite spriteWithRect:CGRectMake((-type - 1) * 40, 64, 40, 32) spriteManager:sm];
+
+ } else if (type < 9) {
+ sprite = [AtlasSprite spriteWithRect:CGRectMake((type - 1) * 40, 0, 40, 32) spriteManager:sm];
+
+ } else if (type == 10) {
+ // perfect hit
+ sprite = [AtlasSprite spriteWithRect:CGRectMake(0, 32, 120, 32) spriteManager:sm];
+
+ } else if (type == 11) {
+ // x2
+ sprite = [AtlasSprite spriteWithRect:CGRectMake(280, 32, 120, 32) spriteManager:sm];
+
+ } else if (type == 12) {
+ // x3
+ sprite = [AtlasSprite spriteWithRect:CGRectMake(400, 32, 120, 32) spriteManager:sm];
+
+ } else if (type == 20) {
+ sprite = [AtlasSprite spriteWithRect:CGRectMake(120, 32, 40, 32) spriteManager:sm];
+
+ } else if (type == 21) {
+ sprite = [AtlasSprite spriteWithRect:CGRectMake(160, 32, 40, 32) spriteManager:sm];
+
+ } else if (type == 22) {
+ sprite = [AtlasSprite spriteWithRect:CGRectMake(200, 32, 80, 32) spriteManager:sm];
+
+ } else {
+ return nil;
+ }
+
+ sprite.position = pos;
+
+ return self;
+}
+
+
+
+-(void)start {
+ [sm addChild:sprite z:1];
+ [super start];
+}
+
+
+
+-(void)stop {
+ [super stop];
+ [sm removeChild:sprite cleanup:YES];
+}
+
+
+
+-(void) update: (ccTime) t
+{
+ if (t <= 0.1) {
+ [sprite setOpacity: 255.0f * t * 10.0f];
+ } else if (t > 0.5) {
+ [sprite setOpacity:255 - (255.0f * (t - 0.5f) * 2.0f)];
+ }
+
+ [sprite setPosition: ccp( (startPosition.x + delta.x * t ), (startPosition.y + delta.y * t ) )];
+}
+
+
+
+@end
27 Classes/Common.h
@@ -0,0 +1,27 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#define D_PI 6.28318530717959f
+
+#define H_PI 1.570796327f
+
+inline float normAngle(float a) {
+ return fmodf(a + D_PI, D_PI);
+}
+
+inline float halfAngle(float a) {
+ return fmodf(a + D_PI, M_PI);
+}
25 Classes/Common.m
@@ -0,0 +1,25 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#define D_PI 6.28318530717959f
+
+float normAngle(float a) {
+ return fmodf(a + D_PI, D_PI);
+}
+
+float halfAngle(float a) {
+ return fmodf(a + D_PI, M_PI);
+}
50 Classes/ComputerPlayer.h
@@ -0,0 +1,50 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "Player.h"
+
+@interface ComputerPlayer : Player {
+ Player *otherPlayer;
+
+ float maxSlideDelay; // max delay between slides in seconds
+ float maxPunchDelay; // max delay between punches in seconds
+ float maxSweep;
+
+ int slideMax;
+ int hitPrecision; // closer to 0 is better
+
+ float turnTime;
+ float punchTime;
+ float slideTime;
+
+ bool firstCycle;
+}
+
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ color:(int)_color
+ game:(Game*)game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer;
+
+
+@end
123 Classes/ComputerPlayer.m
@@ -0,0 +1,123 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ComputerPlayer.h"
+
+
+@implementation ComputerPlayer
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ color:(int)_color
+ game:(Game*)_game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer
+{
+ [super initWithPos:pos
+ left:left
+ color:_color
+ game:_game
+ headSM:_headSM
+ gloveSM:_gloveSM
+ springSM:_springSM
+ bonusSM:_bonusSM
+ headParticleSM:_headParticleSM
+ space:_space];
+
+ holdPosition = false;
+
+ otherPlayer = _otherPlayer;
+ maxSweep = MAX_SWEEP;
+
+ firstCycle = true;
+
+ return self;
+}
+
+
+
+-(void) step:(ccTime) dt {
+ [super step:dt];
+
+ if (firstCycle) {
+ slideTime = time + fabs(fmod(arc4random(), 100)) * maxSlideDelay / 100.0f;
+ turnTime = time + fabs(fmod(arc4random(), 100)) * maxPunchDelay / 100.0f;
+ punchTime = turnTime + fabs(fmod(arc4random(), 100)) * maxSweep / 100.0f;
+ firstCycle = false;
+ }
+
+ if (punchTime < time) {
+ cpVect aim;
+ aim.x = otherPlayer.headBody->p.x + fabs(fmod(arc4random(), hitPrecision * 2)) - hitPrecision;
+ aim.y = otherPlayer.headBody->p.y + fabs(fmod(arc4random(), hitPrecision * 2)) - hitPrecision;
+
+ [self punch:aim];
+
+ turnTime = time + fabs(fmod((float)arc4random(), 100.0f)) * maxPunchDelay / 100.0f;
+ punchTime = turnTime + fabs(fmod(arc4random(), 100)) * maxSweep / 100.0f;
+
+ } else if (turnTime < time) {
+ cpVect aim;
+ aim.x = otherPlayer.headBody->p.x + fabs(fmod(arc4random(), hitPrecision * 2)) - hitPrecision;
+ aim.y = otherPlayer.headBody->p.y + fabs(fmod(arc4random(), hitPrecision * 2)) - hitPrecision;
+
+ [self turn:aim];
+
+ } else if (slideTime < time) {
+ cpVect slideTo;
+ slideTo.x = fmod(arc4random(), (slideMax * 2)) - slideMax;
+ slideTo.y = fmod(arc4random(), (slideMax * 2)) - slideMax;
+
+ if (slideTo.x > 0) {
+ slideTo.x += SLIDE_TARGET_APROX;
+ } else {
+ slideTo.x -= SLIDE_TARGET_APROX;
+ }
+
+ if (slideTo.y > 0) {
+ slideTo.y += SLIDE_TARGET_APROX;
+ } else {
+ slideTo.y -= SLIDE_TARGET_APROX;
+ }
+
+ slideTo.x += headBody->p.y;
+ slideTo.y += headBody->p.x;
+
+ if (slideTo.x < 40) {
+ slideTo.x = 40;
+ } else if (slideTo.x > 440) {
+ slideTo.x = 440;
+ }
+
+ if (slideTo.y < 40) {
+ slideTo.y = 40;
+ } else if (slideTo.y > 280) {
+ slideTo.y = 280;
+ }
+
+ [self slideTo: &slideTo final:true];
+
+ slideTime = time +fmod((float)arc4random(), 100.0f) * maxSlideDelay / 100.0f;
+ }
+
+}
+
+@end
34 Classes/ComputerPlayer1.h
@@ -0,0 +1,34 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ComputerPlayer.h"
+
+@interface ComputerPlayer1 : ComputerPlayer {
+
+}
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ game:(Game*)game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer;
+
+@end
53 Classes/ComputerPlayer1.m
@@ -0,0 +1,53 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ComputerPlayer1.h"
+
+
+@implementation ComputerPlayer1
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ game:(Game*)_game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer{
+ [super initWithPos:pos
+ left:left
+ color:1
+ game:_game
+ headSM:_headSM
+ gloveSM:_gloveSM
+ springSM:_springSM
+ bonusSM:_bonusSM
+ headParticleSM:_headParticleSM
+ space:_space
+ otherPlayer:_otherPlayer];
+
+ maxSlideDelay = 3.5f;
+ maxPunchDelay = 1.5f;
+ slideMax = 10;
+ slideSpeed = 150;
+ hitPrecision = 100;
+
+ return self;
+}
+
+@end
35 Classes/ComputerPlayer2.h
@@ -0,0 +1,35 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ComputerPlayer.h"
+
+@interface ComputerPlayer2 : ComputerPlayer {
+
+}
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ game:(Game*)game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer;
+
+
+@end
54 Classes/ComputerPlayer2.m
@@ -0,0 +1,54 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ComputerPlayer2.h"
+
+
+@implementation ComputerPlayer2
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ game:(Game*)_game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer
+{
+ [super initWithPos:pos
+ left:left
+ color:2
+ game:_game
+ headSM:_headSM
+ gloveSM:_gloveSM
+ springSM:_springSM
+ bonusSM:_bonusSM
+ headParticleSM:_headParticleSM
+ space:_space
+ otherPlayer:_otherPlayer];
+
+ maxSlideDelay = 3.0f;
+ maxPunchDelay = 1.25f;
+ slideMax = 57;
+ slideSpeed = 312;
+ hitPrecision = 80;
+
+ return self;
+}
+
+@end
34 Classes/ComputerPlayer3.h
@@ -0,0 +1,34 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ComputerPlayer.h"
+
+@interface ComputerPlayer3 : ComputerPlayer {
+
+}
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ game:(Game*)game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer;
+
+@end
54 Classes/ComputerPlayer3.m
@@ -0,0 +1,54 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ComputerPlayer3.h"
+
+
+@implementation ComputerPlayer3
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ game:(Game*)_game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer
+{
+ [super initWithPos:pos
+ left:left
+ color:3
+ game:_game
+ headSM:_headSM
+ gloveSM:_gloveSM
+ springSM:_springSM
+ bonusSM:_bonusSM
+ headParticleSM:_headParticleSM
+ space:_space
+ otherPlayer:_otherPlayer];
+
+ maxSlideDelay = 2.5f;
+ maxPunchDelay = 1.0f;
+ slideMax = 105;
+ slideSpeed = 475;
+ hitPrecision = 60;
+
+ return self;
+}
+
+@end
35 Classes/ComputerPlayer4.h
@@ -0,0 +1,35 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ComputerPlayer.h"
+
+@interface ComputerPlayer4 : ComputerPlayer {
+
+}
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ game:(Game*)game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer;
+
+
+@end
55 Classes/ComputerPlayer4.m
@@ -0,0 +1,55 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ComputerPlayer4.h"
+
+
+@implementation ComputerPlayer4
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ game:(Game*)_game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer
+{
+ [super initWithPos:pos
+ left:left
+ color:4
+ game:_game
+ headSM:_headSM
+ gloveSM:_gloveSM
+ springSM:_springSM
+ bonusSM:_bonusSM
+ headParticleSM:_headParticleSM
+ space:_space
+ otherPlayer:_otherPlayer];
+
+
+ maxSlideDelay = 2.0f;
+ maxPunchDelay = 0.75f;
+ slideMax = 152;
+ slideSpeed = 637;
+ hitPrecision = 50;
+
+ return self;
+}
+
+@end
35 Classes/ComputerPlayer5.h
@@ -0,0 +1,35 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ComputerPlayer.h"
+
+@interface ComputerPlayer5 : ComputerPlayer {
+
+}
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ game:(Game*)game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer;
+
+
+@end
54 Classes/ComputerPlayer5.m
@@ -0,0 +1,54 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ComputerPlayer5.h"
+
+
+@implementation ComputerPlayer5
+
+-(id) initWithPos:(cpVect)pos
+ left:(bool)left
+ game:(Game*)_game
+ headSM:(AtlasSpriteManager*)_headSM
+ gloveSM:(AtlasSpriteManager*)_gloveSM
+ springSM:(AtlasSpriteManager*)_springSM
+ bonusSM:(AtlasSpriteManager*)_bonusSM
+ headParticleSM:(AtlasSpriteManager*)_headParticleSM
+ space:(cpSpace*)_space
+ otherPlayer:(Player*)_otherPlayer
+{
+ [super initWithPos:pos
+ left:left
+ color:5
+ game:_game
+ headSM:_headSM
+ gloveSM:_gloveSM
+ springSM:_springSM
+ bonusSM:_bonusSM
+ headParticleSM:_headParticleSM
+ space:_space
+ otherPlayer:_otherPlayer];
+
+ maxSlideDelay = 1.50f;
+ maxPunchDelay = 0.50f;
+ slideMax = 200;
+ slideSpeed = 800;
+ hitPrecision = 40;
+
+ return self;
+}
+
+@end
71 Classes/Config.h
@@ -0,0 +1,71 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#define BORDER_WITDH 10000 // border width - increases this if player or glove get stuck of out bounds
+#define INNER_BORDER 0
+#define DAMPING 0.6 // how much resistance space will have. 1.0 = no resistance
+#define SLIDE_TOUCH_APROX 40 // radius in pixels when sliding touch is registered
+#define COLLISION_TYPE_BORDER 4
+
+#define GLOVE_DIST_MIN 50.0f
+#define GLOVE_DIST_MAX 250.0f
+
+#define COLLISION_TYPE_HEAD 1
+#define COLLISION_TYPE_GLOVE 2
+
+#define MIN_PUNCH_TIME 0.10f
+#define MAX_PUNCH_TIME 0.15f
+
+#define MAX_PUNCH_IMPACT_TIME 0.5f // in seconds
+#define MAX_HIT_IMPACT_TIME 1.0f // in seconds
+
+#define HIT_EFFECT_TIME 0.3f
+#define MAX_HIT_EFFECT_SPEED 150.0f
+
+#define MAX_HEALTH 20.0f
+
+#define DEFAULT_SLIDE_SPEED 1200 // max pixels per second
+
+#define SLIDE_TARGET_APROX 10.0f // by how much pixels head should be from slide target to stop sliding
+
+#define ROTATE_SPEED 12.56 // radians per second 2*pi = 360 degrees
+
+#define ROTATE_APROX 0.17
+
+#define NETWORK_SYNC_DELAY 0.05f // in seconds
+#define NETWORK_SYNC_CORRECTION_INTERVAL 0.5f
+#define NETWORK_SLIDE_INTERVAL 0.1f // how frequently send slide updates in seconds
+
+#define HIT_SCORE 10.0f
+#define PERFECT_HIT_THRESHOLD 0.9f
+#define PERFECT_HIT_SCORE 20
+#define STREAK_2_SCORE 3
+#define STREAK_3_SCORE 5
+
+#define BONUS_TIP_TIME 3.0f
+#define BONUS_LONG_TIP_TIME 3.0f
+#define BONUS_TIP_DIST 600.0f // in pixels
+
+#define GAME_HINT_TIME 3.0f // in seconds
+
+#define MAX_SWEEP 0.5f
+
+#define PUNCH_POWER_COEF 1.25f // max power = after 1 / PUNCH_POWER_COEF - PUNCH_POWER_BASE seconds = 0.7
+#define PUNCH_POWER_BASE 0.1f
+
+#define APP_ID "Punchball"
+#define SECRET "leaderboard_secret_key"
+
25 Classes/Empty.h
@@ -0,0 +1,25 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "cocos2d.h"
+#import "chipmunk.h"
+#import "ReplaceLayerAction.h"
+
+
+@interface Empty : Layer <ReplaceLayerActionDelegate> {
+}
+
+@end
26 Classes/Empty.m
@@ -0,0 +1,26 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "Empty.h"
+
+
+@implementation Empty
+
+- (void)layerReplaced
+{
+}
+
+@end
44 Classes/EnterName.h
@@ -0,0 +1,44 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "ReplaceLayerAction.h"
+
+@protocol EnterNameDelegate
+
+- (void) nameEntered: (NSString*)name;
+
+@end
+
+@interface EnterNameView : UIView<UITextFieldDelegate>{
+ UITextField *nameField;
+ id<EnterNameDelegate> delegate;
+}
+
+- (id) initWithDelegate: (id<EnterNameDelegate>)_delegate;
+
+@end
+
+@interface EnterName : Layer<ReplaceLayerActionDelegate, EnterNameDelegate> {
+ id<EnterNameDelegate> delegate;
+ UIWindow *window;
+ EnterNameView *view;
+}
+
+- (id) initWithDelegate: (id<EnterNameDelegate>)_delegate window:(UIWindow*)_window;
+
+@end
+
+
103 Classes/EnterName.m
@@ -0,0 +1,103 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "EnterName.h"
+#import "Common.h"
+
+@implementation EnterName
+
+- (id) initWithDelegate: (id<EnterNameDelegate>)_delegate window:(UIWindow*)_window {
+ [super init];
+
+ delegate = _delegate;
+ window = _window;
+
+ Sprite *bg = [Sprite spriteWithFile:@"name.png"];
+ bg.anchorPoint = cpvzero;
+ [self addChild:bg z:1];
+
+ view = [[EnterNameView alloc] initWithDelegate:self];
+
+ return self;
+}
+
+
+- (void) dealloc {
+ [view release];
+ [super dealloc];
+}
+
+
+- (void)layerReplaced
+{
+ [window addSubview:view];
+}
+
+- (void) nameEntered: (NSString*)name
+{
+ Label *l = [Label labelWithString:name fontName:@"Courier" fontSize:30];
+ l.anchorPoint = cpvzero;
+ l.position = cpv(30, 225);
+ [self addChild:l];
+
+ [view removeFromSuperview];
+ [delegate nameEntered:name];
+}
+
+@end
+
+
+@implementation EnterNameView
+
+- (id) initWithDelegate: (id)_delegate {
+ if (self = [super initWithFrame:CGRectMake(0,0,480,320)]) {
+ self.userInteractionEnabled = true;
+
+ self.transform = CGAffineTransformMakeRotation(H_PI);
+ self.bounds = CGRectMake(-80, -80, 480, 320);
+
+ delegate = _delegate;
+
+ nameField = [[[UITextField alloc] initWithFrame:CGRectMake(30, 60, 420, 40)] autorelease];
+ nameField.font = [UIFont fontWithName:@"Courier" size:30];
+ nameField.returnKeyType = UIReturnKeyDone;
+ nameField.autocapitalizationType = UITextAutocapitalizationTypeWords;
+ nameField.autocorrectionType = UITextAutocorrectionTypeNo;
+ nameField.keyboardType = UIKeyboardTypeAlphabet;
+ nameField.textColor = [UIColor whiteColor];
+ nameField.delegate = self;
+ [self addSubview:nameField];
+
+ [nameField becomeFirstResponder];
+ }
+
+ return self;
+}
+
+
+- (BOOL)textFieldShouldReturn:(UITextField *)textField {
+ NSString *name = [[nameField text] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ if ([name length] == 0) {
+ UIAlertView *popup = [[UIAlertView alloc] initWithTitle:@"Please enter a name" message:@"It will be used to record your highscores as well as identify you in a multiplayer game." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
+ [popup show];
+ } else {
+ [nameField resignFirstResponder];
+ [delegate nameEntered:[nameField text]];
+ }
+ return YES;
+}
+
+@end
103 Classes/Game.h
@@ -0,0 +1,103 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "cocos2d.h"
+#import "chipmunk.h"
+
+#import "Player.h"
+#import "ReplaceLayerAction.h"
+#import "Gestures.h"
+
+@protocol GameDelegate
+
+- (void) gameOver: (bool)_youWin score:(int)_score opponentName:(NSString*)opponentName;
+- (void) mainMenu;
+
+@end
+
+
+@interface Game : Layer<ReplaceLayerActionDelegate, GesturesDelegate> {
+ id<GameDelegate> delegate;
+
+ cpSpace *space;
+
+ AtlasSpriteManager *headSM;
+ AtlasSpriteManager *gloveSM;
+ AtlasSpriteManager *springSM;
+ AtlasSpriteManager *headParticleSM;
+ AtlasSpriteManager *scoreSM;
+ AtlasSpriteManager *bonusSM;
+
+ AtlasSprite *leftScoreBorder;
+ AtlasSprite *leftScore;
+ AtlasSprite *rightScoreBorder;
+ AtlasSprite *rightScore;
+
+ NSMutableArray *gameObjects;
+
+ Player *leftPlayer;
+ Player *rightPlayer;
+ Player *localPlayer;
+
+ Label *leftLabel;
+ Label *rightLabel;
+ Label *scoreLabel;
+
+ Gestures *gestures;
+
+ bool useAccel;
+ bool gameInProgress;
+ bool isSliding;
+
+ NSString *opponentName;
+
+ UIAlertView* pausePopup;
+
+ bool showHint;
+}
+
+@property (nonatomic, readonly) NSMutableArray *gameObjects;
+@property (nonatomic, readonly) Player *rightPlayer;
+@property (nonatomic, assign) bool showHint;
+
+
+-(void) step: (ccTime) dt;
+-(void) updateScores;
+
+-(id) initWithDelegate: (id<GameDelegate>)_delegate;
+
+-(void)touchBegan:(CGPoint)pos;
+-(void)touchMove:(CGPoint)pos final:(bool)final;
+
+
+-(void) pause;
+-(void) resume;
+-(void) menu;
+
+@end
+
+
+@interface GameHintAction : IntervalAction {
+ Layer *layer;
+ Label *label;
+}
+
++(id) hintWithText:(NSString*)text layer:(Layer*)_layer;
+
+-(id) initWithText:(NSString*)text layer:(Layer*)_layer;
+
+@end
+
450 Classes/Game.m
@@ -0,0 +1,450 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "Game.h"
+
+
+static void eachShape(void *ptr, void* unused)
+{
+ cpShape *shape = (cpShape*) ptr;
+ GameObject* gameObject = shape->data;
+ if (gameObject) {
+ [gameObject updatePosition];
+ }
+}
+
+
+
+static int
+gloveHeadCollision(cpShape *a, cpShape *b, cpContact *contacts, int numContacts, cpFloat normal_coef, void *data)
+{
+ GameObjectWrapper *glovePlayerWrapper = a->data;
+ Player *glovePlayer = (Player*)glovePlayerWrapper.target;
+ Player *headPlayer = b->data;
+ Game *game = data;
+
+ if (glovePlayer != headPlayer) {
+ [headPlayer hitHead:glovePlayer contact:contacts];
+ [game updateScores];
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+
+
+static int
+gloveGloveCollision(cpShape *a, cpShape *b, cpContact *contacts, int numContacts, cpFloat normal_coef, void *data)
+{
+ GameObjectWrapper *w1 = a->data;
+ Player *p1 = (Player*)w1.target;
+ GameObjectWrapper *w2 = b->data;
+ Player *p2 = (Player*)w2.target;
+
+ if (!p1.punchAction.isDone) {
+ [p2 hitGlove:p1 contact: contacts];
+ }
+
+ if (!p2.punchAction.isDone) {
+ [p1 hitGlove:p2 contact: contacts];
+ }
+
+ return 1;
+}
+
+
+
+void drawCollisions(void *ptr, void *data)
+{
+ cpArbiter *arb = (cpArbiter *)ptr;
+ for(int i=0; i<arb->numContacts; i++){
+ cpVect v = arb->contacts[i].p;
+ drawPoint( ccp(v.x, v.y) );
+ }
+}
+
+
+
+@implementation Game
+
+
+
+@synthesize gameObjects, rightPlayer, showHint;
+
+
+
+-(id) initWithDelegate: (id)_delegate
+{
+ [super init];
+
+ gameInProgress = true;
+ isSliding = false;
+
+ delegate = _delegate;
+
+ isTouchEnabled = YES;
+ isAccelerometerEnabled = YES;
+
+ leftLabel = [Label labelWithString:@"" fontName:@"Courier" fontSize:22];
+ leftLabel.position = cpv(30, 10);
+ leftLabel.anchorPoint = cpv(0.0, 0.0);
+ [leftLabel setColor: ccc3(229, 229, 229)];
+ [self addChild:leftLabel z:1];
+
+ rightLabel = [Label labelWithString:@"" fontName:@"Courier" fontSize:22];
+ rightLabel.position = cpv(450, 10);
+ rightLabel.anchorPoint = cpv(1.0, 0.0);
+ [rightLabel setColor: ccc3(229, 229, 229)];
+ [self addChild:rightLabel z:1];
+
+ CGSize wins = [[Director sharedDirector] winSize];
+
+ cpInitChipmunk();
+
+ cpBody *staticBody = cpBodyNew(INFINITY, INFINITY);
+ space = cpSpaceNew();
+ space->damping = DAMPING;
+ cpSpaceResizeStaticHash(space, 400.0f, 40);
+ cpSpaceResizeActiveHash(space, 100, 600);
+
+ space->gravity = ccp(0, 0);
+ space->elasticIterations = space->iterations;
+
+ cpShape *shape;
+
+ // bottom
+ shape = cpSegmentShapeNew(staticBody, ccp(-BORDER_WITDH + INNER_BORDER,-BORDER_WITDH + INNER_BORDER), ccp(wins.width + BORDER_WITDH - INNER_BORDER * 2, -BORDER_WITDH + INNER_BORDER), BORDER_WITDH);
+ shape->e = 1.0; shape->u = 0.0; shape->collision_type = COLLISION_TYPE_BORDER;
+ cpSpaceAddStaticShape(space, shape);
+
+ // top
+ shape = cpSegmentShapeNew(staticBody, ccp(-BORDER_WITDH + INNER_BORDER,wins.height + BORDER_WITDH - INNER_BORDER * 2), ccp(wins.width + BORDER_WITDH - INNER_BORDER * 2, wins.height + BORDER_WITDH - INNER_BORDER * 2), BORDER_WITDH);
+ shape->e = 1.0; shape->u = 0.0; shape->collision_type = COLLISION_TYPE_BORDER;
+ cpSpaceAddStaticShape(space, shape);
+
+ // left
+ shape = cpSegmentShapeNew(staticBody, ccp(-BORDER_WITDH + INNER_BORDER,-BORDER_WITDH + INNER_BORDER), ccp(-BORDER_WITDH + INNER_BORDER,wins.height + BORDER_WITDH - INNER_BORDER * 2), BORDER_WITDH);
+ shape->e = 1.0; shape->u = 0.0; shape->collision_type = COLLISION_TYPE_BORDER;
+ cpSpaceAddStaticShape(space, shape);
+
+ // right
+ shape = cpSegmentShapeNew(staticBody, ccp(wins.width + BORDER_WITDH - INNER_BORDER * 2, -BORDER_WITDH + INNER_BORDER), ccp(wins.width + BORDER_WITDH - INNER_BORDER * 2,wins.height + BORDER_WITDH - INNER_BORDER * 2), BORDER_WITDH);
+ shape->e = 1.0; shape->u = 0.0; shape->collision_type = COLLISION_TYPE_BORDER;
+ cpSpaceAddStaticShape(space, shape);
+
+ springSM = [AtlasSpriteManager spriteManagerWithFile:@"spring.png" capacity:10];
+ [self addChild:springSM z:4];
+
+ gloveSM = [AtlasSpriteManager spriteManagerWithFile:@"glove.png" capacity:10];
+ [self addChild:gloveSM z:5];
+
+ headSM = [AtlasSpriteManager spriteManagerWithFile:@"head.png" capacity:10];
+ [self addChild:headSM z:6];
+
+ headParticleSM = [AtlasSpriteManager spriteManagerWithFile:@"head_p.png" capacity:10];
+ [self addChild:headParticleSM z:7];
+
+ scoreSM = [AtlasSpriteManager spriteManagerWithFile:@"energy.png" capacity:10];
+ [self addChild:scoreSM z:1];
+
+ bonusSM = [AtlasSpriteManager spriteManagerWithFile:@"bonuses.png" capacity:20];
+ [self addChild:bonusSM z:2];
+
+ leftScore = [AtlasSprite spriteWithRect:CGRectMake(0, 0, 15, 300) spriteManager:scoreSM];
+ leftScore.anchorPoint = cpvzero;
+ leftScore.position = cpv(10, 10);
+ [scoreSM addChild:leftScore z:1];
+
+
+ rightScore = [AtlasSprite spriteWithRect:CGRectMake(15, 0, 15, 300) spriteManager:scoreSM];
+ rightScore.anchorPoint = cpvzero;
+ rightScore.position = cpv(455, 10);
+ [scoreSM addChild:rightScore z:1];
+
+ scoreLabel = [Label labelWithString:@"0" fontName:@"Courier" fontSize:22];
+ scoreLabel.position = cpv(240, 300);
+ [self addChild:scoreLabel z:1];
+
+ cpSpaceAddCollisionPairFunc(space, COLLISION_TYPE_GLOVE, COLLISION_TYPE_HEAD, &gloveHeadCollision, self);
+ cpSpaceAddCollisionPairFunc(space, COLLISION_TYPE_GLOVE, COLLISION_TYPE_GLOVE, &gloveGloveCollision, self);
+
+ gameObjects = [[NSMutableArray alloc] init];
+
+ leftPlayer = [[[Player alloc] initWithPos:cpv(120, 160)
+ left:true
+ color:0
+ game:self
+ headSM:headSM
+ gloveSM:gloveSM
+ springSM:springSM
+ bonusSM:bonusSM
+ headParticleSM:headParticleSM
+ space:space] autorelease];
+
+ [gameObjects addObject:leftPlayer];
+
+ gestures = [[Gestures alloc] initWithDelegate:self];
+
+ pausePopup = nil;
+
+ showHint = true;
+
+ return self;
+}
+
+
+
+- (void) dealloc
+{
+ [gestures release];
+ [gameObjects release];
+ cpSpaceFree(space);
+ [super dealloc];
+}
+
+
+
+- (void)layerReplaced
+{
+ [self schedule: @selector(step:)];
+ if (showHint) {
+ [self runAction:[GameHintAction hintWithText:@"Swipe two fingers downwards to pause" layer:self]];
+ }
+}
+
+
+
+-(void) step: (ccTime) delta
+{
+ cpSpaceStep(space, delta);
+
+ cpSpaceHashEach(space->activeShapes, &eachShape, nil);
+ cpSpaceHashEach(space->staticShapes, &eachShape, nil);
+
+ [leftPlayer step:delta];
+ [rightPlayer step:delta];
+}
+
+
+
+-(void) updateScores
+{
+ if (gameInProgress) {
+ if (leftPlayer.health <= 0.0f || rightPlayer.health <= 0.0f) {
+ gameInProgress = false;
+ [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(gameOver) userInfo:nil repeats:NO];
+ }
+
+ leftScore.textureRect = CGRectMake(leftPlayer.color * 15, 0, 15, (leftPlayer.health / MAX_HEALTH) * 300.0f);
+ rightScore.textureRect = CGRectMake(rightPlayer.color * 15, 0, 15, (rightPlayer.health / MAX_HEALTH) * 300.0f);
+ }
+
+ [scoreLabel setString: [NSString stringWithFormat:@"%d", [localPlayer getTotalScore]]];
+}
+
+
+
+- (void)gameOver {
+ if (leftPlayer.health <= 0.0f) {
+ [delegate gameOver:leftPlayer != localPlayer score:[localPlayer getTotalScore] opponentName:opponentName];
+ } else if (rightPlayer.health <= 0.0f) {
+ [delegate gameOver:rightPlayer != localPlayer score:[localPlayer getTotalScore] opponentName:opponentName];
+ }
+}
+
+
+
+- (BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ NSSet *allTouches = [event allTouches];
+ if ([allTouches count] > 1) {
+ [gestures touchesBegan:allTouches];
+ return kEventHandled;
+ }
+
+ for( UITouch *touch in touches ) {
+ CGPoint location = [touch locationInView: [touch view]];
+ location = [[Director sharedDirector] convertCoordinate: location];
+ [self touchBegan:location];
+ break;
+ }
+ return kEventHandled;
+}
+
+
+
+- (BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ NSSet *allTouches = [event allTouches];
+ if ([allTouches count] > 1) {
+ [gestures touchesMoved:allTouches];
+ return kEventHandled;
+ }
+
+
+ for( UITouch *touch in touches ) {
+ CGPoint location = [touch locationInView: [touch view]];
+ location = [[Director sharedDirector] convertCoordinate: location];
+ [self touchMove:location final:false];
+ break;
+ }
+
+ return kEventHandled;
+}
+
+
+
+- (BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ NSSet *allTouches = [event allTouches];
+ if ([allTouches count] > 1) {
+ [gestures touchesEnded:allTouches];
+ return kEventHandled;
+ }
+
+
+ for( UITouch *touch in touches ) {
+ CGPoint location = [touch locationInView: [touch view]];
+ location = [[Director sharedDirector] convertCoordinate: location];
+
+ [self touchMove:location final:true];
+
+ break;
+ }
+
+ return kEventHandled;
+}
+
+
+
+-(void)touchBegan:(CGPoint)pos {
+ if (pos.x >= localPlayer.headBody->p.x - SLIDE_TOUCH_APROX &&
+ pos.x <= localPlayer.headBody->p.x + SLIDE_TOUCH_APROX &&
+ pos.y >= localPlayer.headBody->p.y - SLIDE_TOUCH_APROX &&
+ pos.y <= localPlayer.headBody->p.y + SLIDE_TOUCH_APROX) {
+ isSliding = true;
+ [localPlayer slideTo:&pos final:false];
+ } else {
+ isSliding = false;
+ [localPlayer turn:pos];
+ }
+}
+
+
+
+-(void)touchMove:(CGPoint)pos final:(bool)final {
+ if (isSliding) {
+ [localPlayer slideTo:&pos final:final];
+ } else {
+ if (final) {
+ [localPlayer punch:pos];
+ } else {
+ [localPlayer turn:pos];
+ }
+ }
+}
+
+
+
+-(void) onGesture: (GestureType)gestureType {
+ if (gestureType == TWO_LEFT) {
+ [self pause];
+ }
+}
+
+
+
+-(void) pause {
+ [[Director sharedDirector] pause];
+
+ pausePopup = [[[UIAlertView alloc] init] autorelease];
+ [pausePopup setDelegate:self];
+ [pausePopup setTitle:@"Game paused"];
+ [pausePopup addButtonWithTitle:@"Resume"];
+ [pausePopup addButtonWithTitle:@"Menu"];
+ [pausePopup show];
+}
+
+
+
+- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
+{
+ pausePopup = nil;
+
+ if (buttonIndex == 0) {
+ [self resume];
+ } else {
+ [self menu];
+ }
+}
+
+
+
+-(void) resume {
+ [[Director sharedDirector] resume];
+}
+
+
+
+-(void) menu {
+ [[Director sharedDirector] resume];
+ [delegate mainMenu];
+}
+
+@end
+
+
+
+
+@implementation GameHintAction
+
++(id) hintWithText:(NSString*)t layer:(Layer*)_layer {
+ return [[[self alloc] initWithText:t layer:_layer] autorelease];
+}
+
+-(id) initWithText:(NSString*)text layer:(Layer*)_layer {
+ self = [super initWithDuration:GAME_HINT_TIME];
+
+ layer = _layer;
+ label = [Label labelWithString:text fontName:@"Courier" fontSize:16];
+ label.position = cpv(240, 50);
+ [layer addChild:label];
+
+ return self;
+}
+
+
+
+-(void)stop {
+ [super stop];
+ [layer removeChild:label cleanup:YES];
+}
+
+
+
+-(void) update: (ccTime) t
+{
+ if (t <= 0.1) {
+ [label setOpacity: 255.0f * t * 10.0f];
+ } else if (t > 0.7) {
+ [label setOpacity:255 - (255.0f * (t - 0.3f) * 1.43f)];
+ }
+}
+
+
+
+@end
37 Classes/GameObject.h
@@ -0,0 +1,37 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "cocos2d.h"
+#import "chipmunk.h"
+
+@interface GameObject : NSObject {
+}
+
+- (void)updatePosition;
+
+-(void) step: (ccTime) delta;
+
+@end
+
+@interface GameObjectWrapper : GameObject {
+ GameObject *target;
+}
+
+@property (readonly) GameObject *target;
+
+- (id)initWithTarget:(GameObject*)_target;
+
+@end
45 Classes/GameObject.m
@@ -0,0 +1,45 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "GameObject.h"
+
+
+@implementation GameObject
+
+- (void)updatePosition {
+}
+
+
+
+-(void) step: (ccTime) delta {
+}
+
+@end
+
+
+
+@implementation GameObjectWrapper
+
+@synthesize target;
+
+- (id)initWithTarget:(GameObject*)_target
+{
+ target = _target;
+ return [super init];
+}
+
+
+@end
51 Classes/GameOver.h
@@ -0,0 +1,51 @@
+/*
+ Copyright 2009 Kaspars Dancis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#import "cocos2d.h"
+#import "chipmunk.h"
+#import "ReplaceLayerAction.h"
+#import "TwiztLeague.h"
+
+@protocol GameOverDelegate
+
+-(void) onGameOverReplay;
+-(void) onGameOverMenu;
+-(void) leaderboard;
+
+@end
+
+
+@interface GameOver : Layer <ReplaceLayerActionDelegate,TwiztLeagueDelegate> {
+ id<GameOverDelegate> delegate;
+ bool isActive;
+ int score;
+ int bonus;
+
+ Label *scoreLabel;