コード例 #1
0
ファイル: labyrinth2.py プロジェクト: Torellin/PiTable
 def getWayColor(self, percent):
     return cc.interpolateBetween([[cc.getColor("material_red"), 0.0],
                                   [cc.getColor("material_darkpurple"), 1],
                                   [cc.getColor("material_blue"), 2],
                                   [cc.getColor("material_blue"), 4],
                                   [cc.getColor("material_black"), 5]],
                                  percent)
コード例 #2
0
ファイル: world.py プロジェクト: Torellin/PiTable
 def __init__(self, dy, playerColor):
     self.noise = snoise.SimplexNoise(2, 1, 3)
     self.dy = dy
     self.grassColor = colors.getColor("material_green")
     self.running = False
     self.player = Player(playerColor)
     self.obstacles = []
コード例 #3
0
ファイル: labyrinth2.py プロジェクト: Torellin/PiTable
    def render(self, display):
        display.fill(cc.getColor("material_black"))

        #for pos in self.ways:
        #    display.setPixel(pos.x, pos.y, WAY_COLOR)

        sinceStart = max(1.0, time.time() - self.startTime)
        print(sinceStart)
        n = float(len(self.stack))

        for i, pos in enumerate(self.ways):
            alpha = self.times[hash(pos)]
            #alpha = i/n

            display.setPixel(pos.x, pos.y, self.getWayColor(alpha))

        if len(self.stack) > 0:
            head = self.stack[-1]
            display.setPixel(head.x, head.y, cc.getColor("material_red"))
コード例 #4
0
ファイル: empty.py プロジェクト: Torellin/PiTable
class Empty(Block):

    COLOR = colors.getColor("material_darkbrown")

    def __init__(self):
        Block.__init__(self)

    def getType(self):
        return "empty"

    def getColor(self):
        return Empty.COLOR
コード例 #5
0
ファイル: sky.py プロジェクト: Torellin/PiTable
class Sky(Block):

    COLOR = colors.getColor("material_blue")

    def __init__(self):
        Block.__init__(self)

    def getType(self):
        return "sky"

    def getColor(self):
        return Sky.COLOR
コード例 #6
0
ファイル: ladder.py プロジェクト: Torellin/PiTable
class Ladder(Block):

    COLOR = colors.getColor("woodbrown")

    def __init__(self):
        Block.__init__(self)

    def isClimbable(self):
        return True

    def getType(self):
        return "ladder"

    def getColor(self):
        return Ladder.COLOR
コード例 #7
0
class Dirt(Block, object):

    COLOR = colors.getColor("material_brown")

    def __init__(self):
        Block.__init__(self)

    def getMaxLife(self):
        return 4

    def getType(self):
        return "dirt"

    def getBaseColor(self):
        return Dirt.COLOR
コード例 #8
0
class Stone(Block):

    COLOR = colors.getColor("material_gray")

    def __init__(self):
        Block.__init__(self)

    def getMaxLife(self):
        return 20

    def getType(self):
        return "stone"

    def getBaseColor(self):
        return Stone.COLOR
コード例 #9
0
class Grass(Block):

    COLOR = colors.getColor("material_green")

    def __init__(self):
        Block.__init__(self)

    def getMaxLife(self):
        return 3

    def getType(self):
        return "grass"

    def getBaseColor(self):
        return Grass.COLOR
コード例 #10
0
ファイル: block.py プロジェクト: Torellin/PiTable
class Block():
    emptyColor = colors.getColor("material_darkbrown")

    def __init__(self):
        self.pos = None
        self.life = self.getMaxLife()
        self.fallTimer = 0
        self.falling = False

    def setPos(self, pos):
        self.pos = pos

    def isWalkable(self):
        return self.life == 0

    def isClimbable(self):
        return False

    def addLife(self, dLife):
        self.life = max(0, self.life + dLife)

    def getLife(self):
        return self.life

    def getMaxLife(self):
        return 0

    def getDeath(self):
        return 1 - float(self.getLife()) / self.getMaxLife()

    def getColor(self):
        if self.life == self.getMaxLife():
            return self.getBaseColor()

        return colors.interpolateColor(Block.emptyColor, self.getBaseColor(),
                                       float(self.life) / self.getMaxLife())

    def getBaseColor(self):
        return [0, 0, 0]

    def getType(self):
        return "block"

    def __eq__(self, other):
        return self.pos == other.pos and self.getType() == other.getType()
コード例 #11
0
ファイル: tommyWild.py プロジェクト: Torellin/PiTable
 def __init__(self):
     Game.__init__(self, "Tommy Wild", [16, 16])
     self.fps = 10
     self.fog = Fog(colors.getColor("black"), 0.0)
     self.bloodColor = colors.getColor("red")
     self.camera = Camera(self.size)
コード例 #12
0
class Tommy(Block):

    COLOR = colors.getColor("red")
    FALL_COUNTDOWN = 0.2

    def __init__(self, world):
        Block.__init__(self)

        self.world = world
        self.movement = None
        self.sight = 2

    def update(self, dt):
        # Fall
        self.fallTimer -= dt

        if self.falling and self.fallTimer <= 0:
            self.fallCounter += 1
            self.movement = Pos(0, 1)

        currentBlock = self.world.getBlock(self.pos)
        nextBlock = self.world.getNext(self.pos, self.movement)

        # Move tommy and get action
        action = self.move(currentBlock, nextBlock)

        if action == "destroy":
            self.world.setEmpty(nextBlock.pos)

        # Check fall
        underBlock = self.world.getNext(self.pos, Pos(0, 1))
        currentBlock = self.world.getBlock(self.pos)

        if not self.falling and underBlock.getType() == "empty" \
                and not currentBlock.isClimbable():
            self.falling = True
            self.fallCounter = 0
            self.fallTimer = Tommy.FALL_COUNTDOWN

        elif self.falling and underBlock.getType() != "empty":
            self.falling = False
            dLife = max(0, self.fallCounter - 3)
            self.addLife(-dLife)

    def move(self, currentBlock, nextBlock):
        if nextBlock is None or self.movement is None:
            return "error"

        elif nextBlock.isWalkable():
            if self.movement.isKey("up") and not currentBlock.isClimbable():
                self.movement = None
                return "stuck"

            else:
                self.pos += self.movement
                #self.movement = None
                return "move"
        else:
            nextBlock.addLife(-1)

            if nextBlock.getLife() == 0:
                if self.movement.isKey("down"):
                    self.movement = None

                return "destroy"
            else:
                return "dig"

    def setSight(self, sight):
        self.sight = sight

    def getSight(self):
        return self.sight

    def setMovement(self, movement):
        self.movement = movement

    def getMaxLife(self):
        return 10

    def getType(self):
        return "tommy"

    def getColor(self):
        return Tommy.COLOR