当前位置: 首页>>代码示例>>Python>>正文


Python Region.tiles[(x,y)]方法代码示例

本文整理汇总了Python中region.Region.tiles[(x,y)]方法的典型用法代码示例。如果您正苦于以下问题:Python Region.tiles[(x,y)]方法的具体用法?Python Region.tiles[(x,y)]怎么用?Python Region.tiles[(x,y)]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在region.Region的用法示例。


在下文中一共展示了Region.tiles[(x,y)]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: modify_lvl

# 需要导入模块: from region import Region [as 别名]
# 或者: from region.Region import tiles[(x,y)] [as 别名]

#.........这里部分代码省略.........
	for spec in opts.regs_to_set_aw:
		try:
			rname, xyarena = spec.split('=')
			xyarena = xyarena.split(',')
			if len(xyarena) == 2:
				x, y = xyarena
				arena = None
			elif len(xyarena) == 3:
				x, y, arena = xyarena

			r = lvl.find_region(rname)
			x = int(x)
			y = int(y)
			r.autowarp = (x, y, arena)
			if arena:
				print "set autowarp destination for region %s to %d,%d, arena %s" % \
					(mq(rname), x, y, arena)
			else:
				print "set autowarp destination for region %s to %d,%d" % \
					(mq(rname), x, y)
		except:
			print "*** bad autowarp option: '%s' (should be 'region=x,y[,arena]')" % spec
			sys.exit(1)

	for spec in opts.regs_to_set_tiles:
		try:
			rname, cspec = spec.split('=', 1)
			bmpfile, rgb = cspec.split(':')
			r, g, b = map(int, rgb.split(','))
		except:
			print "*** bad setregiontiles option: '%s' (should be 'region=bmpfile:r,g,b')" % spec
			sys.exit(1)

		rgn = lvl.find_region(rname)
		if not rgn:
			print "*** can't find region %s" % mq(rname)
			sys.exit(1)

		try:
			bmp = BMPFile(bmpfile)
		except:
			print "*** error loading bmp file %s" % mq(bmpfile)
			sys.exit(1)

		if bmp.width != 1024 or bmp.height != 1024:
			print "*** bmp %s has wrong dimensions (must be 1024x1024)" % mq(bmpfile)
			sys.exit(1)

		target = bmp.make_pixel(r, g, b)

		newtiles = {}
		for x in xrange(1024):
			for y in xrange(1024):
				if bmp.get_pixel(x, y) == target:
					newtiles[(x,y)] = 1

		rgn.tiles = newtiles
		print "set region %s tiles from %s with color %d,%d,%d" % \
			(mq(rname), bmpname, r, g, b)

	for rgnv1file in opts.rgnv1files:
		try:
			lines = file(rgnv1file).readlines()
		except:
			print "*** can't read version 1 region file '%s'" % rgnv1file
			sys.exit(1)

		if lines[0].strip() != 'asss region file version 1':
			print "*** bad region file header"
			sys.exit(1)

		def decode_rect(s):
			def char_to_val(c):
				c = ord(c)
				if c >= ord('a') and c <= ord('z'):
					return c - ord('a')
				elif c >= ord('1') and c <= ord('6'):
					return c - ord('1') + 26
			return (char_to_val(s[0]) << 5 | char_to_val(s[1]),
			        char_to_val(s[2]) << 5 | char_to_val(s[3]),
			        char_to_val(s[4]) << 5 | char_to_val(s[5]),
			        char_to_val(s[6]) << 5 | char_to_val(s[7]))

		r = None
		for l in lines:
			l = l.strip().lower()
			if l.startswith('name: '):
				rname = l[6:].strip()
				r = lvl.find_region(rname)
				if not r:
					r = Region([('rNAM', rname)])
					lvl.regions.append(r)
					print "created region %s" % (mq(rname))
			elif l.startswith('| ') and r:
				x0, y0, w, h = decode_rect(l[2:])
				print "adding rect (%d,%d)-(%d,%d) to region %s" % \
					(x0, y0, x0+w, y0+h, r.name)
				for x in xrange(x0, x0+w):
					for y in xrange(y0, y0+h):
						r.tiles[(x, y)] = 1
开发者ID:Ceiu,项目名称:hyperspace-asss,代码行数:104,代码来源:lvltool.py


注:本文中的region.Region.tiles[(x,y)]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。