SlideShare une entreprise Scribd logo
1  sur  54
Télécharger pour lire hors ligne
Saturday, October 26, 13
Saturday, October 26, 13
A game is a system in which players
engage in an artificial conflict,
defined by rules, that results in a
quantifiable outcome.
Rules of Play

Saturday, October 26, 13
Saturday, October 26, 13
[Expect(game)
toBe:Fun]
TDD in Games with Cocos2D

Saturday, October 26, 13
Sprites and Sprite Sheets
Scene Management
Actions and Animations
Effects
Menus
Tile Maps
And more....

Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
The player starts
the game and has
three buckets.  
They can move
the buckets right
and left.

Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
Hello World Layer
+(CCScene *) scene
{
!// 'scene' is an autorelease object.
!CCScene *scene = [CCScene node];
!
!// 'layer' is an autorelease object.
!HelloWorldLayer *layer = [HelloWorldLayer node];
!
!// add layer as a child to scene
![scene addChild: layer];
!
!// return the scene
!return scene;
}

Saturday, October 26, 13
Hello World Layer
// on "init" you need to initialize your instance
-(id) init
{
! // always call "super" init
! // Apple recommends to re-assign "self" with the "super's" return value
! if( (self=[super init]) ) {
!!
! ! // create and initialize a Label
! ! CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World"
fontName:@"Marker Felt" fontSize:64];
!!
!!
!
!!
!!
!!
!!
!!

// ask director for the window size
CGSize size = [[CCDirector sharedDirector] winSize];
// position the label on the center of the screen
label.position = ccp( size.width /2 , size.height/2 );
// add the label as a child to this Layer
[self addChild: label];

Saturday, October 26, 13
Buckets
OCDSpec2Context(BucketsSpec) {
Describe(@"moving", ^{
It(@"moves to the right", ^{
Buckets *buckets = [[Buckets alloc] initWithPosition:CGPointMake(10.0, 10.0)];
[buckets move:1];
[ExpectFloat(buckets.position.x) toBe:11.0 withPrecision:0.00001];
});
It(@"moves to the left", ^{
Buckets *buckets = [[Buckets alloc] initWithPosition:CGPointMake(10.0, 10.0)];
[buckets move:-1.0];
[ExpectFloat(buckets.position.x) toBe:9.0 withPrecision:0.00001];
});
});
}

Saturday, October 26, 13
Buckets
@implementation Buckets
-(id) initWithPosition:(CGPoint) position
{
if (self = [super init])
{
self.position = position;
}
return self;
}
-(void) move:(float) movement
{
self.position = CGPointMake(self.position.x + movement,
self.position.y);
}
@end

Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
Bombing Layer
-(id) init
{
if( (self=[super init]) ) {
! ! // ask director for the window size
! ! CGSize size = [[CCDirector sharedDirector] winSize];
Buckets *buckets = [[Buckets alloc] initWithPosition:CGPointMake(size.width / 2,
size.height / 2)];
BucketsSprite *sprite = [BucketsSprite spriteWithBuckets:buckets];
! ! // add the sprite as a child to this Layer
! ! [self addChild: sprite];
!}
! return self;
}

Saturday, October 26, 13
Buckets Sprite
@implementation BucketsSprite
+(id) spriteWithBuckets:(Buckets *)buckets
{
BucketsSprite *sprite =
[BucketsSprite spriteWithFile:@"buckets.png"];
sprite.buckets = buckets;
[sprite scheduleUpdate];
return sprite;
}
-(void)update:(ccTime)delta {
[self setPosition:self.buckets.position];
}
@end

Saturday, October 26, 13
Saturday, October 26, 13
Bombing Layer
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint point = [touch locationInView:[touch view]];
CGSize size = [[CCDirector sharedDirector] winSize];
if (point.x > size.width / 2)
{
self.movement++;
}
else
{
self.movement--;
}
return YES;
}

Saturday, October 26, 13
Bombing Layer
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint point = [touch locationInView:[touch view]];
CGSize size = [[CCDirector sharedDirector] winSize];
if (point.x > size.width / 2)
{
self.movement--;
}
else
{
self.movement++;
}
}

Saturday, October 26, 13
Bombing Layer
-(void)update:(ccTime)delta
{
BucketsSprite *sprite =
(BucketsSprite *)[self getChildByTag:kBucket];
[sprite move:self.movement];
}

Saturday, October 26, 13
Saturday, October 26, 13
?
Saturday, October 26, 13
Saturday, October 26, 13
Bomber Spec
OCDSpec2Context(BomberSpec) {
Describe(@"moving back and forth", ^{
It(@"moves towards its next spot", ^{
RiggedLocations *locations = [RiggedLocations newWithValues:@[@0.0]];
Bomber *bomber = [[Bomber alloc] initWithPosition:CGPointMake(10, 40)
speed:1.0
locationChooser:locations];
[bomber start];
[bomber update:1.0];
[ExpectFloat(bomber.position.x) toBe:9.0 withPrecision:0.0001];
});

Saturday, October 26, 13
Rigged Locations
@implementation RiggedLocations
-(float) next {
float value = [(NSNumber *) [self.values firstObject]
floatValue];
if (self.values.count > 1) {
[self.values removeObjectAtIndex:0];
}
return value;
}
+(RiggedLocations *) newWithValues:(NSArray *)array {
RiggedLocations *locations = [RiggedLocations new];
locations.values = [NSMutableArray
arrayWithArray:array];
return locations;
}
@end

Saturday, October 26, 13
Random Locations
Describe(@"using the random number generator", ^{
It(@"uses the random number generator for its next location", ^{
id rand = [OCMockObject mockForProtocol:@protocol(RandomNumberGenerator)];
NSRange range = NSMakeRange(0, 100);
RandomLocationChooser *chooser = [RandomLocationChooser newChooserWithRange:range generator:rand];
float retVal = 0.0;
[[[rand stub] andReturnValue:OCMOCK_VALUE(retVal)] generate];
[ExpectFloat([chooser next]) toBe:0.0 withPrecision:0.0001];
});

Saturday, October 26, 13
Saturday, October 26, 13
Bomber Spec
It(@"stops at the location when coming from the left", ^{
RiggedLocations *locations = [RiggedLocations newWithValues:@[@19.0, @22.0]];
Bomber *bomber = [[Bomber alloc] initWithPosition:CGPointMake(17, 40) speed:2.0
locationChooser:locations];
[bomber start];
[bomber update:1.0];
[bomber update:1.0];
[ExpectFloat(bomber.position.x) toBe:21.0 withPrecision:0.0001];
});
It(@"doesn't move until it is started", ^{
RiggedLocations *locations = [RiggedLocations newWithValues:@[@19.0, @22.0]];
Bomber *bomber = [[Bomber alloc] initWithPosition:CGPointMake(17, 40) speed:2.0
locationChooser:locations];
[bomber update:1.0];
[ExpectFloat(bomber.position.x) toBe:17.0 withPrecision:0.0001];
});

Saturday, October 26, 13
Bomber
- (void)update:(float)deltaTime
{
if (self.started)
{
float moveDistance = self.speed * deltaTime;
float distanceRemaining = abs(self.location - self.position.x);
if (self.location > self.position.x) {
self.position = CGPointMake(self.position.x + moveDistance, self.position.y);
}
else {
self.position = CGPointMake(self.position.x - moveDistance, self.position.y);
}
if (moveDistance >= distanceRemaining) {
self.location = [self.locations next];
}
}

Saturday, October 26, 13
“Random”
-(id) init
{
if (self = [super init])
{
srand48(time(0));
}
return self;
}
-(float) generate
{
return drand48();
}

Saturday, October 26, 13
Bombing Layer
Bomber *bomber = [[Bomber alloc]
initWithPosition:CGPointMake(size.width / 2,
speed:60.0
locationChooser:chooser];
BomberSprite *bomberSprite =
[BomberSprite newSpriteWithBomber:bomber];
[self addChild:bomberSprite z:0 tag:kBomber];
[bomber start];

Saturday, October 26, 13
Bomber Sprite
@implementation BomberSprite
+(id) newSpriteWithBomber:(Bomber *)bomber
{
BomberSprite *sprite = [BomberSprite
spriteWithFile:@"bomber.png"];
sprite.bomber = bomber;
[sprite scheduleUpdate];
return sprite;
}
-(void)update:(ccTime)delta
{
[self.bomber update:delta];
[self setPosition:self.bomber.position];
}

Saturday, October 26, 13
Saturday, October 26, 13
Bomber Spec
It(@"drops a bomb when it changes direction", ^{
RiggedLocations *locations = [RiggedLocations
newWithValues:@[@18.0]];
Bomber *bomber = [[Bomber alloc]
initWithPosition:CGPointMake(17.0,
speed:1.0
locationChooser:locations];
[bomber start];
[bomber update:1.0];
[ExpectInt(bomber.bombCount) toBe:1];
});

Saturday, October 26, 13
Bomber Spec
It(@"moves the bomb on each update", ^{
RiggedLocations *locations = [RiggedLocations
newWithValues:@[@18.0]];
Bomber *bomber = [[Bomber alloc]
initWithPosition:CGPointMake(17.0
speed:1.0
locationChooser:locations
height:10
bombHeight:20];
[bomber start];
[bomber update:1.0];
[bomber update:1.0];
CGPoint bombPosition;
[(NSValue *) bomber.bombs[0] getValue:&bombPosition];
[ExpectInt(bombPosition.x) toBe:18];
[ExpectInt(bombPosition.y) toBe:55 - kGravity];
});

Saturday, October 26, 13
Bomber Sprite
[self.bomber.bombs enumerateObjectsUsingBlock:^(id obj, NSUInteger
idx, BOOL *stop) {
[self.parent removeChildByTag:kBomb + idx];
NSValue *bombValue = (NSValue *)obj;
CGPoint location;
[bombValue getValue:&location];
CCSprite *bombSprite = [CCSprite spriteWithFile:@"bomb.png"];
bombSprite.position = location;
[self.parent addChild:bombSprite z:0 tag:kBomb + idx];
}];

Saturday, October 26, 13
SHOW ME

Saturday, October 26, 13
TDD and Games
• Have a Plan
• You Use the Framework
• Keep Views dumb
Bullets Suck - Hi Eric

Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
Saturday, October 26, 13
5!

Saturday, October 26, 13
@paytonrules
www.paytonrules.com
www.8thlight.com
www.github.com/paytonrules

Saturday, October 26, 13

Contenu connexe

Tendances

Universal JavaScript
Universal JavaScriptUniversal JavaScript
Universal JavaScript名辰 洪
 
Nosql hands on handout 04
Nosql hands on handout 04Nosql hands on handout 04
Nosql hands on handout 04Krishna Sankar
 
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9Bongwon Lee
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new featuresGephenSG
 
What they don't tell you about JavaScript
What they don't tell you about JavaScriptWhat they don't tell you about JavaScript
What they don't tell you about JavaScriptRaphael Cruzeiro
 
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021Andrzej Jóźwiak
 
스위프트를 여행하는 히치하이커를 위한 스타일 안내
스위프트를 여행하는 히치하이커를 위한 스타일 안내스위프트를 여행하는 히치하이커를 위한 스타일 안내
스위프트를 여행하는 히치하이커를 위한 스타일 안내Jung Kim
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival GuideGiordano Scalzo
 
Chrome拡張開発者のためのFirefox拡張開発
Chrome拡張開発者のためのFirefox拡張開発Chrome拡張開発者のためのFirefox拡張開発
Chrome拡張開発者のためのFirefox拡張開発swdyh
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simplerAlexander Mostovenko
 
Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019Unity Technologies
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲームNoritada Shimizu
 
Html5 game programming overview
Html5 game programming overviewHtml5 game programming overview
Html5 game programming overview민태 김
 
Kotlin - Coroutine
Kotlin - CoroutineKotlin - Coroutine
Kotlin - CoroutineSean Tsai
 
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
[Ultracode Munich #4] Demo on Animatron by Anton KotenkoBeMyApp
 

Tendances (20)

Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
Universal JavaScript
Universal JavaScriptUniversal JavaScript
Universal JavaScript
 
Nosql hands on handout 04
Nosql hands on handout 04Nosql hands on handout 04
Nosql hands on handout 04
 
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new features
 
What they don't tell you about JavaScript
What they don't tell you about JavaScriptWhat they don't tell you about JavaScript
What they don't tell you about JavaScript
 
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
스위프트를 여행하는 히치하이커를 위한 스타일 안내
스위프트를 여행하는 히치하이커를 위한 스타일 안내스위프트를 여행하는 히치하이커를 위한 스타일 안내
스위프트를 여행하는 히치하이커를 위한 스타일 안내
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
 
Chrome拡張開発者のためのFirefox拡張開発
Chrome拡張開発者のためのFirefox拡張開発Chrome拡張開発者のためのFirefox拡張開発
Chrome拡張開発者のためのFirefox拡張開発
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simpler
 
Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
Html5 game programming overview
Html5 game programming overviewHtml5 game programming overview
Html5 game programming overview
 
Kotlin - Coroutine
Kotlin - CoroutineKotlin - Coroutine
Kotlin - Coroutine
 
ES6 generators
ES6 generatorsES6 generators
ES6 generators
 
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
[Ultracode Munich #4] Demo on Animatron by Anton Kotenko
 
Rethink Async with RXJS
Rethink Async with RXJSRethink Async with RXJS
Rethink Async with RXJS
 

En vedette

HTML5 Space Invaders
HTML5 Space InvadersHTML5 Space Invaders
HTML5 Space InvadersPascal Rettig
 
De Betekenis Van Empowerment Voor Het Opvoedingsondersteunend Werken
De Betekenis Van Empowerment Voor Het Opvoedingsondersteunend WerkenDe Betekenis Van Empowerment Voor Het Opvoedingsondersteunend Werken
De Betekenis Van Empowerment Voor Het Opvoedingsondersteunend Werkenbennydhoop
 
Html5 episode 2
Html5 episode 2Html5 episode 2
Html5 episode 2Eric Smith
 
времена года
времена годавремена года
времена годаSusl1k
 
Legacy codesmalltalk
Legacy codesmalltalkLegacy codesmalltalk
Legacy codesmalltalkEric Smith
 
SCMC HTML5 Game Development
SCMC HTML5 Game DevelopmentSCMC HTML5 Game Development
SCMC HTML5 Game DevelopmentEric Smith
 

En vedette (7)

HTML5 Space Invaders
HTML5 Space InvadersHTML5 Space Invaders
HTML5 Space Invaders
 
De Betekenis Van Empowerment Voor Het Opvoedingsondersteunend Werken
De Betekenis Van Empowerment Voor Het Opvoedingsondersteunend WerkenDe Betekenis Van Empowerment Voor Het Opvoedingsondersteunend Werken
De Betekenis Van Empowerment Voor Het Opvoedingsondersteunend Werken
 
Html5 episode 2
Html5 episode 2Html5 episode 2
Html5 episode 2
 
времена года
времена годавремена года
времена года
 
8thlightu3
8thlightu38thlightu3
8thlightu3
 
Legacy codesmalltalk
Legacy codesmalltalkLegacy codesmalltalk
Legacy codesmalltalk
 
SCMC HTML5 Game Development
SCMC HTML5 Game DevelopmentSCMC HTML5 Game Development
SCMC HTML5 Game Development
 

Similaire à Test Driven Cocos2d

IntroductionFor this program, you will implement an interface that.pdf
IntroductionFor this program, you will implement an interface that.pdfIntroductionFor this program, you will implement an interface that.pdf
IntroductionFor this program, you will implement an interface that.pdfebrahimbadushata00
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfpoblettesedanoree498
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdffonecomp
 
Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012aleks-f
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfcalderoncasto9163
 
Testing a 2D Platformer with Spock
Testing a 2D Platformer with SpockTesting a 2D Platformer with Spock
Testing a 2D Platformer with SpockAlexander Tarlinder
 
Writing a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 CanvasWriting a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 CanvasSteve Purkis
 
Keeping Track of Moving Things: MapKit and CoreLocation in Depth
Keeping Track of Moving Things: MapKit and CoreLocation in DepthKeeping Track of Moving Things: MapKit and CoreLocation in Depth
Keeping Track of Moving Things: MapKit and CoreLocation in DepthGeoffrey Goetz
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming TutorialRichard Jones
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017名辰 洪
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftGiordano Scalzo
 
(Appendix_Codes) Game Programming Portfolio - Soobum Lee
(Appendix_Codes) Game Programming Portfolio - Soobum Lee(Appendix_Codes) Game Programming Portfolio - Soobum Lee
(Appendix_Codes) Game Programming Portfolio - Soobum LeeSOOBUM LEE
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxAhmadAbba6
 

Similaire à Test Driven Cocos2d (14)

Basics cocos2d
Basics cocos2dBasics cocos2d
Basics cocos2d
 
IntroductionFor this program, you will implement an interface that.pdf
IntroductionFor this program, you will implement an interface that.pdfIntroductionFor this program, you will implement an interface that.pdf
IntroductionFor this program, you will implement an interface that.pdf
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdf
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdf
 
Testing a 2D Platformer with Spock
Testing a 2D Platformer with SpockTesting a 2D Platformer with Spock
Testing a 2D Platformer with Spock
 
Writing a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 CanvasWriting a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 Canvas
 
Keeping Track of Moving Things: MapKit and CoreLocation in Depth
Keeping Track of Moving Things: MapKit and CoreLocation in DepthKeeping Track of Moving Things: MapKit and CoreLocation in Depth
Keeping Track of Moving Things: MapKit and CoreLocation in Depth
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in Swift
 
(Appendix_Codes) Game Programming Portfolio - Soobum Lee
(Appendix_Codes) Game Programming Portfolio - Soobum Lee(Appendix_Codes) Game Programming Portfolio - Soobum Lee
(Appendix_Codes) Game Programming Portfolio - Soobum Lee
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptx
 

Dernier

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Dernier (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Test Driven Cocos2d

  • 3. A game is a system in which players engage in an artificial conflict, defined by rules, that results in a quantifiable outcome. Rules of Play Saturday, October 26, 13
  • 5. [Expect(game) toBe:Fun] TDD in Games with Cocos2D Saturday, October 26, 13
  • 6. Sprites and Sprite Sheets Scene Management Actions and Animations Effects Menus Tile Maps And more.... Saturday, October 26, 13
  • 15. The player starts the game and has three buckets.   They can move the buckets right and left. Saturday, October 26, 13
  • 18. Hello World Layer +(CCScene *) scene { !// 'scene' is an autorelease object. !CCScene *scene = [CCScene node]; ! !// 'layer' is an autorelease object. !HelloWorldLayer *layer = [HelloWorldLayer node]; ! !// add layer as a child to scene ![scene addChild: layer]; ! !// return the scene !return scene; } Saturday, October 26, 13
  • 19. Hello World Layer // on "init" you need to initialize your instance -(id) init { ! // always call "super" init ! // Apple recommends to re-assign "self" with the "super's" return value ! if( (self=[super init]) ) { !! ! ! // create and initialize a Label ! ! CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64]; !! !! ! !! !! !! !! !! // ask director for the window size CGSize size = [[CCDirector sharedDirector] winSize]; // position the label on the center of the screen label.position = ccp( size.width /2 , size.height/2 ); // add the label as a child to this Layer [self addChild: label]; Saturday, October 26, 13
  • 20. Buckets OCDSpec2Context(BucketsSpec) { Describe(@"moving", ^{ It(@"moves to the right", ^{ Buckets *buckets = [[Buckets alloc] initWithPosition:CGPointMake(10.0, 10.0)]; [buckets move:1]; [ExpectFloat(buckets.position.x) toBe:11.0 withPrecision:0.00001]; }); It(@"moves to the left", ^{ Buckets *buckets = [[Buckets alloc] initWithPosition:CGPointMake(10.0, 10.0)]; [buckets move:-1.0]; [ExpectFloat(buckets.position.x) toBe:9.0 withPrecision:0.00001]; }); }); } Saturday, October 26, 13
  • 21. Buckets @implementation Buckets -(id) initWithPosition:(CGPoint) position { if (self = [super init]) { self.position = position; } return self; } -(void) move:(float) movement { self.position = CGPointMake(self.position.x + movement, self.position.y); } @end Saturday, October 26, 13
  • 24. Bombing Layer -(id) init { if( (self=[super init]) ) { ! ! // ask director for the window size ! ! CGSize size = [[CCDirector sharedDirector] winSize]; Buckets *buckets = [[Buckets alloc] initWithPosition:CGPointMake(size.width / 2, size.height / 2)]; BucketsSprite *sprite = [BucketsSprite spriteWithBuckets:buckets]; ! ! // add the sprite as a child to this Layer ! ! [self addChild: sprite]; !} ! return self; } Saturday, October 26, 13
  • 25. Buckets Sprite @implementation BucketsSprite +(id) spriteWithBuckets:(Buckets *)buckets { BucketsSprite *sprite = [BucketsSprite spriteWithFile:@"buckets.png"]; sprite.buckets = buckets; [sprite scheduleUpdate]; return sprite; } -(void)update:(ccTime)delta { [self setPosition:self.buckets.position]; } @end Saturday, October 26, 13
  • 27. Bombing Layer -(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint point = [touch locationInView:[touch view]]; CGSize size = [[CCDirector sharedDirector] winSize]; if (point.x > size.width / 2) { self.movement++; } else { self.movement--; } return YES; } Saturday, October 26, 13
  • 28. Bombing Layer -(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint point = [touch locationInView:[touch view]]; CGSize size = [[CCDirector sharedDirector] winSize]; if (point.x > size.width / 2) { self.movement--; } else { self.movement++; } } Saturday, October 26, 13
  • 29. Bombing Layer -(void)update:(ccTime)delta { BucketsSprite *sprite = (BucketsSprite *)[self getChildByTag:kBucket]; [sprite move:self.movement]; } Saturday, October 26, 13
  • 33. Bomber Spec OCDSpec2Context(BomberSpec) { Describe(@"moving back and forth", ^{ It(@"moves towards its next spot", ^{ RiggedLocations *locations = [RiggedLocations newWithValues:@[@0.0]]; Bomber *bomber = [[Bomber alloc] initWithPosition:CGPointMake(10, 40) speed:1.0 locationChooser:locations]; [bomber start]; [bomber update:1.0]; [ExpectFloat(bomber.position.x) toBe:9.0 withPrecision:0.0001]; }); Saturday, October 26, 13
  • 34. Rigged Locations @implementation RiggedLocations -(float) next { float value = [(NSNumber *) [self.values firstObject] floatValue]; if (self.values.count > 1) { [self.values removeObjectAtIndex:0]; } return value; } +(RiggedLocations *) newWithValues:(NSArray *)array { RiggedLocations *locations = [RiggedLocations new]; locations.values = [NSMutableArray arrayWithArray:array]; return locations; } @end Saturday, October 26, 13
  • 35. Random Locations Describe(@"using the random number generator", ^{ It(@"uses the random number generator for its next location", ^{ id rand = [OCMockObject mockForProtocol:@protocol(RandomNumberGenerator)]; NSRange range = NSMakeRange(0, 100); RandomLocationChooser *chooser = [RandomLocationChooser newChooserWithRange:range generator:rand]; float retVal = 0.0; [[[rand stub] andReturnValue:OCMOCK_VALUE(retVal)] generate]; [ExpectFloat([chooser next]) toBe:0.0 withPrecision:0.0001]; }); Saturday, October 26, 13
  • 37. Bomber Spec It(@"stops at the location when coming from the left", ^{ RiggedLocations *locations = [RiggedLocations newWithValues:@[@19.0, @22.0]]; Bomber *bomber = [[Bomber alloc] initWithPosition:CGPointMake(17, 40) speed:2.0 locationChooser:locations]; [bomber start]; [bomber update:1.0]; [bomber update:1.0]; [ExpectFloat(bomber.position.x) toBe:21.0 withPrecision:0.0001]; }); It(@"doesn't move until it is started", ^{ RiggedLocations *locations = [RiggedLocations newWithValues:@[@19.0, @22.0]]; Bomber *bomber = [[Bomber alloc] initWithPosition:CGPointMake(17, 40) speed:2.0 locationChooser:locations]; [bomber update:1.0]; [ExpectFloat(bomber.position.x) toBe:17.0 withPrecision:0.0001]; }); Saturday, October 26, 13
  • 38. Bomber - (void)update:(float)deltaTime { if (self.started) { float moveDistance = self.speed * deltaTime; float distanceRemaining = abs(self.location - self.position.x); if (self.location > self.position.x) { self.position = CGPointMake(self.position.x + moveDistance, self.position.y); } else { self.position = CGPointMake(self.position.x - moveDistance, self.position.y); } if (moveDistance >= distanceRemaining) { self.location = [self.locations next]; } } Saturday, October 26, 13
  • 39. “Random” -(id) init { if (self = [super init]) { srand48(time(0)); } return self; } -(float) generate { return drand48(); } Saturday, October 26, 13
  • 40. Bombing Layer Bomber *bomber = [[Bomber alloc] initWithPosition:CGPointMake(size.width / 2, speed:60.0 locationChooser:chooser]; BomberSprite *bomberSprite = [BomberSprite newSpriteWithBomber:bomber]; [self addChild:bomberSprite z:0 tag:kBomber]; [bomber start]; Saturday, October 26, 13
  • 41. Bomber Sprite @implementation BomberSprite +(id) newSpriteWithBomber:(Bomber *)bomber { BomberSprite *sprite = [BomberSprite spriteWithFile:@"bomber.png"]; sprite.bomber = bomber; [sprite scheduleUpdate]; return sprite; } -(void)update:(ccTime)delta { [self.bomber update:delta]; [self setPosition:self.bomber.position]; } Saturday, October 26, 13
  • 43. Bomber Spec It(@"drops a bomb when it changes direction", ^{ RiggedLocations *locations = [RiggedLocations newWithValues:@[@18.0]]; Bomber *bomber = [[Bomber alloc] initWithPosition:CGPointMake(17.0, speed:1.0 locationChooser:locations]; [bomber start]; [bomber update:1.0]; [ExpectInt(bomber.bombCount) toBe:1]; }); Saturday, October 26, 13
  • 44. Bomber Spec It(@"moves the bomb on each update", ^{ RiggedLocations *locations = [RiggedLocations newWithValues:@[@18.0]]; Bomber *bomber = [[Bomber alloc] initWithPosition:CGPointMake(17.0 speed:1.0 locationChooser:locations height:10 bombHeight:20]; [bomber start]; [bomber update:1.0]; [bomber update:1.0]; CGPoint bombPosition; [(NSValue *) bomber.bombs[0] getValue:&bombPosition]; [ExpectInt(bombPosition.x) toBe:18]; [ExpectInt(bombPosition.y) toBe:55 - kGravity]; }); Saturday, October 26, 13
  • 45. Bomber Sprite [self.bomber.bombs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [self.parent removeChildByTag:kBomb + idx]; NSValue *bombValue = (NSValue *)obj; CGPoint location; [bombValue getValue:&location]; CCSprite *bombSprite = [CCSprite spriteWithFile:@"bomb.png"]; bombSprite.position = location; [self.parent addChild:bombSprite z:0 tag:kBomb + idx]; }]; Saturday, October 26, 13
  • 47. TDD and Games • Have a Plan • You Use the Framework • Keep Views dumb Bullets Suck - Hi Eric Saturday, October 26, 13