Esempio n. 1
0
    def _handle_input(self):
        if keyboard.pressed("w"): self.red_cursor[1] -= 1
        if keyboard.pressed("s"): self.red_cursor[1] += 1
        if keyboard.pressed("a"): self.red_cursor[0] -= 1
        if keyboard.pressed("d"): self.red_cursor[0] += 1

        if self.red_cursor[1] < 0: self.red_cursor[1] = 0
        if self.red_cursor[1] > 31: self.red_cursor[1] = 31
        if self.red_cursor[0] < 0: self.red_cursor[0] = 0
        if self.red_cursor[0] > 31: self.red_cursor[0] = 31

        if keyboard.pressed("up"): self.blu_cursor[1] -= 1
        if keyboard.pressed("down"): self.blu_cursor[1] += 1
        if keyboard.pressed("left"): self.blu_cursor[0] -= 1
        if keyboard.pressed("right"): self.blu_cursor[0] += 1

        if self.blu_cursor[1] < 0: self.blu_cursor[1] = 0
        if self.blu_cursor[1] > 31: self.blu_cursor[1] = 31
        if self.blu_cursor[0] < 0: self.blu_cursor[0] = 0
        if self.blu_cursor[0] > 31: self.blu_cursor[0] = 31

        if keyboard.just_pressed("~"):
            t = raw_input(">>> ")
            exec(t)

        if self.turn_player == P_RED:
            rc = self.red_cursor
            if keyboard.just_pressed("c"):
                self.place_peg(P_RED, rc[0], rc[1])

            if keyboard.just_pressed("v"):
                self.place_obstacle(P_RED, rc[0], rc[1])

            if keyboard.just_pressed("b"):
                self.place_floor(P_RED, rc[0], rc[1])

        if self.turn_player == P_BLU:
            bc = self.blu_cursor
            if keyboard.just_pressed("KP1"):
                self.place_peg(P_BLU, bc[0], bc[1])

            if keyboard.just_pressed("KP2"):
                self.place_obstacle(P_BLU, bc[0], bc[1])

            if keyboard.just_pressed("KP3"):
                self.place_floor(P_BLU, bc[0], bc[1])
Esempio n. 2
0
    def run(self, delta_time):
        if keyboard.just_pressed("escape"):
            self.parent.stop()

        if keyboard.pressed("up"): self.camera.y -= 5
        elif keyboard.pressed("down"): self.camera.y += 5

        if keyboard.pressed("left"): self.camera.x -= 5
        elif keyboard.pressed("right"): self.camera.x += 5

        if keyboard.pressed("w"): self.viewport1.camera.y -= 5
        elif keyboard.pressed("s"): self.viewport1.camera.y += 5

        if keyboard.pressed("a"): self.viewport1.camera.x -= 5
        elif keyboard.pressed("d"): self.viewport1.camera.x += 5

        if keyboard.just_pressed("f"):
            if self.camera.target is None:
                self.camera.follow(self.gem)
            else:
                self.camera.follow(None)
Esempio n. 3
0
    def _handle_input(self):
        for data in self.connection.receive():
            data = data.replace("\n", "")
            command, _, params = data.partition(" ")
            params = params.split(" ")
            if command.startswith("PLACE_"):
                if command == "PLACE_PEG":
                    tile = T_RED_PEG if self.side == 1 else T_BLU_PEG
                elif command == "PLACE_OBSTACLE":
                    tile = T_OBSTACLE2
                    if self.side == P_RED: self.blu_charge_wall = -1
                    else: self.red_charge_wall = -1
                elif command == "PLACE_FLOOR":
                    tile = T_FLOOR2
                    if self.side == P_RED: self.blu_charge_floor = -1
                    else: self.red_charge_floor = -1

                x = int(params[0])
                y = int(params[1])

                self.tilemap.set_tile(x, y, tile)
            elif command == "END_TURN":
                print "Ending turn"
                self._end_turn()
            elif command == "MOVE_CURSOR":
                x = int(params[0])
                y = int(params[1])
                timestamp = int(params[2])

                if timestamp > self.last_cursor_message:
                    self.last_cursor_message = timestamp
                    if self.side == 0:
                        self.blu_cursor = [x, y]
                    else:
                        self.red_cursor = [x, y]
            elif command == "MAP":
                tiles = []
                for y in range(32):
                    row = params[y * 32 : y * 32 + 32]
                    row = map(lambda s: int(s), row)
                    tiles.append(row)
                self.tilemap.from_list(tiles)

                self.no_map_yet = False
            elif command == "DISCONNECT":
                self.connection.close()
                self.parent.set_mode(MenuMode())

        if self.side == 0:
            old_cursor = self.red_cursor[:]
            if keyboard.pressed('w'): self.red_cursor[1] -= 1
            if keyboard.pressed('s'): self.red_cursor[1] += 1
            if keyboard.pressed('a'): self.red_cursor[0] -= 1
            if keyboard.pressed('d'): self.red_cursor[0] += 1
            if self.red_cursor[1] < 0: self.red_cursor[1] = 0
            if self.red_cursor[1] > 31: self.red_cursor[1] = 31
            if self.red_cursor[0] < 0: self.red_cursor[0] = 0
            if self.red_cursor[0] > 31: self.red_cursor[0] = 31

            if self.red_cursor != old_cursor:
                rc = self.red_cursor
                self.connection.send("MOVE_CURSOR %i %i %i" % (rc[0], rc[1], self.frame))

            if self.turn_player == self.side:
                rc = self.red_cursor
                if keyboard.just_pressed("c"):
                    self.place_peg(P_RED, rc[0], rc[1])

                if keyboard.just_pressed("v"):
                    self.place_obstacle(P_RED, rc[0], rc[1])

                if keyboard.just_pressed("b"):
                    self.place_floor(P_RED, rc[0], rc[1])
        else:
            old_cursor = self.blu_cursor[:]
            if keyboard.pressed('w'): self.blu_cursor[1] -= 1
            if keyboard.pressed('s'): self.blu_cursor[1] += 1
            if keyboard.pressed('a'): self.blu_cursor[0] -= 1
            if keyboard.pressed('d'): self.blu_cursor[0] += 1
            if self.blu_cursor[1] < 0: self.blu_cursor[1] = 0
            if self.blu_cursor[1] > 31: self.blu_cursor[1] = 31
            if self.blu_cursor[0] < 0: self.blu_cursor[0] = 0
            if self.blu_cursor[0] > 31: self.blu_cursor[0] = 31

            if self.blu_cursor != old_cursor:
                bc = self.blu_cursor
                self.connection.send("MOVE_CURSOR %i %i %i" % (bc[0], bc[1], self.frame))

            if self.turn_player == self.side:
                bc = self.blu_cursor
                if keyboard.just_pressed("c"):
                    self.place_peg(P_BLU, bc[0], bc[1])

                if keyboard.just_pressed("v"):
                    self.place_obstacle(P_BLU, bc[0], bc[1])

                if keyboard.just_pressed("b"):
                    self.place_floor(P_BLU, bc[0], bc[1])