From 7b417ee0e98de336b529a7fdf6c8b9ede7bf701a Mon Sep 17 00:00:00 2001 From: jy Date: Mon, 19 Aug 2013 14:43:36 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=8C=E6=9C=BA?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=BD=8D=E7=BD=AE=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E5=85=B6=E8=BF=87=E4=BA=8E=E9=9D=A0=E8=BF=91=E5=B1=8F=E5=B9=95?= =?UTF-8?q?=E8=BE=B9=E7=BC=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlaneWar/GameLayer.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PlaneWar/GameLayer.m b/PlaneWar/GameLayer.m index a7481b5..8bea278 100644 --- a/PlaneWar/GameLayer.m +++ b/PlaneWar/GameLayer.m @@ -168,7 +168,7 @@ -(void)showEnemy{ CCSprite *enemy=[CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"enemy%i_fly_1.png",type]]; enemy.anchorPoint=ccp(0.5,0); - enemy.position=ccp(arc4random()%(int)(winSize.width+1),winSize.height); + enemy.position=ccp(20+arc4random()%(int)(winSize.width-40+1),winSize.height); [self addChild:enemy z:4]; //Tag用于记录敌机类型和HP值(这比再写一个类要方便多了) From 9578e3ee86225c55d19973c012c1ae0e9de4c410 Mon Sep 17 00:00:00 2001 From: jy Date: Mon, 19 Aug 2013 15:07:48 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E6=95=B0=E5=87=BD=E6=95=B0=EF=BC=8C=E8=AE=A9=E6=95=8C=E6=9C=BA?= =?UTF-8?q?=E6=9C=89=E4=B8=8D=E5=90=8C=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlaneWar.xcodeproj/project.pbxproj | 12 +++++++++--- PlaneWar/Common.h | 13 +++++++++++++ PlaneWar/Common.m | 20 ++++++++++++++++++++ PlaneWar/GameLayer.m | 5 +++-- 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 PlaneWar/Common.h create mode 100644 PlaneWar/Common.m diff --git a/PlaneWar.xcodeproj/project.pbxproj b/PlaneWar.xcodeproj/project.pbxproj index 78bdc2a..b079706 100644 --- a/PlaneWar.xcodeproj/project.pbxproj +++ b/PlaneWar.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + A40FF94D17C1F8AF00CA29BB /* Common.m in Sources */ = {isa = PBXBuildFile; fileRef = A40FF94C17C1F8AF00CA29BB /* Common.m */; }; A9466EDF17BDDC9E009232EA /* gameArts-hd.plist in Resources */ = {isa = PBXBuildFile; fileRef = A9466EDD17BDDC9E009232EA /* gameArts-hd.plist */; }; A9466EE017BDDC9E009232EA /* gameArts-hd.png in Resources */ = {isa = PBXBuildFile; fileRef = A9466EDE17BDDC9E009232EA /* gameArts-hd.png */; }; A948CDCF17BDD5A300BB9EC9 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A948CDCE17BDD5A300BB9EC9 /* QuartzCore.framework */; }; @@ -149,6 +150,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + A40FF94B17C1F8AF00CA29BB /* Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Common.h; sourceTree = ""; }; + A40FF94C17C1F8AF00CA29BB /* Common.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Common.m; sourceTree = ""; }; A9466EDD17BDDC9E009232EA /* gameArts-hd.plist */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = "gameArts-hd.plist"; sourceTree = ""; }; A9466EDE17BDDC9E009232EA /* gameArts-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "gameArts-hd.png"; sourceTree = ""; }; A948CDCB17BDD5A300BB9EC9 /* PlaneWar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PlaneWar.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -498,14 +501,16 @@ children = ( A948CF7317BDD5A500BB9EC9 /* AppDelegate.h */, A948CF7417BDD5A500BB9EC9 /* AppDelegate.m */, - A948CF7617BDD5A500BB9EC9 /* HelloWorldLayer.h */, - A948CF7717BDD5A500BB9EC9 /* HelloWorldLayer.m */, + A40FF94B17C1F8AF00CA29BB /* Common.h */, + A40FF94C17C1F8AF00CA29BB /* Common.m */, A948CF8117BDD5F200BB9EC9 /* GameLayer.h */, A948CF8217BDD5F200BB9EC9 /* GameLayer.m */, + A948CF7617BDD5A500BB9EC9 /* HelloWorldLayer.h */, + A948CF7717BDD5A500BB9EC9 /* HelloWorldLayer.m */, A948CF7917BDD5A500BB9EC9 /* IntroLayer.h */, A948CF7A17BDD5A500BB9EC9 /* IntroLayer.m */, - A948CDE317BDD5A300BB9EC9 /* Resources */, A948CDFB17BDD5A300BB9EC9 /* libs */, + A948CDE317BDD5A300BB9EC9 /* Resources */, A948CF6F17BDD5A500BB9EC9 /* Supporting Files */, ); path = PlaneWar; @@ -1086,6 +1091,7 @@ A948CF7817BDD5A500BB9EC9 /* HelloWorldLayer.m in Sources */, A948CF7B17BDD5A500BB9EC9 /* IntroLayer.m in Sources */, A948CF8317BDD5F200BB9EC9 /* GameLayer.m in Sources */, + A40FF94D17C1F8AF00CA29BB /* Common.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/PlaneWar/Common.h b/PlaneWar/Common.h new file mode 100644 index 0000000..13e2323 --- /dev/null +++ b/PlaneWar/Common.h @@ -0,0 +1,13 @@ +// +// Common.h +// PlaneWar +// +// Created by jy on 13-8-19. +// Copyright (c) 2013年 GetToSet. All rights reserved. +// + +#import + +float randomFloatRange(float begin, float end); +int randomIntRange(int begin, int end); + diff --git a/PlaneWar/Common.m b/PlaneWar/Common.m new file mode 100644 index 0000000..c7e5e22 --- /dev/null +++ b/PlaneWar/Common.m @@ -0,0 +1,20 @@ +// +// Common.m +// PlaneWar +// +// Created by jy on 13-8-19. +// Copyright (c) 2013年 GetToSet. All rights reserved. +// +#import "Common.h" + +#define ARC4RANDOM_MAX 0x100000000 + +float randomFloatRange(float begin, float end){ + float range = end - begin; + float result = ((float)arc4random() / ARC4RANDOM_MAX) * range + begin; + return result; +} + +int randomIntRange(int begin, int end){ + return arc4random()%(end-begin+1)+begin; +} diff --git a/PlaneWar/GameLayer.m b/PlaneWar/GameLayer.m index 8bea278..a958992 100644 --- a/PlaneWar/GameLayer.m +++ b/PlaneWar/GameLayer.m @@ -7,6 +7,7 @@ // #import "GameLayer.h" +#import "Common.h" @implementation GameLayer @@ -168,7 +169,7 @@ -(void)showEnemy{ CCSprite *enemy=[CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"enemy%i_fly_1.png",type]]; enemy.anchorPoint=ccp(0.5,0); - enemy.position=ccp(20+arc4random()%(int)(winSize.width-40+1),winSize.height); + enemy.position=ccp(randomFloatRange(20.0, winSize.width-20.0),winSize.height); [self addChild:enemy z:4]; //Tag用于记录敌机类型和HP值(这比再写一个类要方便多了) @@ -181,7 +182,7 @@ -(void)showEnemy{ [enemy runAction:action]; } - id enemyMoveDown=[CCMoveBy actionWithDuration:5.0f position:ccp(0,-winSize.height-enemy.boundingBox.size.height)]; + id enemyMoveDown=[CCMoveBy actionWithDuration:(randomFloatRange(3.0, 6.0)) position:ccp(0,-winSize.height-enemy.boundingBox.size.height)]; id enemyMoveEnd=[CCCallFuncND actionWithTarget:self selector:@selector(enemyMoveEndedWithAction:Sprite:) data:enemy]; [enemy runAction:[CCSequence actions:enemyMoveDown,enemyMoveEnd,nil]]; From 4a81e50b34ea54852c44da7abaa986b38da49cc8 Mon Sep 17 00:00:00 2001 From: jy Date: Mon, 19 Aug 2013 15:18:03 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BD=BF=E7=94=A8CGFloat=E5=92=8CNSInteger?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2float=E5=92=8Cint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlaneWar/Common.h | 4 ++-- PlaneWar/Common.m | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/PlaneWar/Common.h b/PlaneWar/Common.h index 13e2323..fd48f21 100644 --- a/PlaneWar/Common.h +++ b/PlaneWar/Common.h @@ -8,6 +8,6 @@ #import -float randomFloatRange(float begin, float end); -int randomIntRange(int begin, int end); +CGFloat randomFloatRange(CGFloat begin, CGFloat end); +NSInteger randomIntRange(NSInteger begin, NSInteger end); diff --git a/PlaneWar/Common.m b/PlaneWar/Common.m index c7e5e22..17bfb01 100644 --- a/PlaneWar/Common.m +++ b/PlaneWar/Common.m @@ -9,12 +9,11 @@ #define ARC4RANDOM_MAX 0x100000000 -float randomFloatRange(float begin, float end){ - float range = end - begin; - float result = ((float)arc4random() / ARC4RANDOM_MAX) * range + begin; - return result; +CGFloat randomFloatRange(CGFloat begin, CGFloat end){ + CGFloat range = end - begin; + return ((CGFloat)arc4random() / ARC4RANDOM_MAX) * range + begin; } -int randomIntRange(int begin, int end){ +NSInteger randomIntRange(NSInteger begin, NSInteger end){ return arc4random()%(end-begin+1)+begin; } From 5b9868e68812d7dcabd70bbe7a7ede77873f631b Mon Sep 17 00:00:00 2001 From: jy Date: Mon, 19 Aug 2013 15:51:25 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E6=9C=89?= =?UTF-8?q?=E6=97=B6=E6=9C=80=E5=A4=A7=E9=A3=9E=E6=9C=BA=E8=A2=AB=E6=89=93?= =?UTF-8?q?=E6=AD=BB=E4=B9=8B=E5=90=8E=E4=BC=9A=E8=B0=83=E7=94=A8=E6=9C=80?= =?UTF-8?q?=E5=B0=8F=E9=A3=9E=E6=9C=BA=E7=9A=84=E5=8A=A8=E7=94=BB=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlaneWar/GameLayer.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/PlaneWar/GameLayer.m b/PlaneWar/GameLayer.m index a958992..1de2878 100644 --- a/PlaneWar/GameLayer.m +++ b/PlaneWar/GameLayer.m @@ -11,6 +11,16 @@ @implementation GameLayer +/** + * 防止出现短时间内击中敌机使得其HP<0导致的type改变 + * 原理:tag = type * 100 + hp, + * 如果敌机type = 2 ,hp = 0,在系统未完成敌机死亡检测时再次被击中,则从tag计算得出的type变成1 + * 加上Buffer后,即使hp变成-1,tag值依然大于type * 100 + * 计算hp时减去Buffer即可 + * PS 依然是ugly hack + */ +static NSInteger hpBuffer = 10; + //基本方法 +(CCScene*)scene{ @@ -173,7 +183,7 @@ -(void)showEnemy{ [self addChild:enemy z:4]; //Tag用于记录敌机类型和HP值(这比再写一个类要方便多了) - [enemy setTag:type*100+hp]; + [enemy setTag:type*100+hp+hpBuffer]; [enemies addObject:enemy]; @@ -470,7 +480,7 @@ -(int)getEnemyTypeWithTag:(NSUInteger)tag{ } -(int)getEnemyHpWithTag:(NSUInteger)tag{ - return tag%100; + return tag%100-hpBuffer; } //对话框回调 From f741ed0ecbc1a0155ba11dbb9169c9cb07723e08 Mon Sep 17 00:00:00 2001 From: jy Date: Mon, 19 Aug 2013 17:56:52 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9A=82=E5=81=9C?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlaneWar/GameLayer.h | 2 ++ PlaneWar/GameLayer.m | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/PlaneWar/GameLayer.h b/PlaneWar/GameLayer.h index 4a1e8a6..a5aa1af 100644 --- a/PlaneWar/GameLayer.h +++ b/PlaneWar/GameLayer.h @@ -15,6 +15,8 @@ CCSprite *playerPlane; CCSprite *bomb; + + CCSprite *pause; CCLabelTTF *scoreLabel; diff --git a/PlaneWar/GameLayer.m b/PlaneWar/GameLayer.m index 1de2878..679bfd2 100644 --- a/PlaneWar/GameLayer.m +++ b/PlaneWar/GameLayer.m @@ -45,6 +45,7 @@ -(id)init{ [self startShowEnemies]; [self startCheckCollision]; [self loadBombButton]; + [self loadPauseButton]; [self startShowProps]; [self loadScoreLabel]; } @@ -406,6 +407,14 @@ -(void)loadBombButton{ [bomb setVisible:NO]; } +-(void)loadPauseButton{ + pause=[CCSprite spriteWithSpriteFrameName:@"game_pause.png"]; + pause.anchorPoint = ccp(0,0); + pause.position = ccp(winSize.width*0.85, winSize.height*0.9); + [self addChild:pause]; + [pause setVisible:YES]; +} + //触摸处理 -(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ @@ -426,11 +435,20 @@ -(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [enemies removeAllObjects]; } + }else if (CGRectContainsPoint(pause.boundingBox, touchLocation)){ + if ([[CCDirector sharedDirector] isPaused]) { + [[CCDirector sharedDirector] resume]; + }else{ + [[CCDirector sharedDirector] pause]; + } } } -(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ - + if ([[CCDirector sharedDirector] isPaused]) { + return; + } + UITouch *touch=[touches anyObject]; CGPoint touchLocation=[touch locationInView:touch.view]; touchLocation=[[CCDirector sharedDirector]convertToGL:touchLocation]; From d6b6217a3d51136cf83e75f673ca4c16ee9d4860 Mon Sep 17 00:00:00 2001 From: jy Date: Mon, 19 Aug 2013 18:01:42 +0800 Subject: [PATCH 6/7] add gitignore --- .gitignore | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7597e94 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Xcode +.DS_Store +*/build/* +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +profile +*.moved-aside +DerivedData +.idea/ +*.hmap + +#CocoaPods +Pods \ No newline at end of file From ca411fddb821a48cb10c8c0e77710c0d18333bca Mon Sep 17 00:00:00 2001 From: jy Date: Mon, 2 Sep 2013 13:06:00 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=93=8D=E6=8E=A7?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=B8=8D=E5=BF=85=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E5=88=B0=E9=A3=9E=E6=9C=BA=E4=B8=8A=E5=B0=B1=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PlaneWar/GameLayer.m | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/PlaneWar/GameLayer.m b/PlaneWar/GameLayer.m index 679bfd2..4273683 100644 --- a/PlaneWar/GameLayer.m +++ b/PlaneWar/GameLayer.m @@ -458,11 +458,9 @@ -(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ CGPoint translation=ccpSub(touchLocation,oldTouchLocation); - if(CGRectContainsPoint(playerPlane.boundingBox,touchLocation)){ - CGPoint newPos = ccpAdd(playerPlane.position,translation); - if(CGRectContainsRect(CGRectMake(0,0,winSize.width,winSize.height),[self newRectWithSize:playerPlane.boundingBox.size Point:newPos AnchorPoint:ccp(0.5,0.5)])){ - playerPlane.position = newPos; - } + CGPoint newPos = ccpAdd(playerPlane.position,translation); + if(CGRectContainsRect(CGRectMake(0,0,winSize.width,winSize.height),[self newRectWithSize:playerPlane.boundingBox.size Point:newPos AnchorPoint:ccp(0.5,0.5)])){ + playerPlane.position = newPos; } }