Ejemplo n.º 1
0
def populate_level(num, level):
    # generate a few groups of mobs
    for i in range(10):
        faction = random.choice(list(factions.keys()))
        groups = factions[faction]['groups']
        group = random.choice(groups)

        # spawn leader at pos, spawn rest of mobs within fov
        leader_info = mobinfo[group[0]]
        leader_pos = get_random_passable_position(level)
        leader = level.mobs[leader_pos] = mob.Mob(leader_pos, num, leader_info)
        tiles_in_sight = list(
            filter(lambda pos: not level.is_blocked(pos),
                   fov.calculate_fov(leader_pos, 5, level)))
        for mob_type in group[1:]:
            info = mobinfo[mob_type]
            pos = random.choice(tiles_in_sight)
            tiles_in_sight.remove(pos)
            level.mobs[pos] = mob.Mob(pos, num, info, leader=leader)
Ejemplo n.º 2
0
 def populate(self, density):
     for a in range(self.sizefactor * density):
         mobbo = mob.Mob(self.level, self.level.mobs)
         mobbo.set_type(random.randrange(7))
         mobbo.set_species(random.randrange(4) + 1)
         mobbo.unpassable.add(self.level.space)
         mobbo.spawn(
             random.randrange(len(self.zone) - 2) + 1,
             random.randrange(len(self.zone[0]) - 2) + 1)
         if mobbo.mapx == self.level.player1.mapx and mobbo.mapy == self.level.player1.mapy:
             mobbo.kill()
Ejemplo n.º 3
0
    def attack_mob(self, mob_name):
        _mob = mob.Mob(mob_name)
        while self.hp > 0 and _mob.hp > 0:
            _mob.be_attacked(self)
            if _mob.hp > 0:
                _mob.attack(self)

        if self.hp < 1:
            ui.mes(self.name,
                   ['I dead.', 'I will revive at ' + self.save + '.'])
            ui.wait()
            self.hp = self.mhp()
            self.status = {}
            self.warp(self.save)
        else:
            _mob.dead(self)
Ejemplo n.º 4
0
    def generate_mobs(self):
        dice = random.random()
        if dice < (.05 + self.time_factor):
            if self.time_factor < 1: self.time_factor += .0005
            
            #print(str(.05 + self.time_factor))
            #print("generating mob")
            x = random.randint(-1000,1000)
            if x > 0:
                x += self.game.display._w

            y = random.randint(-1000,1000)
            if y > 0:
                y += self.game.display._h

            m = mob.Mob(self, self.game, self.player.x + x, self.player.y + y)
            self.game.register_actor(m)
            self.mobs.append(m)
Ejemplo n.º 5
0
def newmob():
    m = mob.Mob(WIDTH, HEIGHT)
    all_sprites.add(m)
    mobs.add(m)
Ejemplo n.º 6
0
    def __init__(self):
        self.running = True # set the game loop good to go
        config = ConfigParser.ConfigParser()
        config.readfp(open('main.cfg'))
        self.fsw = config.getint('main', 'fullscreenwidth')
        self.fsh = config.getint('main', 'fullscreenheight')
        self.ww = config.getint('main', 'windowedwidth')
        self.wh = config.getint('main', 'windowedheight')
        self.tw = config.getint('main', 'tilewidth')
        self.mapw = config.getint('main', 'mapwidth')
        self.maph = config.getint('main', 'mapheight')
        self.fullscreen = config.getboolean('main', 'fullscreen')
        self.paused = False
        self.white = (255, 255, 255) # the colour :)

        #fullscreen = False
        self.FPS = 60
        pygame.init()
        #setup the default screen size
        if self.fullscreen == True:
            self.screen = pygame.display.set_mode((self.fsw, self.fsh), FULLSCREEN)
        else:
            self.screen = pygame.display.set_mode((self.ww, self.wh), RESIZABLE)

        pygame.display.set_caption('pyDF')
        #Intro's on by default, will need to add a config file entry for this.
        self.intro = True
        self.mainclock = pygame.time.Clock()
        # various rendering offsets
        self.vpRenderOffset = (self.tw, self.tw)
        self.statsOffset = (math.floor(int(0.8 * self.ww) + 2 * self.tw), self.tw)
        self.menuOffset = (math.floor(int(0.8 * self.ww) + 2 * self.tw), 4 * self.tw)
        self.menuOffset2 = (math.floor(int(0.8 * self.ww) + 2 * self.tw), 5 * self.tw)
        self.menuOffset3 = (math.floor(int(0.8 * self.ww) + 2 * self.tw), 6 * self.tw) # testing for ezmenu
        self.idleOffset = (math.floor(int(0.8 * self.ww) + 2 * self.tw), 0) # testing for ezmenu
        self.pauseDisplayOffset = (self.tw, 0)
        self.digTypeOffset = (math.floor(int(0.8 * self.ww) + 2 * self.tw), 4 * self.tw)
        self.showmenu = False
        self.currentmenu = None
        self.vpCoordinate = [0, 0] # Starting coordinates for the view port
        self.vpDimensions = (math.floor(int(0.8 * self.ww) / self.tw) * self.tw, math.floor(int(0.9 * self.wh) / self.tw) * self.tw) # resolution of the view port
        self.vpStep = self.tw # move 1 tile over.
        self.vpShiftStep = self.tw * 10 # move 10 tile over.
        self.minHorizScrollBound = 0
        self.minVertScrollBound = 0
        self.maxHorizScrollBound = self.mapw * self.tw
        self.maxVertScrollBound = self.maph * self.tw
        self.numXTiles = int(math.ceil(int(self.vpDimensions[0]) / self.tw)) # the number of tiles to be shown at one time for X
        self.numYTiles = int(math.ceil(int(self.vpDimensions[1]) / self.tw)) # the number of tiles to be shown at one time for y
        self.startXTile = math.floor(int(self.vpCoordinate[0]) / self.tw)
        self.startYTile = math.floor(int(self.vpCoordinate[1]) / self.tw)

        if not pygame.font.get_init():
            pygame.font.init()
        self.arialFnt = pygame.font.SysFont('Arial', 16)
        self.m = gamemap.GameMap(self.tw, self.mapw, self.maph, self.startXTile, self.startYTile, self.numXTiles, self.numYTiles)
        self.m.initMap()
        self.m.initEMap()
        self.editmode = [None, None]
        self.selectmode = False
        self.testmode = False
        self.roomtiles = []
        self.selectcursor = cursor.Cursor(self.tw, self.m.numXTiles / 2 * self.tw, self.m.numYTiles / 2 * self.tw)
        self.queued_jobs = []
        self.mobs = []
        self.mapvalue = None
        self.tilecontent = None
        #self.currentZlevel = self.m.currentZlevel
        openspot = self.m.find_open_spot()
        self.currentZlevel = openspot[2]
        self.mobs.append(mob.Mob(openspot, self.tw))
        self.addTileMob(openspot[0], openspot[1], openspot[2], self.mobs[0])
        self.mobs.append(mob.Mob(openspot, self.tw))
        self.addTileMob(openspot[0], openspot[1], openspot[2], self.mobs[0])
        self.mobs.append(mob.Mob(openspot, self.tw))
        self.addTileMob(openspot[0], openspot[1], openspot[2], self.mobs[0])
        self.buttons = {}
        #self.keys = set()
        self.motion = None
Ejemplo n.º 7
0
    def __init__(self):
        """ Load world from files. """
        self.rList = []

        # open all files in directory world/rooms/
        fileList = os.listdir('world\\rooms\\')

        # find highest room number and create self.rList with that many slots
        highNum = 1
        for f in fileList:
            num = f.split('.')
            if int(num[0]) > highNum:
                highNum = int(num[0])
        self.rList = [0] * (highNum + 1)

        for f in fileList:
            settings = files.loadFromFile('world\\rooms\\%s' % f)
            id = None
            title = None
            desc = None
            exits = [None] * 10
            inventory = []
            mList = []
            for k in settings.keys():
                if k == 'ID':
                    id = int(settings[k])
                elif k == 'Title':
                    title = settings[k]
                elif k == 'Desc':
                    desc = settings[k]
                elif k == 'N':
                    exits[0] = int(settings[k])
                elif k == 'NE':
                    exits[1] = int(settings[k])
                elif k == 'E':
                    exits[2] = int(settings[k])
                elif k == 'SE':
                    exits[3] = int(settings[k])
                elif k == 'S':
                    exits[4] = int(settings[k])
                elif k == 'SW':
                    exits[5] = int(settings[k])
                elif k == 'W':
                    exits[6] = int(settings[k])
                elif k == 'NW':
                    exits[7] = int(settings[k])
                elif k == 'U':
                    exits[8] = int(settings[k])
                elif k == 'D':
                    exits[9] = int(settings[k])
                elif k == 'I':
                    inventory.append(objects.Object(None, settings[k]))
                elif k == 'M':
                    mList.append(mob.Mob(int(settings[k])))
            r = room.Room(id, title, desc, exits)
            r.inventory = inventory
            r.mList = mList
            # update mobs knowledge of their room
            for m in r.mList:
                m.room = r
            self.rList[id] = r

        # loop through rooms and turn exit ints into room links
        for r in self.rList:
            # loop through exits in room
            for e in range(len(r.exits)):
                # if room has an exit
                if r.exits[e] != None:
                    # loop through room list again
                    for t in self.rList:
                        # if current room id == exit int
                        if t.id == r.exits[e]:
                            # set exit to room object
                            r.exits[e] = t
Ejemplo n.º 8
0
def newmob():
    m = mob.Mob()
    all_sprites.add(m)
    mobs.add(m)
Ejemplo n.º 9
0
    data_enemies = json.load(file_mobs)
    data_characters = json.load(file_characters)
    data_projectile = json.load(file_projectile)

SCREEN_WIDTH = 1920
SCREEN_HEIGHT = 1080
GROUND_POSITION = 840

screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

pygame.display.set_caption("Tiro al arco")
bg = pygame.image.load('images/background/background.jpg').convert()

enemy = mob.Mob(data_enemies[0]['walk_left'], data_enemies[0]['walk_right'],
                (data_enemies[0]['x'], data_enemies[0]['y']),
                data_enemies[0]['image'], data_enemies[0]['columns'],
                data_enemies[0]['rows'], data_enemies[0]['end'],
                data_enemies[0]['hitbox'])

scale = data_characters[character_index]['scale'] == "True"

player = player.Player(data_characters[character_index]['walk_left'],
                       data_characters[character_index]['walk_right'],
                       data_characters[character_index]['idle'],
                       (data_characters[character_index]['x'],
                        data_characters[character_index]['y']),
                       data_characters[character_index]['width'],
                       data_characters[character_index]['force'],
                       data_characters[character_index]['velocity'],
                       data_characters[character_index]['image'],
                       data_characters[character_index]['columns'],
Ejemplo n.º 10
0
import mob
import room
import fa
import level
#初始化主角
me = mob.Mob(100, 10, 10, 0, 0)
#关于关卡的选择变量
i = 1
while (i == 0 or i == 1):
    #如果是有怪物的就返回了怪物,没有怪物就返回了None
    enemy = level.got(i, me)
    i = i - 1
    if enemy != None:
        print('round start')
        while 1:
            print('plesase choose your mode:')
            m = input()
            m = int(m)
            temp = fa.cope(m, me, enemy)
            enemy.health = enemy.health - temp
            if enemy.health < 0:
                enemy.health = 0
            print('you caused %d damage' % temp,
                  'your enemy have %d health' % enemy.health)
            if enemy.health <= 0:
                print('you win')
                break
            temp = enemy.attack - me.defense
            if temp <= 0:
                temp = 1
            me.health = me.health - temp