From e96abf6926e8ccae5fbab81edddd2b4e9aec7b34 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Sun, 31 Aug 2008 19:16:46 +0000 Subject: detect when level is complete --- diff --git a/bridge.py b/bridge.py index a0f3c1c..08bdc00 100644 --- a/bridge.py +++ b/bridge.py @@ -12,6 +12,7 @@ class Bridge: self.first_train = None self.train_off_screen = False self.train_was_created = False + self.level_completed = False def create_world(self): self.world.set_color((100,150,50)) @@ -20,7 +21,7 @@ class Bridge: pygame.draw.rect(self.screen, (100,180,255), rect, 3) self.world.add.rect(rect.center, rect.width / 2, rect.height / 2, dynamic=False) - rect = pygame.Rect((1200,800), (-350, -250)) + rect = pygame.Rect((1600,800), (-750, -250)) rect.normalize() pygame.draw.rect(self.screen, (100,180,255), rect, 3) self.world.add.rect(rect.center, rect.width / 2, rect.height / 2, @@ -57,8 +58,10 @@ class Bridge: pygame.draw.circle(self.screen, (int(force/2),255-int(force/2),0), coord, 4) pos = self.first_train.GetPosition() - if pos.y < 0: - print "TRAIN FELL OFF!" + if pos.x > 14.0: + self.level_completed = True + elif pos.y < 0.0: + print "TRAIN FELL OFF!", pos.x self.train_off_screen = True def create_train(self, worldpoint = (-100,490), train = (100, 50), wheelrad = 20, cars = 3, force = False): diff --git a/physics.py b/physics.py index 8b827e8..6108a99 100644 --- a/physics.py +++ b/physics.py @@ -91,7 +91,11 @@ class PhysicsGame: text = self.font.render("Train fell off the screen, try again!", True, (0,0,0)) textpos = text.get_rect(left=700,top=43) self.screen.blit(text,textpos) - + elif self.bridge.level_completed: + text = self.font.render("Level completed, well done!!", True, (0,0,0)) + textpos = text.get_rect(left=700,top=43) + self.screen.blit(text,textpos) + # Flip Display pygame.display.flip() -- cgit v0.9.1