Esempio n. 1
0
    def __init__(self, config, loader, spritesheet_loader, view, sounds,
                 explosions):
        self.config = config
        self.loader = loader
        self.spritesheet_loader = spritesheet_loader
        self.player = None
        self.map = None
        self.zone = None
        self.tiles = {}
        self.zones = {}
        self.ladders = {}
        self.platforms = {}
        self.hazards = {}
        self.items = None
        self.gates = None
        self.enemies = None
        self.explosions = explosions
        self.tile_sprite_group = sprite.Group()
        self.enemy_sprite_group = sprite.Group()
        self.map_size = None
        self.sounds = sounds
        self.music_track = None
        self.start_zone = None
        self.view = view

        self.warp_start_position = Vector2(0, 0)
        self.warp_land_position = Vector2(0, 0)

        self.debug = self.config.get_debug()

        self.load_map()
Esempio n. 2
0
    def init_level(self):
        self.wallsGroup = sprite.Group()
        self.playerGroup = sprite.Group()
        self.foodGroup = sprite.Group()
        self.entities = sprite.LayeredUpdates()

        time.set_timer(FOOD_SPAWN_EVENT, FOOD_SPAWN_TIME)
        self.load_level_file(self.lvl_list[self.current_level %
                                           len(self.lvl_list)])

        self.buildLevel(self.level)
        self.player = Dizzy(self.startx + 7 * self.game.block_size,
                            self.starty + (9 - 1) * self.game.block_size,
                            game=self.game,
                            shape='dizzy')
        self.entities.add(self.player, layer=self.LAYER_PLAYER)
        self.playerGroup.add(self.player)
        self.player2 = Dizzy(self.startx + 5 * self.game.block_size,
                             self.starty + (9 - 1) * self.game.block_size,
                             game=self.game,
                             shape='pacman')
        self.entities.add(self.player2, layer=self.LAYER_PLAYER)
        self.playerGroup.add(self.player2)

        for i in range(3):
            self.spawn_food()
Esempio n. 3
0
    def __init__(self):
        self.width = 640
        self.height = 480
        pygame.time.set_timer(TIMER_EVENT, 25)
        self.screen_lock = thread.allocate()
        self.last_kinect_event = time.clock()
        self.screen = pygame.display.set_mode((self.width, self.height), 0, 32)

        self.dispInfo = pygame.display.Info()
        self.screen.convert()
        pygame.display.set_caption('Python Kinect Game')
        self.screen.fill(THECOLORS["black"])

        self.background = pygame.Surface((self.width, self.height), 0, 32)
        self.background.fill(THECOLORS["black"])
        self.background.convert()

        self.video_screen = pygame.SurfaceType((self.width, self.height), 0,
                                               32)

        self.ball_group = sprite.Group(
            Ball(self, 'white', direction=math.atan2(.5, 1), x=30, y=410),
            Ball(self, 'white', direction=math.atan2(0, -1), x=600, y=400),
            Ball(self, 'white', direction=math.atan2(0, -1), x=30, y=240),
            Ball(self, 'white', direction=math.atan2(1, -1.1), x=10, y=140),
        )
        self.known_players = {}

        self.score_font = pygame.font.SysFont('Segoe UI', 20, bold=True)

        self.pieces_group = sprite.Group()

        self.left_margin = (self.width / 5)
        self.top_margin = (self.height / 5)
        self.blocks_across = 10
        self.blocks_down = 10
        width = ((self.width - self.left_margin) / self.blocks_across) - 5
        height = ((self.height - self.top_margin) / self.blocks_down) - 5
        for y in xrange(self.blocks_down):
            for x in xrange(self.blocks_across):
                if x not in (3, 4, 5, 6) or not y in (4, 5):
                    x_loc = ((self.width - self.left_margin) /
                             self.blocks_across) * x + (self.left_margin / 2)
                    y_loc = ((self.height - self.top_margin) /
                             self.blocks_down) * y + (self.top_margin / 2)

                    bp = BoardPiece(x_loc, y_loc, width, height)
                    bp.add(self.pieces_group)

        self.bumper_group = sprite.Group()

        self.kinect = nui.Runtime()
        self.kinect.skeleton_engine.enabled = True
        self.kinect.skeleton_frame_ready += post_frame
        self.kinect.video_frame_ready += self.video_frame_ready
        self.kinect.video_stream.open(nui.ImageStreamType.Video, 2,
                                      nui.ImageResolution.Resolution640x480,
                                      nui.ImageType.Color)
Esempio n. 4
0
    def __init__(self, mapfile, lvl):
        # load the grass images into an array
        TILES_LOADED = False

        if not TILES_LOADED:
            Map.GRASS_ARRAY = self.load_grass_tiles(lvl)
            TILES_LOADED = True

        # (prepare to read mapfile)#######
        self.map = self.get_map(mapfile)
        # size of an individual block in the grid
        self.grid_size = [50, 50]
        self.grid_dimensions = self.get_dimensions(self.map)
        self.pix_dimensions = [
            self.grid_dimensions[0] * self.grid_size[0],
            self.grid_dimensions[1] * self.grid_size[1]
        ]
        self.surface = PG.Surface(self.pix_dimensions)
        self.object_group = PG.sprite.Group()

        self.grass_array = Map.GRASS_ARRAY
        self.pad_array = Map.PAD_ARRAY
        # list that stores a pair of coordinates for each grass
        # tile that needs to be drawn
        self.grasstiles = []
        self.grass_type = []
        self.padtiles = []
        self.pad_type = []  # hot or cold (and/or others)
        self.allPads = PS.Group()
        # block arrays
        self.wallBlocksV = []  # vertical V
        self.wallBlocksH = []  # horizontal H
        self.wallBlocksE = []
        # edges/corners; correspond to index num (see load_blocks)
        self.doorBlocks = []  # D
        self.shrubBlocks = []  # S
        # tree top = T, tree bottom = Y
        # so it's like ty thank you isn't that cute
        self.treeBlocksT = []  # T
        self.treeBlocksB = []  # Y
        self.keyBlocks = []  # K
        self.ICBlock = []  # I (icecream spots)
        self.disappearing_blocks = PS.Group()

        # enemy stuff
        self.ic_coord = []  # icecream
        self.br_coord = []  # burger
        self.lr_coord = []  # lettuce
        self.cc_coord = []  # cupcake
        self.eg_coord = []  # egg

        self.spots_to_be_filled = []
        # create map from mapfile
        self.load_blocks(lvl)
        self.objectify_map()
        self.fill()
Esempio n. 5
0
    def __init__(self, interval, fps, num_enemies):
        self.interval = interval
        self.fps = fps
        self.num_enemies=num_enemies
    
        PG.init()
        self.screen = PD.set_mode((800, 600))
        self.screen_rect = self.screen.get_rect()
        self.screen.fill((255,255,255))
        PD.set_caption("Master Chef's wicked adventure with his ice cream buddies")
        
        #camera handling
        total_level_width  = 1600
        total_level_height = 1200
        #camera is the class, cam is our object
        self.cam = Camera(camera.complex_camera, total_level_width, total_level_height)
        #camera handling end
        
        self.fps = fps
        self.speed = 4*self.fps
        #sprite group containing all sprites
        self.all_sprites = PS.Group()

        #Initialize objects on screen----------------
        self.character = Player(self.speed)
        self.all_sprites.add(self.character)
        # bad = Enemy()
        #self.charrect = self.character.image_rect
        # badrect = bad.image.get_rect()

        #create enemy group 
        self.enemy_list = PS.Group()

        #add all the enemies to the list of enemies
        for e in range(num_enemies):  
            enemy = Enemy(self.screen, self.speed)
            self.enemy_list.add(enemy)
            # self.all_sprites.add(enemy)

        #get block sprite group from the map file
        self.block_group = Draw.get_block_group('mapfile.txt')
        #add the blocks to the sprite group containing all sprites
        for block in self.block_group:
            self.all_sprites.add(block)


        #I don't actually know what this does
        PE.set_allowed([QUIT, KEYDOWN])

        self.clock = PT.Clock()
        self.current_time = PT.get_ticks()
        self.updates = 0
        self.interval = interval
        Locals.CHANGESTATE = 'Game'
    def __init__(self, game):
        sprite.LayeredUpdates.__init__(self)

        self.game = game

        self.userObjects = sprite.Group()
        self.uiObjects = sprite.Group()

        #sprite.LayeredUpdates.add(self, self.userObjects, self.uiObjects)

        self.setBackgroundSize(self.game.screen.get_size())
Esempio n. 7
0
    def __init__(self, screen):
        super(Level2, self).__init__(screen)

        self.id = 2
        self.should_exit = False
        self.background = image.load("assets/background.png").convert_alpha()

        self.player = Player()
        self.players = sprite.Group([self.player] + self.load_shields())
        self.player_bullets = sprite.Group()
        self.aliens = sprite.Group([Pechatron()])
        self.alien_bullets = sprite.Group()
        self.bonus = sprite.Group([Bonus()])
Esempio n. 8
0
def init_models(filename, scoring_method, bluetooth):
    hand_group = sprite.Group()
    for i in range(2):
        hand_group.add(Hand(i == 0))  # left or right hand

    note_group = sprite.Group()
    song = Song(filename, note_group, scoring_method, bluetooth)

    group = sprite.Group()
    for s in hand_group.sprites():
        group.add(s)

    return group, hand_group, note_group, song
Esempio n. 9
0
    def process(self):
        super(World, self).process()

        bs = self.groups.setdefault('robot', sprite.Group())
        if len(bs) < 5:
            if Robot.counter < 100:
                Robot(self)
            if len(bs) == 0:
                return 'win'

        bs = self.groups.setdefault('player', sprite.Group())
        if len(bs) == 0:
            return 'over'

        return None
Esempio n. 10
0
class Button(sprite.Sprite):
    group = sprite.Group()

    def __init__(self, surf):
        super(Button, self).__init__()
        self.surf = surf
        self.rect = surf.get_rect()
        Button.group.add(self)

    def mouse_signal(self, event):
        pass

    def set_center(self, pos):
        self.rect.x = pos[0] - round(self.surf.get_width() / 2)
        self.rect.y = pos[1] - round(self.surf.get_height() / 2)

    @staticmethod
    def loop(event):
        for i in reversed(Button.group.sprites()):
            if event.type == MOUSEBUTTONDOWN:
                if event.button == 1:
                    if i.rect.collidepoint(event.pos):
                        i.mouse_signal(i, MOUSEBUTTONDOWN)
                        return

            elif event.type == MOUSEBUTTONUP:
                if event.button == 1:
                    i.mouse_signal(i, MOUSEBUTTONUP)

    @staticmethod
    def blit(screen):
        for i in Button.group:
            screen.blit(i.surf, i.rect)
Esempio n. 11
0
 def __init__(self, player_image, x, y, size_x, size_y, speed):
     # Вызываем конструктор класса (Sprite):
     super().__init__(player_image, x, y, size_x, size_y, speed)
     self.bullets = sprite.Group()
     self.last_time = time_t()
     self.life = None
     self.limit_bull = None
Esempio n. 12
0
    def __init__(self, pos):
        sprite.Sprite.__init__(self)

        self.name = "Tower"
        self.pos = pos
        self.grid_pos = tuple([x / 40 for x in self.pos])
        self.image = Surface((40, 40)).convert()
        self.kills = 0
        self.damage_done = 0
        self.image.fill((225, 50, 50))
        self.rect = Rect(self.pos, self.image.get_size())
        self.projectile = Surface((10, 10)).convert()
        self.projectile.fill((0, 255, 255))
        self.projectile_speed = 5
        self.projectiles = sprite.Group()
        self.turn_yield = 0

        self.radius = 200
        self.fire_rate = 1
        self.damage = 25
        self.level = 1
        self.upgrade_cost = 5
        self.description = "A basic tower with moderate fire speed and damage."
        self.cost = 25
        self.value = self.cost

        self.target = None
        self.last_shot = time.time()

        self.image.convert()
        self.projectile.convert()
        self.frame = TowerFrame(self)
Esempio n. 13
0
def create_level(level):
    sprite_group = sprite.Group()
    platforms = []
    #chests = []
    x = 0
    y = 0
    for row in level:
        for col in row:
            if col == "-":
                pf = classes.Platform(x, y)
                platforms.append(pf)
                sprite_group.add(pf)
            if col == "c":
                ch = classes.Chest(x, y)
                #chests.append (ch)
                sprite_group.add(ch)
            if col == "m":
                mn = classes.Monster(x, y, text.zombitext)
                sprite_group.add(mn)
            x += 45
        x = 0
        y += 45
    x = 0
    y = 0
    return platforms, sprite_group
Esempio n. 14
0
    def __init__(self, start: tuple, scale: tuple, *containers: sprite.Group):
        """MacGyver default constructor."""

        # Override default containers
        if containers:
            self.containers = containers

        # Call the parent constructor.
        super().__init__(self.containers)

        # The original graphic representation of MacGyver.
        self.original_img = pygame.image.load(asset(self.MAC_GYVER))

        # Scaled graphic representation of MacGyver.
        self.image = pygame.transform.scale(self.original_img, scale)

        # Represent the hitbox and the position of MacGyver.
        self.rect = self.image.get_rect()

        # Place MacGyver on the starting point.
        self.rect.topleft = scale_position(start, scale)

        # Scale the moves directions of MacGyver.
        self._set_scale_moves(scale)
        self._old_coordinates = (0, 0)

        # Represent the inventory of MacGyver where the items will be stored.
        # This inventory must be filled with the three needed items in order
        # to put the guardian in sleep.
        self.inventory = sprite.Group()
Esempio n. 15
0
    def __init__(self, screen, on_next):
        super(OnWinScene, self).__init__(screen, on_next,
                                         './assets/ganar_nivel.ogg')
        self.loop = False

        mantillin_sprites = SpriteSheet("mantillin").load_strip(
            (432, 0, 108, 121.5), 1)
        hearts_sprites = SpriteSheet("hearts_un").load_strip((0, 0, 51, 48), 6)

        self.mantillin = sprite.Group([
            Particle(mantillin_sprites,
                     (SCREEN_WIDTH / 2 - mantillin_sprites[0].get_width() / 8,
                      SCREEN_HEIGHT / 3 + mantillin_sprites[0].get_height()),
                     0, 0, 0),
            Particle(
                hearts_sprites,
                (SCREEN_WIDTH / 2 + 1.25 * hearts_sprites[0].get_width(),
                 SCREEN_HEIGHT / 3 + 1.5 * hearts_sprites[0].get_height()), 0,
                0, 0)
        ])

        self.text_title = HeadingFont(60).render("YOU WON", True,
                                                 (3, 169, 244))
        self.text_continue = PixelFont(26).render("press enter to continue",
                                                  True, (255, 255, 255))
        self.star = image.load("assets/star.png").convert_alpha()
Esempio n. 16
0
def makeSprites():
    a = makeBox("../RESOURCES/RedSquare.png", (300, 300))
    b = makeBox("../RESOURCES/BlueSquare.png", (500, 300))
    c = makeBox("../RESOURCES/GreenSquare.png", (700, 300))
    d = makeBox("../RESOURCES/YellowSquare.png", (900, 300))

    return PGS.Group(a, b, c, d)
Esempio n. 17
0
 def ma_get_collided_others(self, player):
     others = self.get_others_team(player)
     collided = sprite.Group([])
     for other in others:
         collided.append(self.move_area.get_collided(other))
     LOG.debug("collided sprites %s: " % collided)
     return collided
    def __init__(self, screen, number_of_mice, flee_zone):
        """
        Setup relevant variables and UI components to draw all of the animals
        :param screen: Surface which the game is played on
        :param number_of_mice: The number of mice involved in the game
        """
        super().__init__(screen)

        self.cat = Cat(self._background, 3)
        self._flee_zone = flee_zone

        self._all_animals = sprite.Group()
        self._all_animals.add(self.cat)
        self._mouse_list = self._create_mouse_pool(number_of_mice)
        self._live_mouse_list = self._mouse_list.copy()
        self._dead_mouse_list = sprite.Group()
Esempio n. 19
0
    def __init__(self,x,y,image_name):
        from TT import SCREEN_WIDTH,SCREEN_HEIGHT,archive,Load_Image_From_Zip
        sprite.Sprite.__init__(self)
        

        self.initialX = x
        self.initialY = y

        self.initial_image = transform.scale(Load_Image_From_Zip(archive,image_name),[int(SCREEN_WIDTH / 35.025),int(SCREEN_HEIGHT / 11.636)])
        self.Image = self.initial_image
        self.width = self.initial_image.get_width()
        self.height = self.initial_image.get_height()
        self.mask = mask.from_surface(self.Image)
        self.rect = self.Image.get_rect(center = (x + self.width / 2,y + self.height / 2))
        self.center = self.rect.center
        self.Xmage = Surface([0, 0]).convert_alpha()

        self.dx = 0
        self.dy = Tank.Speed
    

        self.stuck = False
        self.health = 3
        self.bullet_sprites = sprite.Group()

        self.speed_boosted = False
        self.health_boosted = False
Esempio n. 20
0
 def test(self):
     gameOver = False
     BKG_COLOR = (100, 100, 100)
     print("Test...")
     items = []
     item_group = sprite.Group()
     for i in range(5):
         if i == 0:
             item = UnbreakableBlock()
         else:
             item = Chip(cell_class=i)
         item.set_center_pos(i * 70 + 40, 60)
         items.append(item)
     for item in items:
         item_group.add(item)
     item_group.draw(self.display.get_display())
     while (not gameOver):
         for evento in event.get():
             if (evento.type == pygame.QUIT):
                 print('Quiting...')
                 gameOver = True
                 pygame.quit()
                 quit()
             if (evento.type == pygame.KEYDOWN):
                 if (evento.key == pygame.K_a):
                     return
         self.display.bkg_color(BKG_COLOR)
         item_group.update(self.display.get_display())
         pygame.display.update()
Esempio n. 21
0
    def test_has( self ):
        " See if AbstractGroup.has() works as expected. "

        self.assertEqual(True, self.s1 in self.ag)

        self.assertEqual(True, self.ag.has(self.s1))

        self.assertEqual(True, self.ag.has([self.s1, self.s2]))

        # see if one of them not being in there.
        self.assertNotEqual(True, self.ag.has([self.s1, self.s2, self.s3]))
        self.assertNotEqual(True, self.ag.has(self.s1, self.s2, self.s3))
        self.assertNotEqual(True, self.ag.has(self.s1,
                                              sprite.Group(self.s2, self.s3)))
        self.assertNotEqual(True, self.ag.has(self.s1, [self.s2, self.s3]))

        # test empty list processing
        self.assertFalse(self.ag.has(*[]))
        self.assertFalse(self.ag.has([]))
        self.assertFalse(self.ag.has([[]]))

        # see if a second AbstractGroup works.
        self.assertEqual(True, self.ag2.has(self.s3))

        # test exception clause for bad sprite class
        spr = BadSpriteInstance()
        self.assertFalse(self.ag.has(spr))
Esempio n. 22
0
    def __init__(self, prototypes):
        self.prototypes = prototypes
        self.objects = []

        # sprite groups
        self.sprites_all = sprite.Group()
        self.sprites_draw = sprite.Group()
        self.sprites_updateonly = sprite.Group()

        # movement mode controls... how things move
        # strings because that's great
        # possible values:
        # platform
        # topdown
        # more in the future!!!
        self.movement_mode = 'platform'
        self.gravity = Vector2(0.0, 0.1)
Esempio n. 23
0
    def __init__(self, game_state):
        self.done = False
        self.next = None
        self.quit = False
        self.previous = None

        self.game_state = game_state

        self.active_sprites = sprite.Group()
        self.buttons = sprite.Group()
        self.preview = sprite.GroupSingle()

        self.prev_x = c.VIEW_LEFT
        self.prev_y = c.VIEW_TOP

        self.reset = False
        self.quit = False
    def _drop_hearts(self):
        self._hearts = sprite.Group()

        rand_pos_x = WINDOW_WIDTH / 2
        rand_pos_y = (WINDOW_HEIGHT / 2) - 200
        self._hearts.add(
            TreasureSprite(self._res_container,
                           TreasureData(Vector2(rand_pos_x, rand_pos_y), 0)))
Esempio n. 25
0
 def prep_ships(self):
     """ Формируем кол-во оставшихся жизней """
     self.ships = sprite.Group()
     for ship_number in range(self.stats.ships_left):
         ship = Ship(self.settings, self.screen)
         ship.rect.x = 10 + ship_number * ship.rect.width
         ship.rect.y = 10
         self.ships.add(ship)
Esempio n. 26
0
 def spawn_enemies(self):
     self.enemies = PS.Group()
     self.scientists = PS.Group()
     for coords in self.map.sci_coords:
         new_enemy = Scientist.Scientist(coords)
         self.enemies.add(new_enemy)
     for coords in self.map.enemy_coords:
         new_enemy = Slime.Slime(coords)
         self.enemies.add(new_enemy)
     for coords in self.map.bug_coords:
         new_enemy = Bug.Bug(coords)
         self.enemies.add(new_enemy)
     for coords in self.map.ss_coords:
         new_enemy = SuperSlime.SuperSlime(coords)
         self.enemies.add(new_enemy)
     if self.map.boss_coord is not None:
         self.boss = Boss.Boss(self.map.boss_coord)
         self.enemies.add(self.boss)
Esempio n. 27
0
 def add(self, group_name, *sprites):
     """
     向精灵组中添加精灵
     :param group_name: 组名
     :param sprites: 精灵
     :return:
     """
     self.all_sprite.add(*sprites)
     self.groups.setdefault(group_name, sprite.Group()).add(*sprites)
Esempio n. 28
0
 def group(self, group_name=None):
     """
     返回指定的精灵组
     :param group_name: 组名,None: 返回 all_sprite
     :return: 精灵组
     """
     if group_name is None:
         return self.all_sprite
     return self.groups.setdefault(group_name, sprite.Group())
Esempio n. 29
0
 def update(self, target_coordinates, bigmap):
     moved = self.apply(target_coordinates)
     enemy_group = PS.Group()
     if moved:
         self.check_boundary()
         self.background = bigmap. \
             subsurface(self.cameraxy[0], self.cameraxy[1],
                        WIN_WIDTH, WIN_HEIGHT)
     return self.background
Esempio n. 30
0
 def __init__(self, boss_image, x, y, size_x, size_y, speed):
     GameSprite.__init__(self, boss_image, x, y, size_x, size_y, speed)
     self.scaner = Scaner(x + size_x // 2)
     self.right = win_width - 100
     self.left = 100
     self.direction = "right" * randint(0, 1) or "left"
     self.health = 10
     self.last_shot = time_t()
     self.bulletes = sprite.Group()