def _setup(self): self.anim_np = hero_animation.load_hero() self.anim_np.set_pos(Vec3(5, 5, 0)) self.anim_np.enableBlend() self.anim_np.loop("walk") self.anim_np.setSubpartsComplete(False) self.anim_np.makeSubpart(TOOL_SUBPART, ["arm.r", 'weapon.r']) self.anim_np.setPlayRate(5, "walk") self.anim_np.setPlayRate(2, "idle") self.anim_np.setPlayRate(6, TOOL_ANIM_NAME, partName=TOOL_SUBPART) self.anim_np.setControlEffect("walk", 1) self.anim_np.setControlEffect("idle", 0.) self.anim_np.setControlEffect(TOOL_ANIM_NAME, 0) self.anim_np.loop("walk") self.anim_np.loop("idle") # self.physics_np = G.physics_world.addBoxCollider(self.model_np, mass=1, bit_mask=config.BIT_MASK_HERO) self.physics_np = G.physics_world.add_player_controller( self.anim_np, bit_mask=config.BIT_MASK_HERO) self.physics_np.setTag("type", "hero") self.rigid_body = self.physics_np.node() G.accept("b", self.getBored) G.accept("n", self.getNotBored) self.boring_anim = "boring" self.anim_np.setPlayRate(1.1, self.boring_anim)
def __init__(self): self._inventory = None self._main_menu = None self._game_menu = None self._mouse = MouseGUI() G.schedule(self.onUpdate, 'mouse_gui_update') self._event_handler = {} self._mouse_on = False
def __init__(self): self.cam_lerper = lerp_util.LerpVec3(4.3210) self._animator = Animator(hero_config, self) self.anim_np = self._animator.get_actor_np() self._animator.play('idle', once=False) self.physics_np = G.physics_world.add_player_controller( self.anim_np, bit_mask=config.BIT_MASK_HERO) self.controller = MoveController(self.physics_np) G.accept('mouse1', self.use_tool)
def __init__(self, r, g, b, min_dist, max_dist): self.fog = Fog("GlobalFog") self.fog.setColor(r, g, b) dist_base = 100 if G.debug else 0 min_dist += dist_base max_dist += dist_base assert min_dist < max_dist self.fog.set_linear_range(min_dist, max_dist) self.fog.setLinearFallback(15, min_dist, max_dist) G.setBackgroundColor(r, g, b, 1) G.render.setFog(self.fog) self._enabled = True
def __init__(self, key, on_click_cb, on_hold_cb, on_hold_done, click_max_duration=0.12): self._click_max_duration = click_max_duration self._is_down = False self._key_timer = 0 self._on_click = on_click_cb self._on_hold_done = on_hold_done self._on_hold = on_hold_cb self._key = key G.accept(key, self._mouse_click_event, ['down']) G.accept('%s-up' % key, self._mouse_click_event, ['up'])
def test(): def cb(item, idx, button): if button == 'mouse1': button = 'left _mouse' elif button == 'mouse3': button = 'right mose' print 'click %d-th item with key `%s`' % (idx, button) gl = GridLayout(5, 2, cb, alignment=ALIGNMENT_RIGHT) images = 'apple axe orange iron silver sapling cooking_pit cobweb'.split() for image_path in images: used_texture = G.loader.loadTexture("assets/images/items/%s.png" % image_path) gl._addCell(used_texture) gl.setPos(-0.01, 0) gl.setScale(0.5) G.run()
def on_enter(self, last_name): log.process("creating inventory & menu") G.gui_mgr.create_inventory() G.gui_mgr.create_game_menu() G.gui_mgr.set_game_menu_visible(self._main_menu_visible) G.gui_mgr.set_event_handler('game_menu.continue', self._handler_continue) G.gui_mgr.set_event_handler('game_menu.save', self._handler_save) G.gui_mgr.set_event_handler('game_menu.exit', self._handler_exit) log.process("creating game manager") G.game_mgr = game_manager.GameManager() log.process('creating camera manager') G.camera_mgr = camera.CameraManager() log.process('starting operation') G.operation.set_enabled(True) G.accept("escape", self._handler_escape)
def onUpdate(self): mPos = G.getMouse() if not mPos: self.set_item_text("") self.set_object_info("") self.set_mouse_item_info("") return # mPos = Point3(mPos.getX(), 0, mPos.getZ() - 2 * self._scale) self._mouse_gui_root.setPos(mPos)
def __init__(self): self.cam_pos_lerper = lerp_util.LerpVec3(6.6666) self.cam_height_lerper = lerp_util.FloatLerp(30, 15, 2000 if G.debug else 40, 6.666) self.cam_angle_lerper = lerp_util.FloatLerp(0, -100000, 100000, 13.7666) self.xy_ratio = 0.9 # 30-0.9 15-1.2 G.accept('wheel_up', self._wheel_event, [-1]) G.accept('wheel_down', self._wheel_event, [1]) G.accept('e', self._change_angle, [-1]) G.accept('q', self._change_angle, [1]) self._angle_gap = 45 self._angle_index = 0 self._pos_offset = Vec3() self._center_pos = Vec3()
def test(): config = { 'filepath': "../assets/blender/test/hero.egg", 'animations': { "walk": { "events": [['start', 0], ['middle', 40]], "rate": 3, }, "pickup": { "events": [['pickup', 10]], "rate": 1, }, "idle": { "events": [['start', 0], ['middle', 10]], 'rate': 2.1, } }, 'default': 'idle', } ac = Animator(config, Handler()) ac.get_actor_np().reparent_to(G.render) ac.play('idle', False) def up(task): ac.on_update() return task.cont def pickup(): ac.play('pickup', True) G.accept('space', pickup) G.taskMgr.add(up, 'xx') G.cam.set_pos(Vec3(10, 10, 3)) G.cam.look_at(ac._actor_np) G.run()
def __init__(self): G.post_effects = post_effects.PostEffects() def f(): G.post_effects.turn_on() G.accept('z', f) if False: model = G.loader.loadModel("assets/blender/box.egg") model.reparent_to(G.render) G.run() return log.process('setting font') log.process('creating managers') G.storage_mgr = storage_manager.StorageManager() G.storage_mgr.load() G.res_mgr = resource_manager.ResourceManager() G.spawner = spawner.Spawner() G.config_mgr = config_manager.ConfigManager() G.config_mgr.register_map_config('perlin', PerlinMapGenerator) G.config_mgr.register_tile_config('default', 'assets/images/tiles/tiles.json') G.state_mgr = states.StatesManager("menu.menu") G.state_mgr.add_state(game_states.MainMenuState()) G.state_mgr.add_state(game_states.GamePlayState()) G.state_mgr.add_state(game_states.GamePauseState()) G.gui_mgr = gui_system.GUIManager() G.operation = operation.Operation(None) G.context = context.Context() log.process("entering main loop") G.accept('f1', self._render_analysis) G.taskMgr.add(self.physical_loop, name="physical loop") G.taskMgr.add(self.main_loop_task, name="main loop") self._target_framerate = 30. #self.main_loop() G.run() self.main_loop() log.process("main loop finished")
def flatten(idx=0): if idx >= len(roots): return import time var['ts'] = time.time() next_idx = idx + 1 def cb(x): log.debug('x: %s', x) log.debug("time consumed: %s", time.time() - var['ts']) roots[idx].remove_node() roots[idx] = x x.reparent_to(G.render) flatten(next_idx) G.loader.asyncFlattenStrong(roots[idx], False, cb) def stat(): G.render.analyze() lights.create() G.accept('v', flatten) G.accept('b', stat) G.enableMouse() G.cam.set_pos(0, 0, 100) G.cam.look_at(0, 0, 0) G.run()
def test(): mtip = MouseGUI() mtip.setItem(G.loader.loadTexture("assets/images/logo.png")) G.schedule(mtip.onUpdate) G.run()
def add_debug_key(key, fn, args=[]): if key in _keys: assert False, key _keys.add(key) G.accept(key, fn, args)
world.remove_rigid_body(body) # generates a warning world.attachRigidBody(body) shape = BulletBoxShape(Vec3(1, 1, 1)) x = i * 2 y = j * 2 z = 5 body.addShape(shape, TransformState.makePos(Point3(0, 0, 0))) np = G.render.attachNewNode(body) np.setName("physical_box") np.setPos(Vec3(x, y, z)) test2() def up(task): dt = G.taskMgr.globalClock.getDt() world.do_physics(dt, 1) return task.cont G.taskMgr.add(up, 'physics') pos = 130 G.cam.set_pos(pos, pos, pos) G.cam.look_at(0, 0, 0) G.enableMouse() G.run()