Skip to content

Commit

Permalink
change HelloWorld to Ball, add Ball scene
Browse files Browse the repository at this point in the history
  • Loading branch information
saberma committed Apr 3, 2010
1 parent ec1786c commit d366d17
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 61 deletions.
18 changes: 12 additions & 6 deletions BrainShot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
2F7DEE4211639D21004E947B /* fail.png in Resources */ = {isa = PBXBuildFile; fileRef = 2F7DEE4011639D21004E947B /* fail.png */; };
2F7DEE4311639D21004E947B /* pass.png in Resources */ = {isa = PBXBuildFile; fileRef = 2F7DEE4111639D21004E947B /* pass.png */; };
2F7DEE5711639E6A004E947B /* ScoreLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 2F7DEE5611639E6A004E947B /* ScoreLayer.m */; };
2FACE4D611673BE00062B492 /* BallLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 2FACE4D511673BE00062B492 /* BallLayer.m */; };
502BC35D1120837500A0B92A /* CDAudioManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 502BC3551120837500A0B92A /* CDAudioManager.h */; };
502BC35E1120837500A0B92A /* CDAudioManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 502BC3561120837500A0B92A /* CDAudioManager.m */; };
502BC35F1120837500A0B92A /* CDConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 502BC3571120837500A0B92A /* CDConfig.h */; };
Expand All @@ -60,7 +61,7 @@
50674855107A3AF30090963A /* ZAttributedStringPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 50674852107A3AF30090963A /* ZAttributedStringPrivate.h */; };
506EDB88102F4C4000A389B3 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 506EDB87102F4C4000A389B3 /* libz.dylib */; };
506EDBA5102F4C9F00A389B3 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 506EDBA4102F4C9F00A389B3 /* AVFoundation.framework */; };
506EDC31102F528A00A389B3 /* HelloWorldScene.m in Sources */ = {isa = PBXBuildFile; fileRef = 506EDC30102F528A00A389B3 /* HelloWorldScene.m */; };
506EDC31102F528A00A389B3 /* BallScene.m in Sources */ = {isa = PBXBuildFile; fileRef = 506EDC30102F528A00A389B3 /* BallScene.m */; };
506EE1A91030508200A389B3 /* libcocos2d libraries.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 506EE05E10304ED200A389B3 /* libcocos2d libraries.a */; };
50D3B09711498A370002F919 /* CCAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 50D3B00A11498A370002F919 /* CCAction.h */; };
50D3B09811498A370002F919 /* CCAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 50D3B00B11498A370002F919 /* CCAction.m */; };
Expand Down Expand Up @@ -300,6 +301,8 @@
2F7DEE4111639D21004E947B /* pass.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pass.png; sourceTree = "<group>"; };
2F7DEE5511639E6A004E947B /* ScoreLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScoreLayer.h; sourceTree = "<group>"; };
2F7DEE5611639E6A004E947B /* ScoreLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScoreLayer.m; sourceTree = "<group>"; };
2FACE4D411673BE00062B492 /* BallLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BallLayer.h; sourceTree = "<group>"; };
2FACE4D511673BE00062B492 /* BallLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BallLayer.m; sourceTree = "<group>"; };
502BC3551120837500A0B92A /* CDAudioManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDAudioManager.h; sourceTree = "<group>"; };
502BC3561120837500A0B92A /* CDAudioManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDAudioManager.m; sourceTree = "<group>"; };
502BC3571120837500A0B92A /* CDConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDConfig.h; sourceTree = "<group>"; };
Expand All @@ -321,8 +324,8 @@
50674852107A3AF30090963A /* ZAttributedStringPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZAttributedStringPrivate.h; sourceTree = "<group>"; };
506EDB87102F4C4000A389B3 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
506EDBA4102F4C9F00A389B3 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
506EDC2F102F528A00A389B3 /* HelloWorldScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HelloWorldScene.h; sourceTree = "<group>"; };
506EDC30102F528A00A389B3 /* HelloWorldScene.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HelloWorldScene.m; sourceTree = "<group>"; };
506EDC2F102F528A00A389B3 /* BallScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BallScene.h; sourceTree = "<group>"; };
506EDC30102F528A00A389B3 /* BallScene.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BallScene.m; sourceTree = "<group>"; };
506EE05E10304ED200A389B3 /* libcocos2d libraries.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libcocos2d libraries.a"; sourceTree = BUILT_PRODUCTS_DIR; };
50D3B00A11498A370002F919 /* CCAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCAction.h; sourceTree = "<group>"; };
50D3B00B11498A370002F919 /* CCAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCAction.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -592,8 +595,8 @@
children = (
2F7DEDDF116391C8004E947B /* Models */,
2F7DEDA611639134004E947B /* SQLPO */,
506EDC2F102F528A00A389B3 /* HelloWorldScene.h */,
506EDC30102F528A00A389B3 /* HelloWorldScene.m */,
506EDC2F102F528A00A389B3 /* BallScene.h */,
506EDC30102F528A00A389B3 /* BallScene.m */,
1F3B9A2C0EF2145700286867 /* BrainShotAppDelegate.h */,
1F3B9A2B0EF2145700286867 /* BrainShotAppDelegate.m */,
2F07E1FA1160F3650064F846 /* Ball.h */,
Expand All @@ -604,6 +607,8 @@
2F7DECF31163878C004E947B /* LevelScene.m */,
2F7DEE5511639E6A004E947B /* ScoreLayer.h */,
2F7DEE5611639E6A004E947B /* ScoreLayer.m */,
2FACE4D411673BE00062B492 /* BallLayer.h */,
2FACE4D511673BE00062B492 /* BallLayer.m */,
);
path = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -1112,7 +1117,7 @@
files = (
1D60589B0D05DD56006BFB54 /* main.m in Sources */,
1F3B9A2D0EF2145700286867 /* BrainShotAppDelegate.m in Sources */,
506EDC31102F528A00A389B3 /* HelloWorldScene.m in Sources */,
506EDC31102F528A00A389B3 /* BallScene.m in Sources */,
2F07E1FC1160F3650064F846 /* Ball.m in Sources */,
2F6DFD73116241200078600F /* Position.m in Sources */,
2F7DECF41163878C004E947B /* LevelScene.m in Sources */,
Expand All @@ -1134,6 +1139,7 @@
2F7DEDD611639134004E947B /* UIImage-SQLitePersistence.m in Sources */,
2F7DEDE2116391C8004E947B /* Level.m in Sources */,
2F7DEE5711639E6A004E947B /* ScoreLayer.m in Sources */,
2FACE4D611673BE00062B492 /* BallLayer.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
22 changes: 11 additions & 11 deletions Classes/HelloWorldScene.h → Classes/BallLayer.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@

// When you import this file, you import all the cocos2d classes
//
// BallLayer.h
// BrainShot
//
// Created by cogent on 10-4-3.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "LevelScene.h"
#import "Ball.h"
#import "Position.h"
#import "Level.h"
#import "LevelScene.h"
#import "ScoreLayer.h"
#import "Position.h"


// HelloWorld Layer
@interface HelloWorld : CCLayer < BallDelegate >
@interface BallLayer : CCLayer < BallDelegate >
{
NSMutableArray *balls;
NSArray *positions;
Expand All @@ -20,9 +23,6 @@
@property (nonatomic, retain) NSArray *positions;
@property int level;

// returns a Scene that contains the HelloWorld as the only child
+(id) scene;

-(void) start;

-(void) hide: (ccTime) dt;
Expand Down
53 changes: 17 additions & 36 deletions Classes/HelloWorldScene.m → Classes/BallLayer.m
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
//
// cocos2d Hello World example
// http://www.cocos2d-iphone.org
// BallLayer.m
// BrainShot
//
// Created by cogent on 10-4-3.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//

// Import the interfaces
#import "HelloWorldScene.h"
// HelloWorld implementation
@implementation HelloWorld
#import "BallLayer.h"

@synthesize balls, positions, level;
@implementation BallLayer

+(id) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];

// 'layer' is an autorelease object.
HelloWorld *layer = [HelloWorld node];
ScoreLayer *scoreLayer = [ScoreLayer node];

// add layer as a child to scene
[scene addChild: layer];
[scene addChild: scoreLayer];

// return the scene
return scene;
}
@synthesize balls, positions, level;

// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {

// ask director the the window size
//CGSize size = [[CCDirector sharedDirector] winSize];

Expand All @@ -57,10 +42,10 @@ -(void) start
{
[self removeAllChildrenWithCleanup:YES];
[Ball clearClicked];

NSMutableArray *tmpBalls = [[NSMutableArray alloc] init];
NSMutableArray *tmpPositions = [self.positions mutableCopy];

for (int number=0; number<[Level current]; number++) {
int rand = arc4random() % [tmpPositions count];
Position *position = [tmpPositions objectAtIndex:rand];
Expand All @@ -71,11 +56,11 @@ -(void) start
[self addChild:ball];
}
[self setBalls:tmpBalls];

[tmpPositions release];
[tmpBalls release];
[self schedule:@selector(hide:) interval:1.0f];

[self schedule:@selector(hide:) interval:([Level current] * 0.7f)];
}

-(void) hide: (ccTime) dt
Expand All @@ -89,17 +74,13 @@ -(void) hide: (ccTime) dt
-(void) restart: (ccTime) dt
{
[self unschedule:_cmd];
LevelScene *levelScene = [[LevelScene alloc] init];
[[CCDirector sharedDirector] replaceScene: levelScene];
[levelScene release];
[[CCDirector sharedDirector] replaceScene: [LevelScene node]];
}

-(void) nextLevel: (ccTime) dt
{
[self unschedule:_cmd];
LevelScene *levelScene = [[LevelScene alloc] init];
[[CCDirector sharedDirector] replaceScene: levelScene];
[levelScene release];
[[CCDirector sharedDirector] replaceScene: [LevelScene node]];
}

- (void)click: (Ball *) ball
Expand Down Expand Up @@ -137,7 +118,7 @@ - (void) dealloc
// don't forget to call "super dealloc"
[balls release];
[positions release];

[super dealloc];
}
@end
10 changes: 10 additions & 0 deletions Classes/BallScene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

// When you import this file, you import all the cocos2d classes
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "BallLayer.h"


@interface BallScene: CCScene

@end
23 changes: 23 additions & 0 deletions Classes/BallScene.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// cocos2d Hello World example
// http://www.cocos2d-iphone.org
//

#import "BallScene.h"


@implementation BallScene

// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {
[self addChild:[BallLayer node]];
[self addChild:[ScoreLayer node]];
}
return self;
}

@end
2 changes: 1 addition & 1 deletion Classes/BrainShotAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <UIKit/UIKit.h>
#import "cocos2d.h"
#import "HelloWorldScene.h"
#import "BallScene.h"
#import "LevelScene.h"

@interface BrainShotAppDelegate : NSObject <UIApplicationDelegate> {
Expand Down
5 changes: 1 addition & 4 deletions Classes/BrainShotAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ - (void) applicationDidFinishLaunching:(UIApplication*)application
[[CCDirector sharedDirector] attachInView:window];
[window makeKeyAndVisible];

LevelScene *levelScene = [[LevelScene alloc] init];
[[CCDirector sharedDirector] runWithScene: levelScene];
[levelScene release];
}
[[CCDirector sharedDirector] runWithScene: [LevelScene node]];}


- (void)applicationWillResignActive:(UIApplication *)application {
Expand Down
2 changes: 1 addition & 1 deletion Classes/LevelScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "HelloWorldScene.h"
#import "BallScene.h"


@interface LevelScene: CCScene
Expand Down
3 changes: 2 additions & 1 deletion Classes/LevelScene.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "LevelScene.h"
#import "Level.h"


@implementation LevelScene
Expand Down Expand Up @@ -36,6 +37,6 @@ -(id) init

- (void)finished
{
[[CCDirector sharedDirector] replaceScene:[HelloWorld scene]];
[[CCDirector sharedDirector] replaceScene:[BallScene node]];
}
@end
2 changes: 1 addition & 1 deletion Classes/Position.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>


// just for getting random position
@interface Position : NSObject {
int left;
int right;
Expand Down

0 comments on commit d366d17

Please sign in to comment.