Beispiel #1
0
    def __init__(self, window, windowWidth, windowHeight, path, xSpeed=12):

        self.window = window  # remember the window, so we can draw later
        self.windowWidth = windowWidth
        self.windowHeight = windowHeight
        self.path = path
        # ImageCollection to store Penguin sprite sheets
        self.image = pygwidgets.ImageCollection(
            window, (0, 0), {
                'image1': self.path + 'walk1.png',
                'image2': self.path + 'walk2.png',
                'image3': self.path + 'walk3.png',
                'image4': self.path + 'walk4.png',
                'image5': self.path + 'walk5.png',
                'image6': self.path + 'walk6.png'
            }, 'image1')
        # sprite sheet index
        self.index = 1

        startingRect = self.image.getRect()
        self.width = startingRect[2]  # width
        self.height = startingRect[3]  # height

        self.halfHeight = self.height / 2
        self.halfWidth = self.width / 2

        self.x = self.windowWidth / 2
        self.y = windowHeight - self.height - 20
        self.maxX = self.windowWidth - self.width
        self.image.setLoc((self.x, self.y))

        # Choose speed in the x direction
        self.xSpeed = xSpeed
Beispiel #2
0
    def __init__(self, window, rank, suit, value):
        self.window = window
        self.rank = rank
        self.suit = suit
        self.cardName = rank + ' of ' + suit
        self.value = value
        fileName = 'images/' + self.cardName + '.png'
        self.images = pygwidgets.ImageCollection(window, (0, 0), \
                        {'front': fileName, 'back': Card.BACK_OF_CARD_IMAGE}, 'back')
        self.x = 0  # some starting pos, use setLoc below to change
        self.y = 0

        self.conceal()
Beispiel #3
0
    def __init__(self, window):
        self.window = window
        self.minRow = 0
        self.maxRow = 5
        self.minCol = 0
        self.maxCol = 4
        self.hOffset = 10  # horizontal pixels to offset frog to be in center of cell
        self.vOffset = 13  # vertical pixels to offset frog to be in center of cell

        self.image = pygwidgets.ImageCollection(window, (0, 0), {
            'alive': 'images/frog.png',
            'dead': 'images/frogDead.png'
        }, 'alive')

        self.newRound(1)
Beispiel #4
0
    def __init__(self, window, loc):
        self.image = pygwidgets.ImageCollection(window, loc, {'image1':'images/Dino/f1.png',
                                                              'image2':'images/Dino/f2.png',
                                                              'image3':'images/Dino/f3.png',
                                                              'image4':'images/Dino/f4.png',
                                                              'image5':'images/Dino/f5.png',
                                                              'image6':'images/Dino/f6.png',
                                                              'image7':'images/Dino/f7.png',
                                                              'image8':'images/Dino/f8.png',
                                                              'image9':'images/Dino/f9.png',
                                                              'image10':'images/Dino/f10.png',
                                                              'image11':'images/Dino/f11.png',
                                                              'image12':'images/Dino/f12.png',
                                                              'image13':'images/Dino/f13.png',
                                                              'image14':'images/Dino/f14.png',
                                                              'image15':'images/Dino/f15.png',
                                                              'image16':'images/Dino/f16.png',
                                                              'image17':'images/Dino/f17.png'}, 'image1')

        self.rect = self.image.getRect()
        self.animating = False
Beispiel #5
0
    def __init__(self, window, rowIndex, colIndex):
        self.window = window

        # Instance variables:
        self.value = None
        self.revealed = False
        self.flagged = False

        self.rowIndex = rowIndex
        self.colIndex = colIndex
        self.x = self.colIndex * CELL_WIDTH_HEIGHT
        self.y = self.rowIndex * CELL_WIDTH_HEIGHT
        #print('x and y', self.x, self.y)
        self.rect = pygame.Rect(self.x, self.y, CELL_WIDTH_HEIGHT,
                                CELL_WIDTH_HEIGHT)
        self.images = pygwidgets.ImageCollection(window, (self.x, self.y),
                                                 Cell.imagesDict, 'tile')
        if Cell.flagSound is None:
            Cell.flagSound = pygame.mixer.Sound('sounds/flag.wav')
        if Cell.unFlagSound is None:
            Cell.unFlagSound = pygame.mixer.Sound('sounds/unflag.wav')
        if Cell.explosionSound is None:
            Cell.explosionSound = pygame.mixer.Sound('sounds/explosion.wav')
        if Cell.revealSound is None:
            Cell.revealSound = pygame.mixer.Sound('sounds/reveal.wav')
        if Cell.buzzSound is None:
            Cell.buzzSound = pygame.mixer.Sound('sounds/buzz.wav')
        if Cell.dingSound is None:
            Cell.dingSound = pygame.mixer.Sound('sounds/ding.wav')

        self.neighborsList = []
        for offset in NEIGHBOR_OFFSETS:
            neighborRow = rowIndex + offset[0]
            neighborCol = colIndex + offset[1]
            if (neighborRow >= 0) and (neighborRow < N_ROWS) and \
                (neighborCol >= 0) and (neighborCol < N_COLS):
                # Valid neighbor
                self.neighborsList.append((neighborRow, neighborCol))

        self.reset()
                                       str(nRoundsToRun),
                                       fontName='monospaces',
                                       fontSize=28,
                                       width=70,
                                       initialFocus=True)

oDiceImage = pygwidgets.Image(window, (28, 15), 'images/twoDice.png')
imagesDict = {
    1: 'images/dice1.png',
    2: 'images/dice2.png',
    3: 'images/dice3.png',
    4: 'images/dice4.png',
    5: 'images/dice5.png',
    6: 'images/dice6.png'
}
oDie1 = pygwidgets.ImageCollection(window, (630, 15), imagesDict, 1)
oDie2 = pygwidgets.ImageCollection(window, (715, 15), imagesDict, 1)

binsList = []
for diceTotalForBin in range(0, (SIDES_PER_DIE + SIDES_PER_DIE + 1)):
    oBin = Bin(window, diceTotalForBin, nRoundsToRun)
    binsList.append(oBin)

while True:
    # Handle events
    for event in pygame.event.get():
        if oQuitButton.handleEvent(event) or (event.type == pygame.QUIT):
            pygame.quit()
            sys.exit()

        # If the user presses Enter or clickes the Run Button
Beispiel #7
0
    callBack=oTest.myMethod)  # callBack here is not required

oDragger = pygwidgets.Dragger(window, (300, 200),
                              'images/dragMeUp.png',
                              'images/dragMeDown.png',
                              'images/dragMeOver.png',
                              'images/dragMeDisabled.png',
                              nickname='My Dragger')

oPythonIcon = pygwidgets.Image(window, (15, 500), 'images/pythonIcon.png')

oImageCollection = pygwidgets.ImageCollection(window, (400, 490), {
    'start': 'imageStart.jpg',
    'left': 'imageLeft.jpg',
    'right': 'imageRight.jpg',
    'up': 'imageUp.jpg',
    'down': 'imageDown.jpg'
},
                                              'start',
                                              path='images/')

oImageInstructions = pygwidgets.DisplayText(
    window, (400, 595), 'Click then type l, r, d, u, s, or Space')

oIconInstructions = pygwidgets.DisplayText(
    window, (15, 595), 'Click then up or down arrow to resize,\n' +
    'left or right arrow to rotate, \n' +
    'h or v to flip horizontal or vertical')

oFrisbeeImage = pygwidgets.Image(window, (562, 2), 'images/frisbee.png')