Ejemplo n.º 1
0
    def __init__(self, window):
        super().__init__(window)
        self.batch = Batch()
        self.menu = 0
        self.main_index = 0
        self.practice_index = 0
        self.config_index = 0
        self.t = 0

        self.background = Sprite(IMAGES['ui']['mainmenu_bg'], -15, -15)
        self.background.opacity = 100
        self.background2 = Sprite(IMAGES['ui']['mainmenu_bg2'], 0, 0, blend_src=774)
        self.left_sprite = Sprite(IMAGES['ui']['mainmenu_left'], 0, 0, batch=self.batch)
        self.left_sprite.opacity = 50

        # Main menu options:
        options_text = ['Start game', 'Practice', 'High scores', 'Config', 'Exit']
        self.main_options_shadow = [Label(text=options_text[i], font_name=MENU_FONT, color=(100, 100, 100, 100), font_size=22, x=199, y=401 - 32*i, batch=self.batch) for i in range(len(options_text))]
        self.main_options = [Label(text=options_text[i], font_name=MENU_FONT, font_size=22, x=200, y=400 - 32*i, batch=self.batch) for i in range(len(options_text))]

        # Practice options:
        options_text = ['Level 1', 'Level 2', 'Level 3', 'Level 4', 'Level 5']
        self.practice_options_shadow = [Label(text=options_text[i], font_name=MENU_FONT, color=(100, 100, 100, 0), font_size=22, x=499, y=401 - 32*i, batch=self.batch) for i in range(len(options_text))]
        self.practice_options = [Label(text=options_text[i], font_name=MENU_FONT, font_size=22, x=500, y=400 - 32*i, color=(255,255,255,0), batch=self.batch) for i in range(len(options_text))]

        # Config options:
        options_text = ['SFX volume', 'BGM volume', 'Controls']
        self.config_options_shadow = [Label(text=options_text[i], font_name=MENU_FONT, color=(100, 100, 100, 0), font_size=22, x=499, y=401 - 32*i, batch=self.batch) for i in range(len(options_text))]
        self.config_options = [Label(text=options_text[i], font_name=MENU_FONT, font_size=22, x=500, y=400 - 32*i, color=(255,255,255,0), batch=self.batch) for i in range(len(options_text))]
Ejemplo n.º 2
0
	def __init__(self, *args, **kwargs):
		super().__init__(*args, **kwargs)
		self.set_location(400,100)
		self.frame_rate = 1/60.0

		self.episodes = 0
		self.move_count = 0

		self.epsilon = EPSILON

		self.reward = 0
		self.episode_reward = 0
		self.episode_rewards = np.array()

		self.main_batch = pyglet.graphics.Batch()
		backGround = pyglet.graphics.OrderedGroup(0)
		foreGround = pyglet.graphics.OrderedGroup(1)

		backGround_sprite = Sprite(preload_image('backGround.png'), batch=self.main_batch, group=backGround)
		self.backGround = gameObjects(LOW,LOW,backGround_sprite)

		pos = floor((SIZE/2)-(BLACK_ARC_DIAMETER/2))
		blackArc_sprite = Sprite(preload_image('blackArc.png'), batch=self.main_batch, group=foreGround)
		self.blackArc = gameObjects(pos,pos,blackArc_sprite)

		redArc_sprite = Sprite(preload_image('redArc.png'), batch=self.main_batch, group=foreGround)
		self.redArc = gameObjects(LOW,LOW,redArc_sprite)
Ejemplo n.º 3
0
    def on_activate(self):
        super().on_activate()
        if not self.inactive_sprite:
            self.inactive_sprite = Sprite(self.inactive_image,
                                          x=self.viewport.x1,
                                          y=self.viewport.y1,
                                          batch=BATCHES['ui_batch'],
                                          group=GROUPS['button_background'])

        self.inactive_sprite.scale = self.get_scale()
        self.inactive_sprite.opacity = self.opacity
        if self.current_percent == 0:
            image_region = self.active_image.get_region(
                self.active_image.height // 2, self.active_image.height // 2,
                1, 1)
        else:
            image_region = self.active_image.get_region(
                0, 0, self.current_percent * self.active_image.width // 100,
                self.active_image.height)

        if not self.active_sprite:
            self.active_sprite = Sprite(image_region,
                                        x=self.viewport.x1,
                                        y=self.viewport.y1,
                                        batch=BATCHES['ui_batch'],
                                        group=GROUPS['button_text'])
        else:
            self.active_sprite.image = image_region

        self.active_sprite.scale = self.get_scale()
        self.active_sprite.opacity = self.opacity
Ejemplo n.º 4
0
    def enemy_spawn(self, dt):

        self.enemy_typeA_spawner -= dt
        self.enemy_typeB_spawner -= dt
        if self.player_is_alive:
            if self.enemy_typeA_spawner <= 0:
                self.enemy_list.append(
                    GameObject(1000,
                               800,
                               Sprite(self.enemy_imgA, batch=self.main_batch),
                               health=2))
                self.enemy_list[-1].vel_x = randint(100, 300) * choice(
                    self.directions)  # last spawned entity in entity list
                self.enemy_list[-1].vel_y = 30

                self.enemy_typeA_spawner += self.enemy_typeA_counter

            if self.enemy_typeB_spawner <= 0:
                self.enemy_list.append(
                    GameObject(600,
                               950,
                               Sprite(self.enemy_imgB, batch=self.main_batch),
                               health=5))
                self.enemy_list[-1].vel_x = randint(100, 300) * choice(
                    self.directions)  # last spawned entity in entity list
                self.enemy_list[-1].vel_y = 30

                self.enemy_typeB_spawner += self.enemy_typeB_counter

        if self.next_wave >= 20:
            self.enemy_typeA_counter -= 0.05
            self.enemy_typeB_counter -= 0.2
            self.next_wave = 0
Ejemplo n.º 5
0
    def __init__(self,
                 shipTexture,
                 shieldTexture,
                 alienBatch,
                 shipGroup,
                 shieldGroup,
                 x=0,
                 y=0):
        self.ship = Sprite(shipTexture,
                           x=x,
                           y=y,
                           blend_src=770,
                           blend_dest=771,
                           batch=alienBatch,
                           group=shipGroup,
                           usage='dynamic',
                           subpixel=False)
        self.shield = Sprite(shieldTexture,
                             x=x,
                             y=y,
                             blend_src=770,
                             blend_dest=771,
                             batch=alienBatch,
                             group=shieldGroup,
                             usage='dynamic',
                             subpixel=False)

        # Set the physical aspects of the Alien ship
        self.acceleration = np.array((0, 0), dtype=np.float32)
        self.velocity = np.array((0, 0), dtype=np.float32)
        self.position = np.array((x, y), dtype=np.float32)
        self.maxSpeed = 500
Ejemplo n.º 6
0
    def load_data(self):
        player_sprite = Sprite(preload_img("PlayerShip.png"))
        space_sprite = preload_img("space.jpg")

        self.player = GameObject(500, 100, player_sprite)

        self.space_list = []
        for i in range(2):
            self.space_list.append(GameObject(0, i * 1200, Sprite(space_sprite)))

            self.space_list[i].vely = -600
Ejemplo n.º 7
0
 def __init__(self, game_scale, backX, backY):
     self.startX = backX
     self.startY = backY
     self.bar = Sprite(img=Experience.experience_bar,
                       x=backX + (930 * game_scale),
                       y=backY + (940 * game_scale))
     self.bar.scale = game_scale
     self.exp = Sprite(img=Experience.experience_green,
                       x=backX + (930 * game_scale),
                       y=backY + (940 * game_scale))
     self.game_scale = game_scale
     self.exp.scale = 0
     self.total_exp = 0
Ejemplo n.º 8
0
    def init(self, **kwargs):
        self.in_combat_with = []
        self.image = load_image(self.image_file)
        self.sprite = Sprite(self.image, self.x, self.y)
        self.hp_image = load_image('app/assets/healthbar.png')
        self.hp_sprite = Sprite(self.hp_image, self.x + 1,
                                self.y + self.height + 5)
        self.set_sprite_render(self.group)
        self.stats = Stats(modifiers=self.stat_modifiers)

        entity_container = getattr(self.chunk, self.chunk_container)
        if self.chunk and self not in entity_container:
            entity_container.append(self)

        self.post_init(**kwargs)
Ejemplo n.º 9
0
 def set_index(self, index):
     width = get_size()[0]
     for i in range(len(self._element)):
         self._element[i] = Sprite(image.load(
             join(path['texture.ui'], 'hotbar_%d.png' % i)),
                                   x=(width - 450) / 2 + 50 * i,
                                   y=0)
         self._element[i].scale = 2.5
     if 0 <= index < len(self._element):
         self._element[index] = Sprite(image.load(
             join(path['texture.ui'], 'hotbar_highlight.png')),
                                       x=(width - 450) / 2 + 50 * index - 5,
                                       y=-3)
         self._element[index].scale = 2.5
         self.index = index
Ejemplo n.º 10
0
    def set_viewport(self, x, y, w, h):
        tw = self.map.data["tilewidth"]
        th = self.map.data["tileheight"]

        def yrange(f, t, s):
            while f < t:
                yield f
                f += s

        in_use = []
        for j in yrange(y, y + h + th, th):
            py = j // th
            for i in yrange(x, x + w + tw, tw):
                px = i // tw
                in_use.append((px, py))
                if (px, py) not in self.sprites:
                    try:
                        texture = self.map.get_texture(self[px, py])
                    except (KeyError, IndexError):
                        self.sprites[(px, py)] = None
                    else:
                        self.sprites[(px, py)] = Sprite(
                            texture,
                            x=(px * tw),
                            y=h - (py * th) - th,
                            batch=self.map.batch,
                            group=self.group,
                            usage="static",
                        )
        for key in self.sprites.keys():
            if key not in in_use:
                if self.sprites[key] is not None:
                    self.sprites[key].delete()
                del self.sprites[key]
Ejemplo n.º 11
0
    def __init__(self,
                 *,
                 player: Player,
                 space: pymunk.Space,
                 ui_batch=None,
                 background_batch=None):
        super().__init__()

        self.player = player
        self.space = space
        self.background_batch = background_batch

        self.danger_sprite = Sprite(img=resources.danger_image,
                                    batch=background_batch,
                                    x=128,
                                    y=128)
        self.danger_sprite.visible = False

        # Internal score modified by the property below
        self._score = 0
        # Show the score
        self.score_label = Label('',
                                 font_name='m5x7',
                                 font_size=48,
                                 x=WIDTH - 10,
                                 y=HEIGHT,
                                 anchor_x='right',
                                 anchor_y='top',
                                 batch=ui_batch)
        # "call" the property setter below
        self.score = self._score
Ejemplo n.º 12
0
    def load(x, y, create=False):
        loaded_chunk = session.query(models.Chunk).filter_by(x=x, y=y).first()

        if loaded_chunk is None:
            if create:
                chunk = Chunk(x, y)
                chunk.build_blocks()
                chunk.save()
            else:
                return None
        else:
            chunk = Chunk.load_from_db_obj(loaded_chunk)

        if not os.path.isfile(chunk.img_file):
            chunk.build_img()

        bg_img = load_image(chunk.img_file)
        chunk.sprite = Sprite(bg_img,
                              0,
                              0,
                              batch=chunk.draw_batch,
                              group=chunk.background)

        chunk.set_walls()
        chunk.add_npcs(5)

        return chunk
Ejemplo n.º 13
0
 def __init__(self, x, y, width, height, text):
     self._size = win_width, win_height = get_size()
     super().__init__(x, win_height - y, width, height)
     self._width = width
     self._depressed_img = image.load(
         join(path['texture.ui'],
              'widgets.png')).get_region(0, 170, 200, 20)
     self._pressed_img = image.load(join(path['texture.ui'],
                                         'widgets.png')).get_region(
                                             0, 150, 200, 20)
     self._unable_img = image.load(join(path['texture.ui'],
                                        'widgets.png')).get_region(
                                            0, 190, 200, 20)
     self._sprite = Sprite(self._depressed_img, x, win_height - y)
     self._text = text
     self._label = ColorLabel(self._text,
                              color='white',
                              align='center',
                              anchor_x='center',
                              anchor_y='center',
                              x=x + width / 2,
                              y=win_height - y + height / 2 - 2,
                              font_name='minecraftia')
     self._pressed = False
     self._enable = True
Ejemplo n.º 14
0
    def set_viewport(self, x, y, w, h):
        self.h = h
        tw = self.map.data["tilewidth"]
        th = self.map.data["tileheight"]

        in_use = []
        for obj in self.objects:
            if x - tw < obj["x"] < x + w + tw and y - th < obj[
                    "y"] < y + h + th:
                if not obj["visible"]:
                    continue
                if "gid" in obj:
                    in_use.append((obj["x"], obj["y"]))
                    try:
                        texture = self.map.get_texture(obj["gid"])
                        tileoffset = self.map.get_tileoffset(obj["gid"])
                    except (IndexError, KeyError):
                        sprite = None
                    else:
                        sprite = Sprite(
                            texture,
                            x=obj["x"] + tileoffset[0],
                            y=self.h - obj["y"] + tileoffset[1],
                            batch=self.map.batch,
                            group=self.group,
                            usage="static",
                        )

                    self.sprites[(obj["x"], obj["y"])] = sprite

        for key in list(self.sprites):
            if key not in in_use:
                self.sprites[key].delete()
                del self.sprites[key]
Ejemplo n.º 15
0
    def draw_enemy_tanks_remaining(self, game: Game, reset=False):
        if game.game_director.stage is None:
            return

        tank_icon_count = 0
        target_icon_count = game.game_director.stage.active_tanks
        for row in range(0, self.tank_icons.shape[0]):
            for col in range(0, self.tank_icons.shape[1]):
                tank_icon_count += 1
                if tank_icon_count <= target_icon_count:
                    if self.tank_icons[row, col] is None or reset:
                        tank_icon_sprite = Sprite(img=TextureManager.tank_icon,
                                                  x=game.game_map.map_data["pixel_width"]
                                                    + col * constants.UI_TANK_ICON_SIZE
                                                    + col * constants.UI_TANK_ICONS_GAP
                                                    + constants.UI_SIDE_PANEL_SIZE // 2
                                                    - constants.UI_TANK_ICONS_WIDTH // 2,
                                                  y=game.game_map.map_data["pixel_height"]
                                                    - (row * constants.UI_TANK_ICON_SIZE)
                                                    - constants.UI_TANK_ICON_SIZE
                                                    - constants.UI_TANK_ICONS_TOP_PAD,
                                                  batch=self.batch)
                        tank_icon_sprite.scale = 3
                        self.tank_icons[row, col] = tank_icon_sprite
                else:
                    if self.tank_icons[row, col] is not None:
                        self.tank_icons[row, col].delete()
                        self.tank_icons[row, col] = None
Ejemplo n.º 16
0
    def __init__(self, id, pos, rot, weapon, game):
        self.id = id

        self.pos = pos

        self.rot = rot

        self.weapon = weapon

        self.sprite = Sprite(game.player_images[weapon])
        self.width = self.sprite.width
        self.height = self.sprite.height

        self.hit_box = PLAYER_HIT_BOX.copy()
        self.hit_box.x = pos.x
        self.hit_box.y = pos.y

        self.sprite.image.anchor_x = self.sprite.image.width / 2 - WEAPONS[
            weapon]['img_offset'].x
        self.sprite.image.anchor_y = self.sprite.image.height / 2 - WEAPONS[
            weapon]['img_offset'].y

        self.game = game

        self.health = PLAYER_HEALTH
        self.dead = False
Ejemplo n.º 17
0
 def resize(self, width, height):
     self._element = list()
     for x in range(width // self._img.width * 2 + 1):
         for y in range(height // self._img.height * 2 + 1):
             sprite = Sprite(self._img, x=x * self._img.width, y = y * self._img.height)
             sprite.scale = 2
             self._element.append(sprite)
Ejemplo n.º 18
0
    def __init__(self, runner, tile_size):
        width = runner.model.world_shape[0] * tile_size
        height = runner.model.world_shape[1] * tile_size
        super().__init__(runner, width=width, height=height)

        self.sprite = Sprite(img=runner.model.tiles[0].image)
        self.tile_size = tile_size
Ejemplo n.º 19
0
    def __init__(self,
                 window,
                 bus,
                 title='Welcome to tabulr',
                 draw_waves=False):
        """
        Initialize the Scene object.
        :param window: Pyglet window object. Must be same throughout application.
        :param bus: Event bus. Used for communicating scene changes to main application thread.
        """
        self.window = window
        self.window_title = title
        self.bus = bus
        self.batch = Batch()
        self.margin = 36
        self.sprites = {}
        self.inputs = []

        # Error message
        self.error_msg = Text('',
                              size=12,
                              bold=True,
                              batch=self.batch,
                              x=self.margin,
                              color=(236, 64, 122, 255))
        self.error_elapsed = 0
        self.error_opacity = 0

        # Waves background
        if draw_waves:
            waves_img = image('side-waves.png')
            waves_img.anchor_x = waves_img.width
            waves = Sprite(waves_img, x=window.width, y=0, batch=self.batch)
            waves.opacity = 160
            self.init_sprite('waves', waves, is_button=False)
Ejemplo n.º 20
0
 def update_space(self, dt):
     for space in self.space_list:
         space.update()
         space.posy -= 50 * dt
         if space.posy <= -1500:
             self.space_list.remove(space)
             self.space_list.append(GameObject(0, 1500, Sprite(self.space_img)))
Ejemplo n.º 21
0
 def create_car_sprite(self, body, shape, img, x, y, batch, scale=0.25):
     # Car image
     self.car_sprite = Sprite(img=img, x=x, y=y, batch=batch)
     self.car_sprite.shape = shape
     self.car_sprite.body = body
     self.car_sprite.scale = scale
     self.car_sprite.rotation = degrees(-self.car_sprite.body.angle) + 90
Ejemplo n.º 22
0
    def __init__(self, window, bus):
        super().__init__(window, bus)
        self.title = Text('Welcome to',
                          batch=self.batch,
                          x=self.margin,
                          y=(self.window.height // 2) + 100)
        self.title_bold = Text('tabulr',
                               bold=True,
                               batch=self.batch,
                               x=self.margin,
                               y=(self.window.height // 2) + 60)
        self.subtitle = Text(
            'Your schedule, from list to wallpaper. Like magic.',
            size=12,
            batch=self.batch,
            x=self.margin,
            y=self.window.height // 2)
        self.init_sprite(
            'next_button',
            Button('next',
                   self.window,
                   self.batch,
                   x=self.margin,
                   y=(self.window.height // 2) - 100))

        waves = Sprite(image('front-waves.png'), x=0, y=-30, batch=self.batch)
        waves.opacity = 140
        self.elapsed = 0
        self.init_sprite('waves', waves, is_button=False)
Ejemplo n.º 23
0
    def __init__(self, runner):
        super().__init__(runner, width=512, height=512)

        tile = image('tile.png')
        tile.anchor_x = 32
        tile.anchor_y = 32
        self.sprite = Sprite(img=tile, x=0, y=0)
Ejemplo n.º 24
0
	def update_space(self, dt):
		for space in self.space_list:
			space.update(dt)
			if space.posy <= -160:
				self.space_list.remove(space)
				self.space_list.append(GameObject(0, 160,  Sprite(self.space_img)))
			space.vely = -100
Ejemplo n.º 25
0
    def __init__(self, x, y, game):
        self.pos = Vector(x, y)
        self.vel = Vector(0, 0)
        self.acc = Vector(0, 0)

        self.game = game

        self.rot = 0

        self.hit_box = MOB_HIT_BOX.copy()

        self.sprite = Sprite(game.mob_image, batch=game.mob_batch)
        self.width = self.sprite.width
        self.height = self.sprite.height

        self.sprite.image.anchor_x = self.sprite.image.width / 2 - MOB_IMAGE_OFFSET.x
        self.sprite.image.anchor_y = self.sprite.image.height / 2 - MOB_IMAGE_OFFSET.y

        self.sprite.x = x
        self.sprite.y = y

        self.health = MOB_HEALTH

        self.hit_box.x = self.pos.x - self.hit_box.width / 2
        self.hit_box.y = self.pos.y - self.hit_box.height / 2

        self.target = None

        self.q = Queue(self.game)

        self.id = game.new_mob_id()

        self.last_hit = datetime.now()
Ejemplo n.º 26
0
 def player_fire(self, dt):
     self.player_fire_rate -= dt
     if self.player_fire_rate <= 0:
         self.player_laser_list.append(
             GameObject(self.player.posx, self.player.posy + 76, 0, 0,
                        Sprite(self.player_laser)))
         self.player_fire_rate += 0.2
Ejemplo n.º 27
0
    def __init__(self, window, bkg_image, folder):
        self.background = pyglet.graphics.Batch()

        self.width, self.height = window.get_size()

        image = pyglet.image.load(bkg_image)

        self.bkg0 = Sprite(image, batch=self.background)
        self.bkg1 = Sprite(image, batch=self.background)

        self.bkg0.opacity = 128
        self.bkg1.opacity = 128

        scale = self.width / float(self.bkg0.width)
        self.bkg0.scale = scale
        self.bkg1.scale = scale
Ejemplo n.º 28
0
    def __init__(self, *args, **kwargs):
        super(GameWindow, self).__init__(*args, **kwargs)
        self.set_location(400, 100)
        self.frame_rate = 1 / 60.0
        self.fps_display = FPSDisplay(self)
        self.fps_display.label.font_size = 50
        self.fps_display.label.y = 300

        self.right = False
        self.left = False
        self.player_speed = 300
        self.fire = False
        self.player_fire_rate = 0

        player_spr = pyglet.sprite.Sprite(preload_image('Carrot.png'))
        self.player = GameObject(500, 100, 0, 0, player_spr)

        self.player_laser = preload_image('laser.png')
        self.player_laser_list = []

        self.grass_list = []
        self.grass_img = preload_image('Grass.png')
        for i in range(3):
            self.grass_list.append(
                GameObject(0, i * 675, 0, -200, Sprite(self.grass_img)))
Ejemplo n.º 29
0
    def __init__(self, window):
        self.window = window
        self.batch = pyglet.graphics.Batch()

        # Create a
        title_image = pyglet.resource.image('TerraCraft.png')
        title_image.anchor_x = title_image.width // 2
        title_image.anchor_y = title_image.height + 10
        position = self.window.width // 2, self.window.height
        self.title_graphic = Sprite(img=title_image, x=position[0], y=position[1], batch=self.batch)

        self.start_label = pyglet.text.Label('Select save & press Enter to start', font_size=25,
                                             x=self.window.width // 2, y=self.window.height // 2,
                                             anchor_x='center', anchor_y='center', batch=self.batch)

        # Create labels for three save slots:
        self.save_slot_labels = []
        for save_slot in [1, 2, 3]:
            self.scene_manager.save.save_slot = save_slot
            # indicate if an existing save exists
            if self.scene_manager.save.has_save_game():
                label_text = f"{save_slot}:  load"
            else:
                label_text = f"{save_slot}:  new game"
            y_pos = 190 - 50 * save_slot
            label = pyglet.text.Label(label_text, font_size=20, x=40, y=y_pos, batch=self.batch)
            self.save_slot_labels.append(label)

        # Highlight the default save slot
        self.scene_manager.save.save_slot = 1
        self._highlight_save_slot()
Ejemplo n.º 30
0
 def __init__(self):
     width, height = get_size()
     GUI.__init__(self, width, height)
     self._xpbar = Sprite(image.load(join(path['texture.gui'], 'icons.png')).get_region(0, 187, 182, 5),
             x=(width - 364) / 2, y=48)
     self._xpbar.scale_x = 2
     self._xpbar.scale_y = 1.5