Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving in-game music settings and timers to GameScene

  • Loading branch information...
commit 531d2b00c304c4716e227a61a596266856f7eadc 1 parent e424d3f
@fadookie fadookie authored
View
6 Maestro/AppDelegate.m
@@ -12,6 +12,7 @@
#import "BlankScene.h"
#import "GameScene.h"
#import "GameSoundManager.h"
+#import "GameClock.h"
@implementation AppController
@@ -82,7 +83,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Assume that PVR images have premultiplied alpha
[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
-
+
+ // init clock
+ [GameClock sharedInstance];
+
// and add the scene to the stack. The director will run it when it automatically when the view is displayed.
#warning TODO: go straight to GameScene for development
//[director_ pushScene:[BlankScene node]];
View
5 Maestro/GameLayer.h
@@ -10,11 +10,6 @@
#import "chipmunk.h"
@interface GameLayer : CCLayer
-{
- @private
- NSTimeInterval _maestroAudioStartTime;
- BOOL _maestroAudioStarted;
-}
@property (nonatomic) NSInteger levelNum;
@property (readwrite) int tapImpulsePower;
View
32 Maestro/GameLayer.m
@@ -72,9 +72,6 @@ - (id)initWithLevelNum:(NSInteger)levelNum
// enable events
self.isTouchEnabled = YES;
- // init clock
- [GameClock sharedInstance];
-
// init physics
[Physics sharedInstance];
@@ -100,13 +97,6 @@ - (id)initWithLevelNum:(NSInteger)levelNum
tearBin.position = ccp(284, FLOOR_HEIGHT + tearBin.contentSize.height / 2);
[self addChild:tearBin z:1];
[tearBin addToPhysics];
-
- //Fade out the intro music if it's playing
- [[GameSoundManager sharedInstance] fadeOutMusic];
-
- //Wait 3 seconds before playing maestro music
- _maestroAudioStarted = NO;
- _maestroAudioStartTime = [[GameClock sharedInstance] currentTime] + 3;
}
return self;
}
@@ -121,14 +111,6 @@ -(void)update:(ccTime) delta
// update global singletons
[[GameClock sharedInstance] update:delta];
- //Check timers
- if (!_maestroAudioStarted &&
- [[GameClock sharedInstance] currentTime] > _maestroAudioStartTime) {
- NSLog(@"Starting Maestro music.");
- [[GameSoundManager sharedInstance] playMaestro];
- _maestroAudioStarted = YES;
- }
-
// check for level loss/victory
if (!self.leavingScene) {
@@ -240,13 +222,13 @@ - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
*/
//Assuming we roped in some tears, let's change the music on the next loop
- if ([GameSoundManager sharedInstance].nextMaestroTrack < ([GameSoundManager sharedInstance].numMaestroTracks - 1)) {
- [GameSoundManager sharedInstance].nextMaestroTrack++;
- if ([GameSoundManager sharedInstance].nextMaestroTrack == [GameSoundManager sharedInstance].numMaestroTracks - 1) {
- //This is the last track, stop looping
- [[GameSoundManager sharedInstance] stopMaestroAfterNextLoop];
- }
- }
+// if ([GameSoundManager sharedInstance].nextMaestroTrack < ([GameSoundManager sharedInstance].numMaestroTracks - 1)) {
+// [GameSoundManager sharedInstance].nextMaestroTrack++;
+// if ([GameSoundManager sharedInstance].nextMaestroTrack == [GameSoundManager sharedInstance].numMaestroTracks - 1) {
+// //This is the last track, stop looping
+// [[GameSoundManager sharedInstance] stopMaestroAfterNextLoop];
+// }
+// }
}
- (void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event
View
42 Maestro/GameScene.m
@@ -11,11 +11,14 @@
#import "GameManager.h"
#import "GameScene.h"
#import "GameSoundManager.h"
+#import "GameClock.h"
#import "HUDLayer.h"
@interface GameScene()
@property (nonatomic, retain) NSString *background;
-@property (nonatomic, retain) NSString *music;
+@property (nonatomic) int music;
+@property (nonatomic) NSTimeInterval maestroAudioStartTime;
+@property (nonatomic) BOOL maestroAudioStarted;
@end
@implementation GameScene
@@ -23,13 +26,14 @@ @implementation GameScene
@synthesize levelNum = _levelNum;
@synthesize background = _background;
@synthesize music = _music;
+@synthesize maestroAudioStartTime = _maestroAudioStartTime;
+@synthesize maestroAudioStarted = _maestroAudioStarted;
@synthesize maxTime = _maxTime;
@synthesize tearsNeeded = _tearsNeeded;
- (void)dealloc
{
[_background release];
- [_music release];
[super dealloc];
}
@@ -68,19 +72,19 @@ - (void)configureForLevelNum
switch (self.levelNum) {
case 0:
self.background = @"Level1-alt.png";
- self.music = @"maestro_0.wav";
+ self.music = 0;
self.maxTime = 20;
self.tearsNeeded = 1;
break;
case 1:
self.background = @"Level2-alt.png";
- self.music = @"maestro_1.wav";
+ self.music = 1;
self.maxTime = 99;
self.tearsNeeded = 20;
break;
case 2:
self.background = @"Level3-alt.png";
- self.music = @"maestro_2.wav";
+ self.music = 2;
self.maxTime = 99;
self.tearsNeeded = 30;
break;
@@ -93,15 +97,35 @@ - (void)onEnter
{
[super onEnter];
-#warning Make this a smooth audio fade
- [[GameSoundManager sharedInstance].soundEngine stopBackgroundMusic];
+ //Fade out the intro music if it's playing
+ //currently buggy, disabling
//[[GameSoundManager sharedInstance] fadeOutMusic];
- //[[GameSoundManager sharedInstance] playMaestro];
- [[GameSoundManager sharedInstance].soundEngine playBackgroundMusic:self.music];
+ [[GameSoundManager sharedInstance].soundEngine stopBackgroundMusic];
+
+ [GameSoundManager sharedInstance].nextMaestroTrack = self.music;
+ [GameSoundManager sharedInstance].loopMaestroTrack = YES;
+ //Wait 3 seconds before playing maestro music
+ _maestroAudioStarted = NO;
+ _maestroAudioStartTime = [[GameClock sharedInstance] currentTime] + 3;
// set up the GameManager for this level
GameManager *gameManager = [GameManager sharedInstance];
[gameManager resetForGameScene:self];
+ [self scheduleUpdate];
+}
+
+-(void) update:(ccTime) delta
+{
+ // update global singletons
+ [[GameClock sharedInstance] update:delta];
+
+ //Check timers
+ if (!_maestroAudioStarted &&
+ [[GameClock sharedInstance] currentTime] > _maestroAudioStartTime) {
+ NSLog(@"Starting Maestro music.");
+ [[GameSoundManager sharedInstance] playMaestro];
+ _maestroAudioStarted = YES;
+ }
}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.