Пример #1
0
    def isShot(self, pos):
        x1, y1 = self.position
        x2, y2 = pos
        frameX, frameY = FRAME_SIZE

        # If the duck is already dead or flying off, they can't be shot
        if self.flyOff or self.isDead:
            return False

        # If shot was outside the duck image
        if x2 < x1 or x2 > (x1 + frameX):
            return False
        if y2 < y1 or y2 > (y1 + frameY):
            return False

        # Prepare for the fall
        self.isDead = True
        self.justShot = True
        self.frame = 1
        self.dx, self.dy = adjpos (0, 4)
        return True
Пример #2
0
    def changeDirection(self):
        surface = self.registry.get('surface')
        round = self.registry.get('round')
        frameWidth, frameHeight = FRAME_SIZE
        speedRange = range(4+round, 6+round)
        x, y = self.position
        coinToss = 1 if random.randint(0, 1) else -1

        # Only update on key frames
        if not self.frame == 0:
            return

        # Set flyoff
        if self.flyOff:
            self.dx, self.dy = adjpos (0, -4)
            return

        # Die!
        if self.isDead:
            self.dx, self.dy = adjpos (0, 4)
            return

        # At the left side of the screen
        if x <= 0:
            while True:
                self.dx = random.choice(speedRange)
                self.dy = random.randint(-4, 4)
                self.dx, self.dy = adjpos (self.dx, self.dy)
                if not self.dy == 0:
                    break

        # At the right side of the screen
        elif (x + frameWidth) > surface.get_width():
            while True:
                self.dx = random.choice(speedRange) * -1
                self.dy = random.randint(-4, 4)
                self.dx, self.dy = adjpos (self.dx, self.dy)
                if not self.dy == 0:
                    break

        # At the top of the screen
        elif y <= 0:
            while True:
                self.dx = random.choice(speedRange) * coinToss
                self.dy = random.randint(2, 4)
                self.dx, self.dy = adjpos (self.dx, self.dy)
                if not self.dx == 0:
                    break

        # At the bottom of the screen
        elif y > (surface.get_height() / 2):
            while True:
                self.dx = random.choice(speedRange) * coinToss
                self.dy = random.randint(-4, -2)
                self.dx, self.dy = adjpos (self.dx, self.dy)
                if not self.dx == 0:
                    break

        # Reverse image if duck is flying opposite direction
        if self.dx < 0 and not self.imageReversed:
            self.imageReversed = True
        elif self.dx > 0 and self.imageReversed:
            self.imageReversed = False
Пример #3
0
import os, time
import pygame
import sounds
from registry import adjpos, adjrect, adjwidth, adjheight
from gun import Gun
from duck import Duck

DOG_POSITION = adjpos(250, 350)
DOG_FRAME = adjpos(122, 110)
DOG_REPORT_POSITION = adjpos(450, 325)
DOG_LAUGH_RECT = adjrect(385, 120, 80, 85)
DOG_ONE_DUCK_RECT = adjrect(650, 0, 100, 100)
DOG_TWO_DUCKS_RECT = adjrect(630, 115, 120, 100)
HIT_POSITION = adjpos(245, 440)
HIT_RECT = adjrect(0, 0, 287, 43)
HIT_DUCK_POSITION = adjpos(329, 445)
HIT_DUCK_WHITE_RECT = adjrect(218, 44, 18, 15)
HIT_DUCK_RED_RECT = adjrect(200, 44, 18, 15)
SCORE_POSITION = adjpos(620, 440)
SCORE_RECT = adjrect(69, 43, 130, 43)
FONT = os.path.join('media', 'arcadeclassic.ttf')
FONT_STARTING_POSITION = adjpos(730, 442)
FONT_GREEN = 154, 233, 0
FONT_BLACK = 0, 0, 0
FONT_WHITE = 255, 255, 255
ROUND_POSITION = adjpos(60, 410)
SHOT_BG_POSITION = adjpos(60, 440)
SHOT_POSITION = adjpos(60, 440)
SHOT_RECT = adjrect(0, 43, 70, 43)
BULLET_RECT = adjrect(200, 59, 13, 17)
NOTICE_POSITION = adjpos(370, 120)
Пример #4
0
import os, sys, random
import pygame
import states
from registry import adjpos, adjrect, adjwidth, adjheight

FRAME_SIZE = adjpos (81, 75)
XOFFSET, YOFFSET = adjpos (250, 225)
FLYOFF_YOFFSET = YOFFSET + adjheight (155)
FALL_YOFFSET = YOFFSET + adjheight (235)

class Duck(object):

    def __init__(self, registry):
        self.registry = registry
        self.imageReversed = False
        self.isDead = False
        self.isFinished = False
        self.flyOff = False
        self.sprites = registry.get('sprites')
        self.rsprites = registry.get('rsprites')

        # Animation
        self.animationDelay = 8
        self.frame = 0
        self.animationFrame = 0
        self.justShot = False

        # Find a starting position
        surface = registry.get('surface')
        x = random.choice([0, surface.get_width()])
        y = random.randint(0, surface.get_height() / 2)
Пример #5
0
import os, time
import pygame
import sounds
from registry import adjpos, adjrect, adjwidth, adjheight
from gun import Gun
from duck import Duck

DOG_POSITION = adjpos (250, 350)
DOG_FRAME = adjpos (122, 110)
DOG_REPORT_POSITION = adjpos (450, 325)
DOG_LAUGH_RECT = adjrect (385, 120, 80, 85)
DOG_ONE_DUCK_RECT = adjrect (650, 0, 100, 100)
DOG_TWO_DUCKS_RECT = adjrect (630, 115, 120, 100)
HIT_POSITION = adjpos (245, 440)
HIT_RECT = adjrect (0, 0, 287, 43)
HIT_DUCK_POSITION = adjpos (329, 445)
HIT_DUCK_WHITE_RECT = adjrect (218, 44, 18, 15)
HIT_DUCK_RED_RECT = adjrect (200, 44, 18, 15)
SCORE_POSITION = adjpos (620, 440)
SCORE_RECT = adjrect (69, 43, 130, 43)
FONT = os.path.join('media', 'arcadeclassic.ttf')
FONT_STARTING_POSITION = adjpos (730, 442)
FONT_GREEN = 154, 233, 0
FONT_BLACK = 0, 0, 0
FONT_WHITE = 255, 255, 255
ROUND_POSITION = adjpos (60, 410)
SHOT_BG_POSITION = adjpos (60, 440)
SHOT_POSITION = adjpos (60, 440)
SHOT_RECT = adjrect (0, 43, 70, 43)
BULLET_RECT = adjrect (200, 59, 13, 17)
NOTICE_POSITION = adjpos (370, 120)