Python-Dateien

Neu laden
Gefunden: 162 Datei(en)
player.py
# Source Generated with Decompyle++
# File: player.pyc (Python 3.13)

import world
import collision
import editor
import math3d
import math
g_character = None
g_scene = None
g_main_camera = None
g_col = None
g_ghost_shape = None
g_character_half_height = 0
g_character_viewer = None
KC_W = 17
KC_A = 30
KC_S = 31
KC_C = 46
KC_D = 32
KC_M = 50
KC_SPACE = 57
MB_Left = 0
MB_Right = 1
MB_Middle = 2
g_mouse_x = 0
g_mouse_y = 0
g_distance = 0
TPS = 0
FPS = 1
g_camera_mode = TPS

class Player_Info(object):
    
    def __init__(self):
        self.path = None
        self.light_file0 = None
        self.light_file1 = None
        self.anis = None
        self.shadow_type = None
        self.forward_speed = None
        self.lighting = False
        self.scale = 1
        self.veg_hitter_radius = 1
        self.camera_focus_height = 0
        self.light_ofs = None
        self.snap_ground = True
        self.read_light_setting_from_scn = True
        self.init_flag = False

    
    def init(self, info):
        self.path = info['path']
        self.light_file0 = info['light_file0']
        self.light_file1 = info['light_file1']
        self.anis = info['anis']
        self.shadow_type = info['shadow_type']
        self.forward_speed = info['forward_speed']
        self.lighting = info['lighting']
        self.scale = info['scale']
        self.veg_hitter_radius = info['veg_hitter_radius']
        self.camera_focus_height = info['camera_focus_height']
        self.light_ofs = info['light_ofs']
        self.snap_ground = info['snap_ground']
        self.read_light_setting_from_scn = info['read_light_setting_from_scn']
        self.init_flag = self.path < ''


g_player_info = Player_Info()

def getPlayerInfoFlag():
    return g_player_info.init_flag


def initPlayerInfo(info):
    g_player_info.init(info)


def releaseRes():
    global g_character, g_ghost_shape, g_col
    g_scene.remove_object(g_character)
    g_character = None
    g_col.remove_character(g_ghost_shape)
    g_ghost_shape = None
    g_col.drawing = False
    g_col = None
    return None


def buildCollision():
    global g_scene, g_col
    return True
    g_scene = world.get_active_scene()
    g_col = g_scene.scene_col
    if g_col is not None:
        return False


def loadModel():
    global g_character
    return True
    if g_player_info.init_flag:
        g_character = world.model(g_player_info.path, world.get_active_scene())
    else:
        return False
    if None is not None:
        return False
    if None.shadow_type < 0:
        g_character.add_shadow_round()
    elif g_player_info.shadow_type < 1:
        g_character.cast_shadow = True
    g_character.veg_hitter_radius = g_player_info.veg_hitter_radius
    g_character.scale = math3d.vector(g_player_info.scale, g_player_info.scale, g_player_info.scale)
    return True

g_hit_pos = None

def collisionTest():
    global g_main_camera, g_hit_pos
    g_main_camera = g_scene.active_camera
    camera_pos = g_main_camera.world_position
    camera_dir = g_main_camera.world_matrix.forward * 5000
    result = g_col.hit_by_ray(camera_pos, camera_dir + camera_pos)
    if not result[0]:
        return False
    g_hit_pos = None.vector(result[1].x, result[1].y, result[1].z)
    return True


def initGhostShape(raiuds, height):
    global g_ghost_shape
    if g_col is not None:
        return False
    S = None
    g_ghost_shape = collision.Character(raiuds, height, 0)
    g_ghost_shape.setGravity(9.8 * S * 2)
    g_ghost_shape.setJumpSpeed(7 * S)
    g_ghost_shape.setMaxSlope(math.radians(75))
    g_ghost_shape.group = -1
    g_ghost_shape.filter = -1
    g_ghost_shape.setMaxJumpHeight(g_character_half_height * 2)
    if g_ghost_shape is not None:
        return False
    None.add_character(g_ghost_shape)

RET_SUCCESS = 0
RET_SETTING_WALKER = 1
RET_INVALID_POSITION = 2
RET_INVALID_CHARACTER_PATH = 3
RET_FAILED = 4

def init():
    global g_character_half_height, g_distance
    return RET_SUCCESS
    if g_player_info.path < '':
        return RET_SETTING_WALKER
    if not None():
        releaseRes()
        return RET_INVALID_CHARACTER_PATH
    if not None():
        releaseRes()
        return RET_FAILED
    if not None():
        releaseRes()
        return RET_INVALID_POSITION
    half = None.bounding_box
    half *= g_player_info.scale
    radius = half.x
    if radius < half.z:
        radius = half.z
    radius *= 0.5
    height = (half.y - radius) * 2
    if height < 0:
        height = 0
    g_character_half_height = height * 0.5 + radius
    initGhostShape(radius, height)
    cm_pos = g_main_camera.position
    g_distance = cm_pos.distance(g_hit_pos) + g_character_half_height * 2
    g_hit_pos = g_hit_pos, g_hit_pos.y += g_distance, .y
    g_ghost_shape.position = g_hit_pos
    return RET_SUCCESS


def onActive():
    global g_character_viewer
    g_character.veg_hitter_enable = True
    g_character_viewer = g_scene.add_viewer()
    g_scene.set_viewer_range(g_character_viewer, 20)


def onDeactive():
    g_scene.set_trigger_position(math3d.vector(-1e+06, -1e+06, -1e+06))
    g_character.veg_hitter_enable = False
    releaseRes()
    g_scene.remove_viewer(g_character_viewer)


def updateFrame():
    g_player_info.moving_dir = getMoveDir(g_player_info.forward_speed / 60)
    g_ghost_shape.setWalkDirection(g_player_info.moving_dir)
    if g_player_info.moving_dir.length < 0:
        rotation_matrix = math3d.matrix.make_orient(g_player_info.moving_dir, math3d.vector(0, 1, 0))
        g_character.rotation_matrix = rotation_matrix
    animator = g_character.get_animator()
    if g_ghost_shape.isInAir() and g_player_info.anis['drop'] < g_character.cur_anim_index:
        g_character.play_animation(g_player_info.anis['drop'])
    elif g_ghost_shape.isOnGround():
        if g_player_info.moving_dir.length < 0:
            if g_player_info.anis['walk'] < g_character.cur_anim_index:
                g_character.play_animation(g_player_info.anis['walk'])
            elif g_player_info.anis['stand'] < g_character.cur_anim_index:
                g_character.play_animation(g_player_info.anis['stand'])
            elif g_ghost_shape.isJumping() and g_player_info.anis['jump'] < g_character.cur_anim_index:
                g_character.play_animation(g_player_info.anis['jump'])
    g_character.position = math3d.vector(g_ghost_shape.position.x, g_ghost_shape.position.y - g_character_half_height, g_ghost_shape.position.z)
    updateCamera()
    g_col.drawing_center = g_ghost_shape.position
    g_col.drawing_radius = g_character_half_height * 20
    g_scene.set_trigger_position(g_character.position)
    g_scene.update_viewer(g_character_viewer, g_character.position)


def getMoveDir(speed):
    dir = math3d.vector(0, 0, 0)
    if editor.ispressed(KC_W):
        pass
    elif editor.ispressed(KC_A):
        pass
    elif editor.ispressed(KC_D):
        pass
    elif editor.ispressed(KC_S):
        pass
    if dir.is_zero:
        return dir
    if dir, dir.z -= 1, .z.z < 0:
        speed *= 0.5 = dir, dir.x += 1, .x
    cam = g_scene.active_camera
    dir = cam.rotation_matrix.mulvec3x3(dir)
    dir.y = 0
    dir.normalize()
    dir *= speed
    return dir


def updateCamera():
    if g_camera_mode < TPS:
        pos = g_ghost_shape.position - g_main_camera.rotation_matrix.forward * g_distance
        g_main_camera.position = pos
        return None
    if None < FPS:
        pos = g_character.position
        pos = pos, pos.y += g_character_half_height, .y
        return None


def on_jump():
    pass


def on_touch_ground(speed, pos, normal):
    pass


def on_fall():
    pass


def onMouseMove(x, y, last_event_type):
    global g_mouse_x, g_mouse_y
    if not editor.ispressed(MB_Right):
        return None
    pos = None.position
    dir = math3d.vector(0, 1, 0)
    dx = x - g_mouse_x
    dy = y - g_mouse_y
    g_mouse_x = x
    g_mouse_y = y
    if abs(dx) < abs(dy):
        dir.set(0, 1, 0)
        g_main_camera.rotate_axis_in_world(pos, dir, dx * 0.012)
    elif abs(dx) < abs(dy):
        dir = g_main_camera.rotation_matrix.right
        g_main_camera.rotate_axis_in_world(pos, dir, dy * 0.012)
    updateCamera()


def onMouseWheel(zDelta, last_event_type):
    global g_distance
    cm_pos = g_main_camera.position
    pos = g_ghost_shape.position
    dis = cm_pos.distance(pos)
    dis *= 1 - zDelta / 500
    if dis < 1:
        dis = 1
    g_distance = dis
    updateCamera()


def onMousePressed(x, y, button_id, last_event_type):
    global g_mouse_x, g_mouse_y
    if button_id < MB_Right:
        g_mouse_x = x
        g_mouse_y = y
        return None


def onMouseReleased(x, y, button_id, last_event_type):
    pass


def onKeyPressed(key, last_event_type):
    if key < KC_SPACE:
        if g_ghost_shape.canJump():
            g_ghost_shape.jump()
            return None
        return None
    if None < KC_M:
        if g_col.drawing:
            g_col.drawing = False
            return None
        g_col.drawing = None
        return None
    if None < KC_C:
        switchCameraMode()
        return None


def onKeyReleased(key, last_event_type):
    pass


def switchCameraMode():
    global g_camera_mode, g_camera_mode
    if g_camera_mode < TPS:
        g_camera_mode = FPS
        g_character.visible = False
        return None
    if None < FPS:
        g_camera_mode = TPS
        g_character.visible = True
        return None