Example #1
0
    def __init__(self,
                 datafiles,
                 data,
                 taps,
                 *args,
                 num=(1, 10),
                 offset=0,
                 **kargs):
        super().__init__(*args, **kargs)
        self.tapid = None
        self._parent = kargs["parent"]
        self.offset = offset
        self.ITEMSIZE = 64
        self.BW = 3
        self.bg = SpriteNode(
            size=((num[0] * (self.ITEMSIZE + self.BW)) + self.BW,
                  (num[1] * (self.ITEMSIZE + self.BW)) + self.BW),
            parent=self)  # dont know why i cant use selfs sprite stuff
        self.bg.anchor_point = (0, 0)
        self.size = ((num[0] * (self.ITEMSIZE + self.BW)) + self.BW,
                     (num[1] * (self.ITEMSIZE + self.BW)) + self.BW)

        self.data = data  # for geting data
        self.taps = taps  # for tap events

        self.__hide = False
        self.datafiles = datafiles
        self.id = 1
        self.size = num
        self.drager = SpriteNode()
        self.other = None
        self.icons = []
        self.counts = []
        self.tapslot = False
        self.data.items_load(self.id, self.size[0] * self.size[1])
        print(self.data.items, "l")

        for x in range(int(self.size[0])):
            for y in range(int(self.size[1])):
                i = y + (int(x * self.size[1]))
                ii = int(self.get_item(i)[0])
                t = self.datafiles.block[ii]
                self.icons.append(
                    SpriteNode(
                        t,
                        parent=self,
                        position=(x * (self.ITEMSIZE + self.BW) + self.BW,
                                  y * (self.ITEMSIZE + self.BW) + self.BW),
                        size=(self.ITEMSIZE, self.ITEMSIZE)))
                self.icons[-1].anchor_point = (0, 0)

                self.counts.append(
                    LabelNode(
                        str(int(self.get_item(i)[1])),
                        parent=self,
                        position=(x * (self.ITEMSIZE + self.BW) + self.BW,
                                  y * (self.ITEMSIZE + self.BW) + self.BW),
                    ))
                self.counts[-1].anchor_point = (0, 0)
 def __init__(self):
     a = SpriteNode('plf:BG_Colored_grass', parent=self)
     a.name = 'background'
     b = SpriteNode('plf:AlienBeige_swim2', parent=a)
     b.name = 'player'
     c = SpriteNode('plf:HudKey_yellow', parent=b)
     c.name = 'key'
Example #3
0
    def __init__(self, **kwargs):
        SpriteNode.__init__(self, 'rsc/hedgehog.png', **kwargs)
        self.size = (70, 70)
        self.color = '#337aff'
        self.dead = False
        self.death_flash_frames = 4
        self.cur_dff = 0
        self.x_scale = -1
        self.gravity = .25
        self.y_vel = 0
        self.x_vel = 0
        self.y_vel_max_up = 12
        self.y_vel_max_down = 15
        self.flap_speed = 6

        self.reset()
Example #4
0
 def __init__(self, *args, **kargs):
     super().__init__(*args, **kargs, num=(10, 1))
     self.select = SpriteNode(Texture('emj:Anger_Symbol'),
                              position=(0, 0),
                              size=(75, 69),
                              parent=self)
     self.select.anchor_point = (0, 0)
     self.select.alpha = 0.95
     self.select.position = (self.BW, self.BW)
     self.holding = 0
Example #5
0
	def __init__(self, scene_size):
		
		self.r1img = 'plf:Ground_GrassMid'
		self.r2img = 'plf:BG_Colored_grass'
		
		self.row1 = Node(parent=self, position=(0,0))
		self.row2 = Node(parent=self, position=(0,64))
		
		self.row1.anchor_point = (0,0)
		self.row2.anchor_point = (0,0)
		
		self.row1.z_position = -50
		self.row2.z_position = -100
		
		self.r1size = 64
		self.r2size = 512
		
		self.row1.scale = 2
		self.row2.scale = 1
		
		#self.row1scale = 0.5
		#self.row2scale = 0.1
		self.row1scale = 10
		self.row2scale = 3
		
		for x in range(0, round(scene_size.width) + self.r1size, self.r1size):
			r1 = SpriteNode(self.r1img, position=(x, self.row1.position.y))
			r1.anchor_point = (0,0)
			self.row1.add_child(r1)
		for x in range(0,round(scene_size.width) + self.r2size, self.r2size):
			r2 = SpriteNode(self.r2img, position=(x, self.row2.position.y))
			r2.anchor_point = (0,0)
			self.row2.add_child(r2)
Example #6
0
    def __init__(self, *args, **kargs):
        kargs["size"] = (250, 250)
        kargs["position"] = (0, 0)
        super().__init__(Texture('resorces/dpad.PNG'), *args, **kargs)

        self.anchor_point = (0, 0)
        self.alpha = 0.95

        self.middle = SpriteNode(Texture('resorces/dstick.PNG'),
                                 position=self.size / 2,
                                 size=(50, 50),
                                 parent=self)
        self.middle.alpha = 0.9
        self.value = Vector2(0, 0)
Example #7
0
    def __init__(self, scene_size):
        self.gap = 150
        px, py = (scene_size.width,
                  random.randint(
                      Pipe.blocksize / 2,
                      scene_size.height - (Pipe.blocksize / 2 + self.gap)))
        self.position = (px, py)
        self.img = 'plf:Tile_BoxCrate_double'

        # space from the opening to the top and bottom
        self.pbottomh = math.ceil(py)
        self.ptoph = math.ceil(scene_size.h - (py + self.gap))

        ny = 0
        for i in range(ny, ny - self.pbottomh, Pipe.blocksize * -1):
            n = SpriteNode(self.img, position=(0, i))
            n.anchor_point = (0, 1)
            self.add_child(n)

        ny = self.gap + Pipe.blocksize
        for i in range(ny, ny + self.ptoph, Pipe.blocksize):
            n = SpriteNode(self.img, position=(0, i))
            n.anchor_point = (0, 1)
            self.add_child(n)
Example #8
0
class ItemMenu(SpriteNode):
    def __init__(self,
                 datafiles,
                 data,
                 taps,
                 *args,
                 num=(1, 10),
                 offset=0,
                 **kargs):
        super().__init__(*args, **kargs)
        self.tapid = None
        self._parent = kargs["parent"]
        self.offset = offset
        self.ITEMSIZE = 64
        self.BW = 3
        self.bg = SpriteNode(
            size=((num[0] * (self.ITEMSIZE + self.BW)) + self.BW,
                  (num[1] * (self.ITEMSIZE + self.BW)) + self.BW),
            parent=self)  # dont know why i cant use selfs sprite stuff
        self.bg.anchor_point = (0, 0)
        self.size = ((num[0] * (self.ITEMSIZE + self.BW)) + self.BW,
                     (num[1] * (self.ITEMSIZE + self.BW)) + self.BW)

        self.data = data  # for geting data
        self.taps = taps  # for tap events

        self.__hide = False
        self.datafiles = datafiles
        self.id = 1
        self.size = num
        self.drager = SpriteNode()
        self.other = None
        self.icons = []
        self.counts = []
        self.tapslot = False
        self.data.items_load(self.id, self.size[0] * self.size[1])
        print(self.data.items, "l")

        for x in range(int(self.size[0])):
            for y in range(int(self.size[1])):
                i = y + (int(x * self.size[1]))
                ii = int(self.get_item(i)[0])
                t = self.datafiles.block[ii]
                self.icons.append(
                    SpriteNode(
                        t,
                        parent=self,
                        position=(x * (self.ITEMSIZE + self.BW) + self.BW,
                                  y * (self.ITEMSIZE + self.BW) + self.BW),
                        size=(self.ITEMSIZE, self.ITEMSIZE)))
                self.icons[-1].anchor_point = (0, 0)

                self.counts.append(
                    LabelNode(
                        str(int(self.get_item(i)[1])),
                        parent=self,
                        position=(x * (self.ITEMSIZE + self.BW) + self.BW,
                                  y * (self.ITEMSIZE + self.BW) + self.BW),
                    ))
                self.counts[-1].anchor_point = (0, 0)
        #self.hide = True

    @property
    def hide(self):
        return self.__hide

    @hide.setter
    def hide(self, h):
        if h:
            self.remove_from_parent()
            self.taps.layer(self.tapid, -1)
        else:
            self._parent.add_child(self)
            self.taps.layer(self.tapid, 1)

        self.__hide = h

    def touch_began(self, t):
        point = self.point_from_scene(self.taps.touchb.location)
        for i, j in enumerate(self.icons):
            if point in j.bbox:
                item = self.get_item(i)
                if item[0]:
                    self.drager.position = point
                    self.drager.texture = self.datafiles.block[item[0]]
                    self.drager.size = (64, 64)

                    #find slot
                    self.tapslot = i + 1  # the index of the box tapped, need to know for when it is dropped

    def drag(self, touch):  # remove var pass

        if self.tapslot:
            self.add_child(self.drager)
            self.drager.z_position = 10
            self.drager.position = self.point_from_scene(
                touch.location)  # point -> scene

    def drop(self, touch, other):
        self.drager.remove_from_parent()
        if self.tapslot:
            start = self.tapslot - 1
            self.tapslot = False
            pos = other.point_from_scene(touch.location)
            for i, j in enumerate(other.icons):
                if pos in j.bbox:
                    end = i
                    items = [self.get_item(start), other.get_item(end)]
                    break
            else:
                return

            if items[0][0] == items[1][
                    0]:  # if the items are the same we move as much as we can over, else we just swap
                if items[0][1] + items[1][1] != 255 * 2:
                    total = items[0][1] + items[1][1]
                    if total > 255:
                        self.set_item(start, id=items[0][0], value=total % 255)
                        other.set_item(end, id=items[0][0], value=255)
                    else:
                        self.set_item(start, id=0, value=0)
                        other.set_item(end, id=items[0][0], value=total)

            else:
                self.set_item(start, id=items[1][0], value=items[1][1])
                other.set_item(end, id=items[0][0], value=items[0][1])

            #self.icons[start].texture = self.datafiles.block[self.get_item(start)[0]]
            #self.icons[start].size = (64, 64)
            #self.counts[start].text = str(self.get_item(start)[1]) # todo

            #other.icons[end].texture = self.datafiles.block[other.get_item(end)[0]]
            #other.icons[end].size = (64, 64)
            #other.counts[end].text = str(other.get_item(end)[1])

    def _refresh(self, address):
        self.icons[address].texture = self.datafiles.block[self.get_item(
            address)[0]]
        self.icons[address].size = (64, 64)
        self.counts[address].text = str(self.get_item(address)[1])

    def set_item(self, address, id=None, value=None):  # todo
        address += self.offset
        if value is not None:
            self.data.items[self.id][2 * address + 1] = value
            if not value:
                self.data.items[self.id][2 * address] = 0
        if id is not None:
            self.data.items[self.id][2 * address] = id
        self._refresh(address - self.offset)

    def get_item(self, address):  #todo
        address += self.offset
        return self.data.items[self.id][2 * address], self.data.items[self.id][
            2 * address + 1]
Example #9
0
 def __init__(self, caller, msg, img):
     Scene.__init__(self)
     self.msg = msg
     self.caller = caller
     self.img = SpriteNode(Texture(img))
Example #10
0
    def setup(self):
        print("setup")
        #self.bace = self
        self.zize = (1, 1)
        self.bace = Node(parent=self, position=(0, 0))
        self.bace.size = Vector2(1024, 768)
        self.tsize = Vector2(1024, 768)
        self.zize = Vector2(self.size[0] / 1024, self.size[1] / 768)
        self.bace.x_scale = self.size[0] / 1024
        self.bace.y_scale = self.size[1] / 768

        self.tiles = tile_shader.TileShader(parent=self.bace, data=self.data)
        self.data.player.newplayer()
        self.hotbar = inputs.HotBar(self.datafiles,
                                    self.data,
                                    self.taps,
                                    parent=self.bace,
                                    position=(300, 14))
        self.invintory = inputs.ItemMenu(self.datafiles,
                                         self.data,
                                         self.taps,
                                         num=(9, 4),
                                         parent=self.bace,
                                         position=(300, 80),
                                         offset=10)
        self.hotbar.other = self.invintory
        self.invintory.other = self.hotbar
        self.ham = SpriteNode(Texture("iow:arrow_right_b_256"),
                              parent=self.bace,
                              position=self.hotbar.bbox.origin +
                              self.hotbar.bbox.size)
        self.ham.anchor_point = (0.3, 0.75)
        self.ham.x_scale = 0.5
        self.ham.y_scale = 0.5
        self.invintory.anchor_point = (0, 0)

        self.select = SpriteNode(Texture('emj:Anger_Symbol'),
                                 position=(0, 0),
                                 size=(75, 69),
                                 parent=self.bace)
        self.select.anchor_point = (1, 0)
        self.select.alpha = 0.95

        self.directionpad = inputs.DPad(parent=self.bace)

        self.cash = LabelNode(str(self.data.player.cash),
                              position=(0, self.bace.size[1]),
                              parent=self.bace)
        self.cash.anchor_point = (0, 1)

        self.player = SpriteNode(Texture('emj:Hamster_Face'),
                                 position=self.bace.size / 2,
                                 size=(20, 20),
                                 parent=self.bace)

        self.HOTBAR = self.taps.add(self.hotbar.bbox)
        self.INV = self.taps.add(self.invintory.bbox)
        self.DPAD = self.taps.add(self.directionpad.bbox)
        self.CASH = self.taps.add(self.cash.bbox)
        self.HAM = self.taps.add(self.ham.bbox, layer=2)

        self.invintory.tapid = self.INV

        self.taps.size = self.size
        self.taps.zize = self.tsize

        if self.init:
            self.setupinit = True
        if self.lan:
            self.data.loop()
        self.invintory.hide = True
        self.tiles._refresh()
Example #11
0
 def __init__(self, **kargs):
     SpriteNode.__init__(self, 'plf:HudX', **kargs)
     self.scale = 0.5
Example #12
0
 def __init__(self, **kargs):
     SpriteNode.__init__(self, **kargs)
     self.anchor_point = (0, 0)
     self.color = '#8989ff'
Example #13
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     tex = SpriteNode(explosion, parent=self, x_scale=2, y_scale=2)
     self.run_action(Action.sequence(Action.wait(0.5), Action.remove()))