Esempio n. 1
0
def init_entities(num_obstacles, num_rocks, num_explorers, num_carriers, is_collab):
    world = World(500, 500, num_rocks, is_collab)

    mars_base = MarsBase(world.width, world.height)
    world.add_entity(mars_base)

    for _ in range(num_explorers):
        explorer = Explorer(mars_base.x + mars_base.SIZE,
                            mars_base.y + mars_base.SIZE,
                            world)
        world.add_entity(explorer)

    for _ in range(num_carriers):
        carrier = Carrier(mars_base.x + mars_base.SIZE,
                          mars_base.y + mars_base.SIZE,
                          world)
        world.add_entity(carrier)

    obstacles = Obstacle.generate_many(num_obstacles, world)
    for obstacle in obstacles:
        world.add_entity(obstacle)

    rocks = Rock.generate_many(num_rocks, world)
    for rock in rocks:
        world.add_entity(rock)

    return world
Esempio n. 2
0
    def __init__(self, width=400, height=400, snake_value=1, food_value=2):

        os.environ['SDL_VIDEO_CENTERED'] = "1"

        #World attributes
        self.basic_pixel_unit = 20
        self.width = int(width - (width % self.basic_pixel_unit))
        self.height = int(height - (height % self.basic_pixel_unit))
        self.background = (236, 240, 241)
        self.world_width = self.width / self.basic_pixel_unit
        self.world_height = self.height / self.basic_pixel_unit
        self.snake_body_unit_size = self.basic_pixel_unit
        self.snake_body_color = (52, 73, 94)
        self.snake_value = snake_value
        self.food_value = food_value
        self.food_color = (22, 160, 133)
        self.counter = 0

        self.screen = pygame.display.set_mode((self.width, self.height))
        pygame.display.set_caption("Snake")
        pygame.init()  #The main pygame init

        #Game attributes
        self.restart_key = "SPACE"
        self.game_frames = 6
        self.ui_frames = 60
        self.frames_per_action_render = int(self.ui_frames / self.game_frames)
        self.win = False
        self.h1_font = pygame.font.Font(self.fonts("Blinker-Regular.ttf"), 35)
        self.h2_font = pygame.font.Font(self.fonts("Blinker-Regular.ttf"), 20)
        self.win_text = "¡Congratulations!, you won"
        self.win_surface = self.h1_font.render(self.win_text, True,
                                               (110, 193, 229))

        self.dead_text = "You died :("
        self.dead_surface = self.h1_font.render(self.dead_text, True,
                                                (228, 82, 50))

        self.restart_text = f"Press [{self.restart_key}] to restart"
        self.restart_surface = self.h2_font.render(self.restart_text, True,
                                                   (0, 0, 0))

        self.game_text_margins = 10

        #World objects
        self.world = World(int(self.world_width), int(self.world_height))
        self.snake = Snake()
        self.food = Food(self.world_width, self.world_height)
        self.food.generate_food(self.snake.body)

        self.alive = True

        self.main_thread()
Esempio n. 3
0
 def build(self):
     world = World(CONFIG)
     Clock.schedule_interval(world.tick, CONFIG['world']['tick_interval'])
     renderer = WorldRenderer(world)
     Clock.schedule_interval(renderer.update, CONFIG['renderer']['update_interval'])
     return renderer