Ejemplo n.º 1
0
def create_alien(ai_settings, screen, aliens, alien_number, row_number):
    alien = Chicken(ai_settings, screen)
    alien_width = alien.rect.width
    alien.x = alien_width + 2 * alien_width * alien_number
    alien.rect.x = alien.x
    alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number + 30
    aliens.add(alien)
Ejemplo n.º 2
0
 def _create_chicken(self, number_of_chicken_x, row_number):
     new_chicken = Chicken(self)
     chicken_width, chicken_height = new_chicken.rect.size
     new_chicken.x = chicken_width + 2 * chicken_width * number_of_chicken_x + 20
     new_chicken.rect.x = new_chicken.x
     new_chicken.rect.y = new_chicken.rect.height * 2 + 2 * new_chicken.rect.height * row_number
     self.chickens.add(new_chicken)
Ejemplo n.º 3
0
def create_fleet(ai_settings, screen, ship, aliens):
    # Create an alien and find the number of aliens in a row
    alien = Chicken(ai_settings, screen)
    number_aliens_x = get_number_aliens_x(ai_settings, alien.rect.width)
    number_rows = get_number_rows(ai_settings, ship.rect.height,
                                  alien.rect.height)

    # Create the fleet of aliens.
    for row_number in range(number_rows):
        for alien_number in range(number_aliens_x):
            create_alien(ai_settings, screen, aliens, alien_number, row_number)
Ejemplo n.º 4
0
    def _create_fleet(self):
        new_chicken = Chicken(self)
        chicken_width, chicken_height = new_chicken.rect.size
        # get x
        available_space_x = self.settings.screen_width - (2 * chicken_width)
        number_of_chicken_x = available_space_x // (2 * chicken_width)

        # get hight ship and get y
        ship_height = self.ship.rect.height
        available_space_y = self.settings.screen_height - 5 * chicken_height - ship_height
        number_of_rows = available_space_y // (2 * chicken_height)

        # Create full chicken
        for row in range(number_of_rows):
            for column in range(number_of_chicken_x):
                self._create_chicken(column, row)
Ejemplo n.º 5
0
 def char_to_entity(self, x, y, char):
     sprite = None
     solid = None
     name = None
     if (char == 'T'):
         return Tree(x, y)
     if (char == '.'):
         sprite = Sprite.get('GRASS')
         solid = False
         name = 'grass'
     if (char == 'c'):
         sprite = Sprite.get('GRASS')
         solid = False
         name = 'grass'
         self.entities.append(Chicken(x, y))
     if (char == '~'):
         return Water(x, y)
     if (char == '"'):
         return Wheat(x, y)
     entity = Entity(x, y, name, sprite)
     entity.solid = solid
     return entity
Ejemplo n.º 6
0
def ship_hit(ai_settings, stats, sb, screen, ship, aliens, bullets,
             enemy_bullets, game_over):
    if stats.ships_left > 0:
        # Decrement ships left.
        stats.ships_left -= 1

        explosion = mixer.Sound('sounds/explosion.wav')
        explosion.play()
        # Create list to store existing aliens
        enemies = []
        for alien in aliens:
            enemies.append(alien.rect.y)

        # Update scoreboard.
        sb.prep_ships()

        # Empty the list of bullets.
        bullets.empty()
        enemy_bullets.empty()

        #Center the ship and move the aliens up.
        ship.center_ship()
        alien = Chicken(ai_settings, screen)
        print(enemies[0])
        for alien in aliens:
            alien.rect.top -= enemies[0] - 110
        aliens.update(0.18)

        # Pause.
        sleep(0.5)
    else:
        stats.ships_left = -1
        # sb.prep_ships()
        stats.game_active = False
        pygame.mouse.set_visible(True)
        game_over.over = True
        go = mixer.Sound('sounds/game_over.wav')
        go.play()
Ejemplo n.º 7
0
    def update(self, ticktime, objlist):
        self.timeSinceLastSwing += ticktime / 1000.0
        self.invincibleTimeLeft -= ticktime / 1000.0
        self.timeUntilGravChange -= ticktime / 1000.0
        GravityObject.update(self, ticktime, objlist, self.gravity)
        for obj in objlist:
            if obj.__class__.__name__ == 'Room':
                for block in obj.roomBlocks:
                    if self.respawn and block.__class__.__name__ == 'SpawnPoint':
                        self.respawn = False
                        self.changeVec((0, 0))
                        self.moveto(block.rect.center)
                    elif block.__class__.__name__ == 'Wall' and self.nextLevel and block.rect.collidepoint(
                            self.rect.centerx, self.rect.top - 4):
                        self.nextLevel = False
                        self.respawn = True
                        index = objlist.index(obj)
                        objlist[index] = Room(0, obj.floorNumber + 1)
                        if obj.floorNumber + 1 == 4:
                            self.setGravity(-1.0)
                        else:
                            self.setGravity(1.0)
                        objlist[index].show(True)
                        break
                    elif block.__class__.__name__ == 'Boss':
                        if not block.alreadyTalked:
                            self.changeVec((0, 0))
                            self.isInCutScene = True
                            block.alreadyTalked = True
                            self.__BossRoom = obj
                            self.__bossobj = block
                            obj.roomBlocks.append(
                                NpcDialog(
                                    (block.rect.centerx, block.rect.top - 200),
                                    block.nextDialogue(), self.nextBossDialog))
                    if self.isColliding(block):
                        if block.__class__.__name__ == 'Coin':
                            self.score = self.score + 100
                            block.destroy()
                            obj.roomBlocks.remove(block)
                        elif block.__class__.__name__ == 'Chicken':
                            if block.pickupDelay <= 0.0:
                                self.score = self.score + 200
                                block.destroy()
                                obj.roomBlocks.remove(block)
                        elif block.__class__.__name__ == 'Spike':
                            self.takeDamage(200)
                        elif block.__class__.__name__ == 'Spring':
                            self.addToVec(0, -800)
                            self.nextLevel = True
                            block.use()
                        elif block.__class__.__name__ == 'Button':
                            if self.timeUntilGravChange <= 0.0:
                                self.timeUntilGravChange = 2.0
                                self.setGravity(-self.gravity)
                                block.use()
                        elif block.__class__.__name__ == 'PNJ':
                            if not block.alreadyTalked and not self.upgrades.earPods:
                                self.changeVec((0, 0))
                                self.isInCutScene = True
                                obj.roomBlocks.append(
                                    NpcDialog((block.rect.centerx,
                                               block.rect.top - 10),
                                              block.getDialogue(),
                                              self.stopCutscene))

                        # test root class of enemies, to accomodate different enemy levels.
                        elif issubclass(block.__class__, Slime) or issubclass(
                                block.__class__, Bat):
                            if self.isSwingingSword:
                                # damage the enemy
                                block.takeDamage(
                                    self.upgrades.attackMultiplier)
                                if block.hp <= 0:
                                    obj.roomBlocks.append(
                                        Chicken(block.rect.center))
                                    block.destroy()
                                    obj.roomBlocks.remove(block)
                            else:
                                self.takeDamage(block.damage)
Ejemplo n.º 8
0
from chicken import Chicken
from methods import Methods

T_1_0 = 5  # oC
T_2_0 = 5  # oC
f = 0.001

boiling = Methods('Boiling')
baking = Methods('Baking')
bbqing = Methods('BBQing')

chicken_1 = Chicken()
chicken_1.prepare(T_1_0, T_2_0, boiling.T_inf, boiling.h, f)
chicken_1.cook('Boiling')

chicken_2 = Chicken()
chicken_2.prepare(T_1_0, T_2_0, baking.T_inf, baking.h, f)
chicken_2.cook('Baking')

chicken_3 = Chicken()
chicken_3.prepare(T_1_0, T_2_0, bbqing.T_inf, bbqing.h, f)
chicken_3.cook('BBQing')