示例#1
0
文件: game.py 项目: sroskom/umbrella
class Bird(Sprite):
    def __init__(self, pos):
        super(Bird, self).__init__(
            source='atlas://images/flappybird_tutorial/bird_anim/wing-up',
            pos=pos)
        self.boundingbox = Widget()
        self.velocity_y = 0
        self.gravity = -.1 * params.scale

    def update(self):
        self.velocity_y += self.gravity
        self.veloctiy_y = max(self.velocity_y, -5 * params.scale)
        self.y += self.velocity_y
        if self.velocity_y < -5 * params.scale:
            self.source = 'atlas://images/flappybird_tutorial/bird_anim/wing-up'
        elif self.velocity_y < 0:
            self.source = 'atlas://images/flappybird_tutorial/bird_anim/wing-mid'

    def on_touch_down(self, *ignore):
        self.velocity_y = 3 * params.scale
        self.source = 'atlas://images/flappybird_tutorial/bird_anim/wing-down'
        sfx_flap.play()

    def collide_widget(self, widget, *args, **kwargs):
        default = super(Bird, self).collide_widget(widget, *args, **kwargs)
        self.boundingbox.size = [
            self.size[0] * (2.0 / 3.0), self.size[1] * (1.0 / 3.0)
        ]
        self.boundingbox.pos = [
            self.pos[0] + ((self.size[0] * (1.0 / 3.0)) - 4),
            self.pos[1] + (self.size[1] * (1.0 / 3.0))
        ]
        return self.boundingbox.collide_widget(widget)
示例#2
0
def placeTower(*args):
    '''Places a tower at location of the touch'''
    parentPos = Map.mapvar.background.to_parent(*args[1])
    pos = args[1]
    towerselected = args[0].instance
    sufficient_funds = True if towerselected.cost <= Player.player.money else False
    if sufficient_funds == False:
        Messenger.messenger.createMessage("Not Enough Money")
    collide = None
    towerWidget = Widget(pos=parentPos,
                         size=(Map.mapvar.squsize * 2 - 1,
                               Map.mapvar.squsize * 2 - 1))
    for wall in Map.mapvar.wallcontainer.children:
        if towerWidget.collide_widget(wall):
            print towerWidget.pos, wall.pos, wall.size
            collide = wall
            Messenger.messenger.createMessage("Can't Overlap")

    if sufficient_funds and not collide:
        newTower = eval(towerselected.type + "Tower." + towerselected.type +
                        towerselected.base)(pos)
        Player.player.analytics.moneySpent += newTower.cost
        Map.mapvar.towercontainer.add_widget(newTower)
        Player.player.towerSelected = None
        return newTower
示例#3
0
class Platform(Widget):
    colorList = ListProperty([1, 1, 1, 1])
    blockWidth = NumericProperty(1)
    blockHeight = NumericProperty(1)
    blockArea = ReferenceListProperty(blockWidth, blockHeight)
    blockPos_x = NumericProperty(0)
    blockPos_y = NumericProperty(0)
    blockPos = ReferenceListProperty(blockPos_x, blockPos_y)

    def setup(self, size_x, size_y, pos_x, pos_y):
        self.blockWidth = size_x
        self.blockHeight = size_y
        self.blockPos_x = pos_x
        self.blockPos_y = pos_y

    def resize(self, blockSize):
        self.size = blockSize * Vector(self.blockArea)
        self.pos = blockSize * Vector(self.blockPos)

    def repos(self, blockSize):
        self.pos = blockSize * Vector(self.blockPos)

    def testCollide(self, testObject, blockSize, dy):
        w1 = self.blockWidth
        h1 = 1.0 / blockSize
        x1 = self.blockPos_x
        y1 = self.blockPos_y + self.blockHeight - h1
        w2 = testObject.blockWidth
        h2 = abs(dy)
        x2 = testObject.blockPos_x
        y2 = testObject.blockPos_y + dy
        self.tempWid1 = Widget(size=(w1, h1), pos=(x1, y1))
        self.tempWid2 = Widget(size=(w2, h2), pos=(x2, y2))
        if self.tempWid1.collide_widget(
                self.tempWid2) and testObject.crouchTime < 20:
            testObject.onGround = 1
            testObject.groundHeight = self.blockPos_y + self.blockHeight
        self.remove_widget(self.tempWid1)
        self.remove_widget(self.tempWid2)

    def remove(self):
        self.parent.remove_widget(self)
示例#4
0
class Wall(Widget):
    colorList = ListProperty([1, 1, 0, 1])
    blockWidth = NumericProperty(1)
    blockHeight = NumericProperty(1)
    blockArea = ReferenceListProperty(blockWidth, blockHeight)
    blockPos_x = NumericProperty(0)
    blockPos_y = NumericProperty(0)
    blockPos = ReferenceListProperty(blockPos_x, blockPos_y)

    def setup(self, size_x, size_y, pos_x, pos_y):
        self.blockWidth = size_x
        self.blockHeight = size_y
        self.blockPos_x = pos_x
        self.blockPos_y = pos_y

    def resize(self, blockSize):
        self.size = blockSize * Vector(self.blockArea)
        self.pos = blockSize * Vector(self.blockPos)

    def repos(self, blockSize):
        self.pos = blockSize * Vector(self.blockPos)

    def testCollide(self, testObject, blockSize, dy, dx):
        self.tempWid = Widget(size=(self.blockWidth, self.blockHeight),
                              pos=(self.blockPos_x, self.blockPos_y))
        if dy > 0:
            w1 = testObject.blockWidth - 2.0 / blockSize
            h1 = dy
            x1 = testObject.blockPos_x + 1.0 / blockSize
            y1 = testObject.blockPos_y + testObject.blockHeight
        if dy <= 0:
            w1 = testObject.blockWidth - 2.0 / blockSize
            h1 = abs(dy)
            x1 = testObject.blockPos_x + 1.0 / blockSize
            y1 = testObject.blockPos_y + dy
        self.tempWid1 = Widget(size=(w1, h1), pos=(x1, y1))
        if self.tempWid.collide_widget(self.tempWid1):
            if dy > 0:
                testObject.velocity_y = 0
                testObject.blockPos_y = self.blockPos_y - testObject.blockHeight
            elif dy <= 0:
                testObject.onGround = 1
                testObject.groundHeight = self.blockPos_y + self.blockHeight
                testObject.blockPos_y = testObject.groundHeight

        if dx > 0:
            w2 = dx
            h2 = testObject.blockHeight - 2.0 / blockSize
            x2 = testObject.blockPos_x + testObject.blockWidth
            y2 = testObject.blockPos_y + 1.0 / blockSize
        if dx <= 0:
            w2 = abs(dx)
            h2 = testObject.blockHeight - 2.0 / blockSize
            x2 = testObject.blockPos_x + dx
            y2 = testObject.blockPos_y + 1.0 / blockSize
        self.tempWid2 = Widget(size=(w2, h2), pos=(x2, y2))
        if self.tempWid.collide_widget(self.tempWid2):
            if dx > 0:
                testObject.velocity_x = 0
                testObject.blockPos_x = self.blockPos_x - testObject.blockWidth
            elif dx <= 0:
                testObject.velocity_x = 0
                testObject.blockPos_x = self.blockPos_x + self.blockWidth
        if self.text == "kill" and (self.tempWid.collide_widget(
                self.tempWid1) or self.tempWid.collide_widget(self.tempWid2)):
            try:
                testObject.kill()
            except Exception as e:
                print(e)
        self.remove_widget(self.tempWid1)
        self.remove_widget(self.tempWid2)
        self.remove_widget(self.tempWid)

    def remove(self):
        self.parent.remove_widget(self)