From 37c96291fb659393cbc8c05e90486d01ba3247cb Mon Sep 17 00:00:00 2001 From: olegoid Date: Tue, 20 Jan 2015 00:05:53 +0300 Subject: [PATCH] [cocos2d.Jumpy] Migrate sample to unified --- cocos2d/samples/Jumpy/Jumpy/AppDelegate.cs | 42 ++- cocos2d/samples/Jumpy/Jumpy/GameLayer.cs | 277 +++++++++--------- cocos2d/samples/Jumpy/Jumpy/HighScoreLayer.cs | 31 +- cocos2d/samples/Jumpy/Jumpy/Info.plist | 2 + cocos2d/samples/Jumpy/Jumpy/Jumpy.csproj | 11 +- cocos2d/samples/Jumpy/Jumpy/Main.cs | 4 +- cocos2d/samples/Jumpy/Jumpy/MainLayer.cs | 92 +++--- 7 files changed, 226 insertions(+), 233 deletions(-) diff --git a/cocos2d/samples/Jumpy/Jumpy/AppDelegate.cs b/cocos2d/samples/Jumpy/Jumpy/AppDelegate.cs index 5e0af4e6..10ea8775 100644 --- a/cocos2d/samples/Jumpy/Jumpy/AppDelegate.cs +++ b/cocos2d/samples/Jumpy/Jumpy/AppDelegate.cs @@ -23,23 +23,25 @@ using System; using System.Collections.Generic; using System.Linq; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; using MonoTouch.Cocos2D; namespace Jumpy { - // The UIApplicationDelegate for the application. This class is responsible for launching the - // User Interface of the application, as well as listening (and optionally responding) to + // The UIApplicationDelegate for the application. This class is responsible for launching the + // User Interface of the application, as well as listening (and optionally responding) to // application events from iOS. [Register ("AppDelegate")] public partial class AppDelegate : UIApplicationDelegate { // class-level declarations UIWindow window; + public UINavigationController NavController { get ; private set; } - CCDirectorDisplayLink director; - + + CCDirectorDisplayLink director; + /// This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. @@ -48,7 +50,7 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options) { // create a new window instance based on the screen size window = new UIWindow (UIScreen.MainScreen.Bounds); - var glView = new CCGLView(window.Bounds); + var glView = new CCGLView (window.Bounds); director = (CCDirectorDisplayLink)CCDirector.SharedDirector; @@ -56,28 +58,20 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options) //director.DisplayStats = true; - director.AnimationInterval = 1.0/60; + director.AnimationInterval = 1.0 / 60; director.View = glView; director.Projection = CCDirectorProjection.TwoD; - //if (!director.EnableRetinaDisplay(true)) - // Console.WriteLine ("Retina Display not supported"); - CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.Rgba8888; -// CCDirector.SharedDirector.ShouldAutorotateToInterfaceOrientation = (orientation) => { -// return orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight; -// }; - - CCTexture2D.PVRImageHavePremultipliedAlpha = true; director.Run (GameLayer.Scene); // Create a Navigation Controller with the Director - NavController = new UINavigationController(director) {NavigationBarHidden=true, WantsFullScreenLayout=true}; + NavController = new UINavigationController (director) { NavigationBarHidden = true, WantsFullScreenLayout = true }; // set the Navigation Controller as the root view controller window.RootViewController = NavController; @@ -85,32 +79,32 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options) return true; } - + public override void DidEnterBackground (UIApplication application) { if (NavController.VisibleViewController == director) director.StopAnimation (); } - + public override void WillEnterForeground (UIApplication application) { if (NavController.VisibleViewController == director) director.StartAnimation (); } - + public override void WillTerminate (UIApplication application) { - CCDirector.SharedDirector.End(); + CCDirector.SharedDirector.End (); } - + public override void ReceiveMemoryWarning (UIApplication application) { CCDirector.SharedDirector.PurgeCachedData (); } - + public override void ApplicationSignificantTimeChange (UIApplication application) { - CCDirector.SharedDirector.NextDeltaTimeZero=true; + CCDirector.SharedDirector.NextDeltaTimeZero = true; } } } diff --git a/cocos2d/samples/Jumpy/Jumpy/GameLayer.cs b/cocos2d/samples/Jumpy/Jumpy/GameLayer.cs index b8ebc741..7d05cdf4 100644 --- a/cocos2d/samples/Jumpy/Jumpy/GameLayer.cs +++ b/cocos2d/samples/Jumpy/Jumpy/GameLayer.cs @@ -21,17 +21,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using System; -using System.Drawing; -using MonoTouch.UIKit; +using CoreGraphics; +using UIKit; using MonoTouch.Cocos2D; -using MonoTouch.OpenGLES; +using OpenGLES; using OpenTK; namespace Jumpy { public class GameLayer : MainLayer { - public enum Bonus : int { + public enum Bonus : int + { Bonus5 = 0, Bonus10, Bonus50, @@ -50,16 +51,15 @@ public enum Bonus : int { int platformTopPadding = 10; bool birdLookingRight; - PointF bird_pos; + CGPoint bird_pos; Vector2 bird_vel; Vector2 bird_acc; - public static CCScene Scene - { + public static CCScene Scene { get { var scene = new CCScene (); var layer = new GameLayer (); - scene.Add(layer); + scene.Add (layer); return scene; } } @@ -67,23 +67,23 @@ public static CCScene Scene public GameLayer () { gameSuspended = true; - var batchnode = GetChild((int)Tags.SpriteManager) as CCSpriteBatchNode; + var batchnode = GetChild ((int)Tags.SpriteManager) as CCSpriteBatchNode; InitPlatforms (); - var bird = new CCSprite(batchnode.Texture, new RectangleF(608,16,44,32)); - batchnode.Add (bird,4,(int)Tags.Bird); + var bird = new CCSprite (batchnode.Texture, new CGRect (608, 16, 44, 32)); + batchnode.Add (bird, 4, (int)Tags.Bird); CCSprite bonus; - for(int i=0; i<(int)Bonus.NumBonuses; i++) { - bonus = new CCSprite(batchnode.Texture, new RectangleF(608+i*32,256,25,25)); - batchnode.Add(bonus,4,(int)Tags.BomusStart+i); + for (int i = 0; i < (int)Bonus.NumBonuses; i++) { + bonus = new CCSprite (batchnode.Texture, new CGRect (608 + i * 32, 256, 25, 25)); + batchnode.Add (bonus, 4, (int)Tags.BomusStart + i); bonus.Visible = false; } - var scoreLabel = new CCLabelBMFont("0", "Fonts/bitmapFont.fnt") {Position = new PointF(160,430)}; - Add(scoreLabel, 5, (int)Tags.ScoreLabel); + var scoreLabel = new CCLabelBMFont ("0", "Fonts/bitmapFont.fnt") { Position = new CGPoint (160, 430) }; + Add (scoreLabel, 5, (int)Tags.ScoreLabel); } @@ -91,7 +91,7 @@ public GameLayer () public override void OnEnter () { base.OnEnter (); - Schedule(Step); + Schedule (Step); TouchEnabled = false; AccelerometerEnabled = true; @@ -107,8 +107,8 @@ public override void OnEnter () void InitPlatforms () { currentPlatformTag = (int)Tags.PlatformsStart; - while(currentPlatformTag < (int)Tags.PlatformsStart + numPlatforms) { - InitPlatform(); + while (currentPlatformTag < (int)Tags.PlatformsStart + numPlatforms) { + InitPlatform (); currentPlatformTag++; } @@ -117,22 +117,22 @@ void InitPlatforms () void InitPlatform () { - RectangleF rect; - switch(rnd.Next()%2) { + CGRect rect; + switch (rnd.Next () % 2) { case 0: - rect = new RectangleF(608,64,102,36); + rect = new CGRect (608, 64, 102, 36); break; default: - rect = new RectangleF(608,128,90,32); + rect = new CGRect (608, 128, 90, 32); break; } - var batchnode = GetChild((int)Tags.SpriteManager) as CCSpriteBatchNode; - var platform = new CCSprite(batchnode.Texture, rect); - batchnode.Add(platform,3,currentPlatformTag); + var batchnode = GetChild ((int)Tags.SpriteManager) as CCSpriteBatchNode; + var platform = new CCSprite (batchnode.Texture, rect); + batchnode.Add (platform, 3, currentPlatformTag); } - float currentPlatformY; + nfloat currentPlatformY; float currentMaxPlatformStep; int currentBonusPlatformIndex; int currentBonusType; @@ -147,8 +147,8 @@ void ResetPlatforms () currentBonusType = 0; platformCount = 0; - while(currentPlatformTag < (int)Tags.PlatformsStart + numPlatforms) { - ResetPlatform(); + while (currentPlatformTag < (int)Tags.PlatformsStart + numPlatforms) { + ResetPlatform (); currentPlatformTag++; } } @@ -156,35 +156,34 @@ void ResetPlatforms () void ResetPlatform () { - if(currentPlatformY < 0) { + if (currentPlatformY < 0) { currentPlatformY = 30.0f; } else { - currentPlatformY += rnd.Next() % (int)(currentMaxPlatformStep - minPlatformStep) + minPlatformStep; - if(currentMaxPlatformStep < maxPlatformStep) { + currentPlatformY += rnd.Next () % (int)(currentMaxPlatformStep - minPlatformStep) + minPlatformStep; + if (currentMaxPlatformStep < maxPlatformStep) currentMaxPlatformStep += 0.5f; - } } var batchnode = GetChild ((int)Tags.SpriteManager) as CCSpriteBatchNode; - var platform = batchnode.GetChild(currentPlatformTag) as CCSprite; + var platform = batchnode.GetChild (currentPlatformTag) as CCSprite; - if(rnd.Next()%2==1) platform.ScaleX = -1.0f; + if (rnd.Next () % 2 == 1) + platform.ScaleX = -1.0f; - float x; + nfloat x; var size = platform.ContentSize; - if(currentPlatformY == 30.0f) { + if (currentPlatformY == 30.0f) x = 160.0f; - } else { - x = rnd.Next() % (320-(int)size.Width) + size.Width/2; - } + else + x = rnd.Next () % (320 - (int)size.Width) + size.Width / 2; - platform.Position = new PointF(x,currentPlatformY); + platform.Position = new CGPoint (x, currentPlatformY); platformCount++; - if(platformCount == currentBonusPlatformIndex) { + if (platformCount == currentBonusPlatformIndex) { - var bonus = batchnode.GetChild((int)Tags.BomusStart+currentBonusType) as CCSprite; - bonus.Position = new PointF(x,currentPlatformY+30); + var bonus = batchnode.GetChild ((int)Tags.BomusStart + currentBonusType) as CCSprite; + bonus.Position = new CGPoint (x, currentPlatformY + 30); bonus.Visible = true; } @@ -197,15 +196,16 @@ void StartGame () ResetClouds (); ResetPlatforms (); ResetBird (); - ResetBonus(); + ResetBonus (); - UIApplication.SharedApplication.IdleTimerDisabled=true; - gameSuspended = false;; + UIApplication.SharedApplication.IdleTimerDisabled = true; + gameSuspended = false; } - void ResetBird() { - var batchnode = GetChild((int)Tags.SpriteManager) as CCSpriteBatchNode; - var bird = batchnode.GetChild((int)Tags.Bird) as CCSprite; + void ResetBird () + { + var batchnode = GetChild ((int)Tags.SpriteManager) as CCSpriteBatchNode; + var bird = batchnode.GetChild ((int)Tags.Bird) as CCSprite; bird_pos.X = 160; bird_pos.Y = 160; @@ -221,35 +221,37 @@ void ResetBird() { bird.ScaleX = 1.0f; } - void ResetBonus () { - var batchnode = GetChild((int)Tags.SpriteManager) as CCSpriteBatchNode; - var bonus = batchnode.GetChild((int)Tags.BomusStart+currentBonusType) as CCSprite; + void ResetBonus () + { + var batchnode = GetChild ((int)Tags.SpriteManager) as CCSpriteBatchNode; + var bonus = batchnode.GetChild ((int)Tags.BomusStart + currentBonusType) as CCSprite; bonus.Visible = false; - currentBonusPlatformIndex += rnd.Next() % (maxBonusStep - minBonusStep) + minBonusStep; - if(score < 10000) { + currentBonusPlatformIndex += rnd.Next () % (maxBonusStep - minBonusStep) + minBonusStep; + if (score < 10000) { currentBonusType = 0; - } else if(score < 50000) { - currentBonusType = rnd.Next() % 2; - } else if(score < 100000) { - currentBonusType = rnd.Next() % 3; + } else if (score < 50000) { + currentBonusType = rnd.Next () % 2; + } else if (score < 100000) { + currentBonusType = rnd.Next () % 3; } else { - currentBonusType = rnd.Next() % 2 + 2; + currentBonusType = rnd.Next () % 2 + 2; } } - protected override void Step (float dt) { + protected override void Step (float dt) + { base.Step (dt); if (gameSuspended) return; - var batchnode = GetChild((int)Tags.SpriteManager) as CCSpriteBatchNode; - var bird = batchnode.GetChild((int)Tags.Bird) as CCSprite; - var particles = GetChild((int)Tags.Particles) as CCParticleSystem; + var batchnode = GetChild ((int)Tags.SpriteManager) as CCSpriteBatchNode; + var bird = batchnode.GetChild ((int)Tags.Bird) as CCSprite; + var particles = GetChild ((int)Tags.Particles) as CCParticleSystem; bird_pos.X += bird_vel.X * dt; - if(bird_vel.X < -30.0f && birdLookingRight) { + if (bird_vel.X < -30.0f && birdLookingRight) { birdLookingRight = false; bird.ScaleX = -1.0f; } else if (bird_vel.X > 30.0f && !birdLookingRight) { @@ -258,82 +260,92 @@ protected override void Step (float dt) { } var bird_size = bird.ContentSize; - float max_x = 320-bird_size.Width/2; - float min_x = 0+bird_size.Width/2; + nfloat max_x = 320 - bird_size.Width / 2; + nfloat min_x = 0 + bird_size.Width / 2; - if(bird_pos.X>max_x) bird_pos.X = max_x; - 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 * dt; bird_pos.Y += bird_vel.Y * dt; - var bonus = batchnode.GetChild((int)Tags.BomusStart + currentBonusType); - if(bonus.Visible) { + var bonus = batchnode.GetChild ((int)Tags.BomusStart + currentBonusType); + if (bonus.Visible) { var bonus_pos = bonus.Position; float range = 20.0f; - if(bird_pos.X > bonus_pos.X - range && - bird_pos.X < bonus_pos.Y + range && - bird_pos.Y > bonus_pos.Y - range && - bird_pos.Y < bonus_pos.Y + range ) { - switch(currentBonusType) { - case (int)Bonus.Bonus5: score += 5000; break; - case (int)Bonus.Bonus10: score += 10000; break; - case (int)Bonus.Bonus50: score += 50000; break; - case (int)Bonus.Bonus100: score += 100000; break; + if (bird_pos.X > bonus_pos.X - range && + bird_pos.X < bonus_pos.Y + range && + bird_pos.Y > bonus_pos.Y - range && + bird_pos.Y < bonus_pos.Y + range) { + switch (currentBonusType) { + case (int)Bonus.Bonus5: + score += 5000; + break; + case (int)Bonus.Bonus10: + score += 10000; + break; + case (int)Bonus.Bonus50: + score += 50000; + break; + case (int)Bonus.Bonus100: + score += 100000; + break; } - var scorelabel = GetChild((int)Tags.ScoreLabel) as CCLabelBMFont; - scorelabel.Label = score.ToString(); + var scorelabel = GetChild ((int)Tags.ScoreLabel) as CCLabelBMFont; + scorelabel.Label = score.ToString (); - var a1 = new CCScaleTo(.2f,1.5f,.08f); - var a2 = new CCScaleTo(.2f,1f,1f); - var a3 = CCSequence.FromActions(new CCFiniteTimeAction[] {a1,a2,a1,a2,a1,a2}); - scorelabel.RunAction(a3); + var a1 = new CCScaleTo (.2f, 1.5f, .08f); + var a2 = new CCScaleTo (.2f, 1f, 1f); + var a3 = CCSequence.FromActions (new CCFiniteTimeAction[] { a1, a2, a1, a2, a1, a2 }); + scorelabel.RunAction (a3); ResetBonus (); } } int t; - if(bird_vel.Y < 0) { + if (bird_vel.Y < 0) { t = (int)Tags.PlatformsStart; - for(t = (int)Tags.PlatformsStart; t < (int)Tags.PlatformsStart + numPlatforms; t++) { - var platform = batchnode.GetChild(t) as CCSprite; + for (t = (int)Tags.PlatformsStart; t < (int)Tags.PlatformsStart + numPlatforms; t++) { + var platform = batchnode.GetChild (t) as CCSprite; var platform_size = platform.ContentSize; var platform_pos = platform.Position; - max_x = platform_pos.X - platform_size.Width/2 - 10; - min_x = platform_pos.X + platform_size.Width/2 + 10; - float min_y = platform_pos.Y + (platform_size.Height+bird_size.Height)/2 - platformTopPadding; + max_x = platform_pos.X - platform_size.Width / 2 - 10; + min_x = platform_pos.X + platform_size.Width / 2 + 10; + nfloat min_y = platform_pos.Y + (platform_size.Height + bird_size.Height) / 2 - platformTopPadding; - if(bird_pos.X > max_x && - bird_pos.X < min_x && - bird_pos.Y > platform_pos.Y && - bird_pos.Y < min_y) { - Jump(); + if (bird_pos.X > max_x && + bird_pos.X < min_x && + bird_pos.Y > platform_pos.Y && + bird_pos.Y < min_y) { + Jump (); } } - if(bird_pos.Y < -bird_size.Height/2) { - ShowHighScores(); + if (bird_pos.Y < -bird_size.Height / 2) { + ShowHighScores (); } - } else if(bird_pos.Y > 240) { + } else if (bird_pos.Y > 240) { - float delta = bird_pos.Y - 240; + nfloat delta = bird_pos.Y - 240; bird_pos.Y = 240; currentPlatformY -= delta; - for(t = (int)Tags.CloudsStart; t < (int)Tags.CloudsStart + numClouds; t++) { - var cloud = batchnode.GetChild(t) as CCSprite; + for (t = (int)Tags.CloudsStart; t < (int)Tags.CloudsStart + numClouds; t++) { + var cloud = batchnode.GetChild (t) as CCSprite; var pos = cloud.Position; pos.Y -= delta * cloud.ScaleY * 0.8f; - if(pos.Y < -cloud.ContentSize.Height/2) { + if (pos.Y < -cloud.ContentSize.Height / 2) { currentCloudTag = t; - ResetCloud(); + ResetCloud (); } else { cloud.Position = pos; @@ -341,11 +353,11 @@ protected override void Step (float dt) { } - for(t = (int)Tags.PlatformsStart; t < (int)Tags.PlatformsStart + numPlatforms; t++) { - var platform = batchnode.GetChild(t) as CCSprite; + for (t = (int)Tags.PlatformsStart; t < (int)Tags.PlatformsStart + numPlatforms; t++) { + var platform = batchnode.GetChild (t) as CCSprite; var pos = platform.Position; - pos = new PointF(pos.X,pos.Y-delta); - if(pos.Y < -platform.ContentSize.Height/2) { + pos = new CGPoint (pos.X, pos.Y - delta); + if (pos.Y < -platform.ContentSize.Height / 2) { currentPlatformTag = t; ResetPlatform (); } else { @@ -353,50 +365,48 @@ protected override void Step (float dt) { } } - if(bonus.Visible) { + if (bonus.Visible) { var pos = bonus.Position; pos.Y -= delta; - if(pos.Y < -bonus.ContentSize.Height/2) { + if (pos.Y < -bonus.ContentSize.Height / 2) ResetBonus (); - //[self resetBonus]; - } else { + else bonus.Position = pos; - } } score += (int)delta; - var scoreLabel = GetChild((int)Tags.ScoreLabel) as CCLabelBMFont; - scoreLabel.Label = score.ToString(); + var scoreLabel = GetChild ((int)Tags.ScoreLabel) as CCLabelBMFont; + scoreLabel.Label = score.ToString (); } bird.Position = bird_pos; - if (particles !=null) { - var particle_pos = new PointF(bird_pos.X,bird_pos.Y-17); + if (particles != null) { + var particle_pos = new CGPoint (bird_pos.X, bird_pos.Y - 17); particles.Position = particle_pos; } } void Jump () { - bird_vel.Y = 400.0f + Math.Abs(bird_vel.X); + bird_vel.Y = 400.0f + Math.Abs (bird_vel.X); - var old_part = GetChild((int)Tags.Particles); - if (old_part!=null) - Remove(old_part,true); + var old_part = GetChild ((int)Tags.Particles); + if (old_part != null) + Remove (old_part, true); - var particle = new CCParticleFireworks() { + var particle = new CCParticleFireworks () { Position = bird_pos, - Gravity = new PointF(0,-5000), + Gravity = new CGPoint (0, -5000), Duration = .3f, }; - Add (particle,-1,(int)Tags.Particles); + Add (particle, -1, (int)Tags.Particles); } public override void DidAccelerate (UIAccelerometer accelerometer, UIAcceleration acceleration) { - if(gameSuspended) + if (gameSuspended) return; float accel_filter = 0.1f; bird_vel.X = bird_vel.X * accel_filter + (float)acceleration.X * (1.0f - accel_filter) * 500.0f; @@ -405,19 +415,8 @@ public override void DidAccelerate (UIAccelerometer accelerometer, UIAcceleratio void ShowHighScores () { gameSuspended = true; - UIApplication.SharedApplication.IdleTimerDisabled=false; - CCDirector.SharedDirector.ReplaceScene(new CCTransitionFade(1, HighScoreLayer.Scene(score),CCColor3B.White)); + UIApplication.SharedApplication.IdleTimerDisabled = false; + CCDirector.SharedDirector.ReplaceScene (new CCTransitionFade (1, HighScoreLayer.Scene (score), CCColor3B.White)); } } - - //public class AccelerometerDelegate : UIAccelerometerDelegate { - // Action Callback; - // public AccelerometerDelegate (Action callback) { - // Callback = callback; - // } - // public override void DidAccelerate (UIAccelerometer accelerometer, UIAcceleration acceleration) - // { - // Callback(accelerometer,acceleration); - // } - //} } \ No newline at end of file diff --git a/cocos2d/samples/Jumpy/Jumpy/HighScoreLayer.cs b/cocos2d/samples/Jumpy/Jumpy/HighScoreLayer.cs index 1fe0a31e..26d09abc 100644 --- a/cocos2d/samples/Jumpy/Jumpy/HighScoreLayer.cs +++ b/cocos2d/samples/Jumpy/Jumpy/HighScoreLayer.cs @@ -21,48 +21,41 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using System; -using System.Drawing; +using CoreGraphics; using MonoTouch.Cocos2D; namespace Jumpy { public class HighScoreLayer:MainLayer { - - int currentScore; - - public static CCScene Scene (int score) { + public static CCScene Scene (int score) + { var scene = new CCScene (); var layer = new HighScoreLayer (score); - scene.Add(layer); + scene.Add (layer); return scene; } public override void OnEnter () { base.OnEnter (); - Schedule(Step); + Schedule (Step); } - public HighScoreLayer (int score): base() + public HighScoreLayer (int score) : base () { - currentScore = score; - - var batchnode = GetChild ((int)Tags.SpriteManager) as CCSpriteBatchNode; - var title = new CCSprite(batchnode.Texture,new RectangleF(608,192,225,57)) {Position=new PointF(160,240)}; + var title = new CCSprite (batchnode.Texture, new CGRect (608, 192, 225, 57)) { Position = new CGPoint (160, 240) }; batchnode.Add (title); - - - var button1 = new CCMenuItemImage("Images/playAgainButton.png", "Images/playAgainButton.png", (sender)=>{ - CCDirector.SharedDirector.ReplaceScene(new CCTransitionFade(.5f, GameLayer.Scene, CCColor3B.White)); + var button1 = new CCMenuItemImage ("Images/playAgainButton.png", "Images/playAgainButton.png", (sender) => { + CCDirector.SharedDirector.ReplaceScene (new CCTransitionFade (.5f, GameLayer.Scene, CCColor3B.White)); }); - var button2 = new CCMenuItemImage("Images/changePlayerButton.png", "Images/changePlayerButton.png", (sender)=>{ + var button2 = new CCMenuItemImage ("Images/changePlayerButton.png", "Images/changePlayerButton.png", (sender) => { }); - var menu = new CCMenu(new CCMenuItem[] {button1,button2}) {Position=new PointF(160,58)}; - menu.AlignItemsVertically(9); + var menu = new CCMenu (new CCMenuItem[] { button1, button2 }) { Position = new CGPoint (160, 58) }; + menu.AlignItemsVertically (9); Add (menu); diff --git a/cocos2d/samples/Jumpy/Jumpy/Info.plist b/cocos2d/samples/Jumpy/Jumpy/Info.plist index 895c9f80..f3586705 100644 --- a/cocos2d/samples/Jumpy/Jumpy/Info.plist +++ b/cocos2d/samples/Jumpy/Jumpy/Info.plist @@ -10,5 +10,7 @@ UIInterfaceOrientationPortrait + MinimumOSVersion + 5.1.1 diff --git a/cocos2d/samples/Jumpy/Jumpy/Jumpy.csproj b/cocos2d/samples/Jumpy/Jumpy/Jumpy.csproj index 6a6e56f8..7695e774 100644 --- a/cocos2d/samples/Jumpy/Jumpy/Jumpy.csproj +++ b/cocos2d/samples/Jumpy/Jumpy/Jumpy.csproj @@ -6,11 +6,13 @@ 10.0.0 2.0 {F7F2973E-A67D-4719-8B9F-7A16BAE62FA4} - {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Exe Jumpy Resources Jumpy + Xamarin.iOS + v1.0 True @@ -58,6 +60,7 @@ 4 False iPhone Developer + ARMv7, ARM64 none @@ -68,6 +71,7 @@ False True iPhone Distribution + ARMv7, ARM64 none @@ -77,15 +81,16 @@ 4 False iPhone Distribution + ARMv7, ARM64 - ..\..\..\binding\Cocos2D.dll + @@ -97,7 +102,6 @@ - @@ -113,4 +117,5 @@ + \ No newline at end of file diff --git a/cocos2d/samples/Jumpy/Jumpy/Main.cs b/cocos2d/samples/Jumpy/Jumpy/Main.cs index 1c30a0fc..cb69fbdc 100644 --- a/cocos2d/samples/Jumpy/Jumpy/Main.cs +++ b/cocos2d/samples/Jumpy/Jumpy/Main.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.Linq; -using MonoTouch.Foundation; -using MonoTouch.UIKit; +using Foundation; +using UIKit; namespace Jumpy { diff --git a/cocos2d/samples/Jumpy/Jumpy/MainLayer.cs b/cocos2d/samples/Jumpy/Jumpy/MainLayer.cs index 101608ea..347f78e0 100644 --- a/cocos2d/samples/Jumpy/Jumpy/MainLayer.cs +++ b/cocos2d/samples/Jumpy/Jumpy/MainLayer.cs @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using System; -using System.Drawing; +using CoreGraphics; using MonoTouch.Cocos2D; namespace Jumpy @@ -32,7 +32,8 @@ public class MainLayer:CCLayer protected int currentCloudTag; protected int numClouds = 12; - protected enum Tags : int { + protected enum Tags : int + { SpriteManager = 0, Bird, ScoreLabel, @@ -44,106 +45,105 @@ protected enum Tags : int { public MainLayer () { - rnd = new Random(); - var batchnode = new CCSpriteBatchNode("Images/sprites.png",10); + rnd = new Random (); + var batchnode = new CCSpriteBatchNode ("Images/sprites.png", 10); Add (batchnode, -1, (int)Tags.SpriteManager); - var background = new CCSprite(batchnode.Texture, new RectangleF(0,0,320,480)) {Position = new PointF (160,240)}; + var background = new CCSprite (batchnode.Texture, new CGRect (0, 0, 320, 480)) { Position = new CGPoint (160, 240) }; batchnode.Add (background); } public override void OnEnter () { base.OnEnter (); - InitClouds (); - - } - void InitClouds () { + void InitClouds () + { currentCloudTag = (int)Tags.CloudsStart; - while (currentCloudTag < (int)Tags.CloudsStart + numClouds) - { + while (currentCloudTag < (int)Tags.CloudsStart + numClouds) { InitCloud (); currentCloudTag++; } ResetClouds (); } - - void InitCloud () { + + void InitCloud () + { - RectangleF rect; - switch(rnd.Next()%3) { + CGRect rect; + switch (rnd.Next () % 3) { case 0: - rect = new RectangleF(336,16,256,108); + rect = new CGRect (336, 16, 256, 108); break; case 1: - rect = new RectangleF(336,128,257,110); + rect = new CGRect (336, 128, 257, 110); break; default: - rect = new RectangleF(336,240,252,119); + rect = new CGRect (336, 240, 252, 119); break; } var batchNode = GetChild ((int)Tags.SpriteManager) as CCSpriteBatchNode; - var cloud = new CCSprite(batchNode.Texture, rect); - batchNode.Add(cloud,3,currentCloudTag); + var cloud = new CCSprite (batchNode.Texture, rect); + batchNode.Add (cloud, 3, currentCloudTag); cloud.Opacity = 128; } - protected void ResetClouds () { - // NSLog(@"resetClouds"); - + protected void ResetClouds () + { currentCloudTag = (int)Tags.CloudsStart; - while(currentCloudTag < (int)Tags.CloudsStart + numClouds) { + while (currentCloudTag < (int)Tags.CloudsStart + numClouds) { ResetCloud (); - var batchNode = GetChild((int)Tags.SpriteManager) as CCSpriteBatchNode; - var cloud = batchNode.GetChild(currentCloudTag) as CCSprite; - cloud.Position = new PointF(cloud.Position.X, cloud.Position.Y-480); + var batchNode = GetChild ((int)Tags.SpriteManager) as CCSpriteBatchNode; + var cloud = batchNode.GetChild (currentCloudTag) as CCSprite; + cloud.Position = new CGPoint (cloud.Position.X, cloud.Position.Y - 480); currentCloudTag++; } } - - protected void ResetCloud () { + + protected void ResetCloud () + { - var batchNode = GetChild((int)Tags.SpriteManager) as CCSpriteBatchNode; - var cloud = batchNode.GetChild(currentCloudTag) as CCSprite; + var batchNode = GetChild ((int)Tags.SpriteManager) as CCSpriteBatchNode; + var cloud = batchNode.GetChild (currentCloudTag) as CCSprite; - float distance = rnd.Next()%20 + 5; + float distance = rnd.Next () % 20 + 5; float scale = 5.0f / distance; cloud.Scale = scale; - if(rnd.Next()%2==1) cloud.ScaleX = -cloud.ScaleX; + if (rnd.Next () % 2 == 1) + cloud.ScaleX = -cloud.ScaleX; var size = cloud.ContentSize; - float scaled_width = size.Width * scale; - float x = rnd.Next()%(320+(int)scaled_width) - scaled_width/2; - float y = rnd.Next()%(480-(int)scaled_width) + scaled_width/2 + 480; + nfloat scaled_width = size.Width * scale; + nfloat x = rnd.Next () % (320 + (int)scaled_width) - scaled_width / 2; + nfloat y = rnd.Next () % (480 - (int)scaled_width) + scaled_width / 2 + 480; - cloud.Position = new PointF(x,y); + cloud.Position = new CGPoint (x, y); } - protected virtual void Step(float dt) { - // NSLog(@"Main::step"); - - for(var t = (int)Tags.CloudsStart; t < (int)Tags.CloudsStart + numClouds; t++) { - var batchNode = GetChild((int)Tags.SpriteManager) as CCSpriteBatchNode; - var cloud = batchNode.GetChild(t) as CCSprite; + protected virtual void Step (float dt) + { + for (var t = (int)Tags.CloudsStart; t < (int)Tags.CloudsStart + numClouds; t++) { + var batchNode = GetChild ((int)Tags.SpriteManager) as CCSpriteBatchNode; + var cloud = batchNode.GetChild (t) as CCSprite; var pos = cloud.Position; var size = cloud.ContentSize; pos.X += 0.1f * cloud.ScaleY; - if(pos.X > 320 + size.Width/2) { - pos.X = -size.Width/2; - } + + if (pos.X > 320 + size.Width / 2) + pos.X = -size.Width / 2; + cloud.Position = pos; } }