def create_objs(): stone = tower_obj.CGameObj() stone.create_sprite("tower/res/world3d/platform.gim", "platform", tower_const.SCENE_LAYER) stone.create_phy(tower_const.SCENE_LAYER) stone.sprite.scale = (0.1, 0.1, 0.1) stone.pos = (-10, 40, -100) iphy3d.update(tower_const.SCENE_LAYER)
def create_objs(self): self.player = self.create_player() self.player.pos = (17, -15, -100) self.npc = self.create_player() self.npc.pos = (30, 17, -100) self.npc.create_bill('idemos/res/eggyolk/gfx/bill.swf', "npc,撞不到我哦") # 增加三块石头 for pos in ((0,0,-100),(20,30,-100),(-20,-30,-100)): stone = eggyolk2_obj.CGameObj() stone.create_sprite("idemos/res/eggyolk/world3d/dalumian.gim", "s1", eggyolk2_const.SCENE_LAYER) stone.create_phy(eggyolk2_const.SCENE_LAYER) stone.sprite.scale = (0.1,0.1,0.1) # 原来模型太大,需要缩小 stone.sprite.accept_shadow(True) stone.pos = pos self.stones.append(stone) iphy3d.update(eggyolk2_const.SCENE_LAYER)
def switch_phy_type(self, col_type, layer_id): if self.phy is None: return self.set_phy_key(0, 0, 0) if col_type == eggyolk2_const.COL_TYPE_CAPSULE: temp = iphy3d.col_capsule(4, 4, eggyolk2_const.COL_NPC, eggyolk2_const.COL_NPC) elif col_type == eggyolk2_const.COL_TYPE_CYLINDER: temp = iphy3d.col_cylinder(4, 6, eggyolk2_const.COL_NPC, eggyolk2_const.COL_NPC) elif col_type == eggyolk2_const.COL_TYPE_MODEL: temp = iphy3d.col_model(self.sprite, eggyolk2_const.COL_NPC, eggyolk2_const.COL_NPC) temp.rotation_matrix = self.sprite.rotation_matrix # 由于模型翻转过,此处需要翻转 self.set_phy_key(0, 15, 0) # 设置key点 elif col_type == eggyolk2_const.COL_TYPE_SPHERE: temp = iphy3d.col_sphere(6, eggyolk2_const.COL_NPC, eggyolk2_const.COL_NPC) else: return self.phy.remove_from_layer() self.phy = temp self.pos = self.pos self.phy.add_to_layer(layer_id) iphy3d.update(layer_id)
def on_key_msg(msg, key_code): global towers if msg == game.MSG_KEY_UP: if key_code == game.VK_SPACE: t = create_tower() #t.pos = tower_const.TOWER_INIT_POS towers.append(t) iphy3d.update(tower_const.SCENE_LAYER) elif key_code == game.VK_ESCAPE: for t in towers: t.destroy() towers = [] iphy3d.update(tower_const.SCENE_LAYER) elif key_code == game.VK_F3: global col_draw col_draw = not col_draw print col_draw iphy3d.set_debug_draw(tower_const.SCENE_LAYER, col_draw) iphy3d.update(tower_const.SCENE_LAYER) if msg == game.MSG_KEY_PRESSED: key = key_code global cam_rot if key >= game.VK_A and key <= game.VK_Z: # 相机控制演示 # 小键盘46表示相机沿x轴左右平移 # 小键盘28表示相机沿y轴上下平移 # 小键盘13表示相机沿z轴前后平移 # 小键盘79表示相机沿y轴左右旋转 # 小键盘5表示相机对准主角小蛋黄 # 小键盘0表示相机恢复初始状态 cam = iworld3d.get_camera(tower_const.SCENE_LAYER) position = cam.position if key == game.VK_Q: position.x -= CAMERA_MOVE_STEP elif key == game.VK_W: position.x += CAMERA_MOVE_STEP elif key == game.VK_E: position.y -= CAMERA_MOVE_STEP elif key == game.VK_R: position.y += CAMERA_MOVE_STEP elif key == game.VK_A: position.z += CAMERA_MOVE_STEP elif key == game.VK_S: position.z -= CAMERA_MOVE_STEP elif key == game.VK_D: cam_rot -= 1 cam.rotate_to_xyz(y=cam_rot*math.pi/200) elif key == game.VK_F: cam_rot += 1 cam.rotate_to_xyz(y=cam_rot*math.pi/200) elif key == game.VK_Z: cam.look_at(player.sprite.position) elif key == game.VK_X: # 还原位置 position = math3d.vector(0,0,0) forward = math3d.vector(0,0,-1) up = math3d.vector(0,-1,0) # 还原旋转矩阵 # 演示rotation_matrix的用法 cam.rotation_matrix = math3d.matrix.make_orient(forward, up) # 实际上此用法等同于这个接口 #iworld3d.set_camera_placement(tower_const.SCENE_LAYER, position, forward, up) cam.position = position
def logic(self): if self.collision_draw: iphy3d.set_draw_range(eggyolk2_const.SCENE_LAYER, self.player.pos[0], self.player.pos[1], self.player.pos[2], 20) self.player.update() iphy3d.update(eggyolk2_const.SCENE_LAYER)