예제 #1
0
    def wounded(self):
        if self.action != 'Death':
            return BehaviorTree.FAIL
        self.death_time += gfw.delta_time
        self.time += gfw.delta_time
        frame = self.time * Hornet.FPS

        dx, dy = self.delta
        dy -= gravity
        dy = clamp(-15, dy, 15)
        self.delta = (dx, dy)
        landform.move(self)
        _, foot, _, _ = self.get_bb()
        if self.floor is not None:
            l, b, r, t = self.floor.get_bb()
            if foot <= t:
                x, y = self.pos
                self.pos = x, y + t - foot
                self.delta = (0, 0)

        if self.wounded_anim_end:
            self.fidx = int(frame) % 5 + (len(self.images[self.action]) - 5)
        else:
            self.fidx = int(frame) % len(self.images[self.action])
            if self.fidx == len(self.images[self.action]) - 1:
                self.wounded_anim_end = True
        if self.fidx == len(self.images['Death']) - 1:
            return BehaviorTree.SUCCESS
        return BehaviorTree.RUNNING
예제 #2
0
파일: knight.py 프로젝트: mi1128h/2DGP
    def update(self):
        dx, dy = self.knight.delta
        _, foot, _, _ = self.knight.get_bb()
        if self.knight.floor is not None:
            l, b, r, t = self.knight.floor.get_bb()
            if foot > t:
                dy -= gravity
                dy = clamp(-10, dy, 15)
            else:
                x, y = self.knight.pos
                self.knight.pos = x, round(y + t - foot)
                dy = 0

        self.knight.delta = (dx, dy)
        self.time += gfw.delta_time
        landform.move(self.knight)

        frame = self.time * Knight.FPS * 2

        if frame < len(self.images):
            self.fidx = int(frame)
        else:
            if self.knight.floor is not None:
                if foot > t:
                    self.knight.set_state(FallState)
                else:
                    self.knight.set_state(IdleState)
예제 #3
0
파일: knight.py 프로젝트: mi1128h/2DGP
    def update(self):
        dx, dy = self.knight.delta
        dy -= gravity
        dy = clamp(-10, dy, 15)
        self.knight.delta = (dx, dy)
        self.time += gfw.delta_time
        landform.move(self.knight)

        frame = self.time * Knight.FPS
        if self.clockFlap == False:
            self.fidx = int(frame) % len(self.images)
            if self.fidx == len(self.images) - 1:
                self.clockFlap = True
        else:
            self.fidx = int(frame) % 3 + (len(self.images) - 3)

        _, foot, _, _ = self.knight.get_bb()
        if self.knight.floor is not None:
            l, b, r, t = self.knight.floor.get_bb()
            if foot <= t:
                x,y = self.knight.pos
                self.knight.pos = x, round(y + t - foot)
                dx, dy = self.knight.delta
                self.knight.delta = (dx, 0)
                self.knight.set_state(LandState)
예제 #4
0
파일: knight.py 프로젝트: mi1128h/2DGP
    def update(self):
        self.time += gfw.delta_time
        landform.move(self.knight)
        frame = self.time * Knight.FPS * 2
        self.fidx = int(frame) % len(self.images)

        if frame < len(self.images):
            self.fidx = int(frame)
        else:
            self.knight.set_state(FallState)
예제 #5
0
    def dash(self):
        if self.action != 'Dash':
            return BehaviorTree.FAIL

        landform.move(self)
        self.dash_time += gfw.delta_time
        self.time += gfw.delta_time
        frame = self.time * Hornet.FPS
        self.fidx = int(frame) % len(self.images[self.action])

        if self.dash_time > Hornet.DASH_MAX_TIME:
            self.dash_time = 0
            self.action = 'Dash end'
            self.delta = 0, 0
            self.time = 0
            return BehaviorTree.SUCCESS
        return BehaviorTree.RUNNING
예제 #6
0
파일: knight.py 프로젝트: mi1128h/2DGP
    def update(self):
        _, foot, _, _ = self.knight.get_bb()
        if self.knight.floor is not None:
            l, b, r, t = self.knight.floor.get_bb()
            if foot > t:
                self.knight.set_state(FallState)
            else:
                x, y = self.knight.pos
                self.knight.pos = x, round(y + t - foot)

        self.time += gfw.delta_time
        landform.move(self.knight)

        frame = self.time * Knight.FPS
        self.fidx = int(frame) % len(self.images)
        if self.knight.delta[0] == 0:
            self.knight.set_state(IdleState)
예제 #7
0
    def run(self):
        if self.action == 'Death' or self.action == 'Fall':
            return BehaviorTree.FAIL
        if self.action != 'Run':
            self.run_time = random.random()
            self.action = 'Run'
            self.sounds[Hornet.SOUND_NUM['Run']].play()
        if self.pos[0] < self.target.pos[0]:
            self.delta = -3, 0
        else:
            self.delta = 3, 0

        landform.move(self)
        self.time += gfw.delta_time
        self.run_time += gfw.delta_time
        frame = self.time * Hornet.FPS
        self.fidx = int(frame) % len(self.images[self.action])

        if self.run_time > Hornet.RUN_MAX_TIME:
            self.delta = 0, 0
            return BehaviorTree.SUCCESS
        return BehaviorTree.RUNNING
예제 #8
0
파일: main_state.py 프로젝트: mi1128h/2DGP
def check_collide(e):
    global knight, frame
    if gobj.collides_box(knight, e):
        if e.action != 'Death':
            knight_damaged_by(e)

    for s in gfw.world.objects_at(gfw.layer.slash):
        if gobj.collides_box(s, e):
            if e.action != 'Death' and e.slashed != s:
                enemy_damaged.play()
                e.slashed = s
                e.health -= 5
                if s.flip == 'h':
                    temp = e.delta
                    e.delta = (100, 0)
                    landform.move(e)
                    e.delta = temp
                elif s.flip == '':
                    temp = e.delta
                    e.delta = (-100, 0)
                    landform.move(e)
                    e.delta = temp
예제 #9
0
    def fall(self):
        if self.action != 'Fall':
            return BehaviorTree.FAIL

        dx, dy = self.delta
        dy -= gravity
        dy = clamp(-15, dy, 15)
        self.delta = (dx, dy)
        landform.move(self)
        self.time += gfw.delta_time

        _, foot, _, _ = self.get_bb()
        if self.floor is not None:
            l, b, r, t = self.floor.get_bb()
            if foot <= t:
                x, y = self.pos
                self.pos = x, y + t - foot
                dx, dy = self.delta
                self.delta = (dx, 0)
                self.action = 'Land'
                self.sounds[Hornet.SOUND_NUM['Land']].play()
                return BehaviorTree.SUCCESS
        return BehaviorTree.RUNNING