예제 #1
0
def game():
    """Run the game

  :postcondition: calls helper functions to run the game
  :return: string of text
  """
    print("""
    You wake up one day in an open field.
    \"Where am I?\" you wondered. Suddenly,
    you hear a booming voice, \"You have commited
    the highest level of treason. You have forgotten
    to feed the almighty cat this lunch. For this you
    must attone for you sins and collect ten bags of
    kibble...\"
      """)

    input(colors.green("Enter any key to continue...\n"))
    player_health = 10
    coord = [2, 2]
    map_grid.map_draw(coord)
    enemies_killed = 0
    kibble = 0

    while enemies_killed != 10:
        player_health, killed, kibble_gained = map_grid.map_board(coord, player_health)
        enemies_killed += killed
        kibble += kibble_gained
        print(colors.green(enemies_killed))

    boss.boss(player_health, kibble)
    print("""
    Exhausted from the fight you decide to take a break 
    and take a nap on the field. You awake in your bedroom
    and you hear your cat meowing outside. You check the time, 
    it's her lunch time, so you quickly rush out to feed her. 
    While pouring the kibble you wonder, \"Was that all just a dream...\"
  """)
예제 #2
0
 def fight (self,isboss):
     fight_handler = Fight()
     a = True
     #This is the natural regeneration... it only happens when you go into combat, so you can't abuse it by walking between already/cleared areas
     self.my_adventurer.regenerate()
     
     if isboss == False :
         monster = Monster(self.my_adventurer.level)
     elif isboss == True:
         monster = boss(self.my_adventurer.level)
     
     if self.my_adventurer.current_hp > 0 :
         
         a =  fight_handler.fight_calcuation(self.my_adventurer, monster)
         if a ==False :
             quit() 
     else :
         print "You shouldn't see this ever..."
예제 #3
0
def component(df, bill_components):

    #df = component_type(df, bill_components)
    df = connection_type(df, bill_components)
    df = end_forms(df, bill_components)

    df = sleeve.sleeve(df, bill_components, comp_sleeve)
    df = adaptor.adaptor(df, bill_components, comp_adaptor)
    df = boss.boss(df, bill_components, comp_boss)
    df = elbow.elbow(df, bill_components, comp_elbow)
    df = float_.float_(df, bill_components, comp_float)
    df = hfl.hfl(df, bill_components, comp_hfl)
    df = nut.nut(df, bill_components, comp_nut)
    #df = other.other(df, bill_components, comp_other)
    df = straight.straight(df, bill_components, comp_straight)
    df = tee.tee(df, bill_components, comp_tee)
    df = threaded.threaded(df, bill_components, comp_threaded)

    return df
예제 #4
0
level1.makeLevel()
element = [
    'projectiles/fireProj.png', 'projectiles/iceProj.png',
    'projectiles/lightProj.png'
]
magic = pygame.sprite.Group()
obstacles = level1.boxes
obstacleGroup = pygame.sprite.Group()
for spr in level1.boxes:
    allSprites.add(spr)
    obstacleGroup.add(spr)
player = player.player('Character/DownAnim/Down2.png', obstacles,
                       (width / 2, height - 50))
#allSprites.add(player)   =>  removed to implement flashing invincibility => created by Steven Goodchild
heroGroup = pygame.sprite.Group(player)
boss1 = boss.boss('Enemies/orc.png', (400, 32 + 64), [], player)
for Enemy in enemies:
    Enemy.target = player
    allSprites.add(Enemy)
    Enemy.enemies = enemies
enemyGroup = pygame.sprite.Group(enemies)
bossBulletTarget = [player]
bulletLoops = 0
bossGroup.add(boss1)
bosses.append(boss1)

#-----------------------Load images-----------------------
img = pygame.image.load('images/bot_wall.jpg').convert()
wallDown = pygame.image.load('images/Side_Walls_05.jpg').convert()
sFloor = pygame.image.load('images/Left_edge_floor.jpg').convert()
floor = pygame.image.load('images/floor.jpg').convert()
예제 #5
0
 def makeLevel(self):
     counter = 0
     xSpot = 16
     ySpot = 16
     for x in self.design:
         for y in x:
             #print(y)
             if y is '#':
                 self.boxes.append(
                     sprites.sprites('Obstacles/box.png', (xSpot, ySpot)))
                 self.boxGroup.add(self.boxes[counter])
                 counter += 1
             elif y is 'X':
                 self.enemies.append(
                     enemy.enemy('Enemies/slime.png', (xSpot, ySpot),
                                 self.boxes,
                                 0))  #Last parameter is enemy type.
             elif y is '1':
                 self.enemies.append(
                     enemy.enemy('Enemies/flame.png', (xSpot, ySpot),
                                 self.boxes, 1))
             elif y is 'O':
                 self.enemies.append(
                     boss.boss('Enemies/orc.png', (xSpot, ySpot),
                               self.boxes))
             elif y is 'S':
                 self.enemies.append(
                     boss.boss('Enemies/yellow_tenta.png', (xSpot, ySpot),
                               self.boxes))
             elif y is '~':
                 self.enemies.append(
                     boss.boss('Enemies/cat_staff/cat_idle/cat_idle1.png',
                               (xSpot, ySpot), self.boxes))
             elif y is '¡':
                 self.boxes.append(
                     sprites.sprites('Obstacles/torch.gif', (xSpot, ySpot),
                                     'torch'))
                 self.boxGroup.add(self.boxes[counter])
             elif y is '!':
                 self.exit.append(
                     portal.portal('images/portal.png', (xSpot, ySpot),
                                   self.boxes))
             elif y is '*':
                 self.chests.append(
                     chest.chest('Obstacles/chest.png', (xSpot, ySpot),
                                 self.boxes, 1, self.screen))
             elif y is '%':
                 self.chests.append(
                     chest.chest('Obstacles/chest.png', (xSpot, ySpot),
                                 self.boxes, 2, self.screen))
             elif y is '$':
                 self.chests.append(
                     chest.chest('Obstacles/chest.png', (xSpot, ySpot),
                                 self.boxes, 3, self.screen))
             elif y is 'R':
                 self.chests.append(
                     chest.chest('Obstacles/red.png', (xSpot, ySpot),
                                 self.boxes, 4, self.screen))
             elif y is 'B':
                 self.chests.append(
                     chest.chest('Obstacles/blue.png', (xSpot, ySpot),
                                 self.boxes, 5, self.screen))
             xSpot += 48
         xSpot = 0
         ySpot += 58
     #Reset counters to iterate through again -- this time for spawning enemies.
     #(Obstacles list must be passed in for each enemy.)
     #Leaving this in case something breaks
     """
예제 #6
0
from board import Board
from mando import Mando
from boss import boss
# from bg_objects import obstacles
from bg_objects import vertical_obs
from bg_objects import horizontal_obs
from bg_objects import diagonal_obs
from bg_objects import obstacles
from bg_objects import coins
from bg_objects import magnet
from bg_objects import bullets
from snow_balls import snow_balls

boad = Board(50, 600)
boad.create_board()
boss1 = boss([40, 540])
boss1.reappear_boss(boad.matrix)

mag_present = 0
for i in range(0, 6):
    a = random.randint(0, 5)

    if i == 5 and mag_present == 0:
        mag1 = magnet([
            random.randint(5, 43),
            random.randint((i + 1) * 2 * 30, (i + 1) * 2 * 30 + 15)
        ])
        mag1.place_magnet(boad.matrix)
        mag_present = 1
    elif a % 4 == 1:
        obs1 = vertical_obs(random.randint(10, 15), [
예제 #7
0
def main():
    gameOver = False
    menuExit = False
    stageStart = False
    bossStage = False
    gameOverScreen = False

    menuselect = -1
    menuhighlight = 0

    wavecounter = 0
    wave = 0

    starfield1 = stars(1, white, 50, 5)
    starfield2 = stars(1, (150, 150, 150), 75, 3)
    starfield3 = stars(1, (75, 75, 75), 200, 1)

    bullets = pygame.sprite.Group()
    enemybullets = pygame.sprite.Group()
    enemies = pygame.sprite.Group()
    starships = pygame.sprite.Group()
    explosions = pygame.sprite.Group()
    shields = pygame.sprite.Group()
    drones = pygame.sprite.Group()
    saucers = pygame.sprite.Group()
    station = pygame.sprite.Group()
    healthpacks = pygame.sprite.Group()

    bullet.containers = bullets

    starship.containers = starships

    enemybullet.containers = enemybullets
    enemy.containers = enemies
    explosion.containers = explosions
    enemydrone.containers = drones
    enemysaucer.containers = saucers
    enemystation.containers = station

    starship.containers = starships

    healthpack.containers = healthpacks

    user = player()
    pygame.display.set_caption('PyGalaxian')
    bg_music = pygame.mixer.Sound('Sprites/bg_music.ogg')
    boss_music = pygame.mixer.Sound('Sprites/boss_music.ogg')

    (logoimage, logorect) = load_image('gamelogo.png', -1, -1, -1)
    logorect.left = width / 2 - logorect.width / 2
    logorect.top = height / 2 - logorect.height * 5 / 4

    while not gameOver:
        while not menuExit:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    menuExit = True
                    gameOver = True

                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_DOWN or event.key \
                        == pygame.K_UP:
                        menuhighlight += 1
                    elif event.key == pygame.K_RETURN:
                        menuselect = menuhighlight % 2

            if menuselect == 0:
                stageStart = True
                menuExit = True
                bg_music.play(-1)
            elif menuselect == 1:
                pygame.quit()
                quit()
            else:
                pass

            screen.fill(sky)
            starfield1.drawstars()
            starfield2.drawstars()
            starfield3.drawstars()
            user.drawplayer()
            screen.blit(logoimage, logorect)

            displaytext('Play', 32, width / 2 - 20, height * 3 / 4 - 40, white)
            displaytext('Exit', 32, width / 2 - 20, height * 3 / 4, white)
            displaytext('PyGalaxian version 1.0', 12, width - 80, height - 20,
                        white)
            displaytext('Made by: Shivam Shekhar', 12, width - 80, height - 10,
                        white)

            if menuhighlight % 2 == 0:
                screen.blit(pygame.transform.scale(user.image, (25, 25)),
                            [width / 2 - 100, height * 3 / 4 - 55, 15, 15])
            elif menuhighlight % 2 == 1:
                screen.blit(pygame.transform.scale(user.image, (25, 25)),
                            [width / 2 - 100, height * 3 / 4 - 15, 15, 15])
            pygame.display.update()
            clock.tick(FPS)

        while stageStart:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    stageStart = False
                    gameOver = True
                if event.type == pygame.KEYDOWN:
                    user.trigger = 1
                    if event.key == pygame.K_LEFT:
                        user.speed = -2
                    elif event.key == pygame.K_RIGHT:
                        user.speed = 2
                    elif event.key == pygame.K_UP:
                        user.fire = 1
                    elif event.key == pygame.K_ESCAPE:
                        quit()

                if event.type == pygame.KEYUP:
                    if event.key == pygame.K_LEFT or event.key \
                        == pygame.K_RIGHT:
                        user.trigger = 2
                        user.speed = 0
                    if event.key == pygame.K_UP:
                        user.fire = 0

            if wavecounter % 500 == 499 and random.randrange(0, 2) == 1 \
                and len(healthpacks) < 1:
                healthpack(random.randrange(0, width - 50), 0, 10)

            if random.randrange(0, 8) == 1 and len(enemies) < 10 \
                and (wave == 0 or wave == 5 or wave == 6 or wave == 9):
                enemy(random.randrange(0, 4))

            if random.randrange(0, 10) == 1 and len(starships) < 10 \
                and (wave == 2 or wave == 6 or wave == 8 or wave == 9):
                starship(random.randrange(0, 4))

            if random.randrange(0, 20) == 1 and len(saucers) < 3 \
                and (wave == 1 or wave == 5 or wave == 7 or wave == 8):
                enemysaucer(random.randrange(0, width - 50))

            if random.randrange(0, 30) == 21 and len(drones) < 2 \
                and (wave == 2 or wave == 4 or wave == 7 or wave == 9):
                if len(drones) > 0:
                    for drone in drones:
                        if drone.rect.left < width / 2:
                            enemydrone(
                                random.randrange(width / 2 + 60, width - 60))
                        else:
                            enemydrone(random.randrange(0, width / 2 - 60))
                else:
                    enemydrone(random.randrange(0, width - 60))




            if wave == 11 and len(enemies) == 0 and len(saucers) == 0 \
                and len(station) == 0 and len(drones) == 0:
                user.isautopilot = True
                bg_music.fadeout(6000)
                if user.rect.top <= -1 * user.rect.height:
                    wave = 12

            if wave == 12:
                bossStage = True
                stageStart = False
                finalboss = boss()
                user.health += 80
                user.rect.left = width / 2
                user.rect.top = size[1] - 100
                user.isautopilot = False
                user.movement = [0, 0]
                boss_music.play(-1)

            for ship in enemies:
                cpumove(ship, user)

            for ship in starships:
                cpumove(ship, user)

            for enemyhit in pygame.sprite.groupcollide(enemies, bullets, 0, 1):
                enemyhit.health -= 1
                if enemyhit.health <= 0:
                    user.kills += 1
                    user.score += 1

            for starshiphit in pygame.sprite.groupcollide(
                    starships, bullets, 0, 1):
                starshiphit.health -= 1
                if starshiphit.health <= 0:
                    user.kills += 1
                    user.score += 1

            for dronehit in pygame.sprite.groupcollide(drones, bullets, 0, 1):
                dronehit.health -= 1
                if dronehit.health <= 0:
                    user.kills += 1
                    user.score += 10

            for saucerhit in pygame.sprite.groupcollide(
                    saucers, bullets, 0, 1):
                saucerhit.health -= 1
                if saucerhit.health <= 0:
                    user.kills += 1
                    user.score += 5

            for stationhit in pygame.sprite.groupcollide(
                    station, bullets, 0, 1):
                stationhit.health -= 1
                if stationhit.health <= 0:
                    user.kills += 1
                    user.score += 25
                    healthpack(stationhit.rect.centerx,
                               stationhit.rect.centery, 20)

            for firedbullet in pygame.sprite.spritecollide(
                    user, enemybullets, 1):
                user.health -= 1

            for enemycollided in enemies:
                if pygame.sprite.collide_mask(user, enemycollided):
                    user.health -= 2
                    enemycollided.health -= enemycollided.health

            for starshipcollided in starships:
                if pygame.sprite.collide_mask(user, starshipcollided):
                    user.health -= 4
                    starshipcollided.health -= starshipcollided.health

            for dronecollided in drones:
                if pygame.sprite.collide_mask(user, dronecollided):
                    user.health -= 10
                    dronecollided.health -= dronecollided.health

            for saucercollided in saucers:
                if pygame.sprite.collide_mask(user, saucercollided):
                    user.health -= 4
                    saucercollided.health -= saucercollided.health

            for stationcollided in station:
                if pygame.sprite.collide_mask(user, stationcollided):
                    user.health -= 50
                    stationcollided.health -= stationcollided.health

            for health_pack in healthpacks:
                if pygame.sprite.collide_mask(user, health_pack):
                    user.health += health_pack.health
                    health_pack.health -= health_pack.health

            if user.health <= 0:
                gameOverScreen = True
                stageStart = False

            user.update()
            user.checkbounds()

            screen.fill(sky)
            starfield1.drawstars()
            starfield2.drawstars()
            starfield3.drawstars()

            if user.health > 0:
                showhealthbar(user.health, green,
                              [100, height - 20, user.health * 4, 10], 4)
            displaytext('HEALTH', 22, 50, height - 15, white)
            displaytext('Score:', 22, width - 100, 15, white)
            displaytext(str(user.score), 22, width - 35, 15, white)
            user.drawplayer()

            enemies.update()
            bullets.update()
            enemybullets.update()
            explosions.update()
            drones.update()
            saucers.update()
            station.update()
            healthpacks.update()
            starships.update()

            bullets.draw(screen)
            enemybullets.draw(screen)
            enemies.draw(screen)
            explosions.draw(screen)
            drones.draw(screen)
            saucers.draw(screen)
            station.draw(screen)
            healthpacks.draw(screen)
            starships.draw(screen)

            wave = storyboard(wavecounter)

            wavecounter += 1

            pygame.display.update()

            clock.tick(FPS)

            moveplayer(user)

            print(
                wavecounter,
                wave,
                user.kills,
                user.health,
                user.rect.left,
                user.movement[0],
                user.rect.right,
            )

        while bossStage:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gameOver = True
                    bossStage = False
                if event.type == pygame.KEYDOWN:
                    user.trigger = 1
                    if event.key == pygame.K_LEFT:
                        user.speed = -2
                    elif event.key == pygame.K_RIGHT:
                        user.speed = 2
                    elif event.key == pygame.K_UP:
                        user.fire = 1
                    elif event.key == pygame.K_ESCAPE:
                        quit()

                if event.type == pygame.KEYUP:
                    if event.key == pygame.K_LEFT or event.key \
                        == pygame.K_RIGHT:
                        user.trigger = 2
                        user.speed = 0
                    if event.key == pygame.K_UP:
                        user.fire = 0

            bossmove(finalboss, user)

            for ship in enemies:
                cpumove(ship, user)

            for userbullet in bullets:
                if pygame.sprite.collide_mask(finalboss, userbullet):
                    if finalboss.health > 2:
                        finalboss.health -= 1
                    else:
                        bossStage = False
                        gameOverScreen = True
                        user.score += 200
                        user.won = True
                    userbullet.kill()

            for enemyhit in pygame.sprite.groupcollide(enemies, bullets, 0, 1):
                enemyhit.health -= 1
                if enemyhit.health <= 0:
                    user.kills += 1
                    user.score += 1

            for starshiphit in pygame.sprite.groupcollide(
                    starships, bullets, 0, 1):
                starshiphit.health -= 2
                if starshiphit.health <= 0:
                    user.kills += 1
                    user.score += 3

            for dronehit in pygame.sprite.groupcollide(drones, bullets, 0, 1):
                dronehit.health -= 1
                if dronehit.health <= 0:
                    user.kills += 1
                    user.score += 10

            for saucerhit in pygame.sprite.groupcollide(
                    saucers, bullets, 0, 1):
                saucerhit.health -= 1
                if saucerhit.health <= 0:
                    user.kills += 1
                    user.score += 5

            for firedbullet in pygame.sprite.spritecollide(
                    user, enemybullets, 1):
                user.health -= 1

            for enemycollided in enemies:
                if pygame.sprite.collide_mask(user, enemycollided):
                    user.health -= 2
                    enemycollided.health -= enemycollided.health

            for dronecollided in drones:
                if pygame.sprite.collide_mask(user, dronecollided):
                    user.health -= 10
                    dronecollided.health -= dronecollided.health

            for saucercollided in saucers:
                if pygame.sprite.collide_mask(user, saucercollided):
                    user.health -= 4
                    saucercollided.health -= saucercollided.health

            if user.health <= 0:
                gameOverScreen = True
                bossStage = False

            user.update()
            user.checkbounds()

            screen.fill(sky)
            starfield1.drawstars()
            starfield2.drawstars()
            starfield3.drawstars()

            if user.health > 0:
                showhealthbar(user.health, green,
                              [100, height - 20, user.health * 4, 10], 4)
            displaytext('HEALTH', 22, 50, height - 15, white)

            if finalboss.health > 0:
                showhealthbar(finalboss.health, red,
                              [100, 20, finalboss.health * 0.8, 10], 0.8)
            displaytext('BOSS', 22, 50, 25, white)

            displaytext('Score:', 22, width - 100, 15, white)
            displaytext(str(user.score), 22, width - 35, 15, white)

            user.drawplayer()

            enemies.update()
            bullets.update()
            enemybullets.update()
            drones.update()
            saucers.update()
            explosions.update()
            finalboss.update()
            starships.update()

            bullets.draw(screen)
            enemybullets.draw(screen)
            enemies.draw(screen)
            starships.draw(screen)
            drones.draw(screen)
            saucers.draw(screen)
            explosions.draw(screen)
            finalboss.drawplayer()

            pygame.display.update()
            clock.tick(FPS)
            moveplayer(user)

        while gameOverScreen:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gameOverScreen = False
                    gameOver = True

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    gameOverScreen = False
                    gameOver = True

            screen.fill(sky)
            starfield1.drawstars()
            starfield2.drawstars()
            starfield3.drawstars()

            if user.won == False:
                displaytext('Game Over', 26, width / 2 - 30, height / 2, white)
            else:
                displaytext('Congratulations! You Won!', 26, width / 2 - 30,
                            height / 2, white)

            displaytext('Your score: ', 26, width / 2 - 40, height / 2 + 40,
                        white)
            displaytext(str(user.score), 26, width / 2 + 50, height / 2 + 43,
                        white)
            displaytext('Press Enter to exit...', 14, width / 2 - 30,
                        height / 2 + 90, white)
            pygame.display.update()
            clock.tick(FPS)

    pygame.quit()
    quit()
예제 #8
0
 def __init__(self):
     self.__env = environment()
     self.__boss = boss.boss(application=self, env=self.__env)
예제 #9
0
    def render(self):

        os.system('clear')
        self.createBox()

        # setup initial state
        character=boy(self._width,self._height,time.time())
        self._charac=character
        self.writeObject(character,character)
        enemy=boss(4,900)
        self._en=enemy
        self.writeObject(enemy,character)
        
        for i in range(5):
            self._beamsVertical.append(beamVertical(random.randint(2,25),random.randint(30,230)))
            self._beamsVertical.append(beamVertical(random.randint(2,25),random.randint(230,430)))
            self._beamsVertical.append(beamVertical(random.randint(2,25),random.randint(430,630)))
            self._beamsVertical.append(beamVertical(random.randint(2,25),random.randint(630,830)))
            self._beamsHorizontal.append(beamHorizontal(random.randint(2,29),random.randint(30,230)))
            self._beamsHorizontal.append(beamHorizontal(random.randint(2,29),random.randint(230,430)))
            self._beamsHorizontal.append(beamHorizontal(random.randint(2,29),random.randint(430,630)))
            self._beamsHorizontal.append(beamHorizontal(random.randint(2,29),random.randint(630,830)))
            self._beamsDiagnol.append(beamDiagnol(random.randint(2,25),random.randint(30,230)))
            self._beamsDiagnol.append(beamDiagnol(random.randint(2,25),random.randint(230,430)))
            self._beamsDiagnol.append(beamDiagnol(random.randint(2,25),random.randint(430,630)))
            self._beamsDiagnol.append(beamDiagnol(random.randint(2,25),random.randint(630,830)))
            self._coins.append(coin(random.randint(2,28),random.randint(30,330)))
            self._coins.append(coin(random.randint(2,28),random.randint(330,530)))
            self._coins.append(coin(random.randint(2,28),random.randint(330,530)))
            self._coins.append(coin(random.randint(2,28),random.randint(330,530)))
            self._coins.append(coin(random.randint(2,28),random.randint(530,830)))
            self._magnets.append(magnet(random.randint(2,29),random.randint(30,430)))                      
            self._magnets.append(magnet(random.randint(2,29),random.randint(430,830)))          


        # wirte initial state
        for i in self._beamsVertical:
            self.writeObject(i,character)
        for i in self._beamsHorizontal:
            self.writeObject(i,character)
        for i in self._beamsDiagnol:
            self.writeObject(i,character)
        for i in self._coins:
            self.writeObject(i,character)
        for i in self._magnets:
            self.writeObject(i,character)

        x=time.time()
        y=x
        enemy_time=x
        distToMagnet=[self._width+ self._height,-1,-1]
        while True:

            if time.time()-x > self._speed[0]:
                # update beams , coins , bullets
                for i in self._beamsVertical:
                    self.removeObject(i)
                    i.write()
                    self.writeObject(i,character)
                for i in self._beamsHorizontal:
                    self.removeObject(i)
                    i.write()
                    self.writeObject(i,character)
                for i in self._beamsDiagnol:
                    self.removeObject(i)
                    i.write()
                    self.writeObject(i,character)
                for i in self._coins:
                    self.removeObject(i)
                    i.write()
                    self.writeObject(i,character)
                for i in self._bullets:
                    self.removeObject(i)
                    i.write()
                    self.writeObject(i,character)
                for i in self._snowBalls:
                    self.removeObject(i)
                    i.write(enemy.lives)
                    self.writeObject(i,character)
                for i in self._magnets:
                    self.removeObject(i)
                    i.write()
                    if abs(i.position20()-character.position40())+abs(i.position21()-character.position41()) < distToMagnet[0]:
                        distToMagnet[0]=abs(i.position20()-character.position40())+abs(i.position21()-character.position41())
                        distToMagnet[1]=i.position20()
                        distToMagnet[2]=i.position21()
                    self.writeObject(i,character)
                # update characeter
                if distToMagnet[0]>15:
                    self.removeObject(character)
                    character.down()
                    self.writeObject(character,character)
                else:
                    self.removeObject(character)
                    character.towardsMagnet(distToMagnet[1],distToMagnet[2])
                    distToMagnet=[self._width+ self._height,-1,-1]
                    self.writeObject(character,character)

                

                x=time.time()
                if enemy.position01()>self._width-20:
                    self.removeObject(enemy)
                    enemy.write_right()
                    self.writeObject(enemy,character)
                    enemy.defense=1
                elif  x - enemy_time > 0.5:
                    if enemy.defense>0:
                        enemy.defense-=1
                    enemy_time=x
                    self.removeObject(enemy)
                    enemy.write_up_down(character.position30())
                    if character.position30() >= enemy.position00()+6 and character.position30() <= enemy.position00()+15:
                        self._snowBalls.append(snowBall(character.position30(),enemy.position01()-30))
                    elif character.position30() > enemy.position00()+15:
                        self._snowBalls.append(snowBall(enemy.position00()+12,enemy.position01()-30))
                    elif character.position30() < enemy.position00()+6:
                        self._snowBalls.append(snowBall(enemy.position00()+7,enemy.position01()-30))
                    self.writeObject(enemy,character)

                if x-character.lastTime() > 10 and x- character.liveLost() > 3:
                    character.deactivateShield()
                if self._speed[2]==1 and x-self._speed[1] > 10:
                    self._speed[0]=0.1
                self._timeLeft=int(140-(x-y))
                if 140-(x-y) < 0:
                    self.quitX()

                print(Fore.WHITE,"\033[2;2HLive:"+str(character.lives)+"  ",end='')
                print("\033[30;1H")
                print(Fore.WHITE,"\033[2;10HScore:"+str(character.score)+"  ",end='')
                print("\033[30;1H")
                print(Fore.WHITE,"\033[2;20HShield:"+str(int(x-character.lastTime()))+"  ",end='')
                print("\033[30;1H")
                print(Fore.WHITE,"\033[2;32HBoss:"+str(enemy.lives)+"  ",end='')
                print("\033[30;1H")
                print(Fore.WHITE,"\033[2;42HTime Remaining:"+str(int(140-(x-y)))+"  ",end='')
                print("\033[30;1H")

                self.write()
            self.detectKey(character)    
        return True
예제 #10
0
 def __init__(self):
     self.__env = environment()
     self.__boss = boss.boss(application=self, env=self.__env)