Exemplo n.º 1
0
                # if yes, add new building to entity manager and set build mode on
                if bar.check_build(mousePosition) == 'barn':
                    EM.create_building(game_objects.Barn((600, 500), 2))
                    active_build = EM.buildings[-1]
                    active_build.set_build_mode(True)


                # if active build is in progress and offset time elapsed, place building on keypress
                if active_build and active_build.is_build_mode():
                    if build_time_offset > (Constants.FRAMERATE / 3):
                        active_build.build(mousePosition)
                        nd = MG.get_row_column_by_pixel_coords(mousePosition)
                        nodes_to_close = [nd, (nd[0] + 1, nd[1]), (nd[0], nd[1] + 1), (nd[0] + 1, nd[1] + 1)]
                        print("closing ", nodes_to_close)
                        for node in nodes_to_close:
                            MG.close_square(node)
                        build_time_offset = 0



            # LEFT CLICK RELEASE
            if event.type == pygame.MOUSEBUTTONUP and event.button == pygame.BUTTON_LEFT:

                # Movement Grid
                # MG.select_square(MG.get_row_column_by_pixel_coords(mousePosition))
                # MG.deselect_square()

                # Selection drawing
                draw_selection = False
                drawn_selections.append(selection)
                selection = None
Exemplo n.º 2
0
 def test_close_square(self):
     mg = MovementGrid(10, 10, 5)
     mg.close_square((1, 0))
     self.assertIn((1, 0), mg.closed_list)