def destroy(self): for dir in ['north','northwest','northeast','east','west','southwest','southeast','south']: debris.debris(dir,x=self.pos[0],y=self.pos[1],owner=self) if not self.player and not var.cleaning: var.score+=self.score var.ships.remove(self)
def destroy(self): ship.destroy(self) _c = shapes.draw_circle(self.pos,10) if self.life<=0: for _s in var.ships: for pos in _c: pos = list(pos) if _s.pos == pos: _s.life = 0 for pos in _c: debris.debris('',x=pos[0],y=pos[1],owner=self)
def update(self): FrameRate = float(self.clock.tick(60)) self.player.update(FrameRate) self.evil_koi.update(FrameRate) if self.debris == True: new_debris = debris(random.randrange(0, 600), -math.pi/2) self.debris_list.append(new_debris) for thing in self.debris_list: thing.update(FrameRate)
def update(self): """Update every frame""" self.distance += self.time_since_last_frame * self.worldspeed projectiles = self.player.update(self.time_since_last_frame) #If player is dead, deal with lives if self.player_killed == True: if self.distance > self.last_death + self.immortal_time: self.last_death = self.distance self.lives -= 1 self.music.play_hit() self.player_killed = False if self.lives < 0: txtsurf = self.font32.render("GAME OVER", 1, (0,0,0)) txtrect = txtsurf.get_rect() txtrect.center = (300, self.windowy/2) self.screen.blit(txtsurf, txtrect) pygame.display.flip() pygame.time.wait(2000) self.exit_game() else: self.player_killed = False #After updating the player, let's deal with enemies #1. Check for enemies we need to add for enemy in self.enemy_data: if self.distance > enemy[0]: #Create the enemy, add it to self.enemies #print "It's been %i ms, time to spawn an enemy!"%self.distance if enemy[1] == "debris": rdyenemy = debris(enemy[2],-math.pi/2) self.debris_list.append(rdyenemy) elif enemy[1] == "rock": rdyenemy = rock(enemy[2],-math.pi/2) self.rock_list.append(rdyenemy) elif enemy[1] == "side_bear": rdyenemy = side_bear(self.player,enemy[2],enemy[3]) self.sbear_list.append(rdyenemy) elif enemy[1] == "water_bear": rdyenemy = water_bear(self.player,enemy[2],enemy[3]) self.wbear_list.append(rdyenemy) elif enemy[1] == "evil_koi": self.boss = evil_koi(self.windowx) else: print "INVALID ENEMY!" self.exit_game() #Remove from data self.enemy_data.remove(enemy) #2. Update Enemies for en in self.debris_list: en.update(self.time_since_last_frame) for rc in self.rock_list: rc.update(self.time_since_last_frame) for sbr in self.sbear_list: sbr.update(self.time_since_last_frame) for wbr in self.wbear_list: wbr.update(self.time_since_last_frame) if self.boss != None: self.bad_projectiles = self.boss.update(self.time_since_last_frame) #3. Remove Enemies that are off screen for en in self.debris_list: if not(self.screen_rect.colliderect(en.rect)): self.debris_list.remove(en) for rc in self.rock_list: if not(self.screen_rect.colliderect(rc.rect)): self.rock_list.remove(rc) for sbr in self.sbear_list: if not(self.screen_rect.colliderect(sbr.rect)): self.sbear_list.remove(sbr) for wbr in self.wbear_list: if not(self.screen_rect.colliderect(wbr.rect)): self.wbear_list.remove(wbr) #Text Engine #1. Look for adding texts for txt in self.text_data: if self.distance > txt[0]: #Add the text into our list self.text_list.append([txt[1], txt[0] + txt[2]]) self.text_data.remove(txt) #2. Display the texts (SEE DRAW) #3. Remove Out of date texts for i, txt in enumerate(self.text_list): if self.distance > txt[1]: #print "removing %s at time %i"%(txt[0], txt[1]) self.text_list.pop(i) #COLLISION self.handle_collision(projectiles)