Example #1
0
def main():
    pygame.init()
    screen = pygame.display.set_mode([WIDTH, HEIGHT])
    pygame.display.set_caption("pyEdit")

    font = pygame.font.SysFont("consolas", FONT_SIZE)
    font_size = pygame.font.Font.size(font, "a")
    done = False
    camera = Camera()
    cursor = Cursor(0, 0, screen, font_size[0], font_size[1], camera)
    clock = pygame.time.Clock()
    text = Text(cursor, font, FONT_SIZE, font_size, screen, [WIDTH, HEIGHT], camera)
    while not done:
        for event in pygame.event.get():
            if text.handle_event(event):
                done = True

        screen.fill(WHITE)

        text.check_ticks()
        text.draw()

        cursor.draw()

        pygame.display.flip()
        clock.tick(FPS)

    pygame.quit()
Example #2
0
class Game():
    def __init__(self):
        self.sceneManager = SceneManager(self)
        pygame.init()
        self.size = self.width, self.height = 480, 320
        self.backgroundColor = 0, 0, 0
        self.screen = pygame.display.set_mode(self.size)
        self.clock = pygame.time.Clock()
        self.sceneManager.setScene('Menu')
        self.cursor = Cursor(self)
        while 1:
            deltaTime = 1 / float(self.clock.tick(60))
            events = pygame.event.get()
            for event in events:
                if event.type == pygame.QUIT:
                    sys.exit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        sys.exit()
            self.update(deltaTime, events)
            self.screen.fill(self.backgroundColor)
            self.draw(self.screen)
            pygame.display.flip()

    def update(self, deltaTime, events):
        self.cursor.update(deltaTime, events)
        self.sceneManager.update(deltaTime, events)

    def draw(self, screen):
        self.sceneManager.draw(screen)
        self.cursor.draw(screen)
Example #3
0
    def __init__(self):
        super().__init__(WIDTH, HEIGHT, NAME)

        arcade.set_background_color(arcade.color.WHITE)

        self.SERVER = socket.gethostbyname(socket.gethostname())
        self.PORT = 5050
        self.ADDR = (self.SERVER, self.PORT)
        self.FORMAT = 'utf-8'

        try:
            self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.client.setblocking(1)
            self.client.connect(self.ADDR)
        except:
            pass

        self.board_draw = Board()
        self.board = {
            '7': ' ',
            '8': ' ',
            '9': ' ',
            '4': ' ',
            '5': ' ',
            '6': ' ',
            '1': ' ',
            '2': ' ',
            '3': ' '
        }

        self.button_list = []
        self.popup_list = []
        self.cursor = Cursor()

        self.client_ID = None

        self.my_turn = False
        self.game_over = False

        #SERVER REQUEST BOOLS
        self.board_request = False
        self.ID_request = False

        self.player_2 = False
        self.request_reset = False
        self.reset_state = False
        self.clear_state = False

        self.winner = None

        self.popup = Popup(WIDTH / 2, HEIGHT / 2 - HEIGHT / 4, 1)
        self.game_over_popup = Popup(WIDTH / 2, HEIGHT / 2 - HEIGHT / 4, 2)
        self.restart_popup = Popup(WIDTH / 2, HEIGHT / 2 - HEIGHT / 2.5, 3)
        self.popup_list.append(self.restart_popup)

        for x in range(1, 10):
            button = Button(x)
            self.button_list.append(button)
Example #4
0
 def __init__(self):
     self.board = Board(ROWS, COLUMNS)
     self.gui = GUI(ROWS, COLUMNS, SIZE, self.board)
     self.rules = Rules()
     self.cursor = Cursor()
     self.player1 = Player(1)
     self.player2 = AIPlayer(2, self.rules, self.board)
     self.currentPlayer = self.assign_player()
     self.gameOver = False
     self.menuFlag = False
Example #5
0
 def __init__(self):
     
     self.pantalla=pygame.display.set_mode((600,704))
     self.fondo1=fondo("galaxy.jpg")
     self.footPage=pygame.image.load("macro.png").convert_alpha()
     self.Cursor=Cursor()
     self.boton1=Boton("boton3.png","boton4.png")
     self.boton2=Boton("boton5.png","boton6.png",300,350)
     self.boton3=Boton("boton7.png","boton8.png",300,450)
     self.logo=pygame.sprite.Sprite()
     self.logo=pygame.image.load("LogoGame2.png").convert_alpha()
     self.Dibujar_Menu()
Example #6
0
 def __init__(self, screen, **kwargs):
     super().__init__(screen, **kwargs)
     self.rect = Rect(0, 0, kwargs.get("height", 0), kwargs.get("width", 0))
     self.multiline = kwargs.get("multiline", True)
     self.cursor = Cursor(height=self.textheight)
     self.focused = False
     self.highlighted = False
Example #7
0
    def __init__(self):

        self.pantalla = pygame.display.set_mode((600, 704))
        self.fondo1 = fondo("Fondo.jpg")
        self.logo = pygame.sprite.Sprite()
        self.footPage = pygame.image.load("macro.png").convert_alpha()
        self.Cursor = Cursor()
        self.boton1 = Boton("boton3.png", "boton4.png")
        self.boton2 = Boton("boton5.png", "boton6.png", 300, 350)
        self.boton3 = Boton("boton7.png", "boton8.png", 300, 450)
        self.boton4 = Boton("boton1.png", "boton2.png", 500, 600)
        self.logo = pygame.sprite.Sprite()
        self.logo = pygame.image.load("LogoGame2.png").convert_alpha()
        self.visibilidad = True
        #self.lista_menu = pygame.sprite.Group()
        self.Dibujar_Menu()
Example #8
0
def enter():
    hide_cursor()
    global start_select, cursor, background, big_start, small_start
    start_select = False
    cursor = Cursor()
    background = Background()
    big_start = Big_start()
    small_start = Small_start()
    game_world.add_object(cursor, 0)
Example #9
0
class Document:
    def __init__(self):
        self.characters = []
        self.cursor = Cursor(self)
        self.filename = ''

    def insert(self, character):
        self.characters.insert(self.cursor.position, character)
        self.cursor.forward()

    def delete(self):
        del self.characters[self.cursor.position]

    def save(self):
        f = open(self.filename, 'w')
        f.write(''.join(self.characters))
        f.close()

    def __str__(self):
        return "".join(self.characters)
Example #10
0
    def __init__(self, n):
        self.blockFactory = BlockFactory()
        self.grid = []
        #add second, empty grid
        for i in range(n):
            self.grid.append([])
            for j in range(n):
                self.grid[i].append(None)
        #create grid filled with blocks
        for i in range(n):
            self.grid.append([])
            for j in range(n):
                cellPos = (j * (cellWidth + padding),
                           (n + i) * (cellHeight + padding))
                self.grid[n + i].append(self.blockFactory.build(cellPos))
        self.n = n
        self.center = (n * (cellWidth + padding) / 2, n *
                       (cellHeight + padding) + n * (cellHeight + padding) / 2)

        #cursor set to (0,0) on the grid
        self.cursor = Cursor(n, n, [n - 1, 0])
Example #11
0
def enter():
    global cursor, background, sad, happy, selected_character
    cursor = Cursor()
    background = Background()
    sad = Choose_sadness300()
    happy = Choose_happiness300()
    selected_character = 'none'

    game_world.add_object(background, 0)
    game_world.add_object(happy, 1)
    game_world.add_object(sad, 1)
    game_world.add_object(cursor, 2)
Example #12
0
    def __init__(self, parent=None, video="./SampleVideo.mp4"):
        super().__init__(parent)
        self.setLayout(QVBoxLayout())
        self.layout().setSpacing(0)
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.setStyleSheet("border: #f00 solid 5px")

        # Load Video
        self._video_path = video
        self.video = cv2.VideoCapture(video)
        atexit.register(self.video.release)
        self.__fps = self.video.get(cv2.CAP_PROP_FPS)
        self.__resolution = self.video.get(
            cv2.CAP_PROP_FRAME_WIDTH), self.video.get(
                cv2.CAP_PROP_FRAME_HEIGHT)
        self.__number_of_frames = self.video.get(cv2.CAP_PROP_FRAME_COUNT)
        print("Playing {} at {} fps and {}x{}".format(self._video_path,
                                                      self.fps,
                                                      self.resolution[0],
                                                      self.resolution[1]))

        # Video Reader
        self.__image_update_thread = VideoThread(self, video=self.video)
        self.__image_update_thread.changePixmap.connect(self.__setImage)
        self.__image_update_thread.start()
        self.__sizeChanged.connect(self.__image_update_thread.updateSize)

        # Pass through signals
        self.__image_update_thread.newFrame.connect(self.newFrame.emit,
                                                    type=Qt.DirectConnection)
        self.__image_update_thread.positionChanged.connect(
            self.positionChanged.emit)
        self.__image_update_thread.stateChanged.connect(self.stateChanged.emit)

        # Click Events
        # self.mouse_down = pyqtSignal(Video, tuple)
        # self.mouse_move = pyqtSignal(Video, tuple)
        # self.mouse_up = pyqtSignal(Video, tuple)

        self.setFixedWidth(self.resolution[0] / 2)

        # Blurring
        self._blur_strands = []
        self._blur_object = None

        # Set Cursor
        self.setCursor(Cursor())
        # self.setCursor(QCursor(Qt.CrossCursor))
        # cursor_size = self.cursor().pixmap().size()
        # self.cursor().pixmap().load("../assets/erase.png")
        # print("Cursor size",cursor_size.width(), cursor_size.height())
        self.installEventFilter(self)
Example #13
0
class Document:
    def __init__(self):
        self.characters = []
        self.cursor = Cursor(self)
        self.filename = ''

    def insert(self, character):
        if not hasattr(character, 'character'):
            character = Character(character)
        self.characters.insert(self.cursor.position, character)
        self.cursor.forward()

    @property
    def string(self):
        return "".join((str(c) for c in self.characters))

    def delete(self):
        del self.characters[self.cursor.position]

    def save(self):
        f = open(self.filename, 'w')
        f.write(''.join(self.characters))
        f.close()
Example #14
0
 def __init__(self, mainSurface, width, height):
     self.roomWidth = width
     self.roomHeight = height
     self.screenWidth = width
     self.screenHeight = height
     self.assetLoader = AssetLoader(self)
     self.mainSurface = mainSurface
     self.background = Background()
     self.level = 1
     self.cursor = Cursor(self)
     self.loadMenu()
     self.events = []
     self.fullscreen = False
     self.alreadyClicked = False
     pygame.mixer.music.play(-1)
Example #15
0
def make_objs():
    Building.create_buildings()

    i = 0
    # 계단끼리 연결
    while i < 3:
        stair_list[i + 3].other_stair = stair_list[i + 6]
        stair_list[i + 6].other_stair = stair_list[i + 3]
        stair_list[i + 3 + 12].other_stair = stair_list[i + 6 + 12]
        stair_list[i + 6 + 12].other_stair = stair_list[i + 3 + 12]
        i += 1

    # Make Obj
    for j in range(2):
        for i in range(6):
            make_random_floor_obj(j, i)

    random_actor_generator()
    Player2()

    # ui ----------------------------

    Cursor()

    ui_mouse = Ui(1)
    ui_mouse.load_img('img/ui_mouse.png')
    ui_mouse.set_pos(0, 90)
    ui_mouse.set_off((-1, 0))

    ui_keyboard = Ui(1)
    ui_keyboard.load_img('img/ui_keyboard.png')
    ui_keyboard.set_pos(-00, 90)
    ui_keyboard.set_off((1, 0))

    global ui_hp1, ui_hp2
    ui_hp1 = PlayerUI(1)
    ui_hp1.set_pos(-369, 64)
    ui_hp1.size[0], ui_hp1.size[1] = 0, 35
    ui_hp1.init(240, 63, 63, -1.0, ui_keyboard.pos)

    ui_hp2 = PlayerUI(1)
    ui_hp2.set_pos(369, 64)
    ui_hp2.size[0], ui_hp2.size[1] = 0, 35
    ui_hp2.init(91, 215, 232, 1.0, ui_mouse.pos)

    ui_center = Ui(1)
    ui_center.load_img('img/ui_center.png')
    ui_center.set_pos(0, 75)
Example #16
0
 def __init__(self, screen, pos, size, font, **kwargs):
     self.screen = screen
     self.pos = pos
     self.size = size
     self.rect = Rect(self.pos, self.size)
     self.font = font
     self.font_height = self.font.get_height()
     self.command = kwargs.get("command", None)
     self.maxlines = kwargs.get("maxlines", -1)
     self.maxlinelength = kwargs.get("maxlinelength", -1)
     self.focused = False
     self.highlighted = False
     self.cursor = Cursor("|", 700, 500, self.pos)
     self.text = SelectableText(self.screen, "", self.font, self.pos, textwrap=kwargs.get("textwrap", False), maxlinelength=kwargs.get("maxlinelength", -1))
     self.update_text("")
     pygame.key.set_repeat(500, 20)
Example #17
0
def enter():
    global background, smallReplay, smallExit, bigReplay, bigExit, chooseExit, chooseReplay, cursor, crying, score
    background = Background()
    smallReplay = SmallReplay()
    smallExit = SmallExit()
    bigReplay = BigReplay()
    bigExit = BigExit()
    chooseExit = False
    chooseReplay = False
    cursor = Cursor()
    crying = Crying()
    score = Score()
    score.score = main_state.number.score
    game_world.clear()
    game_world.add_object(crying, 0)
    game_world.add_object(score, 0)
    game_world.add_object(cursor, 1)
Example #18
0
    def __init__(self):
        self.climate = "temperate"
        self.current_weather = "clear"
        self.grid = [['0' for x in range(0, 45)] for y in range(0, 30)]
        self.over_grid = [['0' for x in range(0, 45)] for y in range(0, 30)]
        self.cursor_grid = [['0' for x in range(0, 45)] for y in range(0, 30)]
        self.cursor = Cursor(352, 240)
        self.control_panel = pygame.Surface((180, 480))
        self.view_x = 0
        self.view_y = 0

        climate_number = randint(0, 2)
        if (climate_number == 0):
            self.climate = "temperate"
        elif (climate_number == 1):
            self.climate = "hot"
        else:
            self.climate = "cold"

        self.control_panel.fill((0, 100, 0))
Example #19
0
 def __init__(self):
     self.__cursor = Cursor()
     self.__limite = 10
     self.__elementos = 0
Example #20
0
class TextInput(SelectableText):
    def __init__(self, screen, **kwargs):
        super().__init__(screen, **kwargs)
        self.rect = Rect(0, 0, kwargs.get("height", 0), kwargs.get("width", 0))
        self.multiline = kwargs.get("multiline", True)
        self.cursor = Cursor(height=self.textheight)
        self.focused = False
        self.highlighted = False
    def update(self, event=None):
        super().update(event)
        if not None in [self.x2, self.y2]:
            self.cursor.x_index = self.x2
            self.cursor.y_index = self.y2
        significant_event = False
        mouse_pos = pygame.mouse.get_pos()
        if event.type == MOUSEBUTTONDOWN and event.button == 1 and self.rect.collidepoint(mouse_pos):
            self.focused = True
            self.cursor.start()
        elif event.type == MOUSEBUTTONDOWN and event.button == 1 and not self.rect.collidepoint(mouse_pos):
            self.focused = False
            self.cursor.stop()
        elif event.type == MOUSEMOTION:
            if self.pressed:
                significant_event = True
            if self.rect.collidepoint(mouse_pos):
                self.highlighted = True
            else:
                self.highlighted = False
        elif event.type == KEYDOWN and self.focused:
            significant_event = True
            if event.key == K_BACKSPACE:
                new_indeces = self.delete_selection()
                if not new_indeces:
                    self.cursor.x_index -= 1
                    if self.cursor.x_index < 0:
                        if self.cursor.y_index > 0:
                            self.cursor.y_index -= 1
                            self.cursor.x_index = len(self.final_lines[self.cursor.y_index].text)
                            self.join_lines(self.cursor.y_index, self.cursor.y_index + 1)
                        else:
                            self.cursor.x_index = 0
                    else:
                        self.delete((self.cursor.x_index, self.cursor.y_index))
                else:
                    self.cursor.x_index, self.cursor.y_index = new_indeces
            elif event.key == K_DELETE:
                new_indeces = self.delete_selection()
                if not new_indeces:
                    if self.cursor.x_index < len(self.final_lines[self.cursor.y_index].text):
                        self.delete((self.cursor.x_index, self.cursor.y_index))
                    else:
                        if self.cursor.y_index < len(self.final_lines) - 1:
                            self.join_lines(self.cursor.x_index, self.cursor.y_index + 1)
                else:
                    self.cursor.x_index, self.cursor.y_index = new_indeces
            elif event.key == K_RETURN:
                if self.multiline:
                    new_indeces = self.delete_selection()
                    if new_indeces:
                        self.cursor.x_index, self.cursor.y_index = new_indeces
                    self.split_line((self.cursor.x_index, self.cursor.y_index))
                    self.cursor.x_index = 0
                    self.cursor.y_index += 1
            elif event.key == K_UP:
                pos = self.get_index_pos((self.cursor.x_index, self.cursor.y_index))
                self.cursor.x_index, self.cursor.y_index = self.get_nearest_index((pos[0], pos[1] - self.textheight))
            elif event.key == K_DOWN:
                pos = self.get_index_pos((self.cursor.x_index, self.cursor.y_index))
                self.cursor.x_index, self.cursor.y_index = self.get_nearest_index((pos[0], pos[1] + self.lineheight))
            elif event.key == K_LEFT:
                if self.cursor.x_index > 0:
                    self.cursor.x_index -= 1
                elif self.cursor.y_index > 0:
                    self.cursor.y_index -= 1
                    self.cursor.x_index = len(self.final_lines[self.cursor.y_index].text)
            elif event.key == K_RIGHT:
                if self.cursor.x_index < len(self.final_lines[self.cursor.y_index].text):
                    self.cursor.x_index += 1
                elif self.cursor.y_index < len(self.final_lines) - 1:
                    self.cursor.y_index += 1
                    self.cursor.x_index = 0
            else:
                new_indeces = self.delete_selection()
                if new_indeces:
                    self.cursor.x_index, self.cursor.y_index = new_indeces
                character = event.unicode
                if len(character) > 0:
                    self.select_none()
                    self.insert((self.cursor.x_index, self.cursor.y_index), character)
                    self.cursor.x_index += 1
        if significant_event:
            self.cursor.event()
        self.change_color()
    def change_color(self):
        if self.highlighted:
            self.color = (0, 0, 200)
        elif self.focused:
            self.color = (0, 0, 150)
        else:
            self.color = (0, 0, 100)
    def draw(self):
        self.cursor.update()
        pygame.draw.rect(self.screen, self.color, self.rect, 2)
        super().draw()
        self.cursor.draw(self.screen, self.get_index_pos((self.cursor.x_index, self.cursor.y_index)))
Example #21
0
    def __init__(self, w, h):
        #pygame shit
        pygame.init()
        window = pygame.display.set_mode((w, h))
        clock = pygame.time.Clock()
        font = pygame.font.SysFont('Courier', 20)

        #variables +other cool stuff
        im.__init__()
        paused = False
        p1 = Player((-1, 1, 0))
        terrain = TerrainGenerator()
        render = Render()
        cursor = Cursor((4, 2, 0))

        #debug menu
        debug = Menu()
        b1 = Button(pygame.Rect(100, 100, 120, 50), terrain.test, "test", font)
        b3 = Button(pygame.Rect(100, 160, 120, 50), terrain.clear, "clear",
                    font)
        debug.add_buttons(b1, b3)

        #game loop
        while True:
            dt = clock.tick() / 200
            if dt == 0: dt = 0.01

            #input shenanigans
            im.manage_input()
            for e in im.keydown():
                if e.key == pygame.K_ESCAPE:
                    paused = not paused
                    pygame.event.set_grab(not paused)
                    #pygame.mouse.set_visible(paused)
                    print("Paused:", paused)
                elif e.key == pygame.K_RETURN:
                    terrain.test()

            #temporary gibberish
            if not paused:
                pygame.mouse.set_pos(256, 256)
                pygame.event.clear(pygame.MOUSEMOTION)
                p1.update(dt)

                render.cubes(terrain.cube_list, p1)
                render.octree(terrain.map, p1)
                render.draw()

                cursor.update()
                render.cursor(cursor, p1)
            else:
                debug.update()

            window.blit(Render.world_surface, (0, 0))
            if paused:
                window.blit(debug.menu_surface, (0, 0))

            #print out fps
            fps = font.render(str(int(clock.get_fps())), True, (0, 255, 0))
            window.blit(fps, (20, 20))

            pygame.display.flip()
Example #22
0
    def loop(self):
        """
        The main loop

        	@param self -- the JogoDoPiano
	    
        """
        sc = Screen()
        screen = sc.getScreen()

        statusBar = Label(10, 805, [(0, 0), (1, 1), (0, 1)])
        statusBarRight = Label(1100, 805, [(0, 0), (1, 1), (0, 1)])
        #statusBar = Label(10, 10, [(0,0), (1,1), (0,1)])

        lampCursor = Cursor("lamp", 0, 0, [(0, 0), (1, 1), (0, 1)])
        earCursor = Cursor("ear", 0, 0, [(0, 0), (1, 1), (0, 1)])
        lamp = Lamp("lamp", 825, 709, [(836, 721), (868, 721), (836, 779),
                                       (868, 779)], lampCursor)
        #lamp = Lamp("lamp", 825, 709, [(0, 0), (0, 20), (20, 20), (20, 0)], lampCursor)
        game = Game()

        buttons = [
            Key("1", -36, 507, [(28, 508), (0, 566), (0, 639), (31, 649),
                                (49, 602), (30, 595), (58, 514)], game),
            Key("2", 31, 510, [(60, 512), (30, 595), (58, 603), (89, 518)],
                game),
            Key("3", 19, 516, [(89, 518), (59, 603), (49, 602), (34, 649),
                               (88, 664), (100, 615), (84, 610), (104, 520)],
                game),
            Key("4", 85, 517, [(106, 520), (84, 610), (113, 615), (133, 524)],
                game),
            Key("5", 75, 524, [(134, 524), (113, 615), (100, 614), (87, 663),
                               (137, 672), (158, 527)], game),
            Key("6", 131, 527, [(160, 527), (138, 671), (196, 677), (200, 624),
                                (184, 621), (196, 532)], game),
            Key("7", 187, 529, [(194, 532), (184, 621), (213, 623),
                                (221, 536)], game),
            Key("8", 190, 535, [(221, 536), (215, 623), (201, 624), (196, 680),
                                (254, 677), (253, 628), (232, 626),
                                (237, 538)], game),
            Key("9", 234, 534, [(236, 536), (232, 625), (263, 626),
                                (262, 539)], game),
            Key("10", 243, 538,
                [(262, 539), (263, 626), (252, 627), (254, 676), (303, 675),
                 (296, 627), (284, 626), (279, 538)], game),
            Key("11", 282, 532, [(279, 538), (285, 625), (312, 625),
                                 (301, 538)], game),
            Key("12", 295, 540, [(302, 540), (312, 625), (297, 627),
                                 (301, 676), (344, 670), (317, 539)], game),
            Key("13", 320, 537, [(317, 539), (344, 671), (389, 662),
                                 (378, 625), (367, 624), (342, 538)], game),
            Key("14", 342, 532, [(342, 538), (367, 623), (387, 621),
                                 (358, 535)], game),
            Key("15", 358, 535,
                [(358, 535), (387, 620), (378, 625), (389, 661), (432, 651),
                 (418, 618), (407, 619), (376, 534)], game),
            Key("16", 377, 526, [(376, 534), (406, 618), (424, 614),
                                 (394, 530)], game),
            Key("17", 393, 529, [(394, 531), (424, 613), (418, 618),
                                 (431, 653), (473, 639), (411, 529)], game),
            Key("18", 413, 524, [(413, 530), (474, 639), (511, 628),
                                 (496, 603), (484, 605), (434, 525)], game),
            Key("19", 436, 516, [(435, 526), (483, 604), (503, 599),
                                 (456, 521)], game),
            Key("20", 455, 520,
                [(455, 522), (503, 599), (496, 603), (511, 629), (548, 615),
                 (532, 592), (522, 593), (474, 520)], game),
            Key("21", 475, 508, [(473, 520), (522, 592), (542, 585),
                                 (493, 514)], game),
            Key("22", 494, 512,
                [(493, 514), (541, 585), (532, 591), (548, 616), (585, 600),
                 (568, 579), (559, 580), (507, 512)], game),
            Key("23", 510, 502, [(508, 512), (559, 580), (577, 574),
                                 (526, 507)], game),
            Key("24", 526, 506, [(527, 508), (577, 574), (569, 582),
                                 (585, 602), (621, 586), (538, 504)], game),
            Key("25", 539, 496, [(538, 504), (622, 588), (661, 571),
                                 (639, 550), (626, 553), (572, 496)], game),
            Key("26", 572, 485, [(572, 496), (627, 553), (644, 546),
                                 (595, 494)], game),
            Key("27", 595, 492,
                [(596, 493), (645, 546), (639, 551), (662, 572), (698, 562),
                 (672, 538), (664, 539), (610, 491)], game),
            Key("28", 611, 481, [(610, 492), (664, 539), (679, 534),
                                 (632, 488)], game),
            Key("29", 632, 488, [(633, 489), (679, 534), (672, 539),
                                 (698, 562), (729, 553), (646, 488)], game),
            Key("30", 647, 485, [(645, 488), (731, 556), (763, 550),
                                 (739, 531), (728, 531), (671, 485)], game),
            Key("31", 672, 478, [(670, 485), (728, 530), (742, 527),
                                 (690, 484)], game),
            Key("32", 690, 483,
                [(693, 484), (742, 528), (739, 532), (763, 551), (796, 545),
                 (778, 530), (769, 529), (714, 482)], game),
            Key("33", 715, 474, [(714, 483), (770, 529), (784, 525),
                                 (734, 481)], game),
            Key("34", 735, 481,
                [(736, 481), (784, 524), (777, 529), (797, 547), (829, 543),
                 (810, 527), (802, 525), (748, 481)], game),
            Key("35", 746, 472, [(749, 481), (802, 525), (817, 521),
                                 (771, 480)], game),
            Key("36", 771, 482, [(773, 481), (818, 522), (810, 527),
                                 (830, 543), (869, 541), (793, 481)], game),
            Key("37", 794, 481, [(793, 481), (869, 540), (902, 539),
                                 (879, 520), (866, 518), (821, 480)], game),
            Key("38", 823, 472, [(820, 480), (866, 519), (881, 516),
                                 (843, 480)], game),
            Key("39", 843, 480,
                [(843, 480), (881, 518), (878, 520), (902, 539), (936, 537),
                 (909, 515), (899, 516), (852, 480)], game),
            Stick("2", _("Aleluia - Handel - 4 notes"), 892,
                  241, [(1022, 330), (1017, 325), (1011, 327), (1005, 319),
                        (1008, 315), (1010, 301), (1008, 296), (1004, 289),
                        (993, 284), (984, 277), (983, 257), (988, 248),
                        (998, 247), (1007, 247), (1013, 249), (1018, 257),
                        (1020, 269), (1016, 277), (1010, 282), (1007, 285),
                        (1009, 295), (1016, 295), (1021, 326)], game),
            Stick("1", _("Silent Night - Christmas Song - 4 notes"), 885,
                  271, [(1006, 343), (1001, 338), (1006, 330), (1000, 322),
                        (994, 325), (984, 324), (976, 319), (970, 308),
                        (973, 296), (982, 288), (992, 285), (1003, 290),
                        (1008, 299), (1009, 309), (1004, 321), (1010, 327),
                        (1017, 325), (1038, 351)], game),
            Stick("3", _("Save me - Hanson - 4 notes"), 917, 222,
                  [(1039, 351), (1027, 338), (1024, 278), (1031, 276),
                   (1030, 265), (1026, 262), (1019, 256), (1015, 246),
                   (1016, 233), (1026, 229), (1036, 226), (1046, 231),
                   (1049, 238), (1049, 252), (1044, 262), (1036, 266),
                   (1037, 276), (1046, 276), (1049, 352), (1037, 352)], game),
            Stick("4", _("Every breath you take - Sting - 5 notes"), 944, 213,
                  [(1050, 233), (1054, 223), (1063, 218), (1071, 218),
                   (1084, 223), (1087, 235), (1083, 247), (1079, 253),
                   (1070, 250), (1061, 249), (1055, 249), (1053, 248)], game),
            Stick("5", _("Aquarela - Toquinho - 6 notes"), 950, 247,
                  [(1061, 353), (1055, 302), (1063, 299), (1062, 289),
                   (1055, 283), (1048, 276), (1047, 263), (1053, 254),
                   (1059, 250), (1070, 250), (1082, 257), (1086, 271),
                   (1081, 278), (1074, 282), (1070, 289), (1070, 299),
                   (1078, 301), (1081, 351)], game),
            Stick("6", _("Wedding March - Felix Mendelssohn - 7 notes"), 969,
                  202, [(1091, 233), (1091, 239), (1094, 248), (1100, 257),
                        (1108, 257), (1116, 257), (1125, 252), (1128, 242),
                        (1129, 234), (1128, 226), (1122, 222), (1111, 219),
                        (1102, 221), (1096, 226)], game),
            Stick("7", _("Amor Maior - Jota Quest - 8 notes"), 977, 251,
                  [(1081, 352), (1079, 324), (1086, 304), (1093, 308),
                   (1097, 296), (1094, 291), (1090, 283), (1089, 275),
                   (1091, 267), (1096, 263), (1104, 261), (1109, 260),
                   (1114, 262), (1119, 266), (1126, 272), (1126, 279),
                   (1124, 290), (1119, 295), (1108, 298), (1102, 299),
                   (1101, 303), (1098, 311), (1105, 313), (1091, 351)], game),
            Stick("8", _("Greenleaves - Anonymous - 9 notes"), 1014, 211,
                  [(1108, 346), (1118, 296), (1124, 292), (1125, 286),
                   (1127, 279), (1127, 274), (1124, 266), (1129, 267),
                   (1133, 257), (1127, 252), (1128, 251), (1129, 242),
                   (1130, 238), (1130, 230), (1128, 222), (1133, 219),
                   (1136, 217), (1144, 217), (1149, 220), (1155, 226),
                   (1158, 234), (1158, 245), (1152, 252), (1143, 258),
                   (1136, 263), (1135, 267), (1133, 271), (1136, 286),
                   (1134, 278), (1138, 291), (1140, 293), (1140, 301),
                   (1132, 301), (1129, 301), (1126, 316), (1120, 328),
                   (1114, 339), (1111, 344)], game),
            Stick("9", _("Velha Infancia - Tribalistas - 5 notes"), 985, 219,
                  [(1113, 344), (1130, 303), (1139, 303), (1143, 294),
                   (1139, 288), (1136, 282), (1135, 273), (1138, 266),
                   (1140, 262), (1146, 259), (1157, 259), (1167, 260),
                   (1170, 269), (1173, 278), (1171, 286), (1165, 293),
                   (1157, 295), (1149, 297), (1148, 298), (1146, 307),
                   (1151, 309), (1139, 339), (1113, 345)], game),
            Stick("10", _("Jingle Bells - Christmas Song - 11 notes"), 883,
                  496, [(1009, 604), (1002, 560), (1009, 558), (1009, 547),
                        (1004, 545), (996, 543), (991, 533), (990, 526),
                        (995, 513), (997, 510), (1007, 507), (1016, 507),
                        (1021, 511), (1025, 518), (1027, 528), (1024, 536),
                        (1019, 545), (1014, 546), (1014, 557), (1023, 557),
                        (1028, 609)], game),
            Stick("11", _("Habanera - Georges Bizet - 8 notes"), 927, 479,
                  [(1039, 612), (1034, 536), (1040, 533), (1040, 521),
                   (1034, 519), (1029, 515), (1024, 509), (1024, 499),
                   (1026, 490), (1030, 487), (1039, 485), (1048, 484),
                   (1059, 490), (1062, 498), (1062, 509), (1056, 515),
                   (1047, 521), (1046, 523), (1047, 534), (1054, 534),
                   (1059, 612)], game),
            Stick("12", _("Yellow Submarine - Beatles - 10 notes"), 954, 497,
                  [(1060, 609), (1059, 589), (1062, 571), (1066, 552),
                   (1071, 551), (1074, 541), (1068, 537), (1062, 526),
                   (1064, 513), (1071, 504), (1085, 503), (1087, 504),
                   (1096, 512), (1099, 520), (1096, 532), (1089, 539),
                   (1080, 543), (1078, 553), (1086, 556), (1074, 614)], game),
            Stick("13",
                  _("Jesu, Joy of Man's Desiring - J. S. Bach - 12 notes"),
                  995, 495,
                  [(1087, 612), (1105, 549), (1113, 550), (1114, 538),
                   (1110, 533), (1104, 522), (1105, 515), (1112, 506),
                   (1118, 504), (1126, 501), (1134, 503), (1139, 509),
                   (1143, 519), (1139, 533), (1129, 541), (1122, 543),
                   (1117, 553), (1126, 554), (1108, 608)], game),
            Stick("14", _("Symphony No. 9 - Beethoven - 15 notes"), 1027, 515,
                  [(1113, 605), (1133, 566), (1138, 569), (1145, 560),
                   (1142, 551), (1139, 544), (1139, 536), (1145, 529),
                   (1152, 525), (1160, 526), (1169, 529), (1176, 539),
                   (1174, 553), (1169, 560), (1158, 565), (1151, 564),
                   (1146, 572), (1151, 578), (1138, 600)], game), lampCursor,
            earCursor, lamp, statusBar, statusBarRight
        ]

        helps = [
            Help("re", 370, 500, [(0, 0), (1, 1), (0, 1)]),
            Help("re_sust", 380, 458, [(0, 0), (1, 1), (0, 1)]),
            Help("mi", 415, 490, [(0, 0), (1, 1), (0, 1)]),
            Help("fa", 450, 478, [(0, 0), (1, 1), (0, 1)]),
            Help("fa_sust", 455, 435, [(0, 0), (1, 1), (0, 1)]),
            Help("sol", 490, 470, [(0, 0), (1, 1), (0, 1)]),
            Help("sol_sust", 490, 425, [(0, 0), (1, 1), (0, 1)]),
            Help("la", 525, 460, [(0, 0), (1, 1), (0, 1)]),
            Help("la_sust", 530, 417, [(0, 0), (1, 1), (0, 1)]),
            Help("si", 565, 445, [(0, 0), (1, 1), (0, 1)]),
            Help("do", 595, 430, [(0, 0), (1, 1), (0, 1)]),
            Help("do_sust", 600, 395, [(0, 0), (1, 1), (0, 1)]),
            Help("re", 640, 420, [(0, 0), (1, 1), (0, 1)]),
            Help("re_sust", 630, 380, [(0, 0), (1, 1), (0, 1)]),
            Help("mi", 675, 405, [(0, 0), (1, 1), (0, 1)]),
            Help("fa", 708, 402, [(0, 0), (1, 1), (0, 1)]),
            Help("fa_sust", 695, 370, [(0, 0), (1, 1), (0, 1)]),
            Help("sol", 742, 398, [(0, 0), (1, 1), (0, 1)])
        ]

        game.setButtons(buttons, helps)

        stones = [
            Stone("stone", 115, 187, [(116, 188), (159, 188), (159, 234),
                                      (116, 234)], game),
            Stone("stone", 163, 187, [(164, 188), (207, 188), (207, 234),
                                      (164, 234)], game),
            Stone("stone", 211, 187, [(212, 188), (255, 188), (255, 234),
                                      (212, 234)], game),
            Stone("stone", 259, 187, [(260, 188), (303, 188), (303, 234),
                                      (260, 234)], game),
            Stone("stone", 307, 187, [(308, 188), (351, 188), (351, 234),
                                      (308, 234)], game),
            Stone("stone", 355, 187, [(356, 188), (399, 188), (399, 234),
                                      (356, 234)], game),
            Stone("stone", 403, 187, [(404, 188), (447, 188), (447, 234),
                                      (404, 234)], game),
            Stone("stone", 451, 187, [(452, 188), (495, 188), (495, 234),
                                      (452, 234)], game),
            Stone("stone", 498, 187, [(500, 188), (543, 188), (543, 234),
                                      (500, 234)], game),
            Stone("stone", 546, 187, [(548, 188), (591, 188), (591, 234),
                                      (548, 234)], game),
            Stone("stone", 594, 187, [(596, 188), (639, 188), (639, 234),
                                      (596, 234)], game),
            Stone("stone", 642, 187, [(644, 188), (687, 188), (687, 234),
                                      (644, 234)], game),
            Stone("stone", 690, 187, [(692, 188), (735, 188), (735, 234),
                                      (692, 234)], game),
            Stone("stone", 738, 187, [(740, 188), (783, 188), (783, 234),
                                      (740, 234)], game),
            Stone("stone", 786, 187, [(788, 188), (831, 188), (831, 234),
                                      (788, 234)], game)
        ]

        animation = [
            Ball("bar", 80, 287, [(0, 0), (1, 1), (0, 1)], game),
            Ball("redBall", 10, 247, [(8, 247), (100, 247), (100, 338),
                                      (8, 338)], game),
            Ball("greenBall", 10, 247, [(8, 247), (100, 247), (100, 338),
                                        (8, 338)], game),
            Ball("blueBall", 10, 247, [(8, 247), (100, 247), (100, 338),
                                       (8, 338)], game),
            Ball("yellowBall", 10, 247, [(8, 247), (100, 247), (100, 338),
                                         (8, 338)], game),
            Ball("rightBall", 850, 267, [(0, 0), (1, 1), (0, 1)], game)
        ]

        game.addChallenge(
            Challenge("noitefeliz", [20, 22, 20, 17], buttons[40], stones,
                      [5, 7, 5, 2], animation[1], animation[0], animation[5],
                      "easy", game))
        game.addChallenge(
            Challenge("aleluia", [27, 22, 24, 22], buttons[39], stones,
                      [12, 7, 9, 7], animation[3], animation[0], animation[5],
                      "easy", game))
        game.addChallenge(
            Challenge("saveme", [16, 17, 24, 17], buttons[41], stones,
                      [1, 2, 9, 2], animation[2], animation[0], animation[5],
                      "easy", game))
        game.addChallenge(
            Challenge("everybreath", [26, 27, 26, 24, 22], buttons[42], stones,
                      [11, 12, 11, 9, 7], animation[3], animation[0],
                      animation[5], "easy", game))
        game.addChallenge(
            Challenge("aquarela", [15, 15, 20, 20, 19, 17], buttons[43],
                      stones, [0, 0, 5, 5, 4, 2], animation[4], animation[0],
                      animation[5], "easy", game))
        game.addChallenge(
            Challenge("marchanupcial", [25, 24, 19, 22, 20, 18, 15],
                      buttons[44], stones, [10, 9, 4, 7, 5, 3, 0],
                      animation[1], animation[0], animation[5], "easy", game))
        game.addChallenge(
            Challenge("amormaior", [22, 23, 22, 25, 27, 22, 20, 18],
                      buttons[45], stones, [7, 8, 7, 10, 12, 7, 5, 3],
                      animation[2], animation[0], animation[5], "easy", game))
        game.addChallenge(
            Challenge("greenleaves", [17, 20, 22, 24, 25, 24, 22, 19, 15],
                      buttons[46], stones, [], animation[4], animation[0],
                      animation[5], "easy", game))
        game.addChallenge(
            Challenge("velhainfancia", [19, 22, 19, 22, 29], buttons[47],
                      stones, [4, 7, 4, 7, 14], animation[1], animation[0],
                      animation[5], "easy", game))
        game.addChallenge(
            Challenge("jinglebells",
                      [24, 24, 24, 24, 24, 24, 24, 27, 20, 22, 24],
                      buttons[48], stones, [9, 9, 9, 9, 9, 9, 9, 12, 5, 7, 9],
                      animation[1], animation[0], animation[5], "difficult",
                      game))
        game.addChallenge(
            Challenge("habanera", [27, 26, 25, 25, 25, 24, 23, 22],
                      buttons[49], stones, [12, 11, 10, 10, 10, 9, 8, 7],
                      animation[2], animation[0], animation[5], "difficult",
                      game))
        game.addChallenge(
            Challenge("yellow", [27, 27, 27, 27, 29, 24, 22, 22, 22, 22],
                      buttons[50], stones, [12, 12, 12, 12, 14, 9, 7, 7, 7, 7],
                      animation[3], animation[0], animation[5], "difficult",
                      game))
        game.addChallenge(
            Challenge("jesusalegria",
                      [20, 22, 24, 27, 25, 25, 29, 27, 27, 32, 31, 32],
                      buttons[51], stones,
                      [5, 7, 9, 12, 10, 10, 14, 12, 12, 17, 16, 17],
                      animation[0], animation[4], animation[5], "difficult",
                      game))
        game.addChallenge(
            Challenge(
                "nonasinfonia",
                [19, 19, 20, 22, 22, 20, 19, 17, 15, 15, 17, 19, 19, 17, 17],
                buttons[52], stones,
                [4, 4, 5, 7, 7, 5, 4, 2, 0, 0, 2, 4, 4, 2, 2], animation[3],
                animation[0], animation[5], "difficult", game))

        keyboard = pygame.image.load("image/keyboard.png")

        bigBar = pygame.image.load("image/bigBar.png")
        bigBar.set_alpha(None)  # disable alpha.
        bigBar.convert()
        bigBar.set_colorkey((255, 0, 255))  # magenta

        frame = pygame.image.load("image/frame.png")
        frame.set_alpha(None)  # disable alpha.
        frame.convert()
        frame.set_colorkey((255, 0, 255))  # magenta

        bucket1 = pygame.image.load("image/bucket1.png")
        bucket1.set_alpha(None)  # disable alpha.
        bucket1.convert()
        bucket1.set_colorkey((255, 0, 255))  # magenta

        bucket2 = pygame.image.load("image/bucket2.png")
        bucket2.set_alpha(None)  # disable alpha.
        bucket2.convert()
        bucket2.set_colorkey((255, 0, 255))  # magenta

        clock = pygame.time.Clock()
        FPS = 20

        while self.run:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                else:
                    for button in buttons:
                        button.parseEvent(event)
                    for stone in stones:
                        stone.parseEvent(event)
                    for help in helps:
                        help.parseEvent(event)
                    for thing in animation:
                        thing.parseEvent(event)
                    if event.type == MOUSEMOTION:
                        posicao = (event.pos[0], event.pos[1])
                        #pygame.display.set_caption(str(posicao[0])+" x "+str(posicao[1]))

            screen.blit(keyboard, (0, -1))

            for button in buttons:
                button.draw(screen)

            for stone in stones:
                stone.draw(screen)

                for thing in animation:
                    thing.draw(screen)

            screen.blit(frame, (-39, 470))
            screen.blit(bigBar, (114, 274))

            for help in helps:
                help.draw(screen)

            screen.blit(bucket1, (988, 338))
            screen.blit(bucket2, (987, 597))

            lampCursor.draw(screen)
            earCursor.draw(screen)

            #update the surface in the screen
            pygame.display.flip()

            #control number of frames per second
            clock.tick(FPS)
Example #23
0
class Game:
    def __init__(self):
        self.board = Board(ROWS, COLUMNS)
        self.gui = GUI(ROWS, COLUMNS, SIZE, self.board)
        self.rules = Rules()
        self.cursor = Cursor()
        self.player1 = Player(1)
        self.player2 = AIPlayer(2, self.rules, self.board)
        self.currentPlayer = self.assign_player()
        self.gameOver = False
        self.menuFlag = False

    def assign_player(self):
        a = random.randint(0, 1)
        if a == 0:
            self.gui.next_move_message(self.player1.get_id())
            return self.player1
        else:
            self.gui.next_move_message(self.player2.get_id())
            return self.player2

    def switch_players(self):
        if self.currentPlayer == self.player1:
            self.currentPlayer = self.player2
        else:
            self.currentPlayer = self.player1
        self.gui.next_move_message(self.currentPlayer.get_id())

    def reset(self):
        self.menuFlag = False
        self.board.reset()

    def change_rules(self, rule):
        if rule == 1:
            self.rules = Rules()
        elif rule == 2:
            self.rules = DiagonalOnly()
        else:
            self.rules = RowsColumnsOnly()
        self.reset()

    def update_cursor(self, event):
        x = event.pos[0]
        y = event.pos[1]
        self.cursor.update(x, y)

    def mouse_motion(self):
        if self.gameOver is False and self.menuFlag is False:
            if self.gui.are_buttons_hovered(self.cursor.gety()):
                self.gui.buttons_hovered(self.cursor.getx())
            else:
                self.gui.draw_gui(self.board)
        elif self.menuFlag:
            if self.gui.are_rules_hovered(self.cursor.getx(),
                                          self.cursor.gety()):
                self.gui.rules_hovered(self.cursor.getx(), self.cursor.gety())
            else:
                self.gui.draw_gui(self.board)

    def move_made(self):
        if self.rules.winning_move(self.board.get_board(),
                                   self.currentPlayer.get_id(),
                                   self.board.get_columns(),
                                   self.board.get_rows()):
            self.gameOver = True
            self.gui.winning_move_message(self.currentPlayer.get_id())
        elif self.board.is_full():
            self.gui.draw_message()
            self.gameOver = True
        else:
            self.switch_players()
        #print(self.board.get_board())

    def mouse_clicked(self):
        if self.gameOver is False and self.menuFlag is False:
            if self.gui.are_buttons_hovered(self.cursor.gety()):
                col = int(math.floor(self.cursor.getx() / self.gui.get_size()))
                if self.currentPlayer.make_move(self.board, col):
                    self.move_made()
                else:
                    self.gui.not_valid_loc_message(self.currentPlayer.get_id())
            self.gui.draw_gui(self.board)
        elif self.menuFlag:
            if self.gui.are_rules_hovered(self.cursor.getx(),
                                          self.cursor.gety()):
                rule = self.gui.get_rule(self.cursor.getx(),
                                         self.cursor.gety())
                self.change_rules(rule)
                self.gui.shut_rules()
                self.gameOver = self.menuFlag = False
                self.reset()
        if self.gui.reset_hovered(self.cursor.getx(), self.cursor.gety()):
            self.board.reset()
            self.assign_player()
            self.gameOver = self.menuFlag = False
        if self.gui.are_options_hovered(self.cursor.getx(),
                                        self.cursor.gety()):
            self.gui.options_hovered(self.menuFlag)
            self.menuFlag = not self.menuFlag
        self.gui.draw_gui(self.board)

    def start_game(self):
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                if self.currentPlayer.get_type() == "player":
                    if event.type == pygame.MOUSEMOTION:
                        self.update_cursor(event)
                        self.mouse_motion()
                    elif event.type == pygame.MOUSEBUTTONDOWN:
                        self.update_cursor(event)
                        self.mouse_clicked()
                elif self.currentPlayer.get_type() == "AI":
                    if not self.gameOver and not self.menuFlag:
                        if self.currentPlayer.make_move(self.board, 0):
                            self.move_made()
                        else:
                            self.gui.not_valid_loc_message(
                                self.currentPlayer.get_id())
                        self.gui.draw_gui(self.board)
                    else:
                        self.currentPlayer = self.player1
Example #24
0
from Level import Level, Popup, PopupType
import pygame

from ShopEntry import Shop

pygame.init

running = True
size = (1920, 1080)
clock = pygame.time.Clock()

screen = pygame.display.set_mode(size, pygame.FULLSCREEN)


lock = threading.Lock()
cursor = Cursor(lock)
# cursor.start()

pygame.mouse.set_visible(False)

"""" MENU """""


background = pygame.image.load("resources/images/background.png").convert()
gamestate = GameState(GameStateEnum.mainmenu)
level = Level(10, gamestate)
popup = Popup(PopupType.mainmenu, level, gamestate)
shop = Shop(cursor, gamestate)


def shoot():
Example #25
0
 def __init__(self):
     self.characters = []
     self.cursor = Cursor(self)
     self.filename = ''
Example #26
0
class Menu(object):
    """docstring for Menu"""
    def __init__(self):
        
        self.pantalla=pygame.display.set_mode((600,704))
        self.fondo1=fondo("galaxy.jpg")
        self.footPage=pygame.image.load("macro.png").convert_alpha()
        self.Cursor=Cursor()
        self.boton1=Boton("boton3.png","boton4.png")
        self.boton2=Boton("boton5.png","boton6.png",300,350)
        self.boton3=Boton("boton7.png","boton8.png",300,450)
        self.logo=pygame.sprite.Sprite()
        self.logo=pygame.image.load("LogoGame2.png").convert_alpha()
        self.Dibujar_Menu()

    
    
    def Mostrar_Opciones(self):
        
        self.Cursor.update()
        if self.boton1.Colision_Cursor(self.pantalla,self.Cursor):
            pass

        if self.boton2.Colision_Cursor(self.pantalla,self.Cursor):
            pass

        if self.boton3.Colision_Cursor(self.pantalla,self.Cursor):
            pass    
        self.boton1.dibujar(self.pantalla)
        self.boton2.dibujar(self.pantalla)
        self.boton3.dibujar(self.pantalla)

    def Iniciar_Juego(self):
        pass

    def Mostrar_Puntajes(self):
        pass

    def Salir(self):
        pygame.quit()

    def Acciones(self):
        pass    

    def Dibujar_Menu(self):
        pygame.mixer.pre_init(44100, -16, 1, 512)
        pygame.init()    
        salir=False
        
        
        pygame.mixer.music.load("OST/mainTheme.mp3")
        pygame.mixer.music.play()
        reloj1=pygame.time.Clock()
        while salir!=True:
            for event in pygame.event.get():
                if event.type==pygame.QUIT:
                    salir=True
            
            reloj1.tick(30)
            
            
            self.fondo1.update(self.pantalla,False)

            self.pantalla.blit(self.logo,(90,100))
            #pantalla.blit(pressKey,(78,350))
            self.pantalla.blit(self.footPage,(125,650))
            self.Mostrar_Opciones()
            pygame.display.update()
            
        pygame.quit()
Example #27
0
 def test(self):
     c = Cube(Cursor.pos())
     self.define(c)
 def create_cursor(self, coord):
     from Cursor import Cursor
     self.cursor = Cursor('Cursor', coord, fake=True)
Example #29
0
class ColorGrid:

    # None = empty cell
    # 1 - 4 = color cell

    # (n) by (n) grid
    def __init__(self, n):
        self.blockFactory = BlockFactory()
        self.grid = []
        #add second, empty grid
        for i in range(n):
            self.grid.append([])
            for j in range(n):
                self.grid[i].append(None)
        #create grid filled with blocks
        for i in range(n):
            self.grid.append([])
            for j in range(n):
                cellPos = (j * (cellWidth + padding),
                           (n + i) * (cellHeight + padding))
                self.grid[n + i].append(self.blockFactory.build(cellPos))
        self.n = n
        self.center = (n * (cellWidth + padding) / 2, n *
                       (cellHeight + padding) + n * (cellHeight + padding) / 2)

        #cursor set to (0,0) on the grid
        self.cursor = Cursor(n, n, [n - 1, 0])

    def rotateClock(self):
        for i in range(3):
            self.rotateCounter()

    def rotateCounter(self):
        N = self.n
        for x in range(0, int(N / 2)):
            for y in range(x, N - x - 1):
                top = ((x + N), y)
                right = ((y + N), (N - 1 - x))
                bottom = ((N - 1 - x + N), (N - 1 - y))
                left = ((N - 1 - y + N), (x))
                self.grid[top[0]][top[1]].rotate()
                self.grid[right[0]][right[1]].rotate()
                self.grid[bottom[0]][bottom[1]].rotate()
                self.grid[left[0]][left[1]].rotate()
                self.swapCells(top, left)
                self.swapCells(top, bottom)
                self.swapCells(top, right)
        self.rotateCursor(True)

    #coord - (row,col)
    def getCell(self, coord):
        return self.grid[coord[0]][coord[1]]

    #A / B = (row,col) of desired cells
    def swapCells(self, A, B):
        temp = self.grid[A[0]][A[1]]
        self.grid[A[0]][A[1]] = self.grid[B[0]][B[1]]
        self.grid[B[0]][B[1]] = temp
        cellA = self.grid[A[0]][A[1]]
        cellB = self.grid[B[0]][B[1]]
        if cellA != None:
            cellA.updatePosition(
                (A[1] * (cellWidth + padding), A[0] * (cellHeight + padding)))
        if cellB != None:
            cellB.updatePosition(
                (B[1] * (cellWidth + padding), B[0] * (cellHeight + padding)))

    def moveCursor(self, key):
        self.cursor.move(key)

    def rotateCursor(self, counter=True):
        currPos = self.cursor.getPosition()
        n = self.n
        xMin = min(currPos[1], n - currPos[1] - 1)
        yMin = min(currPos[0], n - currPos[0] - 1)
        layer = min(xMin, yMin)
        #top
        if currPos[0] - layer == 0:
            if counter == False:
                #top - > right
                self.cursor.setPosition((currPos[1], self.n - 1 - layer))
            else:
                #top -> left
                self.cursor.setPosition((self.n - currPos[1] - 1, layer))
        #bottom
        elif currPos[0] + layer == self.n - 1:
            if counter == False:
                #bottom -> left
                self.cursor.setPosition((currPos[1], layer))
            else:
                #bottom -> right
                self.cursor.setPosition(
                    (self.n - currPos[1] - 1, self.n - 1 - layer))
        else:
            #left
            if currPos[1] - layer == 0:
                if counter == False:
                    #left -> top
                    self.cursor.setPosition((layer, self.n - currPos[0] - 1))
                else:
                    #left -> bottom
                    self.cursor.setPosition((self.n - 1 - layer, currPos[0]))
            #right
            else:
                if counter == False:
                    #right -> bottom
                    self.cursor.setPosition(
                        (self.n - 1 - layer, self.n - currPos[0] - 1))
                else:
                    #right -> top
                    self.cursor.setPosition((layer, currPos[0]))

    def deleteBlock(self):
        self.grid[self.cursor.position[0] +
                  self.n][self.cursor.position[1]] = None

    def getVerticalMatches(self, minMatchLength):
        matchSet = set([])
        #check bottom -> top
        for col in range(self.n):
            matchStack = []
            #only check the bottom grid (n/2)
            for row in range(self.n - 1, self.n * 2, 1):
                cell = self.grid[row][col]
                if cell != None:
                    if len(matchStack) == 0 or cell.getColor() == self.grid[
                            matchStack[0][0]][matchStack[0][1]].getColor():
                        matchStack.append((row, col))
                    else:
                        if len(matchStack) >= minMatchLength:
                            for cell in matchStack:
                                matchSet.add(cell)
                        matchStack = [(row, col)]
                else:
                    if len(matchStack) >= minMatchLength:
                        for cell in matchStack:
                            matchSet.add(cell)
                    matchStack = []
            if len(matchStack) >= minMatchLength:
                for cell in matchStack:
                    matchSet.add(cell)
        return matchSet

    def getHorizontalMatches(self, minMatchLength):
        matchSet = set([])
        #check L -> R
        #only check the bottom grid (n/2)
        for rowIndex in range(self.n - 1, self.n * 2, 1):
            rowList = self.grid[rowIndex]
            matchStack = []
            for cellIndex, cell in enumerate(rowList):
                if cell != None:
                    if len(matchStack) == 0 or cell.getColor() == self.grid[
                            matchStack[0][0]][matchStack[0][1]].getColor():
                        matchStack.append((rowIndex, cellIndex))
                    else:
                        if len(matchStack) >= minMatchLength:
                            for cell in matchStack:
                                matchSet.add(cell)
                        matchStack = [(rowIndex, cellIndex)]
                else:
                    if len(matchStack) >= minMatchLength:
                        for cell in matchStack:
                            matchSet.add(cell)
                    matchStack = []
            if len(matchStack) >= minMatchLength:
                for cell in matchStack:
                    matchSet.add(cell)
        return matchSet

    def getMatches(self, minMatchLength):
        return self.getHorizontalMatches(minMatchLength).union(
            self.getVerticalMatches(minMatchLength))

    def removeMatches(self, matchList):
        for matchCell in matchList:
            self.grid[matchCell[0]][matchCell[1]] = None

    def moveCellsDown(self):
        colList = []
        for col in range(self.n):
            emptyStack = []
            toMove = []
            for row in range(self.n * 2 - 1, -1, -1):
                if self.grid[row][col] == None:
                    emptyStack.append((row, col))
                else:
                    if self.grid[row][col].getIsMoveable(
                    ) and len(emptyStack) > 0:
                        toMove.append(((row, col), emptyStack.pop(0)))
                        emptyStack.append((row, col))
                    if self.grid[row][col].getIsMoveable() == False:
                        emptyStack = []
            if len(toMove) > 0:
                colList.append(toMove)
        if len(colList) > 0:
            return colList
        return None

    def getEmptyCells(self):
        emptyCellList = []
        for col in range(self.n):
            for row in range(self.n, self.n * 2, 1):
                if self.grid[row][col] == None:
                    emptyCellList.append((row, col))
                else:
                    break
        return emptyCellList

    def spawnNewCells(self, emptyCells):
        for cell in emptyCells:
            self.grid[cell[0] - self.n][cell[1]] = self.blockFactory.build(
                (cell[1] * (cellWidth + padding),
                 (cell[0] - self.n) * (cellHeight + padding)))

    def scaleCells(self, cellList, factor):
        for index in cellList:
            self.grid[index[0]][index[1]].scale(factor)

    def rotateCells(self, cellList, factor):
        for index in cellList:
            self.grid[index[0]][index[1]].rotateInPlace(factor)

    def rotateGrid(self, factor):
        #t = (self.center[0] - 30, self.n*60 + int(self.n/2)*60)
        t = (self.center[0] - 5, self.center[1] - 5)
        for row in self.grid:
            for cell in row:
                if cell != None:
                    #cell.rotateInPlace(-factor)
                    cell.rotateAroundPoint(t, factor)
        self.cursor.poly.rotateAroundPoint(t, factor)

    def draw(self, screen, position, drawCursor=True):
        for row in range(self.n * 2):
            for col in range(self.n):
                if self.grid[row][col] != None:
                    self.grid[row][col].draw(screen, position)
        cursorX = self.cursor.position[1] * (cellWidth + padding) - (
            abs(cellWidth - self.cursor.width)) / 2
        cursorY = (self.cursor.position[0] + self.n) * (
            cellHeight + padding) - (abs(cellHeight - self.cursor.height)) / 2
        #print(position)
        if drawCursor:
            #self.cursor.draw(screen, (position[0] + cursorX, position[1] + cursorY))
            self.cursor.draw(screen, position)

    def __str__(self):
        outStr = ""
        for i in range(len(self.grid)):
            for cell in self.grid[i]:
                cellStr = str(cell)
                if cell == None:
                    cellStr = "0"
                for j in range(len(cellStr), 3):
                    cellStr += " "
                outStr += cellStr + " "
            outStr += "\n"
        return outStr
Example #30
0
    def main_game_loop(self):

        # Define the entity groups
        character_entities = pygame.sprite.Group()  # All character entities (including Player.py)
        built_entities = pygame.sprite.Group()  # Anything the player has built

        # Build the level
        level = Level()
        level.generate(self.tile_cache)

        # Create the player
        player_sprites = "data/images/player/"
        camera = Camera(main_camera, level.width * self.tile_size, level.height * self.tile_size,
                        self.window_width, self.window_height)
        self.player = Player(32, 32, player_sprites, self.tile_size, self.tile_size, 2, camera)
        character_entities.add(self.player)

        # Create cursor entity for better collisions
        cursor = Cursor()

        game_running = True

        up, down, left, right = 0, 0, 0, 0

        while game_running:

            # Reset game variables
            mouse_clicked = False

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    quit_game()

                # Key down events
                if event.type == pygame.KEYDOWN:

                    if event.key in (pygame.K_UP, pygame.K_w):
                        up = 1
                    if event.key in (pygame.K_DOWN, pygame.K_s):
                        down = 1
                    if event.key in (pygame.K_LEFT, pygame.K_a):
                        left = 1
                    if event.key in (pygame.K_RIGHT, pygame.K_d):
                        right = 1

                # Key up events
                if event.type == pygame.KEYUP:

                    if event.key in (pygame.K_UP, pygame.K_w):
                        up = 0
                    if event.key in (pygame.K_DOWN, pygame.K_s):
                        down = 0
                    if event.key in (pygame.K_LEFT, pygame.K_a):
                        left = 0
                    if event.key in (pygame.K_RIGHT, pygame.K_d):
                        right = 0

            cursor.update()

            for tile in level.terrain:
                self.screen.blit(tile.image, self.player.camera.apply(tile))

            for tile in level.obstacles:
                self.screen.blit(tile.image, self.player.camera.apply(tile))

            for character in character_entities:
                self.screen.blit(character.image, self.player.camera.apply(character))

            self.player.update(up, down, left, right, level.obstacles)

            pygame.display.flip()

        self.main_menu_loop()
Example #31
0
run = 1

fd_gr = pg.sprite.Group()
crtb_gr = pg.sprite.Group()
crts_gr = pg.sprite.Group()
deadb_gr = pg.sprite.Group()
deads_gr = pg.sprite.Group()
curs_gr = pg.sprite.Group()
btn_gr = pg.sprite.Group()

vis_gr = []
crt_mas = [Creature(WCR, HCR, SENS) for i in range(count_crt)]
fd_mas = [Food() for i in range(COUNT_FD)]
curs_mas = [
    Cursor(10, 160 + 80 * i, [COUNT_FD / 2000, SPEED, SP_GEN_FD][i])
    for i in range(3)
]

for i in range(count_crt):
    crtb_gr.add(crt_mas[i].body)
    crts_gr.add(crt_mas[i].sens_circ)

for i in range(COUNT_FD):
    fd_gr.add(fd_mas[i])

for i in range(3):
    curs_gr.add(curs_mas[i])

for i in range(len(btn_mas)):
    btn_gr.add(btn_mas[i])
Example #32
0
class ListaDE:
    def __init__(self):
        self.__cursor = Cursor()
        self.__limite = 10
        self.__elementos = 0

    def elementos(self):
        return self.__elementos

    def acessarAtual(self):
        return self.__cursor.atual

    def inserirAntesAtual(self, valor):
        novo = Nodo(valor)

        if self.cheia():
            print('Lista Cheia.')
        elif self.vazia():
            self.__cursor.atual = novo
            self.__elementos += 1
        elif self.__cursor.atual.ant is None:
            self.__cursor.atual.ant = novo
            novo.prox = self.__cursor.atual
            self.__elementos += 1
        else:
            self.__cursor.atual.ant.prox = novo
            novo.ant = self.__cursor.atual.ant
            self.__cursor.atual.ant = novo
            novo.prox = self.__cursor.atual
            self.__elementos += 1

    def inserirPosAtual(self, valor):
        novo = Nodo(valor)

        if self.cheia():
            print('Lista Cheia.')
        elif self.vazia():
            self.__cursor.atual = novo
            self.__elementos += 1
        elif self.__cursor.atual.prox is None:
            self.__cursor.atual.prox = novo
            novo.ant = self.__cursor.atual
            self.__elementos += 1
        else:
            self.__cursor.atual.prox.ant = novo
            novo.prox = self.__cursor.atual.prox
            self.__cursor.atual.prox = novo
            novo.ant = self.__cursor.atual
            self.__elementos += 1

    def inserirFim(self, valor):
        if self.vazia():
            novo = Nodo(valor)
            self.__cursor.atual = novo
            self.__elementos += 1
        else:
            self.__cursor.irParaUltimo()
            self.inserirPosAtual(valor)

    def inserirFrente(self, valor):
        if self.vazia():
            novo = Nodo(valor)
            self.__cursor.atual = novo
            self.__elementos += 1
        else:
            self.__cursor.irParaPrimeiro()
            self.inserirAntesAtual(valor)

    def inserirNaPosicao(self, k, valor):
        self.__cursor.irParaPrimeiro()

        if self.cheia():
            print('Lista Cheia.')
        elif k > self.__elementos or k < 0:
            print('Posicao inexistente.')
        else:
            self.__cursor.avancarKPosicoes(k - 1)
            self.inserirAntesAtual(valor)

    def excluirAtual(self):
        if self.vazia():
            print('Lista vazia.')
        elif self.__cursor.atual.ant is None and self.__cursor.atual.prox is None:
            self.__cursor.atual.prox = None
            self.__cursor.atual.ant = None
            self.__cursor.atual = None
            self.__elementos -= 1
        elif self.__cursor.atual.ant is None:
            self.__cursor.atual.prox.ant = None
            self.__cursor.atual = self.__cursor.atual.prox
            self.__elementos -= 1
        elif self.__cursor.atual.prox is None:
            self.__cursor.atual.ant.prox = None
            self.__cursor.atual = self.__cursor.atual.ant
            self.__elementos -= 1
        else:
            self.__cursor.atual.ant.prox = self.__cursor.atual.prox
            self.__cursor.atual.prox.ant = self.__cursor.atual.ant
            self.__cursor.atual = self.__cursor.atual.prox
            self.__elementos -= 1

    def excluirPrim(self):
        self.__cursor.irParaPrimeiro()
        self.excluirAtual()

    def excluirUlt(self):
        self.__cursor.irParaUltimo()
        self.excluirAtual()

    def excluirElem(self, valor):
        self.Buscar(valor)
        self.excluirAtual()
        print(f'Elemento {valor}, excluido')

    def excluirDaPos(self, k):
        self.__cursor.irParaPrimeiro()
        k -= 1
        if self.vazia():
            print('Lista Vazia.')
        elif k > self.__elementos or k < 0:
            print('Posicao inexistente.')
        else:
            self.__cursor.avancarKPosicoes(k)
            self.excluirAtual()

    def vazia(self):
        return self.__elementos == 0

    def cheia(self):
        return self.__elementos == self.__limite

    def contem(self, valor):
        self.Buscar(valor)

    def posicaoDe(self, valor):
        if self.vazia():
            print('Lista Vazia')
        else:
            self.__cursor.irParaPrimeiro()
            x = self.__cursor.atual
            posicao = 1

            while x.valor != valor:
                if self.__cursor.atual.prox is None:
                    print('Elemento Inexistente')
                    return None
                else:
                    self.__cursor.avancarKPosicoes(1)
                    x = self.__cursor.atual
                    posicao += 1
            print(posicao)
            return posicao

    def Buscar(self, valor):
        self.__cursor.irParaPrimeiro()
        x = self.__cursor.atual

        while x.valor != valor:
            if self.__cursor.atual.prox is None:
                print('False, Elemento Inexistente')
                return False
            else:
                self.__cursor.avancarKPosicoes(1)
                x = self.__cursor.atual
        print('True, Elemento existe')
        return True
class WorldMapBackground(object):
    def __init__(self, sprite, labels=True):
        self.x = 0
        self.y = 0
        self.sprite = sprite

        # for easing
        self.easing_flag = False
        self.target_x = 0
        self.target_y = 0
        self.old_x = 0
        self.old_y = 0
        self.start_time = 0

        # Dictionary of world map sprites
        self.wm_sprites = {}

        # Labels for world map
        self.wm_labels = []
        if labels:
            self.parse_labels('Data/world_map_labels.txt')

        # Highlights
        self.wm_highlights = []

        # Cursor
        self.cursor = None

    def parse_labels(self, fp):
        with open(fp, 'r') as label_data:
            for line in label_data:
                split_line = line.strip().split(';')
                coord = (int(split_line[1]), int(split_line[2]))
                if split_line[3] == '1':
                    font = GC.FONT['chapter_yellow']
                else:
                    font = GC.FONT['chapter_green']
                self.add_label(split_line[0], coord, font)

    def add_label(self, name, position, font=GC.FONT['chapter_yellow']):
        self.wm_labels.append(WMLabel(name, position, font))

    def clear_labels(self):
        self.wm_labels = []

    def add_highlight(self, sprite, position):
        self.wm_highlights.append(WMHighlight(sprite, position))

    def clear_highlights(self):
        for highlight in self.wm_highlights:
            highlight.remove()

    def add_sprite(self, name, klass, gender, team, position):
        # Key is string assigned by user. Value is units class, gender, team, starting_position
        self.wm_sprites[name] = WMSprite(klass, gender, team, position)

    def remove_sprite(self, name):
        del self.wm_sprites[name]

    def move_sprite(self, name, new_pos):
        if name in self.wm_sprites:
            self.wm_sprites[name].move(new_pos)
        elif cf.OPTIONS['debug']:
            print('Error! ', name, ' not in self.wm_sprites')

    def quick_move(self, new_pos):
        self.x += new_pos[0]
        self.y += new_pos[1]

        self.x, self.y = self.bound(self.x, self.y)

    def move(self, new_pos):
        self.old_x = self.x
        self.old_y = self.y
        self.target_x = self.x + new_pos[0]
        self.target_y = self.y + new_pos[1]
        self.start_time = Engine.get_time()
        self.easing_flag = True

        self.target_x, self.target_y = self.bound(self.target_x, self.target_y)

    def bound(self, x, y):
        x = Utility.clamp(x, 0, self.sprite.get_width() - GC.WINWIDTH)
        y = Utility.clamp(y, 0, self.sprite.get_height() - GC.WINHEIGHT)
        return x, y

    def create_cursor(self, coord):
        from Cursor import Cursor
        self.cursor = Cursor('Cursor', coord, fake=True)

    def remove_cursor(self):
        self.cursor = None

    def draw(self, surf):
        # === UPDATE ===
        # Handle easing
        current_time = Engine.get_time()
        if self.easing_flag:
            self.x = Utility.easing(current_time - self.start_time, self.old_x,
                                    self.target_x - self.old_x, 400)
            self.y = Utility.easing(current_time - self.start_time, self.old_y,
                                    self.target_y - self.old_y, 400)
            if self.target_x > self.old_x and self.x >= self.target_x or \
               self.target_x < self.old_x and self.x <= self.target_x or \
               self.target_y > self.old_y and self.y >= self.target_y or \
               self.target_y < self.old_y and self.y <= self.target_y:
                self.easing_flag = False
                self.x = self.target_x
                self.y = self.target_y

        # === DRAW ===
        image = Engine.copy_surface(self.sprite)
        # Highlights
        for highlight in self.wm_highlights:
            highlight.draw(image)
        self.wm_highlights = [
            highlight for highlight in self.wm_highlights
            if not highlight.remove_clear
        ]
        # Draw label
        for label in self.wm_labels:
            label.draw(image)
        # Update world_map_sprites
        for key, wm_unit in self.wm_sprites.items():
            wm_unit.update()
        # World map sprites
        for key, wm_unit in self.wm_sprites.items():
            wm_unit.draw(image)
        # Cursor
        if self.cursor:
            self.cursor.image = Engine.subsurface(
                self.cursor.passivesprite,
                (GC.CURSORSPRITECOUNTER.count * GC.TILEWIDTH * 2, 0,
                 GC.TILEWIDTH * 2, GC.TILEHEIGHT * 2))
            self.cursor.draw(image)

        image = Engine.subsurface(image,
                                  (self.x, self.y, GC.WINWIDTH, GC.WINHEIGHT))
        surf.blit(image, (0, 0))
Example #34
0
class TextInput():
    def __init__(self, screen, pos, size, font, **kwargs):
        self.screen = screen
        self.pos = pos
        self.size = size
        self.rect = Rect(self.pos, self.size)
        self.font = font
        self.font_height = self.font.get_height()
        self.command = kwargs.get("command", None)
        self.maxlines = kwargs.get("maxlines", -1)
        self.maxlinelength = kwargs.get("maxlinelength", -1)
        self.focused = False
        self.highlighted = False
        self.cursor = Cursor("|", 700, 500, self.pos)
        self.text = SelectableText(self.screen, "", self.font, self.pos, textwrap=kwargs.get("textwrap", False), maxlinelength=kwargs.get("maxlinelength", -1))
        self.update_text("")
        pygame.key.set_repeat(500, 20)
    def update_text(self, text):
        self.text.change_text(text)
    def get_text(self):
        return self.text.text.get_text()
    def update(self, event):
        significant_event = False
        mouse_pos = pygame.mouse.get_pos()
        if event.type == MOUSEBUTTONDOWN and event.button == 1 and self.rect.collidepoint(mouse_pos):
            self.focused = True
            self.cursor.start()
        elif event.type == MOUSEBUTTONDOWN and event.button == 1 and not self.rect.collidepoint(mouse_pos):
            self.focused = False
            self.cursor.stop()
        elif event.type == MOUSEMOTION:
            if self.rect.collidepoint(mouse_pos):
                self.highlighted = True
            else:
                self.highlighted = False
        elif event.type == KEYDOWN and self.focused:
            mod = event.mod
            mods = pygame.key.get_mods()
            significant_event = True
            if event.key == K_BACKSPACE:
                if self.text.get_selected_text() != None:
                    points = self.text.get_ordered_points()
                    self.cursor.x, self.cursor.y = points[0]
                    self.text.removeslice(points)
                else:
                    if self.cursor.x > 0:
                        self.text.remove([self.cursor.x - 1, self.cursor.y])
                        self.cursor.x -= 1
                    else:
                        if self.cursor.y > 0:
                            self.cursor.x = len(self.text.lines[self.cursor.y - 1])
                            self.text.remove([-1, self.cursor.y])
                            self.cursor.y -= 1
            elif event.key == K_DELETE:
                if self.text.get_selected_text() != None:
                    points = self.text.get_ordered_points()
                    self.cursor.x, self.cursor.y = points[0]
                    self.text.removeslice(points)
                else:
                    self.text.remove((self.cursor.x, self.cursor.y))
            elif event.key == K_RETURN:
                self.text.insertline((self.cursor.x, self.cursor.y))
                self.cursor.y += 1
                self.cursor.x = 0
                #if self.command != None:
                #    self.command()
            elif event.key == K_LEFT:
                if self.cursor.x > 0:
                    self.cursor.x -= 1
                else:
                    if self.cursor.y > 0:
                        self.cursor.y -= 1
                        self.cursor.x = len(self.text.lines[self.cursor.y])
            elif event.key == K_RIGHT:
                if self.cursor.x < len(self.text.lines[self.cursor.y]):
                    self.cursor.x += 1
                else:
                    if self.cursor.y < len(self.text.lines) - 1:
                        self.cursor.y += 1
                        self.cursor.x = 0
            elif event.key == K_UP:
                self.cursor.move_up(self.text.size_list)
                if self.cursor.x > len(self.text.lines[self.cursor.y]):
                    self.cursor.x = len(self.text.lines[self.cursor.y]) - 1
            elif event.key == K_DOWN:
                self.cursor.move_down(self.text.size_list)
                if self.cursor.x > len(self.text.lines[self.cursor.y]):
                    self.cursor.x = len(self.text.lines[self.cursor.y]) -1
            else:
                if event.unicode != "" and mods in [0, 1, 2, 4096, 8192, 4097, 4098, 8193, 8194]:
                    if self.text.get_selected_text() != None:
                        self.text.replaceslice(self.text.get_ordered_points(), event.unicode)
                        self.cursor.x = self.text.get_ordered_points()[0][0] + 1
                        self.cursor.y = self.text.get_ordered_points()[0][1]
                    else:
                        self.text.insert((self.cursor.x, self.cursor.y), event.unicode)
                        self.cursor.x += 1
            if mods == 0:
                self.text.selectnone()
        if significant_event:
            self.cursor.event()
        self.change_color()
        self.text.update(event)
    def change_color(self):
        if self.highlighted:
            self.color = (0, 0, 200)
        elif self.focused:
            self.color = (0, 0, 150)
        else:
            self.color = (0, 0, 100)
    def draw(self):
        self.cursor.x, self.cursor.y = self.text.wrap([self.cursor.x, self.cursor.y])
        self.cursor.update()
        if self.cursor.visible:
            if self.text.get_selected_text() != None:
                self.cursor.x = self.text.x2
                self.cursor.y = self.text.y2
            self.cursor.calc_pixel_pos(self.text.size_list, self.font.get_height())
            self.screen.blit(self.font.render(self.cursor.string, 1, (255, 255, 255)), (self.cursor.pixelx, self.cursor.pixely))

        pygame.draw.rect(self.screen, self.color, self.rect, 2)
        self.text.draw()
Example #35
0
class Menu(object):
    """docstring for Menu"""
    def __init__(self):

        self.pantalla = pygame.display.set_mode((600, 704))
        self.fondo1 = fondo("Fondo.jpg")
        self.logo = pygame.sprite.Sprite()
        self.footPage = pygame.image.load("macro.png").convert_alpha()
        self.Cursor = Cursor()
        self.boton1 = Boton("boton3.png", "boton4.png")
        self.boton2 = Boton("boton5.png", "boton6.png", 300, 350)
        self.boton3 = Boton("boton7.png", "boton8.png", 300, 450)
        self.boton4 = Boton("boton1.png", "boton2.png", 500, 600)
        self.logo = pygame.sprite.Sprite()
        self.logo = pygame.image.load("LogoGame2.png").convert_alpha()
        self.visibilidad = True
        #self.lista_menu = pygame.sprite.Group()
        self.Dibujar_Menu()

    def ocultarComponentes(self):
        self.visibilidad = False

    def Mostrar_Opciones(self):

        #self.Cursor.update()
        if self.boton1.Colision_Cursor(self.pantalla, self.Cursor):
            if self.boton1.MouseEvento():
                self.Iniciar_Juego()

        if self.boton2.Colision_Cursor(self.pantalla, self.Cursor):
            if self.boton2.MouseEvento():
                self.ocultarComponentes()

        if self.boton3.Colision_Cursor(self.pantalla, self.Cursor):
            if self.boton3.MouseEvento():
                self.Salir()

        self.boton1.dibujar(self.pantalla)
        self.boton2.dibujar(self.pantalla)
        self.boton3.dibujar(self.pantalla)

    def Iniciar_Juego(self):
        nivel1.nivel1()

    def Mostrar_Puntajes(self):
        pass

    def Salir(self):
        pygame.quit()

    def Acciones(self):
        pass

    def Dibujar_Menu(self):
        #pygame.mixer.pre_init(44100, -16, 1, 512)
        pygame.mixer.pre_init(44100, -16, 1, 512)
        pygame.init()
        salir = False

        pygame.mixer.music.load("OST/mainTheme3.mp3")
        pygame.mixer.music.play()
        reloj1 = pygame.time.Clock()
        while salir != True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    salir = True

            reloj1.tick(30)

            self.Cursor.update()
            self.fondo1.update(self.pantalla, False)
            if self.visibilidad:
                self.pantalla.blit(self.logo, (90, 100))
                self.pantalla.blit(self.footPage, (125, 650))
                self.Mostrar_Opciones()
            else:
                self.boton4.dibujar(self.pantalla)
            if self.boton4.Colision_Cursor(
                    self.pantalla, self.Cursor) and self.boton4.MouseEvento():
                self.visibilidad = True
            pygame.display.flip()

        pygame.quit()
Example #36
0
File: Cover.py Project: mdrom/PyAML
if (__name__ == '__main__'):
   import sys
   import EditSession
   file = string.lower(tempcov()) + '.aml'

   f = Cover('i5308fm',file)
   w = Cover('i5308wm',file)
   fjunc = f.reselect('arc',"feat_code = 'junction'")
   wjunc = w.reselect('arc',"lpoly# = 1 | rpoly# = 1")
   wjunc2 = wjunc.reselect('arc',"feat_code = 'junction'")
   fjbuf = fjunc.buffer(1,'line')
   wjbuf = wjunc2.buffer(1,'line')
   wfunion = fjbuf.union(wjbuf)
   wfunion.addxy()

   cur = Cursor(wfunion,'polygon','ro','%s-id = 0 & area > 0'% fjbuf.name)
   proc = '''
          &ty
          &ty Waterbody junction does not have corresponding framework junction
          &ty at [truncate %s],[truncate %s]
          &ty
          ''' % (cur.getitem('x-coord'),cur.getitem('y-coord'))

   cur.iterate(proc)
   cur.remove()

   cur = Cursor(wfunion,'polygon','ro','%s-id = 0 & area > 0' % wjbuf.name)
   proc = '''
          &ty
          &ty Framework junction does not have corresponding waterbody junction
          &ty at [truncate %s],[truncate %s]
Example #37
0
class Game(arcade.Window):
    def __init__(self):
        super().__init__(WIDTH, HEIGHT, NAME)

        arcade.set_background_color(arcade.color.WHITE)

        self.SERVER = socket.gethostbyname(socket.gethostname())
        self.PORT = 5050
        self.ADDR = (self.SERVER, self.PORT)
        self.FORMAT = 'utf-8'

        try:
            self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.client.setblocking(1)
            self.client.connect(self.ADDR)
        except:
            pass

        self.board_draw = Board()
        self.board = {
            '7': ' ',
            '8': ' ',
            '9': ' ',
            '4': ' ',
            '5': ' ',
            '6': ' ',
            '1': ' ',
            '2': ' ',
            '3': ' '
        }

        self.button_list = []
        self.popup_list = []
        self.cursor = Cursor()

        self.client_ID = None

        self.my_turn = False
        self.game_over = False

        #SERVER REQUEST BOOLS
        self.board_request = False
        self.ID_request = False

        self.player_2 = False
        self.request_reset = False
        self.reset_state = False
        self.clear_state = False

        self.winner = None

        self.popup = Popup(WIDTH / 2, HEIGHT / 2 - HEIGHT / 4, 1)
        self.game_over_popup = Popup(WIDTH / 2, HEIGHT / 2 - HEIGHT / 4, 2)
        self.restart_popup = Popup(WIDTH / 2, HEIGHT / 2 - HEIGHT / 2.5, 3)
        self.popup_list.append(self.restart_popup)

        for x in range(1, 10):
            button = Button(x)
            self.button_list.append(button)

    def col_circle_square(self, tx, ty, tr, cx, cy, cr):
        dx = tx - cx
        dy = ty - cy
        distance = math.sqrt(dx * dx + dy * dy)

        if distance < tr + cr:
            return True

    def detect_collision(self, rect1, rect2):
        if (rect1[0] < rect2[0] + rect2[2] and rect1[0] + rect1[2] > rect2[0]
                and rect1[1] < rect2[1] + rect2[3]
                and rect1[1] + rect1[3] > rect2[1]):
            return True

    def decode_board(self, msg):
        utf_json = msg.decode(self.FORMAT)
        json_list = json.loads(utf_json)
        return json_list

    def clear_board(self):
        for x in self.board:
            if self.board[str(x)] == 'X' or self.board[str(x)] == 'O':
                self.board[str(x)] = " "

    def clear_game(self):
        try:
            if self.clear_state:
                msg = '!c'
                self.client.send(msg.encode(self.FORMAT))

                reply = self.client.recv(16)
                reply_decode = reply.decode(self.FORMAT)

                if reply_decode == '!r':
                    self.clear_board()
                    self.game_over = False
                    self.clear_state = False
                    if self.client_ID == 2:
                        self.my_turn = False

        except Exception as e:
            print(e)

    def check_win(self):
        print('2')
        try:
            if not self.clear_state:
                msg = '!w'
                self.client.send(msg.encode(self.FORMAT))
                reply = self.client.recv(128)
                reply_decode = reply.decode(self.FORMAT)

                if reply_decode == 'X':
                    self.winner = 'X'
                    self.game_over = True
                elif reply_decode == 'O':
                    self.winner = 'O'
                    self.game_over = True
                elif reply_decode == '!p':
                    self.game_over = False
                elif reply_decode == '!o':
                    self.game_over = True

        except Exception as e:
            print(e)

    def player_2_connected(self):
        try:
            if self.client_ID == 1:
                if not self.player_2:
                    msg = '!p'
                    self.client.send(msg.encode(self.FORMAT))

                    reply = self.client.recv(2)
                    if reply.decode(self.FORMAT) == '!t':
                        self.player_2 = True
                    else:
                        self.player_2 = False
            elif self.client_ID == 2:
                self.player_2 = True

        except Exception as e:
            print(e)

    def send_board_request(self):
        print('4')
        try:
            if not self.board_request:
                msg = '!board'
                request = msg.encode(self.FORMAT)
                self.client.send(request)

                new_msg = self.client.recv(92)
                utf_string = new_msg.decode(self.FORMAT)
                json_list = json.loads(utf_string)

                self.board = json_list[0]
                self.board_request = True

        except:
            traceback.print_exc()

    def send_ID_request(self):
        try:
            if not self.client_ID:
                msg = '!ID'
                request = msg.encode(self.FORMAT)
                self.client.send(request)

                new_msg = self.client.recv(6)
                message = new_msg.decode(self.FORMAT)
                self.client_ID = int(message)

        except Exception as e:
            pass

    def request_turn(self):
        print('6')
        try:
            if not self.my_turn:
                if self.client_ID:
                    if self.client_ID == 1:
                        msg = '!t1'
                    else:
                        msg = '!t2'

                    self.client.send(msg.encode(self.FORMAT))
                    reply = self.client.recv(2)
                    decoded_reply = reply.decode(self.FORMAT)

                    if decoded_reply == '!t':
                        self.my_turn = True
                        self.board_request = False
                    else:
                        self.my_turn = False

                    self.check_win()

        except Exception as e:
            print(e)

    def on_draw(self):
        arcade.start_render()

        self.board_draw.draw()

        for button in self.button_list:
            button.draw()

        self.cursor.draw()

        if self.client_ID == 1:
            if not self.my_turn or not self.player_2:
                if not self.game_over:
                    self.popup.draw()
        elif self.client_ID == 2:
            if not self.my_turn:
                if not self.game_over:
                    self.popup.draw()

        if self.game_over:
            self.game_over_popup.draw()
            self.restart_popup.draw()

        arcade.finish_render()

    def update(self, delta_time: float):
        self.cursor.update(self._mouse_x, self._mouse_y)

        self.player_2_connected()
        self.send_ID_request()

        if not self.clear_state:
            self.request_turn()
            self.send_board_request()
        elif self.clear_state:
            self.clear_game()

        for button in self.button_list:
            button.update(self.board)

        self.restart_popup.update(self.cursor)

    def on_mouse_press(self, x: float, y: float, button: int, modifiers: int):
        if self.my_turn and not self.game_over:
            if self.player_2:
                if button == 1:
                    c = self.cursor
                    for button in self.button_list:
                        if button.value == button.B:
                            if self.col_circle_square(button.x, button.y,
                                                      button.r, c.x, c.y, c.r):
                                col_list = []
                                col_list.append(button)
                                if (len(col_list) > 1):
                                    col_list.RemoveRange(
                                        0,
                                        col_list.count() - 1)

                                com = '!sub'
                                com_encode = com.encode(self.FORMAT)
                                self.client.send(com_encode)
                                msg = str(col_list[0].ID)
                                self.client.send(msg.encode(self.FORMAT))
                                col_list.clear()
                                self.my_turn = False
                                self.board_request = False
        elif self.game_over:
            if self.restart_popup.colliding:
                self.clear_state = True

    def on_mouse_drag(self, x: float, y: float, dx: float, dy: float,
                      buttons: int, modifiers: int):
        pass
        '''for button in self.button_list:
            if button.dragging:
                button.x, button.y = self.cursor.x, self.cursor.y'''

    def on_mouse_release(self, x: float, y: float, button: int,
                         modifiers: int):
        pass
        '''for button in self.button_list: