Esempio n. 1
0
    def init(self):
        margin = self.width * 0.10
        pygame.font.init()

        self.score = 0

        # Ship
        Ship.init(self.width)
        self.shipGroup = pygame.sprite.Group(Ship(self.width/2, \
                                                  self.height - margin))
        col = self.width // 10
        self.enemies = pygame.sprite.Group()

        # Boss
        Boss.init(self.width, 'images/boss.png')
        wB, hB = Boss.image.get_size()
        for i in range(3, 7):
            x = i * col + wB / 2
            y = margin
            self.enemies.add(Boss(x, y))

        # Guards
        Guard.init(self.width)
        for i in range(1, 9):
            for j in range(2, 4):
                x = i * col + wB / 2 + 1  # centered based on boss
                y = margin * j
                self.enemies.add(Guard(x, y))

        # Grunts
        Grunt.init(self.width)
        for i in range(10):
            for j in range(4, 6):
                x = i * col + wB / 2 + 1  # centered based on boss
                y = margin * j
                self.enemies.add(Grunt(x, y))

        self.bullets = pygame.sprite.Group()
Esempio n. 2
0
    def init(self):
        self.introMusic = pygame.mixer.Sound('sounds/stage-intro.ogg')
        self.introTimer = 7
        self.playedIntro = False
        self.intro = True

        self.error = 3
        if self.difficulty == "easy":
            self.error = 3
        elif self.difficulty == "normal":
            self.error = 2
        elif self.difficulty == "hard":
            self.error = 1

        self.margin = self.width * 0.12
        offset = self.width * 0.07  # For alien separation
        self.time = 0

        self.score = 0
        # For score text
        self.scoreFont = pygame.font.SysFont('emulogic', 15)
        self.text = self.scoreFont.render('Score ', False, (255, 0, 0),
                                          (0, 0, 0))
        self.scoreTxt = self.scoreFont.render(str(self.score), False,
                                              (255, 255, 255), (0, 0, 0))

        # Ship
        Ship.init(self.width)
        self.startX = self.width / 2
        self.startY = self.height - self.margin
        self.shipGroup = pygame.sprite.Group(Ship(self.startX, self.startY))

        # Ship lives
        imageSize = self.shipGroup.sprites()[0].size // 2
        livesImage = pygame.transform.scale(\
                          pygame.image.load('images/ship-lives.png').convert_alpha(),\
                                           (imageSize, imageSize))
        self.shipLives = []
        for i in range(self.shipGroup.sprites()[0].lives):
            self.shipLives.append(livesImage)

        self.deathTime = 0

        # Explosions
        self.shipExpl = pygame.sprite.Group()
        self.enemyExpl = pygame.sprite.Group()
        self.shipDead = pygame.mixer.Sound('sounds/explosion.ogg')
        self.enemyDead = pygame.mixer.Sound('sounds/enemy-dead.ogg')

        self.canShoot = True
        self.divingSound = pygame.mixer.Sound('sounds/enemy-diving.ogg')
        self.respawn = True

        col = self.width // 10
        self.enemies = pygame.sprite.Group()

        # Boss
        Boss.init(self.width, 'images/boss.png')
        wB, hB = Boss.image.get_size()
        for i in range(3, 7):
            x = i * col + wB / 2
            y = self.margin
            self.enemies.add(Boss(x, y, self.difficulty))

        # Guards
        Guard.init(self.width, 'images/guard.png')
        for i in range(1, 9):
            for j in range(2, 4):
                x = i * col + wB / 2 + 1  # centered based on boss
                y = self.margin / 2 + offset * j
                self.enemies.add(Guard(x, y, self.difficulty))

        # Grunts
        Grunt.init(self.width, 'images/grunt.png')
        for i in range(10):
            for j in range(4, 6):
                x = i * col + wB / 2 + 1  # centered based on boss
                y = self.margin / 2 + offset * j
                self.enemies.add(Grunt(x, y, self.difficulty))

        self.buckets = {}
        self.midBuckets = set()  # middle of buckets
        for enemy in self.enemies:
            if isinstance(enemy, Grunt):
                enemyRect = enemy.rect
                x, y = enemyRect.topright
                cx = enemyRect.centerx
                self.buckets[x] = []
                self.midBuckets.add(cx)
        self.midBuckets = sorted(list(self.midBuckets))
        self.bucketsLst = sorted(self.buckets.keys())

        # self.flap = False

        self.shipBullets = pygame.sprite.Group()
        self.shipSound = pygame.mixer.Sound('sounds/ship-shot.ogg')
        self.enemyBullets = pygame.sprite.Group()

        stateFont = pygame.font.SysFont('emulogic', 20)

        self.gameOver = False
        self.gOMusic = pygame.mixer.Sound('sounds/game-over.ogg')
        # game over text
        self.gO = stateFont.render('GAME OVER', False, (255, 0, 0))

        self.won = False
        self.wonMusic = pygame.mixer.Sound('sounds/game-won.ogg')
        # wining text
        self.win = stateFont.render('YOU WON', False, (0, 255, 255))

        self.playedMusic = False

        self.restartFont = pygame.font.SysFont('emulogic', 15)
        self.restartTxt = self.restartFont.render("Press 'R' to restart.", False, \
                        (255,0,0))
        self.displayTxt = True
Esempio n. 3
0
    def init(self):
        pygame.font.init()
        self.state = "start"

        # Start state

        self.logo = pygame.transform.scale(pygame.image.load('images/galaga-logo.png').convert_alpha(), \
                (int(self.height/2), int(self.width/2)))
        startFont = pygame.font.SysFont('emulogic', 15)
        self.startTxt = startFont.render("Press 'SPACE' to start.", False, \
                        (0,255,255))
        self.displayTxt = True

        # Game state
        margin = self.width * 0.12
        offset = self.width * 0.07 # For alien separation
        self.time = 0

        self.score = 0
        # For score text
        self.scoreFont = pygame.font.SysFont('emulogic', 15)
        self.text = self.scoreFont.render('Score ', False, (255,0,0), (0,0,0))
        self.scoreTxt = self.scoreFont.render(str(self.score), False, (255,255,255), (0,0,0))

        # Ship
        Ship.init(self.width)
        self.startX = self.width/2
        self.startY = self.height - margin
        self.shipGroup = pygame.sprite.Group(Ship(self.startX, self.startY))

        col = self.width//10
        self.enemies = pygame.sprite.Group()

        # Boss
        Boss.init(self.width, 'images/boss.png')
        wB, hB = Boss.image.get_size()
        for i in range(3, 7):
            x = i * col + wB/2
            y = margin
            self.enemies.add(Boss(x, y))

        # Guards
        Guard.init(self.width)
        for i in range(1, 9):
            for j in range(2, 4):
                x = i * col + wB/2 + 1 # centered based on boss
                y = margin/2 + offset * j
                self.enemies.add(Guard(x, y))

        # Grunts
        Grunt.init(self.width)
        for i in range(10):
            for j in range(4, 6):
                x = i * col + wB/2 + 1 # centered based on boss
                y = margin/2 + offset * j
                self.enemies.add(Grunt(x, y))

        self.shipBullets = pygame.sprite.Group()
        self.enemyBullets = pygame.sprite.Group()

        stateFont = pygame.font.SysFont('emulogic', 20)

        self.gameOver = False
        # game over text
        self.gO = stateFont.render('GAME OVER', False, (255, 0, 0))
        self.won = False
        # wining text
        self.win = stateFont.render('YOU WON', False, (0,255,255))