コード例 #1
0
ファイル: player.py プロジェクト: giginet/FormationPuzzle
class NPC(Player):
    def __init__(self, n):
        super(NPC, self).__init__(n)
        self.act_timer = Timer(1)
        self.goal = LocalPoint(0,0)
        self.interfaces = ['npc']
        self.rotate = False
        
    def update(self):
        self.act_timer.tick()
        if self.point == self.goal:
            self.goal = LocalPoint(random.randint(0,settings.STAGE_WIDTH),random.randint((1-self.number)*settings.STAGE_WIDTH/2,(1-self.number)*settings.STAGE_WIDTH/2+settings.STAGE_WIDTH/2-3))
            self.rotate = True
        else:
            if not self.act_timer.is_over(): return
            sub = self.goal - self.point
            if sub.x >0:
                self.point.x +=1
            elif sub.x < 0:
                self.point.x -=1
            if sub.y >0:
                self.point.y +=1
            elif sub.y < 0:
                self.point.y -=1
        self.move_pointer()
        self.act_timer.reset()
        self.act_timer.play()
        
    def poll(self):
        if self.rotate:
            self.rotate = False
            return random.choice([-1,1])
コード例 #2
0
class GameTimer(Number):
    def __init__(self):
        self.timer = Timer(settings.FPS*settings.YEARS)
        super(GameTimer, self).__init__(u"../resources/image/main/navigation/timer.png", w=36, h=90)
        self.x, self.y = settings.TIMER_POSITON
        self.align = Number.TEXTALIGNCENTER
        self.n = int((self.timer.max-self.timer.now)/settings.FPS)
    def update(self):
        self.timer.tick()
        self.n = int((self.timer.max-self.timer.now)/settings.FPS)
    def play(self):
        self.timer.play()
    def is_over(self):
        return self.timer.is_over()
    def reset(self):
        self.timer.reset()
    @property
    def now(self):
        return self.n
コード例 #3
0
ファイル: __init__.py プロジェクト: giginet/FormationPuzzle
class Unit(object):
    animation_enable = False
    offset = (0,0)
    parameter = ATTACK
    name = 'unit'
    degree = LocalPoint(0,0)
    
    def __init__(self, panels, stage):
        self.panels = panels
        self.stage = stage
        self.owner = panels[0].owner
        self.color = panels[0].color
        self.degree = LocalPoint(0, -1+self.owner*2)
        self.image = Animation(self.parameter['image'], AnimationInfo(self.owner,0,0,self.parameter['width'],self.parameter['height'],0))
        self.hp = self.parameter['hp']
        self.attack = self.parameter['attack']
        self.limit = self.parameter['limit']
        self.count = 0
        self.timer = Timer(self.parameter['frequency'])
        appear_sound = Sound(u'../resources/sound/appear.wav')
        appear_sound.play()
        self.image.x, self.image.y = (self.panels[0].point + LocalPoint(self.offset)).to_global().to_pos()
        self.delay = Timer()
        if self.parameter['effect']['enable'] and settings.EFFECTENABLE:
            ef = self.parameter['effect']
            Effect(ef['appear'], AnimationInfo(0,0,ef['frame'],ef['width'],ef['height'],1), x=self.image.x-ef['offset'][0], y=self.image.y-ef['offset'][1])
            self.delay.set(self.parameter['delay'])
        self.delay.play()
        
    
    @classmethod
    def generate(cls, panels, map):
        raise NotImplementedError
    
    @staticmethod
    def check(panels):
        color = panels[0].color
        owner = panels[0].owner
        for panel in panels:
            if not panel.can_unit() or not color == panel.color or not owner == panel.owner:
                return False
        else:
            return True
        
    def update(self):
        u"""1のとき進める、-1のとき消す"""
        for panel in self.panels:
            if panel.disable or not panel.owner == self.owner:
                return -1
        self.image.x, self.image.y = (self.panels[0].point + LocalPoint(self.offset)).to_global().to_pos()
        self.delay.tick()
        if self.delay.is_over(): self.timer.play()
        self.timer.tick()
        if self.timer.is_over():
            if self.count < self.limit:
                self.timer.reset()
                self.count+=1
                return 1
            else: return -1
        return
    
    def move(self, panels):
        pass
    
    def draw(self):
        if self.delay.is_over(): self.image.draw()
        
    def get_front(self, vector):
        x, y = vector.to_pos()
        if x is 0 and y is -1:
            return self.panels.sort(cmp=lambda x, y: cmp(x.y,y.y))[0]
        elif x is 1 and y is 0:
            return self.panels.sort(cmp=lambda x, y: cmp(x.x,y.x), reverse=True)[0]
        elif x is 0 and y is 1:
            return self.panels.sort(cmp=lambda x, y: cmp(x.y,y.y), reverse=True)[0]
        elif x is -1 and y is 0:
            return self.panels.sort(cmp=lambda x, y: cmp(x.x,y.x))[0] 
        
    def has(self, panel): return panel in self.panels
    
    def disappear(self):
        if not self.name == 'bomb':
            disappear_sound = Sound(u'../resources/sound/disappear.wav')
            disappear_sound.play()
        for panel in self.panels: 
            panel.change_color()
            panel.unit = False
コード例 #4
0
ファイル: city.py プロジェクト: maraigue/MachiMatch
class City(object):
    u"""街クラス。人口や発展状況などを管理する"""
    def __init__(self, owner, world):
        u"""
            owner : この街を所持するプレイヤー
            world : Worldクラスインスタンス
        """
        self.owner = owner
        self.world = world
        self.population = 0
        self.level = 1
        self.buildings = []
        self.territories = []
        self.flow_timer = Timer(settings.FPS*settings.FLOW_POPULATION_YEAR)
        self.building_matrix = []
        for x in xrange(0, 4):
            row = []
            for y in xrange(0, 4):
                u"""領土内相対座標の二次配列作成"""
                row.append(None)
            self.building_matrix.append(row)
    def increase_population(self, p=None):
        u"""人口を増やす。その後、レベルアップの判定をする
            増える人口はレベルに依存する。 p*2^(lv-1)
        """
        self.flow_timer.reset()
        self.flow_timer.play()
        if not p:
            self.population += self._calc_population()
        else:
            self.population += p
        if self.level < 5 and settings.LEVELUP_BORDERLINES[self.level] < self.population:
            self.level +=1
            print "LevelUp! %d" % self.level
    def decrease_population(self, p):
        u"""
            p人人口を減らす
            実際に減った人数を返す
        """
        self.flow_timer.reset()
        self.flow_timer.play()
        if self.population < p:
            p = self.population
            self.population = 0
        else:
            self.population -= p
        return p
    def _create_building(self):
        if self.population <= 0: return
        if random.randint(0, settings.BUILDING_POP_RATE) != 0: return
        x = random.randint(0, 3)
        y = random.randint(0, 3)
        if not self.building_matrix[x][y] or (self.building_matrix[x][y] and self.building_matrix[x][y].level != self.level):
            bs = LEVEL_BUILDINGS[self.level-1]
            if len(bs) == 0: return
            building = random.choice(bs)(self.root_point.x+x, self.root_point.y+y)
            for sx in xrange(x, x+building.size):
                for sy in xrange(y, y+building.size):
                    self.building_matrix[sx][sy] = building
    def _calc_population(self):
        u"""レベルに応じた増減する人口を算出する"""
        p = random.randint(8000, 12000)
        return p*2**(self.level-1)
        
    def update(self):
        self.flow_timer.tick()
        if self.flow_timer.is_over() and self.population > 0:
            u"""人を流出させる"""
            bottom_territories = self._get_bottom_territories()
            for territory in bottom_territories:
                u"""最も手前にある領土の一覧を取ってきて、繋がっているかどうか調査する"""
                front = self.world.get_panel_from(territory, 2)
                if territory.is_connect_with(front):
                    self._flow_immigration(territory, front)
        self._create_building()
        updated = []
        for x in xrange(0, 4):
            for y in xrange(0, 4):
                b = self.building_matrix[x][y]
                if b and not b in updated:
                    b.update()
                    updated.append(b)
    def draw(self):
        rendered = []
        for x in xrange(0, 4):
            for y in xrange(0, 4):
                b = self.building_matrix[x][y]
                if b and not b in rendered:
                    b.draw()
                    rendered.append(b)
    def _flow_immigration(self, territory, front):
        immigrant = self.world.i_manager.create_immigrant(territory.point.x, territory.point.y)
        p = self._calc_population()
        p = self.decrease_population(p)
        immigrant.population = p
        immigrant.direction = 2
        immigrant.ainfo.index = 2
        immigrant.current_ground = territory
        immigrant.x, immigrant.y = territory.surface_bottom_edge.to_pos()
        immigrant.goal_ground = front
        self.flow_timer.reset()
    def _get_bottom_territories(self):
        u"""領土最下層のTerritoryのみを取ってくる"""
        list = []
        for territory in self.territories:
            if territory.point.y == 3:
                list.append(territory)
        return list
    @property
    def root_point(self):
        return Vector(self.owner.number*4, 0)
コード例 #5
0
ファイル: city.py プロジェクト: giginet/MachiMatch
class City(object):
    u"""街クラス。人口や発展状況などを管理する"""    
    def __init__(self, owner, world):
        u"""
            owner : この街を所持するプレイヤー
            world : Worldクラスインスタンス
        """
        self.owner = owner
        self.world = world
        self.levelup_sound = Sound("../resources/sound/levelup.wav")
        self.increase_sound = Sound("../resources/sound/increase.wav")
        self.population = 0
        self.level = 1
        self.buildings = []
        self.territories = []
        self.flow_timer = Timer(settings.FPS*settings.FLOW_POPULATION_YEAR)
        self.building_matrix = [[None for col in range(settings.STAGE_HEIGHT)] for row in range(settings.STAGE_WIDTH)] # 二次配列を生成してNoneで初期化
        #self._constract_building(Laputa, 0, 0)
    def increase_population(self, p=None):
        u"""人口を増やす。その後、レベルアップの判定をする
            増える人口はレベルに依存する。 p*2^(lv-1)
        """
        self.flow_timer.reset()
        self.flow_timer.play()
        if not p:
            self.population += self._calc_population()
        else:
            self.population += p
        if self.level < 5 and settings.LEVELUP_BORDERLINES[self.level] < self.population:
            self.levelup_sound.play()
            self.level +=1
        else:
            self.increase_sound.play()
    def decrease_population(self, p):
        u"""
            p人人口を減らす
            実際に減った人数を返す
        """
        self.flow_timer.reset()
        self.flow_timer.play()
        if self.population < p:
            p = self.population
            self.population = 0
        else:
            self.population -= p
        return p
    def _pop_building(self):
        u"""ビルを建てる"""
        if self.population <= 0: return
        if random.randint(0, settings.BUILDING_POP_RATE) != 0: return
        buildings = LEVEL_BUILDINGS[self.level-1]
        if len(buildings) == 0: return
        if self.level <= 2:
            x = random.randint(0, 3)
            y = random.randint(0, 3)
        elif self.level <= 4:
            x, y = random.choice(((0, 0), (2, 0), (0, 2), (2, 2)))
        elif self.level == 5:
            x, y = (0, 0)
        if not self.building_matrix[x][y] or (self.building_matrix[x][y] and self.building_matrix[x][y].level != self.level):
                building = random.choice(buildings)
                self._constract_building(building, x, y)
    def _constract_building(self, cls, x, y):
        building = cls(self.root_point.x+x, self.root_point.y+y)
        for sx in xrange(x, x+building.size):
            for sy in xrange(y, y+building.size):
                self.building_matrix[sx][sy] = building
        self.buildings.append(building)
    
    def _calc_population(self):
        u"""レベルに応じた増減する人口を算出する"""
        p = random.randint(8000, 12000)
        return p*2**(self.level-1)
        
    def update(self):
        self.flow_timer.tick()
        if self.flow_timer.is_over() and self.population > 0:
            u"""人を流出させる"""
            bottom_territories = self._get_bottom_territories()
            for territory in bottom_territories:
                u"""最も手前にある領土の一覧を取ってきて、繋がっているかどうか調査する"""
                front = self.world.get_panel_from(territory, 2)
                if territory.is_connect_with(front):
                    self._flow_immigration(territory, front)
        self._pop_building()
        updated = []
        for x in xrange(0, 4):
            for y in xrange(0, 4):
                b = self.building_matrix[x][y]
                if b and not b in updated:
                    b.update()
                    updated.append(b)
    def draw(self):
        rendered = []
        for x in xrange(0, 4):
            for y in xrange(0, 4):
                b = self.building_matrix[x][y]
                if b and not b in rendered:
                    b.draw()
                    rendered.append(b)
    def _flow_immigration(self, territory, front):
        u"""移民を流出させる"""
        immigrant = self.world.i_manager.create_immigrant(territory.point.x, territory.point.y)
        p = self._calc_population()
        p = self.decrease_population(p)
        immigrant.population = p
        immigrant.direction = 2
        immigrant.ainfo.index = 2
        immigrant.current_ground = territory
        immigrant.x, immigrant.y = territory.surface_bottom_edge.to_pos()
        immigrant.goal_ground = front
        self.flow_timer.reset()
    def _get_bottom_territories(self):
        u"""領土最下層のTerritoryのみを取ってくる"""
        list = []
        for territory in self.territories:
            if territory.point.y == 3:
                list.append(territory)
        return list
    @property
    def root_point(self):
        u"""街の左上の座標を返す"""
        pc = self.world.player_count
        if pc == 1:
            return Vector(6, 0)
        elif pc == 2:
            return (Vector(2, 0), Vector(10, 0))[self.owner.number]
        elif pc == 3:
            return (Vector(1, 0), Vector(6, 0), Vector(11, 0))[self.owner.number]
        elif pc == 4:
            return Vector(self.owner.number*4, 0)
コード例 #6
0
ファイル: city.py プロジェクト: giginet/MachiMatch
class City(object):
    u"""街クラス。人口や発展状況などを管理する"""
    def __init__(self, owner, world):
        u"""
            owner : この街を所持するプレイヤー
            world : Worldクラスインスタンス
        """
        self.owner = owner
        self.world = world
        self.levelup_sound = Sound("../resources/sound/levelup.wav")
        self.increase_sound = Sound("../resources/sound/increase.wav")
        self.population = 0
        self.level = 1
        self.buildings = []
        self.territories = []
        self.flow_timer = Timer(settings.FPS * settings.FLOW_POPULATION_YEAR)
        self.building_matrix = [[None for col in range(settings.STAGE_HEIGHT)]
                                for row in range(settings.STAGE_WIDTH)
                                ]  # 二次配列を生成してNoneで初期化
        #self._constract_building(Laputa, 0, 0)
    def increase_population(self, p=None):
        u"""人口を増やす。その後、レベルアップの判定をする
            増える人口はレベルに依存する。 p*2^(lv-1)
        """
        self.flow_timer.reset()
        self.flow_timer.play()
        if not p:
            self.population += self._calc_population()
        else:
            self.population += p
        if self.level < 5 and settings.LEVELUP_BORDERLINES[
                self.level] < self.population:
            self.levelup_sound.play()
            self.level += 1
        else:
            self.increase_sound.play()

    def decrease_population(self, p):
        u"""
            p人人口を減らす
            実際に減った人数を返す
        """
        self.flow_timer.reset()
        self.flow_timer.play()
        if self.population < p:
            p = self.population
            self.population = 0
        else:
            self.population -= p
        return p

    def _pop_building(self):
        u"""ビルを建てる"""
        if self.population <= 0: return
        if random.randint(0, settings.BUILDING_POP_RATE) != 0: return
        buildings = LEVEL_BUILDINGS[self.level - 1]
        if len(buildings) == 0: return
        if self.level <= 2:
            x = random.randint(0, 3)
            y = random.randint(0, 3)
        elif self.level <= 4:
            x, y = random.choice(((0, 0), (2, 0), (0, 2), (2, 2)))
        elif self.level == 5:
            x, y = (0, 0)
        if not self.building_matrix[x][y] or (
                self.building_matrix[x][y]
                and self.building_matrix[x][y].level != self.level):
            building = random.choice(buildings)
            self._constract_building(building, x, y)

    def _constract_building(self, cls, x, y):
        building = cls(self.root_point.x + x, self.root_point.y + y)
        for sx in xrange(x, x + building.size):
            for sy in xrange(y, y + building.size):
                self.building_matrix[sx][sy] = building
        self.buildings.append(building)

    def _calc_population(self):
        u"""レベルに応じた増減する人口を算出する"""
        p = random.randint(8000, 12000)
        return p * 2**(self.level - 1)

    def update(self):
        self.flow_timer.tick()
        if self.flow_timer.is_over() and self.population > 0:
            u"""人を流出させる"""
            bottom_territories = self._get_bottom_territories()
            for territory in bottom_territories:
                u"""最も手前にある領土の一覧を取ってきて、繋がっているかどうか調査する"""
                front = self.world.get_panel_from(territory, 2)
                if territory.is_connect_with(front):
                    self._flow_immigration(territory, front)
        self._pop_building()
        updated = []
        for x in xrange(0, 4):
            for y in xrange(0, 4):
                b = self.building_matrix[x][y]
                if b and not b in updated:
                    b.update()
                    updated.append(b)

    def draw(self):
        rendered = []
        for x in xrange(0, 4):
            for y in xrange(0, 4):
                b = self.building_matrix[x][y]
                if b and not b in rendered:
                    b.draw()
                    rendered.append(b)

    def _flow_immigration(self, territory, front):
        u"""移民を流出させる"""
        immigrant = self.world.i_manager.create_immigrant(
            territory.point.x, territory.point.y)
        p = self._calc_population()
        p = self.decrease_population(p)
        immigrant.population = p
        immigrant.direction = 2
        immigrant.ainfo.index = 2
        immigrant.current_ground = territory
        immigrant.x, immigrant.y = territory.surface_bottom_edge.to_pos()
        immigrant.goal_ground = front
        self.flow_timer.reset()

    def _get_bottom_territories(self):
        u"""領土最下層のTerritoryのみを取ってくる"""
        list = []
        for territory in self.territories:
            if territory.point.y == 3:
                list.append(territory)
        return list

    @property
    def root_point(self):
        u"""街の左上の座標を返す"""
        pc = self.world.player_count
        if pc == 1:
            return Vector(6, 0)
        elif pc == 2:
            return (Vector(2, 0), Vector(10, 0))[self.owner.number]
        elif pc == 3:
            return (Vector(1, 0), Vector(6, 0), Vector(11,
                                                       0))[self.owner.number]
        elif pc == 4:
            return Vector(self.owner.number * 4, 0)