Example #1
0
def remove_wire(position):
    global active_objects
    order = detect_item(position)
    if "wire" in active_objects[order]:
        active_objects[order] = "none"
        graphics.redraw(position[0], position[1], position[0] + tile_w, position[1] + tile_h)
        return True
    else:
        return False  # not on a wire
Example #2
0
def create_wire(position, type="electric_insulated"):  # TODO: wiretypes
    global active_objects, wires_update
    wires_update = True
    order = detect_item(position)
    if active_objects[order] == "none":
        active_objects[order] = "electric_insulated_wire_connect"
        graphics.redraw(position[0], position[1], position[0] + tile_w, position[1] + tile_h)
        return True
    elif "box" in active_objects[order]:
        active_objects[order] += " electric_insulated_wire_connect"
        graphics.redraw(position[0], position[1], position[0] + tile_w, position[1] + tile_h)
    else:
        return False  # attempted place on other item
Example #3
0
 def main_loop(self):
     global solid, open_doors, request, response, handler_output, handler_output_position, first_time, obj_loop_end, obj_loop_start, nail_list, wires_update
     obj_loop_start = 0
     obj_loop_end = len(handler_input_all)
     box_solid_position = len(solid)
     for j in range(obj_loop_start, obj_loop_end):
         block = handler_input_all[j]
         counter = j
         if "door" in active_objects[counter]:
             if wires_update:
                 self.door_state = self.door_opening_check(block)
                 wires_update = False
             if self.door_state == False:
                 if not (block, counter) in solid:
                     solid.append((block, counter))
                 if block in open_doors:
                     tmp = []
                     for i in range(0, len(open_doors)):
                         if open_doors[i] == block:
                             pass
                     else:
                         tmp.append(open_doors[i])
                     open_doors = tmp
             else:
                 if not block in open_doors:
                     open_doors.append(block)
                 if (block, counter) in solid:
                     tmp = []
                     for i in range(0, len(solid)):
                         if solid[i] == (block, counter):
                             pass
                         else:
                             tmp.append(solid[i])
                     solid = tmp
         if "meatuara_ns" in active_objects[counter]:
             tmp = active_objects[counter].split(" ")
             tmp[1] = int(tmp[1])
             tmp[2] = int(tmp[2])
             tmp[3] = int(tmp[3])
             if tmp[4] == "s":
                 tmp[3] += 1
                 if tmp[3] > tmp[1] * tile_h:
                     tmp[4] = "n"
             elif tmp[4] == "n":
                 tmp[3] -= 1
                 if tmp[3] < tmp[2] * tile_h * -1:
                     tmp[4] = "s"
             active_objects[counter] = (
                 tmp[0] + " " + str(tmp[1]) + " " + str(tmp[2]) + " " + str(tmp[3]) + " " + tmp[4]
             )
             if request == "answered":
                 request = ""
                 if not self.check_collisions(response, (block[0], block[1] + tmp[3])):
                     die()
             else:
                 request = "posxy"
         # Put objects that only need be loaded once here
         if first_time:
             graphics.object_surface.fill((255, 0, 255))
             if "wall" in active_objects[counter]:
                 if not (block, counter) in solid:
                     solid.append((block, counter))
         # === END OF FIRST TIME === #
         else:  # Limit updates to blocks surrounding player.
             """********************************************************** """
             start = (int(player_position[0] / tile_h) - 1, int(player_position[1] / tile_w) - 1)
             end = (int(player_position[0] / tile_h) + 1, int(player_position[1] / tile_w) + 1)
             obj_loop_start = (start[1] * map_w) + start[0]
             obj_loop_end = (end[1] * map_w) + end[0]
         if "wire" in active_objects[counter]:
             if "electric" in active_objects[counter]:
                 if "insulated" in active_objects[counter]:
                     if "refill" in active_objects[counter]:
                         if self.players_items.wires != 50:
                             self.players_items.wires = 50
                 else:
                     if not self.check_collisions(player_position, block):
                         die()
         if "box" in active_objects[counter]:
             tmp = active_objects[counter].split(" ")
             # push right
             if (
                 block[0] + int(tmp[1]) - 5 <= player_position[0] + player_size[0]
                 and block[0] + int(tmp[1]) + 5 >= player_position[0] + player_size[0]
             ):
                 if (
                     block[1] + int(tmp[2]) <= player_position[1] + player_size[1]
                     and block[1] + int(tmp[2]) + tile_h >= player_position[1] + player_size[1]
                 ):
                     for i in range(0, len(solid)):
                         if solid[i] == ((block[0] + int(tmp[1]), block[1] + int(tmp[2])), counter):
                             solid.pop(i)
                     solid.append(((block[0] + int(tmp[1]) + 3, block[1] + int(tmp[2])), counter))
                     active_objects[counter] = tmp[0] + " " + str(int(tmp[1]) + 3) + " " + tmp[2]
                     block_wipe_nail((block[0] + int(tmp[1]) + 3, block[1] + int(tmp[2])))
                     graphics.redraw(
                         block[0] + int(tmp[1]),
                         block[1] + int(tmp[2]),
                         block[0] + int(tmp[1]) + tile_w,
                         block[1] + int(tmp[2]) + tile_h,
                     )
             # left
             if (
                 block[0] + int(tmp[1]) + tile_w - 5 <= player_position[0]
                 and block[0] + int(tmp[1]) + tile_w + 5 >= player_position[0]
             ):
                 if (
                     block[1] + int(tmp[2]) <= player_position[1] + player_size[1]
                     and block[1] + int(tmp[2]) + tile_h >= player_position[1] + player_size[1]
                 ):
                     for i in range(0, len(solid)):
                         if solid[i] == ((block[0] + int(tmp[1]), block[1] + int(tmp[2])), counter):
                             solid.pop(i)
                     solid.append(((block[0] + int(tmp[1]) - 3, block[1] + int(tmp[2])), counter))
                     active_objects[counter] = tmp[0] + " " + str(int(tmp[1]) - 3) + " " + tmp[2]
                     block_wipe_nail((block[0] + int(tmp[1]) - 3, block[1] + int(tmp[2])))
                     graphics.redraw(
                         block[0] + int(tmp[1]),
                         block[1] + int(tmp[2]),
                         block[0] + int(tmp[1]) + tile_w,
                         block[1] + int(tmp[2]) + tile_h,
                     )
             # down
             if (
                 block[0] + int(tmp[1]) <= player_position[0]
                 and block[0] + int(tmp[1]) + tile_w >= player_position[0]
             ):
                 if (
                     block[1] + int(tmp[2]) - 5 <= player_position[1] + player_size[1]
                     and block[1] + int(tmp[2]) + 5 >= player_position[1]
                 ):
                     for i in range(0, len(solid)):
                         if solid[i] == ((block[0] + int(tmp[1]), block[1] + int(tmp[2])), counter):
                             solid.pop(i)
                     solid.append(((block[0] + int(tmp[1]), block[1] + int(tmp[2]) + 3), counter))
                     active_objects[counter] = tmp[0] + " " + tmp[1] + " " + str(int(tmp[2]) + 3)
                     block_wipe_nail((block[0] + int(tmp[1]), block[1] + int(tmp[2]) + 3))
                     graphics.redraw(
                         block[0] + int(tmp[1]),
                         block[1] + int(tmp[2]),
                         block[0] + int(tmp[1]) + tile_w,
                         block[1] + int(tmp[2]) + tile_h,
                     )
                 # up
                 if (
                     block[1] + int(tmp[2]) + tile_h - 5 <= player_position[1]
                     and block[1] + int(tmp[2]) + tile_h + 5 >= player_position[1]
                 ):
                     for i in range(0, len(solid)):
                         if solid[i] == ((block[0] + int(tmp[1]), block[1] + int(tmp[2])), counter):
                             solid.pop(i)
                     solid.append(((block[0] + int(tmp[1]), block[1] + int(tmp[2]) - 3), counter))
                     active_objects[counter] = tmp[0] + " " + tmp[1] + " " + str(int(tmp[2]) - 3)
                     block_wipe_nail((block[0] + int(tmp[1]), block[1] + int(tmp[2]) - 3))
                     graphics.redraw(
                         block[0] + int(tmp[1]),
                         block[1] + int(tmp[2]),
                         block[0] + int(tmp[1]) + tile_w,
                         block[1] + int(tmp[2]) + tile_h,
                     )
         if "nails" in active_objects[counter]:
             if not self.check_collisions(player_position, block):
                 die()
             if not block in nail_list:
                 nail_list.append((block, counter))
         # noinspection PyInterpreter
         if "computer" in active_objects[counter]:
             if not self.check_collisions(player_position, (block[0], block[1] - 1)):
                 comp = hud.Computer_ui()
                 # comp_note = hud.Hud((block[0], block[1]-40), "Hold 'e'", timeout=3)
                 if key.get_pressed()[K_e]:
                     comp = hud.Computer_ui()
                     print "e"
         graphics.prepare_object_blit(active_objects[counter], block)
     first_time = False