Exemplo n.º 1
0
 def think(self, things):
     indices = self.rect_of_awareness.collidelistall(things)
     beast = grid.obstruance("beast")
     dangers = self.find_nearest(things[i] for i in indices if things[i].obstruance & beast)
     if dangers:
         danger = dangers[0]
         self.walking = True
         direction = (self.orientation_towards(danger.rect.center) + 4) % 8
         self.orient(direction)
         self.navigate(self.step_position())
         fear = 2
     else:
         flock = self.find_nearest(
             [things[i] for i in indices if isinstance(things[i], Sheep) and things[i] != self]
         )
         if flock:
             choice = random.choice(flock)
             x, y = self.rect.center
             ox, oy = choice.rect.center
             dx, dy = (ox - x, oy - y)
             dist2 = dx * dx + dy * dy
             if 1024 < dist2 <= 4096:
                 self.walking = True
                 self.orient(self.orientation_towards((ox, oy)))
                 self.navigate(self.step_position())
             else:
                 self.walking = False
         fear = 1
     if random.random() < 0.01 * fear:
         phonographs.play(self.attack_phonograph)
 def initialize(self):
     self.titletext = typefaces.prepare_title("Onslaught of Enormities",colour=(255,64,64))
     self.scenery = chromographs.obtain("background.png")
     self.cursor = chromographs.obtain("iconic/unit-cursor.png")
     self.chapter = chapters.open_chapter(self.situation.chapter)
     wave = self.situation.wave
     self.dinosaurs = self.chapter.spawn_wave(wave)
     phonographs.play(self.dinosaurs[-1].attack_phonograph)
     for name in self.chapter.beasts_in_this_chapter():
         if name not in self.situation.seen_dinosaurs:
             self.situation.seen_dinosaurs.append(name)
     self.finished = False
     self.result = "Preparation"
     self.statusbar = gui.StatusBar()
     self.statusbar.push_messages(
         "Protect your ships!",
         "Cannons need soldiers nearby to man them",
         "Click again on the field to direct a soldier",
         "Click on a soldier to select them",
         )
     if self.situation.chapter == 0:
         self.statusbar.flash(80)
     self.situation.update_status_bar(self.statusbar)
     self.selected_unit = None
     # orchestrate the battle music
     phonographs.orchestrate("onslaughtmusic.ogg")
 def bite_target(self, target, damage, cause="eaten"):
     """ because one can get very weary of constant roaring """
     bite = self.attack(audible=False)
     if bite:
         target.harm(damage, cause)
         if target.destroyed():
             phonographs.play(self.attack_phonograph)
     return bite
 def build_a_thing(self,thingclass):
     if self.situation.can_afford_a(thingclass):
         place = self.current_edge if self.current_edge else self.current_lot
         if place:
             self.situation.add_installation_if_possible(thingclass, place, charge=True)
             if hasattr(thingclass,"placement_phonograph"):
                 phonographs.play(thingclass.placement_phonograph)
             self.situation.last_build = thingclass
             self.situation.update_status_bar(self.statusbar)
Exemplo n.º 5
0
 def attack(self, audible=True):
     """ Assume a ferocius aspect """
     if self.attacking or not self.attacking_animations:
         return
     if self.reload_time > time():
         return
     self.temporal_accumulator = 0
     self.attacking = True
     self.reload_time = time() + 5.0 / self.rapidity
     self.animation_frame = self.walking_animations + 1
     self.image = self.obtain_frame()
     if audible:
         phonographs.play(self.attack_phonograph)
     return True
 def explode(self):
     """ The purpose of this operation requires little explanation.
     Unlike the phenomemon itself, which makes no sense at all.
     """
     self.exploding = True
     self.obstruance = 0
     self.pace = 40
     self.animated_chromograph_name = self.exploding_chromograph_name
     self.attacking_animations = self.explosion_frames
     self.walking_animations = 0
     self.animation_frame = 1
     self.attacking = True
     self.rect_of_awareness.center = self.rect.center
     self.orientation_indices = (0,) * 8
     self.image = self.obtain_frame()
     phonographs.play(self.exploding_phonograph_name)
    def operate(self, current_situation):
        self.situation = current_situation
        self.initialize()

        while not self.finished:
            ms = self.clock.tick(60)
            self.respond_to_the_will_of_the_operator()
            self.move_dinosaurs(ms)
            self.move_units(ms)
            self.situation.update_status_bar(self.statusbar)
            self.render()
            self.dead_test()
            self.win_test()
        phonographs.play("fanfare.ogg")
        phonographs.diminuendo(1000)
        # calculate the death statistics
        for u in self.situation.installations:
            if u.human and u.destroyed():
                self.situation.death_stats[u.killed_by] += 1
        return self.result
 def repair(self):
     self.damage = 0
     self.condition = 0
     self.image = self.obtain_frame()
     phonographs.play("cannon-place.ogg")