Skip to content

Commit

Permalink
initial import. raw file copies from Jacob's Shapes. http://www.littl…
Browse files Browse the repository at this point in the history
  • Loading branch information
jashmenn committed Sep 7, 2010
0 parents commit 45e640c
Show file tree
Hide file tree
Showing 31 changed files with 9,672 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
@@ -0,0 +1,14 @@
.DS_Store
*.swp
*~.nib
build/
*.pbxuser
*.perspective
*.perspectivev3
*.mode1v3
*.mode2v3
.autosession.vim
./html/
session.vim
*/.DS_Store
Resources/sounds/raw/
14 changes: 14 additions & 0 deletions Classes/Controllers/CocosOverlayViewController.h
@@ -0,0 +1,14 @@
//
// CocosOverlayViewController.h
// shapes
//
// Created by Nate Murray on 8/23/10.
// Copyright 2010 LittleHiccup. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface CocosOverlayViewController : UIViewController
{
}
@end
32 changes: 32 additions & 0 deletions Classes/Controllers/CocosOverlayViewController.m
@@ -0,0 +1,32 @@
//
// CocosOverlayViewController.m
// shapes
//
// Created by Nate Murray on 8/23/10.
// Copyright 2010 LittleHiccup. All rights reserved.
//

#import "CocosOverlayViewController.h"
#import "CocosOverlayScrollView.h"

@implementation CocosOverlayViewController

// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
CocosOverlayScrollView *scrollView = [[CocosOverlayScrollView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];

// NOTE - I have hardcoded the size to 1024x1024 as that is the size of the levels in
// our game. Ideally this value would be parameterized or configurable.
//
scrollView.contentSize = CGSizeMake(1024, 1024);

scrollView.delegate = scrollView;
[scrollView setUserInteractionEnabled:TRUE];
[scrollView setScrollEnabled:TRUE];

self.view = scrollView;

[scrollView release];
}
@end
52 changes: 52 additions & 0 deletions Classes/Controllers/GameController.h
@@ -0,0 +1,52 @@
/*
* GameController.h
* deadmanschest
*
* Created by Nate Murray on 6/27/10.
* Copyright 2010 YetiApps. All rights reserved.
*
*/

#import "cocos2d.h"
#import "common.h"
#import "SynthesizeSingleton.h"

@class HSGameScene;
@class JSWorld;
@class JSLevel;

@interface GameController : NSObject {
int piecesRemaining;
JSWorld* currentWorld;
JSLevel* currentLevel;
int currentWorld_i;
int currentLevel_i;
NSString* currentVoice;
NSOperationQueue* operationQueue;
BOOL newPlayer;
BOOL levelReady;
// HSGameScene* gameScene;
}
@property(nonatomic) int piecesRemaining;
@property(nonatomic, retain) JSWorld* currentWorld;
@property(nonatomic, retain) JSLevel* currentLevel;
@property(nonatomic) int currentWorld_i;
@property(nonatomic) int currentLevel_i;
@property(nonatomic, retain) NSString* currentVoice;
@property(nonatomic, retain) NSOperationQueue* operationQueue;
@property(nonatomic) BOOL newPlayer;
@property(nonatomic) BOOL levelReady;
// @property(nonatomic, retain) HSGameScene* gameScene;

+(GameController *) sharedGameController;
- (void) noPiecesRemaining;
- (void) piecePlaced;
- (void)setWorld:(int)i level:(int)j;
- (void)replaceWorld:(int)i level:(int)j;
- (HSGameScene*) gameScene;
- (void) cleanupCaches;
- (void) loadVoicePrefs;
- (void) changeVoiceTo: (NSString*) newVoice;
- (void) levelIsReady;
- (BOOL) firstLaunch;
@end
174 changes: 174 additions & 0 deletions Classes/Controllers/GameController.mm
@@ -0,0 +1,174 @@
/*
* GameController.mm
* deadmanschest
*
* Created by Nate Murray on 6/27/10.
* Copyright 2010 YetiApps. All rights reserved.
*
*/

/*
game controller should hold a reference to the current world, the current
world holds a reference to the current level the world and level know how to
parse the plists. we need to have the world class load the world
definitions dictionary then it can create a level with a particular
dictionary then the game controller asks its world for the current level and
builds the gamescene based on the level. it gives the gamescene the level
the panel scene has one panel for all. and otherwise builds a panel for each
world. it asks the or maybe just the world class method. for the dictionary
of worlds
when you are playing the game, you start on the first level of the world. if
you win, you get a little message, and then its on to the next level of the
world. if there is no next level in this world. then you go to the first
level of the next world.
one problem is how does one get back to the panel world chooser once they
have started the game.
*/

#include "GameController.h"
#import "GameSoundManager.h"
#import "HSGameScene.h"
#import "JSWorld.h"

@interface GameController (Private)
@end

@implementation GameController
@synthesize piecesRemaining;
@synthesize currentWorld;
@synthesize currentLevel;
@synthesize currentWorld_i;
@synthesize currentLevel_i;
@synthesize currentVoice;
@synthesize operationQueue;
@synthesize newPlayer;
@synthesize levelReady;
// @synthesize gameScene;

SYNTHESIZE_SINGLETON_FOR_CLASS(GameController);
SimpleAudioEngine *soundEngine;

-(id)init {
if ((self = [super init])){
self.piecesRemaining = 0;
soundEngine = [GameSoundManager sharedManager].soundEngine;
[soundEngine retain];
[self setWorld: 0 level: 0];
// [self setWorld: 16 level: 0];
[self loadVoicePrefs];
self.operationQueue = [[NSOperationQueue alloc] init];
self.newPlayer = YES;
self.levelReady = YES;
}
return self;
}

- (void)setWorld:(int)i level:(int)j {
self.currentWorld = [JSWorld world: i];
self.currentLevel = [currentWorld level: j];
self.currentWorld_i = i;
self.currentLevel_i = j;
}

- (void)replaceWorld:(int)i level:(int)j {
// this isn't called when you press the green button
CGSize s = [[CCDirector sharedDirector] winSize];
[self setWorld:i level:j];
HSGameScene *currentLevelLayer = [self gameScene];

// HSGameScene* nextLevelLayer = [[HSGameScene alloc] init];
HSGameScene* nextLevelLayer = [HSGameScene node];
[[currentLevelLayer parent] addChild: nextLevelLayer]; // add nextLevel to the same scene
nextLevelLayer.position = ccp(s.width, 0);

/* race condition here? */
nextLevelLayer.tag = kTag_GameScene;
currentLevelLayer.tag = kTag_OldGameScene;

float move_t = 1.0f;

CCLOG(@"replacing world");
self.levelReady = NO;

id move_in = [CCMoveTo actionWithDuration:move_t position:ccp(0, 0)];
id move_out = [CCMoveTo actionWithDuration:move_t position:ccp(-s.width, 0)];
id rm = [CCCallFuncND actionWithTarget:currentLevelLayer selector:@selector(removeFromParentAndCleanup:) data:(void*)YES];
id ready = [CCCallFunc actionWithTarget:self selector:@selector(levelIsReady)];
id cleanup = [CCCallFunc actionWithTarget:self selector:@selector(cleanupCaches)];

[currentLevelLayer runAction: [CCSequence actions: move_out, rm, cleanup, nil]];
[nextLevelLayer runAction: [CCSequence actions: move_in, ready, nil]];
}

- (HSGameScene*) gameScene {
CCScene* scene = [[CCDirector sharedDirector] runningScene];
// HSGameScene* layer = (HSGameScene*)[[scene children] objectAtIndex:0]; // thin ice, use a tag!
HSGameScene* layer = (HSGameScene*)[scene getChildByTag:kTag_GameScene];
return layer;
}

-(void)dealloc {
[soundEngine release];
self.currentVoice = nil;
self.operationQueue = nil;
[super dealloc];
}

- (void) piecePlaced {
self.piecesRemaining -= 1;
if(self.piecesRemaining <= 0) {
[self noPiecesRemaining];
}
}

- (void) noPiecesRemaining {
// [[self gameScene] levelPassed];

// todo, i don't like putting this here, but it is the best place
// id delay = [CCDelayTime actionWithDuration: 1.0]; // delay to allow the last sound to play
id delay = [CCDelayTime actionWithDuration: 1.2]; // delay to allow the last sound to play
id passed = [CCCallFunc actionWithTarget:[self gameScene] selector:@selector(levelPassed)];
[[self gameScene] runAction: [CCSequence actions: delay, passed, nil]];
}

- (void) cleanupCaches {
// [[CCTextureCache sharedTextureCache] removeUnusedTextures];
}

- (void) levelIsReady {
CCLOG(@"level is ready!");
self.levelReady = YES;
}

- (void) loadVoicePrefs {
if (![[NSUserDefaults standardUserDefaults] valueForKey:@"currentVoice"]) {
CCLOG(@"setting default voice");
[self changeVoiceTo:@"addie"];
} else {
NSString* voiceName = [[NSUserDefaults standardUserDefaults] objectForKey:@"currentVoice"];
CCLOG(@"loading voice: %@", voiceName);
self.currentVoice = voiceName;
}
}

- (void) changeVoiceTo: (NSString*) newVoice {
self.currentVoice = newVoice;
[[NSUserDefaults standardUserDefaults] setObject:newVoice forKey:@"currentVoice"];
}

- (BOOL) firstLaunch {
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"launchedBefore"]) {
CCLOG(@"first launch");
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"launchedBefore"];
return YES;
} else {
CCLOG(@"launched before");
// return [[NSUserDefaults standardUserDefaults] boolForKey:@"launchedBefore"];
return NO;
}
}

@end

0 comments on commit 45e640c

Please sign in to comment.