Permalink
Browse files

background dynamic

  • Loading branch information...
alamboley committed Apr 24, 2012
1 parent bb39635 commit 354bdc1945b685136582b3a6fa0204c1042bcf2d
@@ -8,8 +8,11 @@
#import "CitrusObject.h"
-@interface BigPicture : CitrusObject
+@interface BigPicture : CitrusObject {
+
+ CitrusObject *hero;
+}
-- (id) initWithName:(NSString *)paramName params:(NSDictionary *)params andPictures:(NSArray *)pictures;
+- (id) initWithName:(NSString *)paramName params:(NSDictionary *)params andWorld:(NSString *)world;
@end
@@ -11,22 +11,32 @@
@implementation BigPicture
-- (id) initWithName:(NSString *)paramName params:(NSDictionary *)params andPictures:(NSArray *)pictures {
+- (id) initWithName:(NSString *)paramName params:(NSDictionary *)params andWorld:(NSString *)world; {
if (self = [super initWithName:paramName params:params]) {
+ //chargement XML :
+ NSBundle *bundle = [NSBundle mainBundle];
+ NSString *plistChemin = [bundle pathForResource:@"DonneesAleatoires" ofType:@"plist"];
+ NSDictionary *dictionnaire = [[NSDictionary alloc] initWithContentsOfFile:plistChemin];
+ NSArray *niveauUn = [NSArray arrayWithObject:[dictionnaire valueForKey:@"Root"]];
+
+ niveauUn = [niveauUn valueForKey:world];
+
+ NSArray *imgWorldRed = [NSArray arrayWithArray:[niveauUn objectAtIndex:0]];
+
graphic = [[SPSprite alloc] init];
[self addChild:graphic];
- for (NSString *picture in pictures) {
+ for (NSString *picture in imgWorldRed) {
SPImage *img = [SPImage imageWithContentsOfFile:picture];
[graphic addChild:img];
- img.x = self.x;
+ img.x = self.posX;
img.y = self.y;
-
- self.x += img.width;
+
+ self.posX += img.width;
}
}
@@ -41,4 +51,27 @@ - (void) destroy {
[super destroy];
}
+- (void) update {
+
+ [super update];
+
+ if (!hero) {
+
+ hero = [ce.state getObjectByName:@"hero"];
+
+ } else {
+
+ if (hero.x > self.width - 480) {
+
+ SPImage *img = [SPImage imageWithContentsOfFile:@"parallaxe1_1.png"];
+ [graphic addChild:img];
+
+ img.x = self.posX;
+ img.y = self.y;
+
+ self.posX += img.width;
+ }
+ }
+}
+
@end
@@ -31,6 +31,7 @@
@property int group;
@property float parallax;
@property BOOL kill;
+@property float posX, posY;
- (id) initWithName:(NSString *)paramName params:(NSDictionary *)params;
- (id) initWithName:(NSString *)paramName params:(NSDictionary *)params andGraphic:(SPDisplayObject *)displayObject;
@@ -20,6 +20,7 @@ @implementation CitrusObject
@synthesize ce, name, graphic;
@synthesize group, parallax;
@synthesize kill;
+@synthesize posX, posY;
- (id) initWithName:(NSString *)paramName params:(NSDictionary *)params {
@@ -39,7 +39,7 @@ - (void) simpleInit {
[body setMoment:INFINITY];
- velocityX = 50;
+ velocityX = 80;
isOnGround = FALSE;
@@ -130,11 +130,8 @@ - (void) update {
[body setVelocity:velocity];
- if (body.position.x > 2600) {
-
- velocityX = 0;
-
- }
+ //if (body.position.x > 2600)
+ // velocityX = 0;
[self updateAnimation];
}
@@ -47,14 +47,16 @@
- (id) init;
-- (void)showHideDebugDraw;
+- (void) showHideDebugDraw;
- (void) addObject:(CitrusObject *) object;
- (void) setupCamera:(PhysicsObject *) target andOffset:(CGPoint) offset andBounds:(CGRect) bounds andEasing:(CGPoint) easing;
- (void) updateGroupForSprite:(CitrusObject *) object;
-- (void)update;
+- (void) update;
+
+- (CitrusObject *) getObjectByName:(NSString *) objectName;
@end
@@ -164,6 +164,16 @@ - (void) update {
}
+- (CitrusObject *) getObjectByName:(NSString *) objectName {
+
+ for (CitrusObject *object in objects) {
+ if (object.name == objectName)
+ return object;
+ }
+
+ return nil;
+}
+
- (void) dealloc {
UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
@@ -4,7 +4,7 @@
<dict>
<key>Root</key>
<dict>
- <key>WorldRed</key>
+ <key>WorldYellow</key>
<array>
<string>parallaxe1_1.png</string>
<string>parallaxe1_2.png</string>
@@ -29,24 +29,14 @@ - (id) init {
[self showHideDebugDraw];
- gameWidth = 2868;
-
- //chargement XML :
- NSBundle *bundle = [NSBundle mainBundle];
- NSString *plistChemin = [bundle pathForResource:@"DonneesAleatoires" ofType:@"plist"];
- NSDictionary *dictionnaire = [[NSDictionary alloc] initWithContentsOfFile:plistChemin];
- NSArray *niveauUn = [NSArray arrayWithObject:[dictionnaire valueForKey:@"Root"]];
-
- niveauUn = [niveauUn valueForKey:@"WorldRed"];
-
- NSLog(@"%@", [[niveauUn objectAtIndex:0] objectAtIndex:1]);
+ gameWidth = 28680;
couleurs = [[Couleurs alloc] initWithRouge:130 andBleu:20 andJaune:45 andOrange:12 andVert:8 andViolet:58];
CitrusObject *parallaxe1 = [[CitrusObject alloc] initWithName:@"bg" params:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"0", @"0", @"0.1", nil] forKeys:[NSArray arrayWithObjects:@"x:", @"y:", @"parallax:", nil]] andGraphic:[SPImage imageWithContentsOfFile:@"parallaxe2.png"]];
[self addObject:parallaxe1];
- BigPicture *parallaxe2 = [[BigPicture alloc] initWithName:@"bg" params:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"0", @"0", nil] forKeys:[NSArray arrayWithObjects:@"x:", @"y:", nil]] andPictures:[NSArray arrayWithObjects:@"parallaxe1_1.png", @"parallaxe1_2.png", @"parallaxe1_3.png", nil]];
+ BigPicture *parallaxe2 = [[BigPicture alloc] initWithName:@"bg" params:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"0", @"0", nil] forKeys:[NSArray arrayWithObjects:@"x:", @"y:", nil]] andWorld:@"WorldYellow"];
[self addObject:parallaxe2];
Platform *platformBot = [[Platform alloc] initWithName:@"platform" params:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithFormat:@"%f", gameWidth / 2], @"320", [NSString stringWithFormat:@"%f", gameWidth], @"10", @"TRUE", nil] forKeys:[NSArray arrayWithObjects:@"x:", @"y:", @"width:", @"height:", @"isStatic:", nil]]];
@@ -87,14 +77,9 @@ - (id) init {
CitrusObject *firstPlan2 = [[CitrusObject alloc] initWithName:@"firstPlan2" params:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"3000", @"200", @"2", nil] forKeys:[NSArray arrayWithObjects:@"x:", @"y:", @"parallax:", nil]] andGraphic:[SPImage imageWithContentsOfFile:@"1erplan2.png"]];
[self addObject:firstPlan2];
- CitrusObject *portal1 = [[CitrusObject alloc] initWithName:@"portal1" params:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"2800", @"170", nil] forKeys:[NSArray arrayWithObjects:@"x:", @"y:", nil]] andGraphic:[SPImage imageWithContentsOfFile:@"portail_bleu.png"]];
- [self addObject:portal1];
-
- CitrusObject *portal2 = [[CitrusObject alloc] initWithName:@"portal2" params:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"2800", @"20", nil] forKeys:[NSArray arrayWithObjects:@"x:", @"y:", nil]] andGraphic:[SPImage imageWithContentsOfFile:@"portail_vert.png"]];
- [self addObject:portal2];
-
[self setupCamera:hero andOffset:CGPointMake(hero.width / 2, 0) andBounds:CGRectMake(0, 0, gameWidth, 1000) andEasing:CGPointMake(0.25, 0.05)];
+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(colorPicked:) name:@"colorJaune" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(colorPicked:) name:@"piege" object:nil];
}

0 comments on commit 354bdc1

Please sign in to comment.