Permalink
Browse files

added jumping bird, platforms, vertical scrolling. cocos2d-iphone inc…

…luded
  • Loading branch information...
1 parent 5d115db commit 39094687a913b3b0ec8e312f916b07852189d906 haqu committed May 24, 2009
Showing with 21,696 additions and 4,838 deletions.
  1. BIN .DS_Store
  2. +5 −0 .gitignore
  3. BIN Classes/.DS_Store
  4. +4 −3 Classes/AppDelegate.h
  5. +19 −25 Classes/AppDelegate.m
  6. +1 −0 Classes/Constants.h
  7. +15 −0 Classes/GameLayer.h
  8. +155 −0 Classes/GameLayer.m
  9. +4 −0 Classes/GameScene.h
  10. +17 −0 Classes/GameScene.m
  11. +0 −4 Classes/InfoViewController.h
  12. +0 −21 Classes/InfoViewController.m
  13. +0 −4 Classes/MainViewController.h
  14. +0 −30 Classes/MainViewController.m
  15. BIN Images/fps_images.png
  16. BIN Images/sprites.png
  17. +1 −3 Info.plist
  18. +7 −2 README.md
  19. +110 −0 Support/cocos2d/Action.h
  20. +222 −0 Support/cocos2d/Action.m
  21. +70 −0 Support/cocos2d/AtlasNode.h
  22. +146 −0 Support/cocos2d/AtlasNode.m
  23. +146 −0 Support/cocos2d/AtlasSprite.h
  24. +508 −0 Support/cocos2d/AtlasSprite.m
  25. +70 −0 Support/cocos2d/AtlasSpriteManager.h
  26. +315 −0 Support/cocos2d/AtlasSpriteManager.m
  27. +93 −0 Support/cocos2d/BitmapFontAtlas.h
  28. +379 −0 Support/cocos2d/BitmapFontAtlas.m
  29. +69 −0 Support/cocos2d/Camera.h
  30. +158 −0 Support/cocos2d/Camera.m
  31. +57 −0 Support/cocos2d/CameraAction.h
  32. +127 −0 Support/cocos2d/CameraAction.m
  33. +436 −0 Support/cocos2d/CocosNode.h
  34. +830 −0 Support/cocos2d/CocosNode.m
  35. +283 −0 Support/cocos2d/Director.h
  36. +966 −0 Support/cocos2d/Director.m
  37. +72 −0 Support/cocos2d/EaseAction.h
  38. +230 −0 Support/cocos2d/EaseAction.m
  39. +32 −0 Support/cocos2d/Grabber.h
  40. +74 −0 Support/cocos2d/Grabber.m
  41. +108 −0 Support/cocos2d/Grid.h
  42. +480 −0 Support/cocos2d/Grid.m
  43. +191 −0 Support/cocos2d/Grid3DAction.h
  44. +522 −0 Support/cocos2d/Grid3DAction.m
  45. +156 −0 Support/cocos2d/GridAction.h
  46. +345 −0 Support/cocos2d/GridAction.m
  47. +95 −0 Support/cocos2d/InstantAction.h
  48. +221 −0 Support/cocos2d/InstantAction.m
  49. +356 −0 Support/cocos2d/IntervalAction.h
  50. +1,124 −0 Support/cocos2d/IntervalAction.m
  51. +50 −0 Support/cocos2d/Label.h
  52. +86 −0 Support/cocos2d/Label.m
  53. +43 −0 Support/cocos2d/LabelAtlas.h
  54. +134 −0 Support/cocos2d/LabelAtlas.m
  55. +122 −0 Support/cocos2d/Layer.h
  56. +312 −0 Support/cocos2d/Layer.m
  57. +72 −0 Support/cocos2d/Menu.h
  58. +391 −0 Support/cocos2d/Menu.m
  59. +199 −0 Support/cocos2d/MenuItem.h
  60. +564 −0 Support/cocos2d/MenuItem.m
  61. +32 −0 Support/cocos2d/ParallaxNode.h
  62. +105 −0 Support/cocos2d/ParallaxNode.m
  63. +82 −0 Support/cocos2d/ParticleExamples.h
  64. +883 −0 Support/cocos2d/ParticleExamples.m
  65. +251 −0 Support/cocos2d/ParticleSystem.h
  66. +209 −0 Support/cocos2d/ParticleSystem.m
  67. +34 −0 Support/cocos2d/PointParticleSystem.h
  68. +248 −0 Support/cocos2d/PointParticleSystem.m
  69. +48 −0 Support/cocos2d/Primitives.h
  70. +106 −0 Support/cocos2d/Primitives.m
  71. +44 −0 Support/cocos2d/QuadParticleSystem.h
  72. +310 −0 Support/cocos2d/QuadParticleSystem.m
  73. +33 −0 Support/cocos2d/Scene.h
  74. +32 −0 Support/cocos2d/Scene.m
  75. +86 −0 Support/cocos2d/Scheduler.h
  76. +216 −0 Support/cocos2d/Scheduler.m
  77. +100 −0 Support/cocos2d/Sprite.h
  78. +251 −0 Support/cocos2d/Sprite.m
  79. +222 −0 Support/cocos2d/Support/CGPointExtension.h
  80. +55 −0 Support/cocos2d/Support/CGPointExtension.m
  81. +134 −0 Support/cocos2d/Support/EAGLView.h
  82. +316 −0 Support/cocos2d/Support/EAGLView.m
  83. +24 −0 Support/cocos2d/Support/FileUtils.h
  84. +34 −0 Support/cocos2d/Support/FileUtils.m
  85. +79 −0 Support/cocos2d/Support/OpenGL_Internal.h
  86. +81 −0 Support/cocos2d/Support/PVRTexture.h
  87. +280 −0 Support/cocos2d/Support/PVRTexture.m
  88. +55 −0 Support/cocos2d/Support/TGAlib.h
  89. +272 −0 Support/cocos2d/Support/TGAlib.m
  90. +224 −0 Support/cocos2d/Support/Texture2D.h
  91. +521 −0 Support/cocos2d/Support/Texture2D.m
  92. +19 −0 Support/cocos2d/Support/TransformUtils.h
  93. +34 −0 Support/cocos2d/Support/TransformUtils.m
  94. +30 −0 Support/cocos2d/Support/UIColor-OpenGL.h
  95. +69 −0 Support/cocos2d/Support/UIColor-OpenGL.m
  96. +212 −0 Support/cocos2d/Support/ccArray.h
  97. +112 −0 Support/cocos2d/Support/glu.c
  98. +21 −0 Support/cocos2d/Support/glu.h
  99. +32 −0 Support/cocos2d/TargetedTouchDelegate.h
  100. +115 −0 Support/cocos2d/TextureAtlas.h
  101. +271 −0 Support/cocos2d/TextureAtlas.m
  102. +81 −0 Support/cocos2d/TextureMgr.h
  103. +176 −0 Support/cocos2d/TextureMgr.m
  104. +49 −0 Support/cocos2d/TextureNode.h
  105. +98 −0 Support/cocos2d/TextureNode.m
  106. +61 −0 Support/cocos2d/TileMapAtlas.h
  107. +204 −0 Support/cocos2d/TileMapAtlas.m
  108. +198 −0 Support/cocos2d/TiledGridAction.h
  109. +660 −0 Support/cocos2d/TiledGridAction.m
  110. +51 −0 Support/cocos2d/TouchDispatcher.h
  111. +209 −0 Support/cocos2d/TouchDispatcher.m
  112. +38 −0 Support/cocos2d/TouchHandler.h
  113. +42 −0 Support/cocos2d/TouchHandler.m
  114. +261 −0 Support/cocos2d/Transition.h
  115. +892 −0 Support/cocos2d/Transition.m
  116. +23 −0 Support/cocos2d/ccExceptions.h
  117. +55 −0 Support/cocos2d/ccMacros.h
  118. +173 −0 Support/cocos2d/ccTypes.h
  119. +92 −0 Support/cocos2d/cocos2d.h
  120. +22 −0 Support/cocos2d/cocos2d.m
  121. +0 −1,077 app.xcodeproj/haqu (haqu.air's conflicted copy 2009-03-08).pbxuser
  122. +0 −1,451 app.xcodeproj/haqu.mode1v3
  123. +0 −225 app.xcodeproj/haqu.pbxuser
  124. +0 −1,602 app.xcodeproj/haqu.perspectivev3
  125. +0 −291 app.xcodeproj/project.pbxproj
  126. +0 −4 app_Prefix.pch
  127. BIN images/bgr.png
  128. +5 −4 main.m
  129. +78 −92 {app.xcodeproj → tweejump.xcodeproj}/haqu.mode2v3
  130. +145 −0 tweejump.xcodeproj/haqu.pbxuser
  131. +605 −0 tweejump.xcodeproj/project.pbxproj
  132. +4 −0 tweejump_Prefix.pch
View
BIN .DS_Store
Binary file not shown.
View
@@ -0,0 +1,5 @@
+.DS_Store
+build
+*.pbxuser
+*.mode1v3
+*.mode2v3
View
Binary file not shown.
View
@@ -1,5 +1,6 @@
-#import <UIKit/UIKit.h>
+#import "cocos2d.h"
-@interface AppDelegate : NSObject <UIApplicationDelegate,UINavigationControllerDelegate>
+@interface AppDelegate : NSObject <UIApplicationDelegate, UIAccelerometerDelegate> {
+ UIWindow *window;
+}
@end
-
View
@@ -1,38 +1,32 @@
#import "AppDelegate.h"
-#import "MainViewController.h"
+#import "GameScene.h"
+#import "Constants.h"
@implementation AppDelegate
-- (void)applicationDidFinishLaunching:(UIApplication*)application {
+- (void)applicationDidFinishLaunching:(UIApplication *)application {
- // window
- UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-
- // status bar
[application setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
- // main view and navigation controller
- MainViewController *mainView = [[MainViewController alloc] init];
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mainView];
- [mainView release];
- nav.delegate = self;
- nav.navigationBar.barStyle = UIBarStyleBlackTranslucent;
- nav.navigationBar.frame = CGRectMake(0,20,320,44);
- nav.view.frame = CGRectMake(0,0,320,480);
-
- // window
- [window addSubview:nav.view];
+ window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ [window setUserInteractionEnabled:YES];
+ [window setMultipleTouchEnabled:YES];
+
+ [[Director sharedDirector] setPixelFormat:kRGBA8];
+ [[Director sharedDirector] attachInWindow:window];
+ [[Director sharedDirector] setDisplayFPS:YES];
+ [[Director sharedDirector] setAnimationInterval:1.0/kFPS];
+
+ [Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
+
[window makeKeyAndVisible];
+
+ [[Director sharedDirector] runWithScene: [GameScene node]];
}
-- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
- NSLog(@"navigationController");
- NSLog(@"viewController.title = %@",viewController.title);
- if([viewController.title isEqualToString:@"TweeJump"]) {
- navigationController.navigationBarHidden = YES;
- } else {
- navigationController.navigationBarHidden = NO;
- }
+- (void)dealloc {
+ [window release];
+ [super dealloc];
}
@end
View
@@ -0,0 +1 @@
+#define kFPS 60
View
@@ -0,0 +1,15 @@
+#import "cocos2d.h"
+
+@interface GameLayer : Layer
+{
+ AtlasSpriteManager *mgr;
+ AtlasSprite *background;
+ AtlasSprite *bird;
+ NSMutableArray *platforms;
+ ccVertex2F bird_pos;
+ ccVertex2F bird_vel;
+ ccVertex2F bird_acc;
+
+ float highestPlatformY;
+}
+@end
View
@@ -0,0 +1,155 @@
+#import "GameLayer.h"
+#import "Constants.h"
+#import <mach/mach_time.h>
+
+#define RANDOM_SEED() srandom((unsigned)(mach_absolute_time() & 0xFFFFFFFF))
+
+#define kPlatformStep 100.0f
+
+@interface GameLayer (Private)
+- (void)jump;
+@end
+
+@implementation GameLayer
+
+- (id)init {
+
+ if(self = [super init]) {
+
+ mgr = [AtlasSpriteManager spriteManagerWithFile:@"sprites.png" capacity:3];
+ [self addChild:mgr];
+
+ background = [AtlasSprite spriteWithRect:CGRectMake(0,0,320,480) spriteManager:mgr];
+ [mgr addChild:background];
+ [background setPosition:CGPointMake(160,240)];
+
+ platforms = [[NSMutableArray alloc] init];
+ AtlasSprite *platform;
+
+ float x = 160;
+ float y = 30;
+ int pwidth;
+ for(int i=0; i<5; i++) {
+ NSLog(@"x = %f, y = %f",x,y);
+ platform = [AtlasSprite spriteWithRect:CGRectMake(321,64,86,24) spriteManager:mgr];
+ [mgr addChild:platform];
+ [platform setPosition:CGPointMake(x,y)];
+ [platforms addObject:platform];
+ [platform release];
+ pwidth = (int)platform.contentSize.width;
+ x = random() % (320-pwidth) + pwidth/2;
+ y += kPlatformStep;
+ }
+ highestPlatformY = y - kPlatformStep;
+
+ NSLog(@"platforms count = %d",[platforms count]);
+
+ bird = [AtlasSprite spriteWithRect:CGRectMake(321,0,63,45) spriteManager:mgr];
+ [mgr addChild:bird];
+
+ bird_pos.x = 160;
+ bird_pos.y = 160;
+ [bird setPosition:bird_pos];
+
+ bird_vel.x = 0;
+ bird_vel.y = 0;
+
+ bird_acc.x = 0;
+ bird_acc.y = -0.25;
+
+ isTouchEnabled = YES;
+ isAccelerometerEnabled = YES;
+
+ [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kFPS)];
+ }
+
+ return self;
+}
+
+- (void)dealloc {
+ for(AtlasSprite *platform in platforms) {
+ [platform release];
+ }
+ [platforms removeAllObjects];
+ [bird release];
+ [background release];
+ [mgr release];
+ [super dealloc];
+}
+
+- (void)draw {
+ bird_pos.x += bird_vel.x;
+
+ CGSize bsize = CGSizeMake(64,40);
+ float max_x = 320-bsize.width/2;
+ float min_x = 0+bsize.width/2;
+
+ if(bird_pos.x>max_x) bird_pos.x = max_x;
+ if(bird_pos.x<min_x) bird_pos.x = min_x;
+
+ bird_vel.y += bird_acc.y;
+ bird_pos.y += bird_vel.y;
+
+ if(bird_vel.y < 0) {
+
+ CGSize psize;
+ CGPoint ppos;
+ for(AtlasSprite *platform in platforms) {
+ psize = platform.contentSize;
+ ppos = platform.position;
+ if(bird_pos.x > ppos.x-psize.width/2-10 &&
+ bird_pos.x < ppos.x+psize.width/2+10 &&
+ bird_pos.y > ppos.y &&
+ bird_pos.y < ppos.y+(psize.height+bsize.height)/2) {
+ [self jump];
+ }
+ }
+
+ if(bird_pos.y < bsize.height/2) {
+ bird_pos.y = bsize.height/2;
+ [self jump];
+ }
+
+ } else if(bird_pos.y > 240) {
+
+ float delta = bird_pos.y - 240;
+ bird_pos.y = 240;
+ highestPlatformY -= delta;
+
+ CGPoint ppos;
+ int pwidth;
+ float x;
+ for(AtlasSprite *platform in platforms) {
+ ppos = platform.position;
+ platform.position = CGPointMake(ppos.x,ppos.y-delta);
+
+ ppos = platform.position;
+ if(ppos.y < -platform.contentSize.height/2) {
+ pwidth = (int)platform.contentSize.width;
+ x = random() % (320-pwidth) + pwidth/2;
+ highestPlatformY += kPlatformStep;
+ platform.position = CGPointMake(x,highestPlatformY);
+ }
+ }
+
+ }
+
+ [bird setPosition:CGPointMake(bird_pos.x,bird_pos.y)];
+}
+
+- (void)jump {
+ bird_vel.y = 9;
+}
+
+- (BOOL)ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
+ NSLog(@"ccTouchesEnded");
+ [self jump];
+ return kEventHandled;
+}
+
+- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration {
+ float accel_filter = 0.2f;
+ bird_vel.x = bird_vel.x * accel_filter + acceleration.x * (1.0f - accel_filter) * 15;
+}
+
+@end
View
@@ -0,0 +1,4 @@
+#import "cocos2d.h"
+
+@interface GameScene : Scene
+@end
View
@@ -0,0 +1,17 @@
+#import "GameScene.h"
+#import "GameLayer.h"
+
+@implementation GameScene
+
+- (id)init {
+ if(self = [super init]) {
+ [self addChild:[GameLayer node]];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+@end
@@ -1,4 +0,0 @@
-#import <UIKit/UIKit.h>
-
-@interface InfoViewController : UIViewController
-@end
@@ -1,21 +0,0 @@
-#import "InfoViewController.h"
-
-@implementation InfoViewController
-
-- (id)init {
- if (self = [super init]) {
- self.title = @"About";
- }
- return self;
-}
-
-- (void)loadView {
- self.view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
-}
-
-- (void)dealloc {
- [self.view release];
- [super dealloc];
-}
-
-@end
@@ -1,4 +0,0 @@
-#import <UIKit/UIKit.h>
-
-@interface MainViewController : UIViewController
-@end
@@ -1,30 +0,0 @@
-#import "MainViewController.h"
-#import "InfoViewController.h"
-
-@implementation MainViewController
-
-- (id)init {
- if (self = [super init]) {
- self.title = @"TweeJump";
- }
- return self;
-}
-
-- (void)loadView {
- self.view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
-
- UIImageView *bgr = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgr.png"]];
- [self.view addSubview:bgr];
- [bgr release];
-}
-
-- (void)dealloc {
- [self.view release];
- [super dealloc];
-}
-
-- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
- NSLog(@"touchesBegan");
-}
-
-@end
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -9,7 +9,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
- <string>icon.png</string>
+ <string></string>
<key>CFBundleIdentifier</key>
<string>com.iplayful.*</string>
<key>CFBundleInfoDictionaryVersion</key>
@@ -24,7 +24,5 @@
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
- <key>UIPrerenderedIcon</key>
- <false/>
</dict>
</plist>
View
@@ -1,8 +1,8 @@
-# TweeJump
+# Tweejump
inspired by [Icy Tower](http://www.freelunchdesign.com/games.php?id=6), [PapiJump](http://linktoapp.com/PapiJump), [Doodle Jump](http://linktoapp.com/Doodle+Jump) and... [Twitter](http://twitter.com)!
-![TweeJump](http://simple.st/i/tweejump.png)
+![Tweejump](http://fc05.deviantart.com/fs45/f/2009/144/f/5/Tweejump_WIP_1_by_sthaqu.jpg)
## Notes
@@ -14,3 +14,8 @@ inspired by [Icy Tower](http://www.freelunchdesign.com/games.php?id=6), [PapiJum
- on the way you collect:
- replies -- '@' symbols
- hashtags -- '#' symbols
+
+# References
+
+- [cocos2d-iphone](http://code.google.com/p/cocos2d-iphone/)
+- [cocos2d-iphone API](http://www.sapusmedia.com/cocos2d-iphone-api-doc/)
Oops, something went wrong.

0 comments on commit 3909468

Please sign in to comment.