Example #1
0
	def MoveUp(self):
		self.camPos[1] -= self.stepY
		iworld2d.camera_world_pos( self.camPos[0], self.camPos[1] )
Example #2
0
	def MoveRight(self):
		self.camPos[0] += self.stepX
		iworld2d.camera_world_pos( self.camPos[0], self.camPos[1] ) 
Example #3
0
	def MoveDown(self):
		self.camPos[1] += self.stepY
		iworld2d.camera_world_pos( self.camPos[0], self.camPos[1] )
Example #4
0
	def MoveLeft(self):
		self.camPos[0] -= self.stepX
		iworld2d.camera_world_pos( self.camPos[0], self.camPos[1] ) 
Example #5
0
def on_key_msg(msg, key):
	global ball
	if msg == game.MSG_KEY_DOWN:
		if key is game.VK_F1:
			for i in range(20):
				test = create_obj("bear", 100, random.randint(50, 1000), random.randint(0, 100))
				test.phy.body_type = iphy2d.DYNAMIC_BODY
		elif key is  game.VK_F2:
			iphy2d.set_gravity((10, 1))
		elif key is game.VK_F3:
			iphy2d.set_gravity((0, 10))
		elif key is game.VK_F4:
			# 球和曲面的弹性系数均为0
			test = create_obj("sin", 10, 250, 560)
			ball = create_obj("obj", 11, 250, 400)
			# 小球的碰撞参数是2,如果设为1,则不产生碰撞
			ball.phy.category = 2
		elif key == game.VK_F5:
			iphy2d.set_gravity((0, 10))
			destroy_map()
			create_map()
		elif key == game.VK_F7:
			if not background.is_hide():
				# 进入debug模式
				background.hide()
				import rabbit_obj
				iworld2d.camera_world_scale(rabbit_obj.MAP_SCALE)
				iworld2d.camera_world_pos(-512+rabbit_obj.MAP_SCALE*2+4, -368+rabbit_obj.MAP_SCALE*2-20)
				iphy2d.set_debug_draw(True)
			else:
				# 还原
				iphy2d.set_debug_draw(False)
				background.show()
				iworld2d.camera_world_scale(1)
				iworld2d.camera_world_pos(0, 0)
		elif key == game.VK_F11:
			global pflag
			pflag = not pflag
			idemo_glb.API.show_performance(pflag)
		elif key == game.VK_SPACE:
			if ball:
				ball.phy.apply_linear_impulse(math3d.vector2(0,100), ball.phy.position)
				ball.phy.density = 100
				ball.phy.restitution = 0
		elif key == game.VK_1:
			# 进入距离关节的演示(相当于box2d testbed的web)
			rabbit_test_1.start()
		elif key == game.VK_2:
			# 进入旋转关节的演示(相当于box2d testbed的bridge)
			rabbit_test_2.start()
		elif key == game.VK_3:
			# 进入移动关节的演示(相当于box2d testbed的prismatic)
			rabbit_test_3.start()
		elif key == game.VK_4:
			# 进入组合关节的演示(相当于box2d testbed的slider crank)
			rabbit_test_4.start()
		elif key == game.VK_5:
			# 进入摩擦关节的演示(相当于box2d testbed的apply force)
			rabbit_test_5.start()
	elif msg == game.MSG_KEY_PRESSED:
		if key == game.MOUSE_BUTTON_LEFT:
			# 如果按住鼠标左键,则更新浣熊位置
			x = game.mouse_x
			y = game.mouse_y
			if obj_on_mouse:
				obj_on_mouse.pos = (x, y)
				obj_on_mouse.phy.body_type = iphy2d.STATIC_BODY
	elif msg == game.MSG_KEY_UP:
		if key == game.VK_SPACE:
			if ball:
				ball.phy.density = 0.3