示例#1
0
 def create_genesis_block(self):
     """
     A function to generate genesis block and appends it to
     the chain. The block has index 0, previous_hash as 0, and
     a valid hash.
     """
     genesis_block = Block(0, [], time.time(), "0")
     genesis_block.hash = genesis_block.compute_hash()
     self.chain.append(genesis_block)
示例#2
0
    def generate_map(self):
        color_prec_block = None

        grey, white = settings.grid["colors"]
        color = grey

        blocks = []

        for y in range(0, settings.layout["numbers_on_height"]):
            for x in range(0, settings.screen["width"], settings.blocks["wh"]):
                r = random.randint(0, 100)

                if (r > random.randint(
                        100 - settings.blocks["wall_probability"], 100)):
                    status = "wall"
                else:
                    status = None

                new_block = Block(
                    x, y * settings.blocks["wh"] + settings.layout["header"],
                    status)

                blocks.append(new_block)

        return blocks
示例#3
0
文件: Main.py 项目: Gini5/Game
    def __init__(self):
        #initialize canvas
        super(JumpPikachu, self).__init__(255, 255, 255, 255, 800, 1000)
        # frames per buffer
        self.numSamples = 1000

        #voice control bar
        self.vbar = Sprite('block.png')
        self.vbar.position = 20,450
        self.vbar.scale_y = 0.1     #bar height
        self.vbar.image_anchor = 0,0
        self.add(self.vbar)
        #Pikachu instance
        self.pikachu = Pikachu()
        self.add(self.pikachu)

        #cocosnode, draw blocks
        self.floor = cocos.cocosnode.CocosNode()
        self.add(self.floor)
        position = 0, 100
        for i in range(10):
            block = Block(position)
            self.floor.add(block)
            position = block.x + block.width, block.height

        # audio input
        audio = PyAudio()
        SampleRate = int(audio.get_device_info_by_index(0)['defaultSampleRate'])
        self.stream = audio.open(format = paInt16,
                                 channels = 1,
                                 rate = SampleRate,
                                 input = True,
                                 frames_per_buffer = self.numSamples)
        self.schedule(self.update)
示例#4
0
def main():
	blockchain = []
	genesis_hash = 0
	genesis_transactions = [Transaction('don', 'don', 0)]
	genesis_block = Block(
		genesis_hash,
		genesis_transactions
	)
	blockchain.append(genesis_block)
	block =  Block(
		blockchain[len(blockchain)-1]._id,
		[Transaction('don', 'don', 1)]
	)
	blockchain.append(block)
	block =  Block(
		blockchain[len(blockchain)-1]._id,
		[Transaction('don', 'don', 2),
		 Transaction('don', 'hazel', 3)]
	)
	blockchain.append(block)
	[print(block._id) for block in blockchain]
示例#5
0
    def read_save(name, hero, block, wall, animals, time, time_speed):
        with open('data\saves\{save}'.format(save=name), 'r') as file:
            load_text = loads(file.read())
        hero.x, hero.y = load_text['hero']['x'], load_text['hero']['y']
        hero.hp, hero.hunger = load_text['hero']['hp'], load_text['hero'][
            'hunger']
        hero.spawn_point = load_text['hero']['spawn_point']

        hero.inventory = load_text['hero']['inventory']

        for unit in load_text['block']:
            block.append(
                Block(x=unit['x'],
                      y=unit['y'],
                      name=unit['name'],
                      collision=unit['collision'],
                      wall=unit['wall'],
                      content=unit['content'],
                      cooldown=unit['cooldown'],
                      explored=unit['explored']))

        for unit in load_text['wall']:
            wall.append(
                Wall(x=unit['x'],
                     y=unit['y'],
                     name=unit['name'],
                     explored=unit['explored']))

        for type0 in load_text['animal']:
            if type0 == 'sheep':
                for unit in load_text['animal']['sheep']:
                    animals['sheep'].append(Sheep(unit['x'], unit['y']))
                    animals['sheep'][-1].grow_time0 = unit['grow_time0']
            if type0 == 'pig':
                for unit in load_text['animal']['pig']:
                    animals['pig'].append(Pig(unit['x'], unit['y']))
            if type0 == 'bird':
                for unit in load_text['animal']['bird']:
                    animals['bird'].append(Bird(unit['x'], unit['y']))
        time[0] = load_text['environment']['time']
        time_speed[0] *= load_text['environment']['direction']
示例#6
0
    def mine(self, network):
        """
        This function serves as an interface to add the pending
        transactions to the blockchain by adding them to the block
        and figuring out Proof of Work.
        """
        if not self.unconfirmed_transactions:
            return False

        last_block = self.last_block

        new_block = Block(index=last_block.index + 1,
                          transactions=self.unconfirmed_transactions,
                          timestamp=time.time(),
                          previous_hash=last_block.hash)

        proof = self.proof_of_work(new_block)
        self.add_block(new_block, proof)

        self.unconfirmed_transactions = []
        # announce it to the network
        network.announce_new_block(new_block)
        self.data_files.update_chain(self.chain)
        return new_block.index
示例#7
0
    def create_map(hero, block, wall):
        trees = [
            lambda x, y: [[x, y, 'log'], [x, y - 1, 'log'], [x, y - 2, 'log'],
                          [x, y - 3, 'log'], [x - 1, y - 2, 'leaves'],
                          [x + 1, y - 2, 'leaves'], [x - 1, y - 3, 'leaves'],
                          [x + 1, y - 3, 'leaves'], [x, y - 4, 'leaves']],
            lambda x, y: [[x, y, 'log'], [x, y - 1, 'log'], [x, y - 2, 'log'],
                          [x, y - 3, 'log'], [x, y - 4, 'log'],
                          [x - 1, y - 2, 'leaves'], [x + 1, y - 2, 'leaves'],
                          [x - 1, y - 3, 'leaves'], [x + 1, y - 3, 'leaves'],
                          [x, y - 5, 'leaves'], [x - 1, y - 4, 'leaves'],
                          [x + 1, y - 4, 'leaves'], [x - 1, y - 5, 'leaves'],
                          [x + 1, y - 5, 'leaves'], [x, y - 6, 'leaves'],
                          [x - 2, y - 2, 'leaves'], [x + 2, y - 2, 'leaves'],
                          [x - 2, y - 3, 'leaves'], [x + 2, y - 3, 'leaves']],
            lambda x, y: [[x, y, 'log'], [x, y - 1, 'log'], [x, y - 2, 'log'],
                          [x, y - 3, 'log'], [x, y - 4, 'log'],
                          [x, y - 5, 'log'], [x - 1, y - 4, 'leaves'],
                          [x + 1, y - 4, 'leaves'], [x - 1, y - 5, 'leaves'],
                          [x + 1, y - 5, 'leaves'], [x, y - 6, 'leaves']]
        ]
        win = pygame.Surface((int(F_SIZE[0] / 25), int(F_SIZE[1] / 25)))
        win.fill((100, 100, 255))
        w, h = win.get_size()
        gen = OpenSimplex()

        off0 = [uniform(0, 1024), uniform(0, 1024)]
        off1 = [uniform(0, 1024), uniform(0, 1024)]
        off2 = [uniform(0, 1024), uniform(0, 1024)]
        off3 = [uniform(0, 1024), uniform(0, 1024)]
        off4 = [uniform(0, 1024), uniform(0, 1024)]
        altarX = randint(10, w - 10)
        for x in range(w):
            y = int(h / 10 * 7 +
                    gen.noise2d(off0[0] + x / 20, off0[1]) * h / 10 * 2)
            for i in range(y):
                if i > h / 10 * 7 + gen.noise2d(off1[0] + x / 10,
                                                off1[1]) * h / 10 * 2 - h / 8:
                    if gen.noise2d(off4[0] + x / 30, off4[1] + i / 30) > .3:
                        # Sand
                        win.set_at((x, h - i), (210, 204, 148))
                    else:
                        if i == y - 1:
                            # Grass
                            win.set_at((x, h - i), (0, 174, 0))

                            # Tall grass
                            if uniform(0, 1) > .7:
                                win.set_at((x, h - i - 1), (150, 173, 150))

                            # Tree
                            if uniform(0, 1) > .9:
                                for unit in choice(trees)(x, h - i - 1):
                                    if unit[2] == 'log':
                                        c = (153, 81, 9)
                                    elif unit[2] == 'leaves':
                                        c = (66, 255, 0)
                                    win.set_at((unit[0], unit[1]), c)
                        else:
                            # Dirt
                            win.set_at((x, h - i), (196, 112, 23))
                else:
                    # Stone
                    win.set_at((x, h - i), (122, 122, 122))
            # Add altar
            if x - 1 == altarX:
                win.set_at((x - 1, h - i - 1), (255, 199, 48))
                win.set_at((x, h - i), (167, 167, 167))
                win.set_at((x - 1, h - i), (167, 167, 167))
                win.set_at((x - 2, h - i), (167, 167, 167))

        # Making holes
        for x in range(w):
            for y in range(h):
                if gen.noise2d(off1[0] + x / 10, off1[1] + y / 5) < -.3:
                    if win.get_at((x, y)) == (196, 112, 23):
                        # Dirt wall
                        win.set_at((x, y), (99, 78, 64))
                    elif win.get_at((x, y)) == (122, 122, 122):
                        # Stone wall
                        win.set_at((x, y), (81, 81, 81))
                    elif win.get_at((x, y)) == (210, 204, 148):
                        # Sand wall
                        win.set_at((x, y), (158, 153, 112))

        # Add chest
        x0, y0 = randint(5,
                         w - 5), int(h / 10 * 4 + randint(h / 10, h / 10 * 3))
        for x, y in [[x0 - 1, y0], [x0, y0], [x0 + 1, y0], [x0 - 1, y0 - 1],
                     [x0, y0 - 1], [x0 + 1, y0 - 1], [x0, y0 - 2],
                     [x0 + 1, y0 - 2]]:
            if win.get_at((x, y)) == (196, 112, 23):
                # Dirt wall
                win.set_at((x, y), (99, 78, 64))
            elif win.get_at((x, y)) == (122, 122, 122):
                # Stone wall
                win.set_at((x, y), (81, 81, 81))
            elif win.get_at((x, y)) == (210, 204, 148):
                # Sand wall
                win.set_at((x, y), (158, 153, 112))

        for x, y in [[x0 - 1, y0], [x0, y0], [x0, y0], [x0 + 1, y0]]:
            # Cobblestone
            win.set_at((x, y), (167, 167, 167))
        # Chest
        win.set_at((x0, y0 - 1), (255, 135, 15))

        # Add ore
        off0 = [uniform(0, 1024), uniform(0, 1024)]
        off1 = [uniform(0, 1024), uniform(0, 1024)]
        off2 = [uniform(0, 1024), uniform(0, 1024)]
        off3 = [uniform(0, 1024), uniform(0, 1024)]
        for x in range(w):
            for y in range(h):
                if win.get_at((x, y)) == (122, 122, 122):
                    if gen.noise2d(off0[0] + x / 5, off0[1] + y / 5) > .5:
                        # Coal
                        win.set_at((x, y), (68, 68, 68))
                    if gen.noise2d(off1[0] + x / 5, off1[1] + y / 5) > .7:
                        # Iron
                        win.set_at((x, y), (192, 158, 133))
                    if gen.noise2d(off2[0] + x / 5,
                                   off2[1] + y / 5) > .7 and y > h / 20 * 15:
                        # Gold
                        win.set_at((x, y), (255, 255, 0))
                    if gen.noise2d(off3[0] + x / 5,
                                   off3[1] + y / 5) > .6 and y > h / 20 * 17:
                        # Diamond
                        win.set_at((x, y), (0, 182, 255))

        # Add bedrock
        for x in range(w):
            for y in range(0, randint(2, 4)):
                win.set_at((x, h - y), (0, 0, 0))

        # Add items to the world
        for x in range(w):
            isTop = True
            for y in range(h):
                color = win.get_at((x, y))
                if x == hero.x / 25 and isTop:
                    hero.y = y * 25 - 50
                if color == (210, 204, 148):
                    block.append(
                        Block(x * 25,
                              y * 25,
                              'sand',
                              True,
                              'sand_wall',
                              explored=isTop))
                    isTop = False
                elif color == (196, 112, 23):
                    block.append(
                        Block(x * 25,
                              y * 25,
                              'dirt',
                              True,
                              'dirt_wall',
                              explored=isTop))
                    isTop = False
                elif color == (122, 122, 122):
                    block.append(
                        Block(x * 25,
                              y * 25,
                              'stone',
                              True,
                              'stone_wall',
                              explored=isTop))
                    isTop = False
                elif color == (99, 78, 64):
                    wall.append(
                        Wall(x * 25, y * 25, 'dirt_wall', explored=isTop))
                elif color == (81, 81, 81):
                    wall.append(
                        Wall(x * 25, y * 25, 'stone_wall', explored=isTop))
                elif color == (158, 153, 112):
                    wall.append(
                        Wall(x * 25, y * 25, 'sand_wall', explored=isTop))
                elif color == (68, 68, 68):
                    block.append(
                        Block(x * 25,
                              y * 25,
                              'coal_ore',
                              True,
                              'stone_wall',
                              explored=isTop))
                    isTop = False
                elif color == (192, 158, 133):
                    block.append(
                        Block(x * 25,
                              y * 25,
                              'iron_ore',
                              True,
                              'stone_wall',
                              explored=isTop))
                    isTop = False
                elif color == (255, 255, 0):
                    block.append(
                        Block(x * 25,
                              y * 25,
                              'gold_ore',
                              True,
                              'stone_wall',
                              explored=isTop))
                    isTop = False
                elif color == (0, 182, 255):
                    block.append(
                        Block(x * 25,
                              y * 25,
                              'diamond_ore',
                              True,
                              'stone_wall',
                              explored=isTop))
                    isTop = False
                elif color == (0, 0, 0):
                    block.append(
                        Block(x * 25, y * 25, 'bedrock', True, explored=isTop))
                    isTop = False
                elif color == (0, 174, 0):
                    block.append(
                        Block(x * 25,
                              y * 25,
                              'grass',
                              True,
                              'dirt_wall',
                              explored=True))
                    isTop = False
                elif color == (150, 173, 150):
                    block.append(
                        Block(x * 25,
                              y * 25,
                              'tall_grass',
                              False,
                              explored=True))
                elif color == (153, 81, 9):
                    block.append(
                        Block(x * 25, y * 25, 'log', False, explored=True))
                elif color == (66, 255, 0):
                    block.append(
                        Block(x * 25, y * 25, 'leaves', False, explored=True))
                elif color == (167, 167, 167):
                    block.append(
                        Block(x * 25,
                              y * 25,
                              'cobblestone',
                              True,
                              explored=isTop))
                elif color == (255, 135, 15):
                    block.append(
                        Block(x * 25,
                              y * 25,
                              'chest',
                              True,
                              explored=isTop,
                              content=[['eye_call', 1]]))
                elif color == (255, 199, 48):
                    block.append(
                        Block(x * 25, y * 25, 'altar', True, explored=isTop))
示例#8
0
        def key_event(self, game):
            if self.left:
                if self.dx - self.Move >= -self.Max_Speed:
                    self.dx -= self.Move

            if self.right:
                if self.dx + self.Move <= self.Max_Speed:
                    self.dx += self.Move

            if self.up:
                if self.Ground and self.ladder is False:
                    self.dy -= self.Jump

            if self.left_click:
                xx, yy = game.camera.get_pos(self.rect.centerx, self.rect.centery)

                if self.inventory[self.inventory_menu_pos - 1]:
                    if self.inventory[self.inventory_menu_pos - 1][0] == 'bow' and \
                            self.bow_cooldown0 == self.bow_cooldown:
                        self.bow_cooldown0 -= 1

                        if self.remove_item(self.inventory, ['arrow', 1]):
                            game.arrow.append(Arrow(self.rect.centerx, self.rect.centery,
                                                    self.cursor[0] + game.camera.x, self.cursor[1] + game.camera.y))
                        return
                if sqrt(pow(self.cursor[0] - xx, 2) + pow(self.cursor[1] - yy, 2)) <= self.reach:
                    for e in game.enemy:
                        _x, _y = game.camera.get_pos(e.rect.x, e.rect.y)
                        if (_x < self.cursor[0] < _x + e.rect.width) and (_y < self.cursor[1] < _y + e.rect.height):
                            _dx = 8
                            e.hp -= self.damage
                            if self.inventory[self.inventory_menu_pos - 1]:
                                if self.inventory[self.inventory_menu_pos - 1][0] == 'wooden_sword':
                                    e.hp -= 0.4
                                    _dx += 2
                                elif self.inventory[self.inventory_menu_pos - 1][0] == 'stone_sword':
                                    e.hp -= 0.8
                                    _dx += 4
                                elif self.inventory[self.inventory_menu_pos - 1][0] == 'iron_sword':
                                    e.hp -= 1.2
                                    _dx += 6
                                elif self.inventory[self.inventory_menu_pos - 1][0] == 'golden_sword':
                                    e.hp -= 1.6
                                    _dx += 8
                                elif self.inventory[self.inventory_menu_pos - 1][0] == 'diamond_sword':
                                    e.hp -= 2
                                    _dx += 10
                            if type(e) not in [Eye, EyeServant, Cthulhu, Worm]:
                                if self.x < e.rect.x:
                                    e.dx += _dx
                                else:
                                    e.dx -= _dx
                                e.dy -= 5
                            del _dx
                            break
                        del _x, _y
                    else:
                        for a in game.animals['pig'] + game.animals['sheep']:
                            _x, _y = game.camera.get_pos(a.rect.x, a.rect.y)
                            if (_x < self.cursor[0] < _x + a.rect.width) and (_y < self.cursor[1] < _y + a.rect.height):

                                if (a in game.animals['sheep']) and (self.inventory[self.inventory_menu_pos - 1]) and \
                                        (self.inventory[self.inventory_menu_pos - 1][0] == 'scissors'):
                                    if a.grow_time0 == Sheep.grow_time:
                                        a.grow_time0 -= 1
                                    break

                                _dx = 8
                                a.hp -= self.damage
                                if self.inventory[self.inventory_menu_pos - 1]:
                                    if self.inventory[self.inventory_menu_pos - 1][0] == 'wooden_sword':
                                        a.hp -= self.damage * 2
                                        _dx += 2
                                    elif self.inventory[self.inventory_menu_pos - 1][0] == 'stone_sword':
                                        a.hp -= self.damage * 4
                                        _dx += 4
                                    elif self.inventory[self.inventory_menu_pos - 1][0] == 'iron_sword':
                                        a.hp -= self.damage * 6
                                        _dx += 6
                                    elif self.inventory[self.inventory_menu_pos - 1][0] == 'golden_sword':
                                        a.hp -= self.damage * 8
                                        _dx += 8
                                    elif self.inventory[self.inventory_menu_pos - 1][0] == 'diamond_sword':
                                        a.hp -= self.damage * 10
                                        _dx += 10
                                if self.x < a.rect.x:
                                    a.dx += _dx
                                else:
                                    a.dx -= _dx
                                a.dy -= 5
                                del _dx
                                break
                            del _x, _y
                        else:
                            for n in game.block:
                                if n.Visible and n.explored:
                                    _x, _y = game.camera.get_pos(n.rect.x, n.rect.y)
                                    if (_x + 1 <= self.cursor[0] <= _x + 24) and (_y + 1 <= self.cursor[1] <= _y + 24):
                                        if (n.name != 'bedrock') and (n.name != 'altar'):
                                            n.hp0 -= self.block_damage
                                            if self.inventory[self.inventory_menu_pos - 1]:
                                                _name = self.inventory[self.inventory_menu_pos - 1][0]
                                                if n.name in axe_damage:
                                                    if _name == 'wooden_axe':
                                                        n.hp0 -= self.block_damage * 0.7
                                                    elif _name == 'stone_axe':
                                                        n.hp0 -= self.block_damage * 1.1
                                                    elif _name == 'iron_axe':
                                                        n.hp0 -= self.block_damage * 1.5
                                                    elif _name == 'golden_axe':
                                                        n.hp0 -= self.block_damage * 1.9
                                                    elif _name == 'diamond_axe':
                                                        n.hp0 -= self.block_damage * 2.3
                                                if n.name in pickaxe_damage:
                                                    if _name == 'wooden_pickaxe':
                                                        n.hp0 -= self.block_damage * 0.7
                                                    elif _name == 'stone_pickaxe':
                                                        n.hp0 -= self.block_damage * 1.4
                                                    elif _name == 'iron_pickaxe':
                                                        n.hp0 -= self.block_damage * 2.1
                                                    elif _name == 'golden_pickaxe':
                                                        n.hp0 -= self.block_damage * 2.8
                                                    elif _name == 'diamond_pickaxe':
                                                        n.hp0 -= self.block_damage * 3.5
                                                if n.name in shovel_damage:
                                                    if _name == 'wooden_shovel':
                                                        n.hp0 -= self.block_damage * 0.7
                                                    elif _name == 'stone_shovel':
                                                        n.hp0 -= self.block_damage * 1.4
                                                    elif _name == 'iron_shovel':
                                                        n.hp0 -= self.block_damage * 2.1
                                                    elif _name == 'golden_shovel':
                                                        n.hp0 -= self.block_damage * 2.8
                                                    elif _name == 'diamond_shovel':
                                                        n.hp0 -= self.block_damage * 3.5
                                        break
                                    del _x, _y
                            else:
                                for n in game.wall:
                                    if n.Visible:
                                        _x, _y = game.camera.get_pos(n.x, n.y)
                                        if (_x + 1 <= self.cursor[0] <= _x + 24) and (_y + 1 <= self.cursor[1] <= _y + 24):
                                            if self.inventory[self.inventory_menu_pos - 1]:
                                                if self.inventory[self.inventory_menu_pos - 1][0] == 'wooden_hammer':
                                                    n.hp -= self.block_damage * 1.7
                                                elif self.inventory[self.inventory_menu_pos - 1][0] == 'stone_hammer':
                                                    n.hp -= self.block_damage * 2.4
                                                elif self.inventory[self.inventory_menu_pos - 1][0] == 'iron_hammer':
                                                    n.hp -= self.block_damage * 3.1
                                                elif self.inventory[self.inventory_menu_pos - 1][0] == 'golden_hammer':
                                                    n.hp -= self.block_damage * 3.8
                                                elif self.inventory[self.inventory_menu_pos - 1][0] == 'diamond_hammer':
                                                    n.hp -= self.block_damage * 4.5
                                                if n.hp <= 0:
                                                    game.wall.remove(n)
                                            break

            if self.right_click:
                xx, yy = game.camera.get_pos(self.rect.centerx, self.rect.centery)
                if sqrt(pow(self.cursor[0] - xx, 2) + pow(self.cursor[1] - yy, 2)) <= self.reach:
                    go = True
                    _x = round((self.cursor[0] + game.camera.x - 12) / 25) * 25
                    _y = round((self.cursor[1] + game.camera.y - 12) / 25) * 25

                    if (self.x - 25 < _x < self.x + 21) and (self.y - 25 < _y < self.y + 49):
                        go = False

                    _name = ''

                    if self.inventory[self.inventory_menu_pos - 1]:
                        if self.inventory[self.inventory_menu_pos - 1][1] <= 0:
                            go = False
                        else:
                            _name = self.inventory[self.inventory_menu_pos - 1][0]

                    if _name == 'bread':
                        self.inventory[self.inventory_menu_pos - 1][1] -= 1
                        go = False
                        self.hunger += 2
                    elif _name == 'mushroom_stew':
                        self.inventory[self.inventory_menu_pos - 1][1] -= 1
                        go = False
                        self.hunger += 3
                    elif _name in ['cooked_porkchop', 'cooked_fowl', 'cooked_mutton']:
                        self.inventory[self.inventory_menu_pos - 1][1] -= 1
                        go = False
                        self.hunger += 4

                    elif _name[-3:] == 'axe' or _name[-7:] == 'pickaxe' or _name[-6:] == 'shovel' or \
                            _name[-5:] == 'sword' or _name[-6:] == 'hammer' or _name == 'grown_wheat' or \
                            _name[-8:] == 'porkchop' or _name == 'arrow' or _name == 'bow' or  _name[-4:] == 'fowl' or \
                            _name[-5:] == 'ingot' or _name == 'diamond' or _name == 'iron_helmet' or \
                            _name == 'iron_chestplate' or _name == 'iron_leggings' or _name == 'iron_boots' or \
                            _name == 'eye_call' or _name[-6:] == 'mutton' or _name == 'thread' or _name == 'stick' or \
                            _name == 'scissors' or _name == 'coal':
                        go = False

                    for n in game.block:
                        if n.Visible:
                            if (n.name == 'door') and (n.rect.x == _x) and (_y - 25 <= n.rect.y <= _y):
                                go = False
                                if n.Collision:
                                    n.Collision = False
                                elif n.Collision is False:
                                    if pygame.sprite.collide_rect(self, n) == 0:
                                        n.Collision = True
                            if (n.name == 'bed') and (_x - 25 <= n.rect.x <= _x) and (n.rect.y == _y):
                                go = False

                            if ((n.name == 'trapdoor') or (n.name == 'fence')) and (n.rect.x == _x) and (_y == n.rect.y):
                                go = False
                                if n.Collision:
                                    n.Collision = False
                                elif n.Collision is False:
                                    if pygame.sprite.collide_rect(self, n) == 0:
                                        n.Collision = True

                            if (n.rect.x == _x) and (n.rect.y == _y):
                                go = False

                                if (n.name == 'altar') and (_name == 'eye_call'):
                                    self.remove_item(self.inventory, ['eye_call', 1])
                                    game.enemy.append(Eye(self.x - 800, self.y - 800))
                                    go = False

                                if n.name == 'chest':
                                    game.inventory(n.content)

                            if (_name == 'door') and (n.rect.x == _x) and (_y <= n.rect.y <= _y + 49):
                                go = False
                            if (_name == 'bed') and (n.rect.x == _x + 25) and (n.rect.y == _y):
                                go = False

                    if _name[-4:] == 'wall':
                        for n in game.wall:
                            if n.Visible:
                                if (n.x == _x) and (n.y == _y):
                                    go = False
                                    break

                    for e in game.enemy:
                        if (e.rect.x - 25 < _x < e.rect.x + 3) and (e.rect.y - 25 < _y < e.rect.y + 63):
                            go = False

                    if (_name == 'sapling') or (_name == 'wheat_seed'):
                        for q in game.block:
                            if q.Visible:
                                if (_x == q.rect.x) and (_y + 25 == q.rect.y) and (
                                        (q.name == 'dirt') or (q.name == 'grass')):
                                    break
                        else:
                            go = False
                    if _name == 'wheat_seed':
                        for q in game.animals['sheep'] + game.animals['pig']:
                            q_x, q_y = game.camera.get_pos(q.rect.x, q.rect.y)
                            if q_x < self.cursor[0] < q_x + q.rect.width and \
                                    q_y < self.cursor[1] < q_y + q.rect.height and q.active_cooldown == 0 and \
                                    q.active == type(q).active_time:
                                go = False
                                q.active = 0
                                self.inventory[self.inventory_menu_pos - 1][1] -= 1
                                break

                    if _name == 'mushroom':
                        for q in game.block:
                            if q.Visible and q.Collision:
                                if (_x == q.rect.x) and (_y + 25 == q.rect.y):
                                    break
                        else:
                            go = False

                    if go:
                        if _name == 'bed':
                            self.spawn_point.append([_x, _y - 25])
                        if _name[-4:] == 'wall':
                            self.inventory[self.inventory_menu_pos - 1][1] -= 1
                            game.wall.append(Wall(_x, _y, self.inventory[self.inventory_menu_pos - 1][0], explored=True))
                        elif _name != '':
                            self.inventory[self.inventory_menu_pos - 1][1] -= 1
                            if self.inventory[self.inventory_menu_pos - 1][0] != 'wheat_seed':
                                game.block.append(Block(_x, _y, self.inventory[self.inventory_menu_pos - 1][0],
                                                        explored=True))
                            else:
                                game.block.append(Block(_x, _y, 'wheat', explored=True))

                    del _x, _y, _name, go

            if self.k_up:
                if self.furnace_available:
                    if self.menu_pos <= len(self.furnace_available):
                        if self.add_item(self.inventory, self.furnace_available[self.menu_pos - 1][0]):
                            for rem_item in self.furnace_available[self.menu_pos - 1][1]:
                                self.remove_item(self.inventory, rem_item)
                else:
                    if self.menu_pos <= len(self.craft_available):
                        if self.add_item(self.inventory, self.craft_available[self.menu_pos - 1][0]):
                            for rem_item in self.craft_available[self.menu_pos - 1][1]:
                                self.remove_item(self.inventory, rem_item)

                self.k_up = False

            if self.k_down:
                self.k_down = False

            if self.k_left:
                self.menu_pos -= 1
                self.k_left = False

            if self.k_right:
                self.menu_pos += 1
                self.k_right = False

            if self.q:
                if self.inventory[self.inventory_menu_pos - 1]:
                    if pygame.key.get_mods() == 1:
                        self.inventory[self.inventory_menu_pos - 1][1] -= 50
                    else:
                        self.inventory[self.inventory_menu_pos - 1][1] -= 1
                self.q = False