Exemplo n.º 1
0
	def update_dropping(self):
		if self.state == tower_const.TOWER_STATE_MOVING:
			return

		down = math3d.vector(0, tower_const.GRAVITY, 0)

		cur_pos = math3d.vector(*self.pos)

		self.target_pos = cur_pos + down

		result = self.sweep_test(cur_pos, self.target_pos)

		if not result.hit:
			self.pos = self.target_pos.x, self.target_pos.y, self.target_pos.z
			self.set_state(tower_const.TOWER_STATE_DROPPING)
			return
		self.update_collide_pos(result.fraction)
		self.set_state(tower_const.TOWER_STATE_MOVING)

		global g_tower_init_pos
		init_z = g_tower_init_pos[1]
		init_z -= 5
		g_tower_init_pos = (0, init_z, -100)

		cam = iworld3d.get_camera(tower_const.SCENE_LAYER)
		position = cam.position
		position.y -= 5
		cam.position = position
Exemplo n.º 2
0
	def on_key_msg(self, msg, key):
		super(demo, self).on_key_msg(msg, key)
		if msg == game.MSG_KEY_PRESSED:
			if key >= game.VK_NUM0 and key <= game.VK_NUM9:
				# 相机控制演示
				# 小键盘46表示相机沿x轴左右平移
				# 小键盘28表示相机沿y轴上下平移
				# 小键盘13表示相机沿z轴前后平移
				# 小键盘79表示相机沿y轴左右旋转
				# 小键盘5表示相机对准主角小蛋黄
				# 小键盘0表示相机恢复初始状态
				cam = iworld3d.get_camera(SCENE_LAYER)
				position = cam.position
				if key == game.VK_NUM4:
					position.x -= CAMERA_MOVE_STEP
				elif key == game.VK_NUM6:
					position.x += CAMERA_MOVE_STEP
				elif key == game.VK_NUM8:
					position.y -= CAMERA_MOVE_STEP
				elif key == game.VK_NUM2:
					position.y += CAMERA_MOVE_STEP
				elif key == game.VK_NUM1:
					position.z += CAMERA_MOVE_STEP
				elif key == game.VK_NUM3:
					position.z -= CAMERA_MOVE_STEP
				elif key == game.VK_NUM7:
					self.cam_rot -= 1
					cam.rotate_to_xyz(y=self.cam_rot*math.pi/200)
				elif key == game.VK_NUM9:
					self.cam_rot += 1
					cam.rotate_to_xyz(y=self.cam_rot*math.pi/200)
				elif key == game.VK_NUM5:
					cam.look_at(self.player.position)
				elif key == game.VK_NUM0:
					# 还原位置
					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(SCENE_LAYER, position, forward, up)
				cam.position = position
Exemplo n.º 3
0
	def __init__(self):
		super(demo, self).__init__()
		iworld3d.init()
		self.scn = iworld3d.create_scene3d(SCN_FILE%1)
		
		self.player = iworld3d.model3d("idemos/res/eggyolk/world3d/xiaodanhuang.gim")
		self.player.pos = (0,0,0)
		
		self.camera = iworld3d.get_camera(iworld3d.NO_2D_LAYER)

		# 预先生成如下分块的场景,其中1为刚生成的self.scn
		# 323
		# 212
		# 323
		for offset in ((-1,0), (1,0), (0,-1), (0,1)):
			self.scn.auto_load_scene(SCN_FILE%2, math3d.vector(offset[0]*400, 0, offset[1]*400))
		for offset in ((1,1), (-1,1), (1,-1), (-1,-1)):
			self.scn.auto_load_scene(SCN_FILE%3, math3d.vector(offset[0]*400, 0, offset[1]*400))
		
		self.scn.set_view_range(100)
		# 如果设置1000,则一开始就能看到所有场景
		# self.scn.set_view_range(1000)

		self.scene_pos = {}	# 记录动态加载的场景位置
Exemplo n.º 4
0
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