Permalink
Browse files

Added window animation and improved mechanics

  • Loading branch information...
1 parent 722ea80 commit 7cc110277b1d45b8740631f8b49a1aacb6645c9f @jakeboxer committed Mar 23, 2011
@@ -12,6 +12,8 @@
23335EF01339747200450E90 /* bg_loss-hd.png in Resources */ = {isa = PBXBuildFile; fileRef = 23335EEE1339747200450E90 /* bg_loss-hd.png */; };
23335EF11339747200450E90 /* bg_loss.png in Resources */ = {isa = PBXBuildFile; fileRef = 23335EEF1339747200450E90 /* bg_loss.png */; };
23335EF41339748400450E90 /* LossLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 23335EF31339748400450E90 /* LossLayer.m */; };
+ 23335EF713397E7A00450E90 /* bg_window-hd.png in Resources */ = {isa = PBXBuildFile; fileRef = 23335EF513397E7A00450E90 /* bg_window-hd.png */; };
+ 23335EF813397E7A00450E90 /* bg_window.png in Resources */ = {isa = PBXBuildFile; fileRef = 23335EF613397E7A00450E90 /* bg_window.png */; };
23B4512913381ED60096FD8D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23B4512813381ED60096FD8D /* QuartzCore.framework */; };
23B4512B13381ED60096FD8D /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23B4512A13381ED60096FD8D /* OpenGLES.framework */; };
23B4512D13381ED60096FD8D /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23B4512C13381ED60096FD8D /* OpenAL.framework */; };
@@ -136,6 +138,8 @@
23335EEF1339747200450E90 /* bg_loss.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bg_loss.png; sourceTree = "<group>"; };
23335EF21339748400450E90 /* LossLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LossLayer.h; sourceTree = "<group>"; };
23335EF31339748400450E90 /* LossLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LossLayer.m; sourceTree = "<group>"; };
+ 23335EF513397E7A00450E90 /* bg_window-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "bg_window-hd.png"; sourceTree = "<group>"; };
+ 23335EF613397E7A00450E90 /* bg_window.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bg_window.png; sourceTree = "<group>"; };
23B4512413381ED60096FD8D /* SubwaySlide.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SubwaySlide.app; sourceTree = BUILT_PRODUCTS_DIR; };
23B4512813381ED60096FD8D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
23B4512A13381ED60096FD8D /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
@@ -395,6 +399,8 @@
23335EEF1339747200450E90 /* bg_loss.png */,
23335ED21339682E00450E90 /* bg_subway-hd.png */,
23335ED31339682E00450E90 /* bg_subway.png */,
+ 23335EF513397E7A00450E90 /* bg_window-hd.png */,
+ 23335EF613397E7A00450E90 /* bg_window.png */,
);
path = Backgrounds;
sourceTree = "<group>";
@@ -835,6 +841,8 @@
23335ED51339682E00450E90 /* bg_subway.png in Resources */,
23335EF01339747200450E90 /* bg_loss-hd.png in Resources */,
23335EF11339747200450E90 /* bg_loss.png in Resources */,
+ 23335EF713397E7A00450E90 /* bg_window-hd.png in Resources */,
+ 23335EF813397E7A00450E90 /* bg_window.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -3,9 +3,11 @@
@interface GameLayer : CCLayer {
@private
float _accelerometerVelocity;
+ float _actualSubwayVelocity;
BOOL _canChangeSubwayVelocity;
- float _subwayVelocity;
+ float _modifyingSubwayVelocity;
CCLabelTTF* _subwayVelocityLabel;
+ CCSprite* _subwayWindow;
}
+ (CCScene*)scene;
@@ -4,9 +4,11 @@
@interface GameLayer ()
@property (nonatomic, assign) float accelerometerVelocity;
+@property (nonatomic, assign) float actualSubwayVelocity;
@property (nonatomic, assign) BOOL canChangeSubwayVelocity;
-@property (nonatomic, assign) float subwayVelocity;
+@property (nonatomic, assign) float modifyingSubwayVelocity;
@property (nonatomic, assign) CCLabelTTF* subwayVelocityLabel;
+@property (nonatomic, assign) CCSprite* subwayWindow;
- (void)allowChangingSubwayVelocity;
- (void)changeSubwayVelocityTo:(NSNumber*)newVelocity;
@@ -18,9 +20,11 @@ - (void)update:(ccTime)dt;
@implementation GameLayer
@synthesize accelerometerVelocity = _accelerometerVelocity;
+@synthesize actualSubwayVelocity = _actualSubwayVelocity;
@synthesize canChangeSubwayVelocity = _canChangeSubwayVelocity;
-@synthesize subwayVelocity = _subwayVelocity;
+@synthesize modifyingSubwayVelocity = _modifyingSubwayVelocity;
@synthesize subwayVelocityLabel = _subwayVelocityLabel;
+@synthesize subwayWindow = _subwayWindow;
#pragma mark -
#pragma mark Creation/Removal Methods
@@ -46,6 +50,12 @@ - (id)init {
background.position = ccp(winSize.width * 0.5, winSize.height * 0.5);
[self addChild:background z:-1];
+ // Window
+ self.subwayWindow = [CCSprite spriteWithFile:@"bg_window.png" rect:CGRectMake(0, 0, 500, 193)];
+ self.subwayWindow.position = ccp(25 + self.subwayWindow.contentSize.width * 0.5,
+ 242 + self.subwayWindow.contentSize.height * 0.5);
+ [self addChild:self.subwayWindow];
+
self.subwayVelocityLabel = [CCLabelTTF labelWithString:@"Go!" fontName:@"Helvetica" fontSize:24];
self.subwayVelocityLabel.position = ccp(winSize.width * 0.5,
winSize.height - (self.subwayVelocityLabel.contentSize.height / 2));
@@ -63,23 +73,59 @@ - (id)init {
- (void)considerChangingSubwayVelocity:(ccTime)dt {
if (self.canChangeSubwayVelocity && CCRANDOM_0_1() < 0.25) {
- self.canChangeSubwayVelocity = NO;
float newVelocity = MAX(-100, MIN(100, CCRANDOM_MINUS1_1() * 2.5));
- if (newVelocity > self.subwayVelocity) {
- [self.subwayVelocityLabel setString:@"About to speed up!"];
- } else {
- [self.subwayVelocityLabel setString:@"About to slow down!"];
+ if (newVelocity != 0.0f) {
+ self.canChangeSubwayVelocity = NO;
+
+ if (newVelocity > self.actualSubwayVelocity) {
+ [self.subwayVelocityLabel setString:@"About to speed up!"];
+ } else {
+ [self.subwayVelocityLabel setString:@"About to slow down!"];
+ }
+
+ [self performSelector:@selector(changeSubwayVelocityTo:)
+ withObject:[NSNumber numberWithFloat:newVelocity]
+ afterDelay:4];
}
-
- [self performSelector:@selector(changeSubwayVelocityTo:)
- withObject:[NSNumber numberWithFloat:newVelocity]
- afterDelay:4];
}
}
- (void)update:(ccTime)dt {
- float newRotation = self.rotation - (self.accelerometerVelocity + self.subwayVelocity);
+ CGRect newTextureRect = self.subwayWindow.textureRect;
+
+ if (newTextureRect.origin.x > 640) {
+ newTextureRect.origin.x = 0;
+ } else {
+ newTextureRect.origin.x += (self.actualSubwayVelocity + 2.5) * dt * 60;
+ }
+
+ if (self.modifyingSubwayVelocity != 0.0f) {
+ float newModifyingSubwayVelocity = self.modifyingSubwayVelocity;
+
+ // If the subway is adding velocity, decrease it.
+ if (newModifyingSubwayVelocity > 0.0f) {
+ newModifyingSubwayVelocity -= dt;
+ } else {
+ newModifyingSubwayVelocity += dt;
+ }
+
+ // If the subway velocity changed signs, set it to 0 and allow changes in
+ // 2 seconds
+ if ((self.modifyingSubwayVelocity > 0.0f && newModifyingSubwayVelocity <= 0.0f) ||
+ (self.modifyingSubwayVelocity < 0.0f && newModifyingSubwayVelocity >= 0.0f)){
+ newModifyingSubwayVelocity = 0;
+ [self performSelector:@selector(allowChangingSubwayVelocity)
+ withObject:nil
+ afterDelay:2];
+ }
+
+ self.modifyingSubwayVelocity = newModifyingSubwayVelocity;
+ }
+
+ self.subwayWindow.textureRect = newTextureRect;
+
+ float newRotation = self.rotation - (self.accelerometerVelocity + self.modifyingSubwayVelocity);
if (fabsf(newRotation) > 90.0f) {
[[CCDirector sharedDirector] replaceScene:[LossLayer scene]];
@@ -122,19 +168,9 @@ - (void)allowChangingSubwayVelocity {
}
- (void)changeSubwayVelocityTo:(NSNumber*)newVelocity {
- float newVelocityFloat = [newVelocity floatValue];
-
- if (newVelocityFloat > self.subwayVelocity) {
- [self.subwayVelocityLabel setString:@"Speeding up!"];
- } else {
- [self.subwayVelocityLabel setString:@"Slowing down!"];
- }
-
- self.subwayVelocity = newVelocityFloat;
-
- [self performSelector:@selector(allowChangingSubwayVelocity)
- withObject:nil
- afterDelay:2];
+ [self.subwayVelocityLabel setString:@""];
+ self.actualSubwayVelocity = [newVelocity floatValue];
+ self.modifyingSubwayVelocity = self.actualSubwayVelocity;
}
#pragma mark -
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7cc1102

Please sign in to comment.