def activate_special(self): if self.can_use_special() == False: return start_hex = (self._pos.x, self._pos.y) target_hex = start_hex self._hexes_this_turn.add((self._pos.x, self._pos.y)) for i in range(5): target_hex = \ hex_math.neighbor((target_hex[0], target_hex[1]), self._pos.facing) self._hexes_this_turn.add(target_hex) self._pos._x = target_hex[0] self._pos._y = target_hex[1] new_anim = ShipAnimation( ship=self, start_pos=start_hex, stop_pos=target_hex, csys_pos="HEX", start_ang=self._pos.facing, stop_ang=self._pos.facing, csys_ang="HEX", frac_rate=1./20. ) self._animations.append(new_anim) self._special_this_turn = True self._special_uses += 1
def move(self, ship, move_type): """ Return a new ship position object produced by the specified move type. """ # MAKE A NEW POSITION new_pos = ShipPos(x=self._x, y=self._y, facing=self._facing, curr_move=self._curr_move, evasion=self._evasion, momentum=self._momentum) # DEDUCT THE MOVEMENT COST new_pos._curr_move = self._curr_move - ship.move_cost[move_type] # ----------------------------------------------------- # FORWARD # ----------------------------------------------------- if move_type == "FORWARD": new_pos._x, new_pos._y = \ hex_math.neighbor((self._x, self._y), self._facing) if (self._momentum > 0): new_pos._momentum = self._momentum - 1 # ----------------------------------------------------- # FORWARD AND THEN TURN ONE # ----------------------------------------------------- if move_type == "TURN_LEFT": new_pos._x, new_pos._y = \ hex_math.neighbor((self._x, self._y), self._facing) if (ship.inertia > 0): new_pos._momentum = ship.inertia new_pos._facing = str(Hex_Direction(self._facing)-1) if move_type == "TURN_RIGHT": new_pos._x, new_pos._y = \ hex_math.neighbor((self._x, self._y), self._facing) if (ship.inertia > 0): new_pos._momentum = ship.inertia new_pos._facing = str(Hex_Direction(self._facing)+1) # ----------------------------------------------------- # FORWARD AND THEN TURN TWO # ----------------------------------------------------- if move_type == "HARD_LEFT": new_pos._x, new_pos._y = \ hex_math.neighbor((self._x, self._y), self._facing) if (ship.inertia > 0): new_pos._momentum = ship.inertia new_pos._facing = str(Hex_Direction(self._facing)-2) if move_type == "HARD_RIGHT": new_pos._x, new_pos._y = \ hex_math.neighbor((self._x, self._y), self._facing) if (ship.inertia > 0): new_pos._momentum = ship.inertia new_pos._facing = str(Hex_Direction(self._facing)+2) if move_type == "REVERSE": new_pos._x, new_pos._y = \ hex_math.neighbor((self._x, self._y), self._facing) if (ship.inertia > 0): new_pos._momentum = ship.inertia self._facing = str(Hex_Direction(self._facing)+3) # ----------------------------------------------------- # JINK (DIAGONAL WITHOUT TURNING) # ----------------------------------------------------- if move_type == "JINK_LEFT": jink_dir = Hex_Direction(self._facing)-1 new_pos._x, new_pos._y = \ hex_math.neighbor((self._x, self._y), jink_dir) if (ship.inertia > 0): new_pos._momentum = ship.inertia if move_type == "JINK_RIGHT": jink_dir = Hex_Direction(self._facing)+1 new_pos._x, new_pos._y = \ hex_math.neighbor((self._x, self._y), jink_dir) if (ship.inertia > 0): new_pos._momentum = ship.inertia return new_pos