Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit 9050bbd54eeb2a2ad0b5583400512694c39824db

  • avatar
  • alanjas
  • Tue Jan 07 19:02:59 EST 2014
only update score render when score changes
SpaceWar.py
(13 / 13)
  
3838 self.count = 0
3939 self.level = 1
4040 self.points = 0
41 self.old_points = 0
42 self.running = True
43 self.screen = None
4144
4245 def load_all(self):
4346 # Dun dun duuuuuuuun
5151 if not(self.screen):
5252 info = pygame.display.Info()
5353 size = (info.current_w, info.current_h)
54 size = (800, 600)
55 self.screen = pygame.display.set_mode(size) #, pygame.FULLSCREEN)
56 pygame.display.set_caption('SpaceWar')
54 self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
55 pygame.display.set_caption(_('SpaceWar'))
5756 self.rect = self.screen.get_rect()
5857
5958 # Core objects
6059 self.clock = pygame.time.Clock()
61 self.running = True
62
60
6361 # images
6462 self.ship_img = pygame.image.load('img/Space/ship1.png').convert_alpha()
6563 self.shot_img = pygame.image.load('img/Space/bullet4.png').convert_alpha()
9898 p = str(self.points)
9999 c = (8 - len(p)) * '0'
100100 msg = c + p
101
102101 self.points_msg = self._font.render(_('Score: %s') % msg, 1, (255, 255, 255))
103102
104103 def run(self):
135135 self.enemies.update(delta)
136136 # Look for shot-enemy collisions
137137 d = pygame.sprite.groupcollide(self.enemies, self.shots, True, True)
138
138 # add points for each enemy killed
139139 for ship in d:
140140 self.points = self.points + POINTS_ENEMY
141
141 # delay between killed all enemies and appears more
142142 if len(self.enemies) == 0:
143143 self.count = self.count + 1
144
145144 if self.count > 10:
146145 self.count = 0
147146 self.level = self.level + 1
148147 self.level_msg = self._font.render(_('Level: %s') % self.level, 1, (255, 255, 255))
149148 self.add_enemies(self.level)
150
151 self.do_score_msg()
152
149 # update score msg
150 if not(self.points == self.old_points):
151 self.do_score_msg()
152 self.old_points = self.points
153153 # Display phase
154154 self.screen.fill((0,0,0))
155155 self.screen.blit(self.points_msg, (self.rect[2] - 250, 10))
189189
190190 # Load and play the shot sound
191191 self.sound = parent.shot_sound
192 #self.sound.play()
192 self.sound.play()
193193
194194 def update(self, delta):
195195 self.rect.move_ip(0, -1*delta*self.speed)