示例#1
0
    def __init__(self):
        self.pos = Pt(0, 0)
        self.size = Pt(80, 100)

        self.name = None
        self.action = None
        self.target = None
示例#2
0
 def transform(self, X):
     if isinstance(X, Pt):
         return self.screen_center + (X - self.pos) * self.scale
     if isinstance(X, Rect):
         center = Pt(X.center)
         size = Pt(X.size) * self.scale
         pos = self.screen_center + (center - self.pos) * self.scale
         return Rect((pos + (size * 0.5)), size)
示例#3
0
文件: game.py 项目: keltoff/Demiurge
    def handle_key(self, key, release=False):
        pressed = _key_transform_(key)

        if key == pygame.K_HOME:
            self.camera.focus_on(self.player)
        if key == pygame.K_INSERT:
            self.camera.focus_on(Pt(0, 0))
        if key == pygame.K_PAGEUP:
            self.camera.focus_on(Pt(400, 200))

        if release == False:
            self.player.control(pressed)
示例#4
0
 def update(self):
     if isinstance(self.target, Pt):
         self.pos = self.target
     elif isinstance(self.target, tuple):
         self.pos = Pt(self.target)
     elif hasattr(self.target, 'pos'):
         self.pos = self.target.pos
示例#5
0
 def __init__(self):
     self.hlines = []
     self.vlines = []
     self.bodies = []
     self.objects = []
     self.net = None
     self.G = Pt(0, -5)
示例#6
0
    def __init__(self):
        self.pos = Pt(0, 0)
        # self.radius = Position(15, -25)
        self.shape = Rect(0, 0, 30, 50)

        self.scheme = None
        self.name = None
示例#7
0
文件: box.py 项目: keltoff/Demiurge
    def update(self, level, keys, is_player):
        if is_player:
            shift = Pt(0, 0)
            for key, change in {
                    'UP': (0, 10),
                    'DN': (0, -10),
                    'LT': (-10, 0),
                    'RT': (10, 0)
            }.iteritems():
                if key in keys:
                    shift += change
            self.pos = self.on_line.try_move(self.pos + shift)

            switch, dist = None, float('inf')
            if isinstance(self.on_line, HLine):
                if 'UP' in keys:
                    switch, dist = self.on_line.up_closest(self.pos)
                if 'DN' in keys:
                    switch, dist = self.on_line.down_closest(self.pos)
            if isinstance(self.on_line, VLine):
                if 'LT' in keys:
                    switch, dist = self.on_line.left_closest(self.pos)
                if 'RT' in keys:
                    switch, dist = self.on_line.right_closest(self.pos)

            if switch and dist <= self.speed:
                self.on_line = switch
                self.pos = switch.try_move(self.pos)
        else:
            # AI
            pass
示例#8
0
文件: box.py 项目: keltoff/Demiurge
    def __init__(self):
        self.pos = Pt(0, 0)
        self.shape = Rect(0, 0, 30, 50)

        self.scheme = None
        self.name = None

        self.speed = 10

        self.on_line = None
示例#9
0
    def from_xml(xml_node):
        def load_tuple(val):
            return make_tuple(xml_node.attrib[val])

        position = load_tuple('pos')

        node = Node()
        node.pos = Pt(position)
        node.name = xml_node.attrib['id']
        node.type = xml_node.attrib.get('type', 'junction')
        return node
示例#10
0
    def from_xml(xml_node):
        def load_tuple(val):
            return make_tuple(xml_node.attrib[val])

        position = load_tuple('pos')

        obj = Interactable()
        obj.pos = Pt(position)
        # obj.name = xml_node.attrib['id']
        obj.action = 'uplink'
        obj.target = xml_node.attrib['node']
        return obj
示例#11
0
文件: box.py 项目: keltoff/Demiurge
    def parse(self, xml_node):
        position = make_tuple(xml_node.attrib['pos'])
        model = xml_node.attrib['type']
        id = xml_node.attrib['id']

        body = Body()
        body.pos = Pt(position)
        body.name = id
        body.scheme = model
        body.shape = self.library[model]

        return body
示例#12
0
    def __init__(self, name, img, shift, hold=None, end='last', speed=None):
        self.sprite = None
        self.name = name
        self.img = img
        self.shift = shift
        self.hold = hold

        self.end = end

        if speed is None:
            self.speed = Pt(0, 0)
        else:
            self.speed = speed
示例#13
0
    def draw(self, surface, camera):
        Line.draw(self, surface, camera)

        l_color = (200, 0, 0)

        for l in self.links:
            l_pt = Pt(l.x, self.y)

            pygame.draw.line(surface, l_color,
                             camera.transform(l_pt + (10, 10)),
                             camera.transform(l_pt + (-10, 10)))
            pygame.draw.line(surface, l_color,
                             camera.transform(l_pt + (10, -10)),
                             camera.transform(l_pt + (-10, -10)))
示例#14
0
    def from_xml(xml_node):
        def load_tuple(val):
            return make_tuple(xml_node.attrib[val])

        position = load_tuple('pos')
        size = load_tuple('size')
        scheme = xml_node.attrib['scheme']

        body = Body()
        body.pos = Pt(position)
        body.shape = Rect((0, 0), size)
        body.name = xml_node.attrib['id']
        # body.scheme = schemes.get(scheme)
        body.scheme = scheme
        return body
示例#15
0
文件: game.py 项目: keltoff/Demiurge
    def __init__(self):
        self.background = empty()

        self.level = Lines.from_xml('data/level2.xml')

        self.gui = gui.GUI()

        self.camera = cam.Camera(Pt(320, 240))

        # sophia = soph.sophia()
        # sophia.pos = Position(10, 10)

        # self.player = sophia
        # self.sprites = [sophia]
        self.sprites = []
示例#16
0
def marker(pt, surface, mark='+', color='red'):
    if isinstance(color, str):
        color = pygame.Color(color)

    size = 5

    if mark == '+':
        pygame.draw.line(surface, color, pt, pt + Pt(-size, 0))
        pygame.draw.line(surface, color, pt, pt + Pt(size, 0))
        pygame.draw.line(surface, color, pt, pt + Pt(0, size))
        pygame.draw.line(surface, color, pt, pt + Pt(0, -size))
    elif mark == 'o':
        pygame.draw.circle(surface, color, pt.as_int(), size, 1)
    elif mark == 'x':
        pygame.draw.line(surface, color, pt, pt + Pt(-size, -size))
        pygame.draw.line(surface, color, pt, pt + Pt(-size, size))
        pygame.draw.line(surface, color, pt, pt + Pt(size, -size))
        pygame.draw.line(surface, color, pt, pt + Pt(size, size))
示例#17
0
    def __init__(self):
        Screen.__init__(self)
        self.background = empty()

        self.level = Linkage.from_xml('data/prototyp_1.xml')
        self.bodies = FlipThroughList(self.level.bodies)
        self.focus = None

        self.gui = gui.GUI()

        self.camera = cam.Camera(Pt(320, 240))

        # sophia = soph.sophia()
        # sophia.pos = Position(10, 10)

        # self.player = sophia
        # self.sprites = [sophia]
        self.sprites = []
示例#18
0
    def handle_key(self, key, release=False):
        pressed = _key_transform_(key)

        if release:
            return

        if key == pygame.K_HOME:
            self.focus = None
            self.bodies.clear()
            self.camera.focus_on(Pt(0, 0))
        if key == pygame.K_DELETE:
            self.focus = None
            self.bodies.clear()
            self.camera.focus_on(self.camera.pos)
        if key == pygame.K_PAGEDOWN:
            self.focus = self.bodies.next()
            self.camera.focus_on(self.focus)
        if key == pygame.K_PAGEUP:
            self.focus = self.bodies.last()
            self.camera.focus_on(self.focus)
示例#19
0
def _end2(line):
    if isinstance(line, HLine):
        return Pt(line.x2, line.y)
    if isinstance(line, VLine):
        return Pt(line.x, line.y2)
示例#20
0
 def try_move(self, pos):
     if pos.y < self.y1:
         return self.end1
     if pos.y > self.y2:
         return self.end2
     return Pt(self.x, pos.y)
示例#21
0
 def end1(self):
     return Pt(0, 0)
示例#22
0
    def __init__(self):
        self.pos = Pt(0, 0)
        self.radius = Pt(15, -25)
        self.rect = Rect(0, 0, 30, 50)
        self.speed = 10
        self.stick = None

        self.jump_height_left = 0

        self.states = dict()

        base = {'LT': 'left_run', 'RT': 'right_run', 'UP': 'back'}
        left = {'JMP': 'left_jump', 'DN': 'left_crouch', 'drop': 'left_fall'}
        right = {
            'JMP': 'right_jump',
            'DN': 'right_crouch',
            'drop': 'right_fall'
        }

        self.add_state(
            state('left', img=1, shift=_merge_(base, left,
                                               {'LT': 'left_run'})))
        self.add_state(
            state('left_run',
                  img=3,
                  hold='LT',
                  end='left',
                  speed=Pt(-self.speed, 0),
                  shift=_merge_(base, left, {
                      'DN': 'left_slide',
                      'hit_L': 'left',
                      'JMP': 'left_jump_l'
                  })))
        self.add_state(
            state('left_crouch',
                  img=4,
                  hold='DN',
                  end='left',
                  shift={'LT': 'left_slide'}))
        self.add_state(
            state('left_jump',
                  img=5,
                  speed=Pt(0, 15),
                  hold='JMP',
                  end='left_fall',
                  shift={'RT': 'right_jump_r'}))
        self.add_state(
            state('left_jump_l',
                  img=5,
                  speed=Pt(-5, 15),
                  hold='LT',
                  end='left_jump',
                  shift={'RT': 'right_jump_r'}))
        self.add_state(
            state('left_fall',
                  img=1,
                  speed=Pt(0, -5),
                  end='left',
                  shift={
                      'hit_D': 'left',
                      'LT': 'left_fall_l',
                      'RT': 'right_fall_r'
                  }))
        self.add_state(
            state('left_fall_l',
                  img=1,
                  speed=Pt(-5, -5),
                  hold='LT',
                  end='left_fall',
                  shift={
                      'hit_D': 'left_run',
                      'RT': 'right_fall_r'
                  }))

        self.add_state(
            state('right',
                  img=1,
                  shift=_merge_(base, right, {'RT': 'right_run'})))
        self.add_state(
            state('right_run',
                  img=3,
                  hold='RT',
                  end='right',
                  speed=Pt(self.speed, 0),
                  shift=_merge_(base, right, {'DN': 'right_slide'})))
        self.add_state(
            state('right_crouch',
                  img=4,
                  hold='DN',
                  end='right',
                  shift={'RT': 'right_slide'}))
        self.add_state(
            state('right_jump',
                  img=5,
                  speed=Pt(0, 15),
                  hold='JMP',
                  end='right_fall',
                  shift={'LT': 'left_jump_l'}))
        self.add_state(
            state('right_jump_r',
                  img=5,
                  speed=Pt(5, 15),
                  hold='left',
                  end='right_jump',
                  shift={'LT': 'left_jump_l'}))
        self.add_state(
            state('right_fall',
                  img=1,
                  speed=Pt(0, -5),
                  end='right',
                  shift={
                      'hit_D': 'right',
                      'LT': 'left_fall_l',
                      'RT': 'right_fall_r'
                  }))
        self.add_state(
            state('right_fall_r',
                  img=1,
                  speed=Pt(5, -5),
                  hold='RT',
                  end='right_fall',
                  shift={
                      'hit_D': 'right_run',
                      'LT': 'left_fall_l'
                  }))

        self.add_state(state('back', img=10, hold='DN', end='left',
                             shift=base))

        # self.add_state(state('blastoff', img=12, speed=Position(0, 12), shift={'DN':'left'}))

        self.state = self.states['left']

        self.sprites = self.load_img()
示例#23
0
 def __init__(self, screen_center):
     self.pos = Pt(0, 0)
     self.scale = Pt(1.0, -1.0)
     self.screen_center = screen_center
     self.target = self.pos
示例#24
0
 def end2(self):
     return Pt(0, 0)
示例#25
0
 def end1(self):
     return Pt(self.x1, self.y)
示例#26
0
 def end2(self):
     return Pt(self.x2, self.y)
示例#27
0
 def __init__(self):
     self.pos = Pt(0, 0)
     self.name = None
     self.links = dict()
     self.type = None
示例#28
0
 def try_move(self, pos):
     if pos.x < self.x1:
         return self.end1
     if pos.x > self.x2:
         return self.end2
     return Pt(pos.x, self.y)
示例#29
0
 def end1(self):
     return Pt(self.x, self.y1)
示例#30
0
 def end2(self):
     return Pt(self.x, self.y2)