Example #1
0
def monster_spawn(side):
    """
	Spawns a monster at the specified side of the board
	"""

    if side:
        monster = monsters.Monster(maze, screen, 1, pacman1)
        right_monsters.append(monster)
    else:
        monster = monsters.Monster(maze, screen, 0, pacman0)
        left_monsters.append(monster)
Example #2
0
 def test_create_monster(self):
     model = game_model.GameModel("levels/graphic_test.json", 800, 600)
     gm_monster = model.createMonster(0, 100, 300, 1, 1000)
     monster = monsters.Monster(100, 300, 1, 1000)
     self.assertEqual(gm_monster.start_x, monster.start_x)
     self.assertEqual(gm_monster.start_y, monster.start_y)
     self.assertEqual(gm_monster.walking_length, monster.walking_length)
     self.assertEqual(gm_monster.x_speed, monster.x_speed)
Example #3
0
 def add_monsters(self, charactersprites, level):
     if level.bossRoom==self.cord:
         temp_monster = monsters.Monster(monsters.BOSS, level.levelNumber)
         temp_monster.rect.topleft = (random.randint(32,temp_monster.area.right-32), random.randint(0,temp_monster.area.bottom-32))
         while (pygame.sprite.spritecollide(temp_monster, charactersprites, 0) != [] or pygame.sprite.spritecollide(temp_monster, self.walls, 0) != []
            or pygame.sprite.spritecollide(temp_monster, self.monsters, 0) != []):
                 temp_monster.rect.topleft = (random.randint(0,temp_monster.area.right), random.randint(0,temp_monster.area.bottom))
         self.monsters.add(temp_monster)
         self.moveables.add(self.monsters)
         return
     for i in range(random.randint(3,5)):
         x = random.randint(0,1)
         if x == 0:
             temp_monster = monsters.Monster(monsters.MNM, level.levelNumber)
         if x == 1:
             temp_monster = monsters.Monster(monsters.MNM_RANGED,level.levelNumber)
         temp_monster.rect.topleft = (random.randint(32,temp_monster.area.right-64), random.randint(0,temp_monster.area.bottom-64))
         while (pygame.sprite.spritecollide(temp_monster, charactersprites, 0) != [] or pygame.sprite.spritecollide(temp_monster, self.walls, 0) != []
            or pygame.sprite.spritecollide(temp_monster, self.monsters, 0) != []):
                 temp_monster.rect.topleft = (random.randint(0,temp_monster.area.right), random.randint(0,temp_monster.area.bottom))
         self.monsters.add(temp_monster)
     level.num_monsters += len(self.monsters.sprites())
     self.moveables.add(self.monsters)
Example #4
0
    def __init__(self):

        self.borders = [
            loadAndTransfer("images\\items\\border\\" + str(i) + ".png",
                            setting.grid_scale, setting.grid_scale)
            for i in range(1, 5)
        ]
        self.property_icon = [
            loadAndTransfer("images\\items\\property\\" + str(i) + ".png",
                            setting.grid_scale * 2, setting.grid_scale * 2)
            for i in range(1, 4)
        ]
        self.property = [
            loadAndTransfer("images\\items\\property\\" + str(i) + "_.png",
                            setting.grid_scale, setting.grid_scale)
            for i in range(1, 4)
        ]

        # 初始化地图
        self.plat = plats.Map()
        bubbles.Bubble.plat = self.plat
        characters.Character.plat = self.plat
        monsters.Monster.plat = self.plat
        monsters.Bleach.plat = self.plat

        self.chars = []
        name = heroes.randHero()
        color = heroes.randColor()
        # 初始化人物
        self.chars.append(characters.Character(name, color))
        # 初始化AI
        self.chars.append(AIModel.AI())

        monsters.Monster.chars = self.chars
        monsters.Bleach.chars = self.chars
        AIModel.AI.character = self.chars[0]

        # 初始化怪物
        self.monster = monsters.Monster()

        self.bleaches = []
        monsters.Bleach.bleaches = self.bleaches

        # 初始化道具记录榜
        self.propboard = props.PropBoard(self.screen)

        self.update_times = 0
        self.result = None  # 游戏结束的判断
Example #5
0
    def run(self):
        mainloop = True

        M = pygame.sprite.Group()

        mn = monsters.Monster(100, 450, 2, 0, 150, 0)
        P = []
        P.append(mn)
        M.add(mn)

        while mainloop:
            # Limit frame speed to 50 FPS
            self.clock.tick(50)

            screen.blit(mn.image, (50, 250))
            M.update(P)

            mpos = pygame.mouse.get_pos()

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    mainloop = False
                if event.type == pygame.KEYDOWN:
                    self.mouse_is_visible = False
                    self.set_keyboard_selection(event.key)
                if event.type == pygame.MOUSEBUTTONDOWN:
                    for item in self.items:
                        if item.is_mouse_selection(mpos):
                            self.funcs[item.text]()

            if pygame.mouse.get_rel() != (0, 0):
                self.mouse_is_visible = True
                self.cur_item = None

            self.set_mouse_visibility()

            # Redraw the background
            self.screen.fill(self.bg_color)

            for item in self.items:
                if self.mouse_is_visible:
                    self.set_mouse_selection(item, mpos)
                self.screen.blit(item.label, item.position)

            pygame.display.flip()
Example #6
0
def loadLevel():
    global playerX, playerY  # объявляем глобальные переменные, это координаты героя

    levelFile = open('%s/levels/1.txt' % FILE_DIR)
    line = " "
    commands = []
    while line[0] != "/":  # пока не нашли символ завершения файла
        line = levelFile.readline()  #считываем построчно
        if line[0] == "[":  # если нашли символ начала уровня
            while line[0] != "]":  # то, пока не нашли символ конца уровня
                line = levelFile.readline()  # считываем построчно уровень
                if line[0] != "]":  # и если нет символа конца уровня
                    endLine = line.find("|")  # то ищем символ конца строки
                    level.append(
                        line[0:endLine]
                    )  # и добавляем в уровень строку от начала до символа "|"

        if line[0] != "":  # если строка не пустая
            commands = line.split()  # разбиваем ее на отдельные команды
            if len(commands
                   ) > 1:  # если количество команд > 1, то ищем эти команды
                if commands[0] == "player":  # если первая команда - player
                    playerX = int(
                        commands[1])  # то записываем координаты героя
                    playerY = int(commands[2])
                if commands[
                        0] == "portal":  # если первая команда portal, то создаем портал
                    tp = blocks.BlockTeleport(int(commands[1]),
                                              int(commands[2]),
                                              int(commands[3]),
                                              int(commands[4]))
                    entities.add(tp)
                    platforms.append(tp)
                    animatedEntities.add(tp)
                if commands[
                        0] == "monster":  # если первая команда monster, то создаем монстра
                    mn = monsters.Monster(int(commands[1]), int(commands[2]),
                                          int(commands[3]), int(commands[4]),
                                          int(commands[5]), int(commands[6]))
                    entities.add(mn)
                    platforms.append(mn)
                    MasMons.add(mn)
Example #7
0
def main():
    pygame.init()  # инициация PyGame
    screen = pygame.display.set_mode(DISPLAY)
    pygame.display.set_caption("Super Mario Boy")
    BACKGROUND = pygame.image.load(os.path.join('fon', '0.jpg')).convert()

    timer = pygame.time.Clock()

    level = [
        "--------------------------------------",
        "-                                    -",
        "-      --               -            -",
        "-                                    -",
        "-            --                      -",
        "-                      -             -",
        "--                          ------   -",
        "-                             Z      -",
        "-   -               ----     ---     -",
        "-                                    -",
        "--       --                     --   -",
        "-                 --                 -",
        "-                            ---     -",
        "- --          --                     -",
        "-                           --     ---",
        "-      ---              *            -",
        "-                             *      -",
        "-   -------         ----             -",
        "-                                    -",
        "-                         -          -",
        "--                          --      -",
        "----       *                         -",
        "-                                    -",
        "--------------------------------------"
    ]

    player = hero.Hero(40, 50)  # создаем персонажа по (x,y) координатам
    left = right = False  # по умолчанию — стоим
    up = False

    player2 = hero.Hero(70, 40)

    entities = pygame.sprite.Group()  # все объекты
    platforms = []  # проверка на поверхность
    entities.add(player)

    entities.add(player2)

    animatedEntities = pygame.sprite.Group(
    )  # все анимированные объекты, за исключением героя

    tp = blocks.BlockTeleport(128, 512, 800, 64)
    entities.add(tp)
    platforms.append(tp)
    animatedEntities.add(tp)

    #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#
    x = y = 0  # координаты
    for row in level:  # вся строка
        for col in row:  # каждый символ
            if col == "-":
                pf = blocks.Platform(x, y)
                entities.add(pf)
                platforms.append(pf)
            if col == "*":
                bd = blocks.BlockDie(x, y)
                entities.add(bd)
                platforms.append(bd)
            if col == "Z":
                pr = blocks.Emblem(x, y)
                entities.add(pr)
                platforms.append(pr)
                animatedEntities.add(pr)

            x += PLATFORM_WIDTH  #блоки платформы ставятся на ширине блоков
        y += PLATFORM_HEIGHT  #то же самое и с высотой
        x = 0

    total_level_width = len(
        level[0]) * PLATFORM_WIDTH  # Высчитываем фактическую ширину уровня
    total_level_height = len(level) * PLATFORM_HEIGHT  # высоту

    camera = Camera(camera_configure, total_level_width, total_level_height)

    TimeFor = time.time()
    ff = True

    running = False
    NFOn = 1

    Nmonsters = pygame.sprite.Group()  # Все передвигающиеся объекты
    mn1 = monsters.Monster(190, 200, 2, 2, 150, 15)

    mn2 = monsters.Monster(344, 511, 0, 1, 0, 150)

    entities.add(mn1)
    platforms.append(mn1)
    Nmonsters.add(mn1)

    entities.add(mn2)
    platforms.append(mn2)
    Nmonsters.add(mn2)

    pygame.joystick.init()

    while not player.winner:  # основной цикл программы
        timer.tick(60)

        if time.time() - TimeFor > 5:
            if NFOn < 8:
                BACKGROUND = RFon(NFOn)
                TimeFor = time.time()
                NFOn += 1
            else:
                NFOn = 0
                BACKGROUND = RFon(NFOn)
                TimeFor = time.time()

        for e in pygame.event.get():  # обрабатываем события
            if e.type == pygame.QUIT:
                sys.exit()
            if e.type == pygame.KEYDOWN and e.key == pygame.K_LEFT:
                left = True
            if e.type == pygame.KEYDOWN and e.key == pygame.K_RIGHT:
                right = True
            if e.type == pygame.KEYUP and e.key == pygame.K_RIGHT:
                right = False
            if e.type == pygame.KEYUP and e.key == pygame.K_LEFT:
                left = False
            if e.type == pygame.KEYDOWN and e.key == pygame.K_UP or e.type == pygame.JOYBUTTONDOWN:
                up = True
            if e.type == pygame.KEYUP and e.key == pygame.K_UP or e.type == pygame.JOYBUTTONUP:
                up = False
            if e.type == pygame.KEYDOWN and e.key == pygame.K_LSHIFT:
                running = True
            if e.type == pygame.KEYUP and e.key == pygame.K_LSHIFT:
                running = False

        screen.blit(BACKGROUND,
                    (0, 0))  # каждую итерацию необходимо всё перерисовывать

        #на каждой новой строчке начинаем с нуля

        camera.update(player)
        player.update(left, right, up, running, platforms)

        # player2.update(left,right, up, platforms)

        #player.draw(screen)
        #player.collide(screen)
        #entities.draw(screen)

        for e in entities:
            screen.blit(e.image, camera.apply(e))

        animatedEntities.update()  # показываем анимацию
        Nmonsters.update(platforms)  # передвигаем всех монстров

        pygame.display.update()  # обновление и вывод всех изменений на экран
Example #8
0
def test_exceptionIfBaseMonsterInvoked():
    try:
        baseMonster = m.Monster()
        return False
    except NotImplementedError:
        return True
Example #9
0
def game_loop(load):
    """Main Function"""

    width, height = 16, 12
    Board = setup_Board([[0]*width for _ in range(height)])
    Lives, Cash = 100, 750
    selection = Selection()
    score = 0
    startButton = Start()
    Images = load_images("Images")
    abilityCooldown = False
    settings = Settings()
    cooldown = 100

    #Generating each of the waves
    wave = 1

    #Loading your save file
    if load:
        file = open("SaveFile/saveFile.txt", "r")
        data = file.readline().split("#")
        if len(data) >= 197:
            count = 0
            #Loading all the tiles
            for j, row in enumerate(Board):
                    for i, tile in enumerate(row):
                        if data[count] == "2":
                            count += 1
                            #Loading all variables for a tower
                            Board[j][i] = tower.Tower(i*40+5, j*40+5, int(data[count]))
                            Board[j][i].pops = int(data[count+1])
                            Board[j][i].score = int(data[count+2])
                            Board[j][i].pierce = int(data[count+3])
                            Board[j][i].damage = int(data[count+4])
                            Board[j][i].speed = float(data[count+5])
                            Board[j][i].shotAmount = int(data[count+6])
                            Board[j][i].size = int(data[count+7])
                            Board[j][i].path = int(data[count+8])
                            Board[j][i].seeking = data[count+9] == "True"
                            Board[j][i].bulletSpeed = float(data[count+10])
                            Board[j][i].camo = data[count+11] == "True"
                            Board[j][i].dead = data[count+12] == "True"
                            Board[j][i].fireDamage = int(data[count+13])
                            Board[j][i].fireLength = float(data[count+14])
                            Board[j][i].fireLasting = float(data[count+15])
                            Board[j][i].Permaslow = data[count+16] == "True"
                            Board[j][i].slowAmount = float(data[count+17])
                            Board[j][i].ExplodeTime = float(data[count+18])
                            Board[j][i].bombRange = float(data[count+19])
                            Board[j][i].crateValue = int(data[count+20])
                            Board[j][i].autoCollect = data[count+21] == "True"
                            Board[j][i].expireTime = int(data[count+22])
                            Board[j][i].glaiveCount = int(data[count+23])
                            Board[j][i].glaiveSpeed = float(data[count+24])
                            Board[j][i].glaiveRings = int(data[count+25])
                            Board[j][i].selected = False
                            Board[j][i].value = int(data[count+26])
                            Board[j][i].range = float(data[count+27])
                            count += 28


                            #Loads all upgrades
                            for h, item in enumerate(Board[j][i].upgrades):
                                for g, subItem in enumerate(item):
                                    Board[j][i].upgrades[h][g] = int(data[count])
                                    count += 1
                  
                            Board[j][i].currentUpgrade = [int(data[count]), int(data[count+1])]
                            count += 2

                            for item in Board[j][i].ability:
                                Board[j][i].ability.append([data[count], int(data[count+1]), int(data[count+2]), int(data[count+3])])
                                count += 4

                        else:
                            Board[j][i] = int(data[count])
                            count += 1

            Cash = int(data[count])
            Lives = int(data[count+1])
            settings.autoPlay.switch = data[count+3] == "True"
            score = int(data[count+2])
            wave = int(data[count+4])
            count += 5
        else:
            print("Invalid Save File")

    #Generating the monsters
    Monsters = waves.genEnemies(wave, Images)
          
    game_run = True
    while game_run:

        #Grabbing mouse cordinates
        pos = pygame.mouse.get_pos()

        gameDisplay.fill((130,90,50))

        #Drawing the background
        for j, row in enumerate(Board):
            for i, tile in enumerate(row):
                if Board[j][i] == 0:
                    Color = (0, 150, 0)
                elif Board[j][i] == 1:
                    Color = (210, 180, 140)
                else:
                    Color = (0, 150, 0)
                pygame.draw.rect(gameDisplay, Color, (i*40,j*40,40,40), 0)
                pygame.draw.rect(gameDisplay, (0, 150, 0), (i*40, j*40, 40, 40), 1)

        #Updating all monsters on the board:
        for monster in Monsters:
            if monster[1] > 0:
                monster[1] -= 1*startButton.speed
            else:
                if monster[0].dead:
                    Monsters.pop(Monsters.index(monster))
                else:
                    Lives = monster[0].update(Lives, startButton.speed, gameDisplay)
                    if monster[0].duplicate:
                        monster[0].duplicate = False
                        tempMonster = [monsters.Monster(5,wave,monster[0].camo, Images),monster[1]-30]
                        tempMonster[0].x, tempMonster[0].y = monster[0].x, monster[0].y
                        tempMonster[0].step = monster[0].step
                        tempMonster[0].cooldown = 5
                        tempMonster[0].hit = monster[0].hit
                        tempMonster[0].fire = monster[0].fire
                        tempMonster[0].speedModifier = monster[0].speedModifier
                        Monsters.append(tempMonster)
                    if len(monster[0].addMonster) != 0:
                        for i, mons in enumerate(monster[0].addMonster):
                            tempMonster = [monsters.Monster(mons,wave,monster[0].camo, Images),monster[1]-30*(i+1)]
                            tempMonster[0].x, tempMonster[0].y = monster[0].x, monster[0].y
                            tempMonster[0].step = monster[0].step
                            tempMonster[0].cooldown = 5
                            tempMonster[0].hit = monster[0].hit
                            tempMonster[0].fire = monster[0].fire
                            tempMonster[0].speedModifier = monster[0].speedModifier
                            Monsters.append(tempMonster)
                    monster[0].addMonster = []
                                
        if len(Monsters) == 0:

            #Starting the new wave
            Cash += 100+wave+1
            wave += 1
            Monsters = waves.genEnemies(wave, Images)
            if not settings.autoPlay.switch:
                startButton.speed = 0
            for j, row in enumerate(Board):
                for i, tile in enumerate(row):
                    try:
                        tile = int(tile)
                    except Exception:
                        tile.Projectiles = []

            #Saving after a wave ends
            data = ""
            for j, row in enumerate(Board):
                for i, tile in enumerate(row):
                    stop = False
                    try:
                        tile = int(tile)
                    except Exception:
                        data += "2" + "#"
                        for item in [tile.rank, tile.pops, tile.score, tile.pierce, tile.damage, tile.speed, tile.shotAmount, tile.size, tile.path, tile.seeking,
                                     tile.bulletSpeed, tile.camo, tile.dead, tile.fireDamage, tile.fireLength, tile.fireLasting, tile.Permaslow, tile.slowAmount,
                                     tile.ExplodeTime, tile.bombRange, tile.crateValue, tile.autoCollect, tile.expireTime, tile.glaiveCount, tile.glaiveSpeed,
                                     tile.glaiveRings, tile.value, tile.range]:
                            data += str(item) + "#"
                        for item in tile.upgrades:
                            for subItem in item:
                                data += str(subItem) + "#"
                        for item in tile.currentUpgrade:
                            data += str(item) + "#"
                        for ability in tile.ability:
                            for item in ability:
                                data += str(item) + "#"
                        stop = True
                    if not stop:
                        data += str(tile) + "#"

            data += str(Cash) + "#"
            data += str(Lives) + "#"
            data += str(score) + "#"
            data += str(settings.autoPlay.switch) + "#"
            data += str(wave) + "#"

            file = open("SaveFile/saveFile.txt", "w")
            file.write(data)

        #Making the selection bar
        pygame.draw.rect(gameDisplay, (130, 90, 50), (640, 0, 200, 580), 0)
        ColorBoard = [[(200, 0, 0), (0, 0, 200)], [(200, 200, 0), (0, 200, 200)], [(100, 100, 100), (0, 200, 0)], [(200, 200, 200), (100, 150, 200)]]
        for j in range(4):
            for i in range(2):
                pygame.draw.rect(gameDisplay, (140, 90, 40), (660+i*100, 150+j*70, 60, 60), 0)
                pygame.draw.rect(gameDisplay, (210, 180, 140), (660+i*100, 150+j*70, 60, 60), 3)
                if (j != 1 or i != 0) and (j != 0 or i != 1) and (j != 1 or i != 1):
                    pygame.draw.rect(gameDisplay, ColorBoard[j][i], (660+i*100+10, 150+j*70+10, 40, 40), 0)
                elif j == 0 and i == 1:
                    gameDisplay.blit(pygame.transform.scale(Images["NinjaBase"], (30, 30)), (660+i*100+15, 150+j*70+20))
                    gameDisplay.blit(pygame.transform.scale(Images["NinjaGun"], (30, 40)), (660+i*100+15, 150+j*70+5))
                elif j == 1 and i == 1:
                    gameDisplay.blit(pygame.transform.scale(Images["IceTower"], (30, 30)), (660+i*100+15, 150+j*70+20))                  
                else:
                    gameDisplay.blit(pygame.transform.scale(Images["Flamethrower"], (40, 60)), (660+i*100+10, 150+j*70))

        #Drawing Lives/Cash
        gameDisplay.blit(pygame.transform.scale(Images["Heart"], (20, 20)), (660, 60))
        gameDisplay.blit(pygame.transform.scale(Images["InstantMoney"], (20, 20)), (660, 20))
        gameDisplay.blit(font_20.render(str(Cash), True, (0, 0, 0)), (690, 16))
        gameDisplay.blit(font_20.render(str(Lives), True, (0, 0, 0)), (690, 56))
        gameDisplay.blit(font_20.render("Wave: " + str(wave), True, (0, 0, 0)), (660, 96))

        if Lives <= 0:
            game_run = False

        #Event handler
        for event in pygame.event.get():
            if event.type == QUIT:
              pygame.quit()
              sys.exit()

        #Drawing all towers:
        stop = False
        pos, pressed = pygame.mouse.get_pos(), pygame.mouse.get_pressed()
        for j, row in enumerate(Board):
            for i, tile in enumerate(row):
                try:
                    tile = int(tile)
                except Exception:
                    tile.update(Monsters, startButton.speed, Cash, Board, Images, gameDisplay)
                    if tile.x <= pos[0] <= tile.x + tile.width and tile.y <= pos[1] <= tile.y + tile.height and pressed[0] == True:
                        for h, k in enumerate(Board):
                            for l, s in enumerate(k):
                                try:
                                    s = int(s)
                                except Exception:
                                    s.selected = False
                        tile.selected = True
                        stop = True
                    Cash += tile.cash

                    #Checking to see whether something was bought today
                    if tile.cash < 0 or not (0 <= pos[0] <= 640 and 0 <= pos[1] <= 480):
                        stop = True
                        

                    tile.cash = 0
                    score += tile.score
                    tile.score = 0

                    if tile.dead == True:
                        Board[j][i] = 0
        if stop == False and pressed[0] == True:
            for j, row in enumerate(Board):
                for i, tile in enumerate(row):
                    try:
                        tile = int(tile)
                    except Exception:
                        tile.selected = False
        

        Board, Cash = selection.update(Board, Cash)

        #The start button
        startButton.update()

        #Updates the settings
        gameDisplay.blit(font_15.render("Settings", True, (0, 0, 0)), (565, 490))
        settings.update()

        #Updating all crates so their drawn on a higher level then towers
        for j, row in enumerate(Board):
            for i, tile in enumerate(row):
                try:
                    tile = int(tile)
                except Exception:
                    if tile.rank == 6:
                        for crate in tile.Crates:
                            crate.update(startButton.speed, gameDisplay)

                            if crate.expireTime <= 0:
                                tile.Crates.pop(tile.Crates.index(crate))

                            if crate.collected:
                                Cash += crate.value
                                tile.Crates.pop(tile.Crates.index(crate))
                    elif tile.rank == 7:
                        for glaive in tile.Glaives:
                            glaive.update(startButton.speed, gameDisplay)

        #Abilities
        Abilities = []
        for j, row in enumerate(Board):
            for i, tile in enumerate(row):
                try:
                    tile = int(tile)
                except Exception:
                    for ability in tile.ability:
                        #Checks for all ready abilities
                        if ability[1] == 0:
                            Abilities.append(ability[0])
                        elif ability[1] == -1:
                            pass
                        else:
                            ability[1] -= 1

        
        if len(Abilities) != 0:
            alreadyUsed = {}
            for ability in Abilities:
                if ability not in alreadyUsed.keys():
                    alreadyUsed[ability] = 1
                else:
                    alreadyUsed[ability] += 1

            count = 0
            for k, v in alreadyUsed.items():
                pygame.draw.rect(gameDisplay, (210, 180, 140), (10+55*count, 430, 40, 40), 0)
                pygame.draw.rect(gameDisplay, (180, 140, 80), (10+55*count, 430, 40, 40), 2)
                if k == "Bullet Time":
                    
                    pygame.draw.rect(gameDisplay, (255,215,0), (20+55*count, 435, 15, 10), 0)
                    pygame.draw.circle(gameDisplay, (255, 215, 0), (35+55*count, 440), 5, 0)                

                    pygame.draw.circle(gameDisplay, (255, 255, 255), (25+55*count, 458), 10, 0)
                    pygame.draw.circle(gameDisplay, (0, 0, 0), (25+55*count, 458), 11, 1)
                    pygame.draw.line(gameDisplay, (0, 0, 0), (25+55*count, 458), (25+55*count, 450), 2)
                    pygame.draw.line(gameDisplay, (0, 0, 0), (25+55*count, 458), (20+55*count, 455), 2)

                elif k == "Forest Fire":
                    gameDisplay.blit(pygame.transform.scale(Images["ForestFire"],(20,30)),(20+55*count,435))

                elif k == "The Arctic":
                    gameDisplay.blit(pygame.transform.scale(Images["TheArctic"],(100,30)),(-20+55*count,435))

                elif k == "Smoke Bomb":
                    gameDisplay.blit(pygame.transform.scale(Images["SmokeBomb"],(50,50)),(55*count,425))

                elif k == "Instant Money":
                    gameDisplay.blit(pygame.transform.scale(Images["InstantMoney"],(30,30)),(15+55*count,435))

                elif k == "Complete Reform":
                    gameDisplay.blit(pygame.transform.scale(Images["CompleteReform"],(30,30)),(15+55*count,435))
                elif k == "Unleash Havoc":
                    gameDisplay.blit(pygame.transform.scale(Images["UnleashHavoc"],(30,30)),(15+55*count,435))
                    
                gameDisplay.blit(font_20.render(str(v), True, (0, 0, 0)), (40+55*count, 450))

                

                stop = False
                if 10+55*count <= pos[0] <= 10+55*count+40 and 430 <= pos[1] <= 470 and pressed[0] == 1:
                    for j, row in enumerate(Board):
                        for i, tile in enumerate(row):
                            try:
                                tile = int(tile)
                            except Exception:
                                for ability in tile.ability:
                                    stop2 = False
                                    for a in tile.effects:
                                        if a[0] == ability[0]:
                                            stop2 = True
                                    if not stop and ability[0] == k and not stop2 and not abilityCooldown:
                                        abilityCooldown = True
                                        stop = True
                                        ability[1] = ability[2] + 0
                                        tile.effects.append([k,ability[3],False])
                count += 1

        if pressed[0] == 0:
            abilityCooldown = False
                    
        #Drawing range of selected tower
        for j, row in enumerate(Board):
            for i, tile in enumerate(row):
                try:
                    tile = int(tile)
                except Exception:
                    if tile.selected:
                        pygame.draw.circle(gameDisplay, (0, 0, 0, 125), (tile.x+int(tile.width/2), tile.y+int(tile.height/2)),int(tile.range), 2)
        
        pygame.display.flip()
        fpsClock.tick(fps)

    print("Score: " + str(score))
Example #10
0
 def createMonster(self, monster_id, *args):
     if monster_id == 0:
         monster = monsters.Monster(*args)
         self.entities.add(monster)
         self.monsters.add(monster)
         self.platforms.append(monster)
Example #11
0
def genEnemies(wave, Images, mapName):
    """Outputs a list of all enemies based on a certain wave"""
    Monsters = []
    if wave == 1:
        for i in range(20):
            Monsters.append(
                [monsters.Monster(1, wave, False, Images, mapName), 30 * i])
    elif wave == 2:
        for i in range(35):
            Monsters.append(
                [monsters.Monster(1, wave, False, Images, mapName), 15 * i])
    elif wave == 3:
        for i in range(5):
            Monsters.append(
                [monsters.Monster(2, wave, False, Images, mapName), 60 * i])
        for i in range(20):
            Monsters.append([
                monsters.Monster(1, wave, False, Images, mapName),
                30 * (i + 21)
            ])
    elif wave == 4:
        for j in range(5):
            for i in range(2):
                Monsters.append([
                    monsters.Monster(2, wave, False, Images, mapName),
                    45 * (i + j * 10)
                ])
            for i in range(8):
                Monsters.append([
                    monsters.Monster(1, wave, False, Images, mapName),
                    30 * (i + j * 10 + 2)
                ])
    elif wave == 5:
        for j in range(3):
            Monsters.append([
                monsters.Monster(1, wave, False, Images, mapName),
                30 * (1 + j * 10)
            ])
            for i in range(9):
                Monsters.append([
                    monsters.Monster(2, wave, False, Images, mapName),
                    30 * (i + 1 + j * 10)
                ])
    elif wave == 6:
        for j in range(3):
            for i in range(5):
                Monsters.append([
                    monsters.Monster(1, wave, False, Images, mapName),
                    30 * (i * 2 + j * 11)
                ])
                Monsters.append([
                    monsters.Monster(2, wave, False, Images, mapName),
                    30 * (i * 2 + 1 + j * 11)
                ])
            Monsters.append([
                monsters.Monster(3, wave, False, Images, mapName),
                30 * (10 + j * 11)
            ])
        Monsters.append(
            [monsters.Monster(3, wave, False, Images, mapName), 60 * (18)])
    elif wave == 7:
        for j in range(5):
            for i in range(4):
                Monsters.append([
                    monsters.Monster(1, wave, False, Images, mapName),
                    30 * (i * 2 + j * 9)
                ])
                Monsters.append([
                    monsters.Monster(2, wave, False, Images, mapName),
                    30 * (i * 2 + 1 + j * 9)
                ])
            Monsters.append([
                monsters.Monster(3, wave, False, Images, mapName),
                30 * (8 + j * 9)
            ])
    elif wave == 8:
        for i in range(10):
            Monsters.append(
                [monsters.Monster(1, wave, False, Images, mapName), 30 * i])
        for i in range(20):
            Monsters.append([
                monsters.Monster(2, wave, False, Images, mapName),
                30 * (i + 10)
            ])
        for i in range(14):
            Monsters.append([
                monsters.Monster(3, wave, False, Images, mapName),
                30 * (i + 30)
            ])
    elif wave == 9:
        for i in range(30):
            Monsters.append(
                [monsters.Monster(3, wave, False, Images, mapName), 45 * i])
    elif wave == 10:
        for i in range(102):
            Monsters.append(
                [monsters.Monster(2, wave, False, Images, mapName), 20 * i])
    elif wave == 11:
        for j in range(3):
            for i in range(2):
                Monsters.append([
                    monsters.Monster(1, wave, False, Images, mapName),
                    30 * (i + j * 11)
                ])
            for i in range(4):
                Monsters.append([
                    monsters.Monster(2, wave, False, Images, mapName),
                    30 * (i * 2 + j * 11)
                ])
                Monsters.append([
                    monsters.Monster(3, wave, False, Images, mapName),
                    30 * (i * 2 + 1 + j * 11)
                ])
            Monsters.append([
                monsters.Monster(4, wave, False, Images, mapName),
                30 * (10 + j * 11)
            ])
    elif wave == 12:
        for j in range(5):
            for i in range(3):
                Monsters.append([
                    monsters.Monster(2, wave, False, Images, mapName),
                    30 * (i + j * 7)
                ])
            for i in range(2):
                Monsters.append([
                    monsters.Monster(3, wave, False, Images, mapName),
                    30 * (i + 3 + j * 7)
                ])
            Monsters.append([
                monsters.Monster(4, wave, False, Images, mapName),
                30 * (6 + j * 7)
            ])
    elif wave == 13:
        for i in range(50):
            Monsters.append(
                [monsters.Monster(2, wave, False, Images, mapName), 15 * (i)])
        for i in range(23):
            Monsters.append([
                monsters.Monster(3, wave, False, Images, mapName),
                15 * (i + 50)
            ])
    elif wave == 14:
        for i in range(10):
            Monsters.append(
                [monsters.Monster(3, wave, False, Images, mapName), 30 * (i)])
        for i in range(20):
            Monsters.append([
                monsters.Monster(2, wave, False, Images, mapName),
                30 * (i + 10)
            ])
        for i in range(8):
            Monsters.append([
                monsters.Monster(4, wave, False, Images, mapName),
                30 * (i + 30)
            ])
    elif wave == 15:
        for j in range(5):
            Monsters.append([
                monsters.Monster(1, wave, False, Images, mapName),
                30 * (1 + j * 5)
            ])
            Monsters.append([
                monsters.Monster(2, wave, False, Images, mapName),
                30 * (2 + j * 5)
            ])
            Monsters.append([
                monsters.Monster(3, wave, False, Images, mapName),
                30 * (3 + j * 5)
            ])
            Monsters.append([
                monsters.Monster(4, wave, False, Images, mapName),
                30 * (4 + j * 5)
            ])
            Monsters.append([
                monsters.Monster(5, wave, False, Images, mapName),
                30 * (5 + j * 5)
            ])
    elif wave == 16:
        for j in range(8):
            for i in range(5):
                Monsters.append([
                    monsters.Monster(3, wave, False, Images, mapName),
                    30 * (i + j * 6)
                ])
            Monsters.append([
                monsters.Monster(4, wave, False, Images, mapName),
                30 * (5 + j * 6)
            ])
    elif wave == 17:
        for i in range(12):
            Monsters.append(
                [monsters.Monster(4, wave, False, Images, mapName), 30 * (i)])
    elif wave == 18:
        for i in range(80):
            Monsters.append(
                [monsters.Monster(3, wave, False, Images, mapName), 20 * (i)])
    elif wave == 19:
        for i in range(5):
            Monsters.append(
                [monsters.Monster(3, wave, False, Images, mapName), 30 * (i)])
        for i in range(7):
            Monsters.append([
                monsters.Monster(5, wave, False, Images, mapName), 30 * (i + 5)
            ])
        for i in range(10):
            Monsters.append([
                monsters.Monster(4, wave, False, Images, mapName),
                30 * (i + 12)
            ])
    elif wave == 20:
        for i in range(5):
            Monsters.append(
                [monsters.Monster(6, wave, False, Images, mapName), 30 * (i)])

        Monsters.append(
            [monsters.Monster(7, wave, False, Images, mapName), 150])
    elif wave == 21:
        for j in range(7):
            for i in range(5):
                Monsters.append([
                    monsters.Monster(4, wave, False, Images, mapName),
                    30 * (i + j * 6)
                ])
            Monsters.append([
                monsters.Monster(5, wave, False, Images, mapName),
                30 * (5 + j * 6)
            ])
    elif wave == 22:
        for i in range(16):
            Monsters.append(
                [monsters.Monster(6, wave, False, Images, mapName), 60 * (i)])
    elif wave == 23:
        for i in range(7):
            Monsters.append([
                monsters.Monster(5, wave, False, Images, mapName), 30 * (i * 2)
            ])
            Monsters.append([
                monsters.Monster(6, wave, False, Images, mapName),
                30 * (i * 2 + 1)
            ])
    elif wave == 24:
        for i in range(5):
            Monsters.append(
                [monsters.Monster(3, wave, True, Images, mapName), 30 * (i)])
    elif wave % 25 == 0 and wave != 25:
        Monsters.append(
            [monsters.Monster(10, wave, False, Images, mapName), 30])
    else:
        for i in range(random.randint(5, 15)):
            n = random.randint(1, 100)
            if n <= 40 - wave:
                Monsters.append([
                    monsters.Monster(1, wave,
                                     random.randint(1, 10) == 1, Images,
                                     mapName),
                    random.randint(15, 30) * (i)
                ])
            elif n <= 50 - wave:
                Monsters.append([
                    monsters.Monster(2, wave,
                                     random.randint(1, 10) == 1, Images,
                                     mapName),
                    random.randint(15, 30) * (i)
                ])
            elif n <= 65 - wave:
                Monsters.append([
                    monsters.Monster(3, wave,
                                     random.randint(1, 10) == 1, Images,
                                     mapName),
                    random.randint(15, 30) * (i)
                ])
            elif n <= 75 - wave:
                Monsters.append([
                    monsters.Monster(4, wave,
                                     random.randint(1, 10) == 1, Images,
                                     mapName),
                    random.randint(15, 30) * (i)
                ])
            elif n <= 85 - wave:
                Monsters.append([
                    monsters.Monster(5, wave,
                                     random.randint(1, 10) == 1, Images,
                                     mapName),
                    random.randint(15, 30) * (i)
                ])
            elif n <= 100 - wave:
                Monsters.append([
                    monsters.Monster(6, wave,
                                     random.randint(1, 10) == 1, Images,
                                     mapName),
                    random.randint(15, 30) * (i)
                ])
            elif n <= 125 - wave:
                Monsters.append([
                    monsters.Monster(7, wave, False, Images, mapName),
                    random.randint(15, 30) * (i)
                ])
            elif n <= 130 - wave:
                Monsters.append([
                    monsters.Monster(8, wave,
                                     random.randint(1, 10) == 1, Images,
                                     mapName),
                    random.randint(15, 30) * (i)
                ])
            elif n <= 175 - wave:
                Monsters.append([
                    monsters.Monster(9, wave,
                                     random.randint(1, 10) == 1, Images,
                                     mapName),
                    random.randint(15, 30) * (i)
                ])
            elif n <= 200 - wave:
                Monsters.append([
                    monsters.Monster(10, wave, False, Images, mapName),
                    random.randint(15, 30) * i
                ])
    return Monsters