Example #1
0
    def MoveUpdate(self, frame_time):
        dist = math.fabs(self.target.x - self.x)
        if self.x > self.target.x:
            self.direction = self.LEFT
        else:
            self.direction = self.RIGHT

        if dist >= self.detect_range / 2:
            if self.direction == self.LEFT:
                self.vx = -self.run_speed
            else:
                self.vx = self.run_speed
        else:
            self.vx = 0

        if self.vy == 0:
            cbList = game_framework.get_top_state().map.colBox
            rayBox = self.GetCollisionBox()

            # 장애물 점프
            rayBox.top, rayBox.bottom = self.y + 1, self.y - 1
            if self.direction == self.LEFT:
                rayBox.right = rayBox.left
                rayBox.left -= self.run_speed
            else:
                rayBox.left = rayBox.right
                rayBox.right += self.run_speed
            for cb in cbList:
                if cb.CollisionCheck(rayBox):
                    self.vy = 7
                    break

            # 낭떨어지 정지
            rayBox = self.GetCollisionBox()
            rayBox.top = rayBox.bottom
            rayBox.bottom -= 500
            if self.direction == self.LEFT:
                rayBox.right = rayBox.left - 1
                rayBox.left -= 5
            else:
                rayBox.left = rayBox.right + 1
                rayBox.right += 5

            isFall = True
            for cb in cbList:
                if cb.CollisionCheck(rayBox):
                    isFall = False
                    break
            if isFall:
                self.vx = 0
Example #2
0
    def Update(self, frame_time):
        # 애니메이션 프레임 처리
        anim = self.anim
        if self.frame < anim.frame:
            self.frame += anim.frame * (1 / anim.time) * frame_time
        elif anim.repeat:
            self.frame -= anim.frame

        if anim == self.animationList['hit'] and self.frame > anim.frame:
            self.ChangeState(self.state)

        # 총 정보 갱신
        self.gun.Update(frame_time)

        # 발포
        if self.isShooting and self.gun.Shoot():
            gx, gy = self.x + 10, self.y - 25
            tx, ty = Camera.GetWorldPos(self.targetX, self.targetY)
            tx = max(tx, gx+1)
            rad = math.atan2(ty-gy, tx-gx)
            vcos, vsin = math.cos(rad), math.sin(rad)

            bullet = Gun.Bullet(vcos + gx, vsin + gy + 3,
                                self.gun.bullet_image, 'PLAYER', self.gun.damage,
                                vcos*self.gun.bullet_speed, vsin*self.gun.bullet_speed, rad, self.gun.piercing)

            stage = game_framework.get_top_state()
            stage.objList[stage.OBJECT].append(bullet)

        # 쉴드 갱신
        if self.lastHitDuration < self.shield_charge_time:
            self.lastHitDuration += frame_time
        elif self.shield < self.max_shield:
            self.shield += 300 * frame_time
            if self.shield > self.max_shield:
                self.shield = self.max_shield

        self.stateList[self.state](frame_time)

        self.x += self.vx * self.PPM * frame_time
        self.y += self.vy * self.PPM * frame_time
Example #3
0
    def Update(self, frame_time):
        # 애니메이션 프레임 처리
        anim = self.anim
        if self.frame <= anim.frame:
            self.frame += anim.frame * (1 / anim.time) * frame_time
        elif anim.repeat:
            self.frame -= anim.frame

        if anim == self.animationList['hit'] and self.frame >= self.anim.frame:
            self.ChangeState(self.state)

        # 총 정보 갱신
        self.gun.Update(frame_time)

        # 발포
        if self.state == 'MOVE' and self.gun.Shoot():
            if self.direction == self.LEFT:
                gx = self.x - 10
            else:
                gx = self.x + 10
            gy = self.y - 25
            tx, ty = self.target.x, self.target.y
            if self.direction == self.LEFT:
                tx = min(tx, gx - 1)
            else:
                tx = max(tx, gx + 1)
            rad = math.atan2(ty - gy, tx - gx)
            vcos, vsin = math.cos(rad), math.sin(rad)

            bullet = Gun.Bullet(vcos + gx, vsin + gy + 3,
                                self.gun.bullet_image, 'MONSTER', self.gun.damage,
                                vcos * self.gun.bullet_speed, vsin * self.gun.bullet_speed, rad, self.gun.piercing)

            stage = game_framework.get_top_state()
            stage.objList[stage.OBJECT].append(bullet)

        self.stateList[self.state](frame_time)

        self.x += self.vx * self.PPM * frame_time
        self.y += self.vy * self.PPM * frame_time