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


Python Ship.move方法代码示例

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


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

示例1: main

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import move [as 别名]
def main():
	WINSIZE = 640,480	
	NUMBER_OF_STARS = 250
	STARTING_ANGLE = 180
  	CLOSEST_STAR_COLOR = (255, 255, 255)
	STAR_SIZE_IN_PIXELS = 1
	#_V_ = 1
	pygame.init()
	pygame.key.set_repeat(1,1)
	screen = pygame.display.set_mode(WINSIZE,pygame.SWSURFACE)
	stars = Starfield(screen,screen.get_rect(),NUMBER_OF_STARS,STARTING_ANGLE,(40,4),STAR_SIZE_IN_PIXELS,CLOSEST_STAR_COLOR)
	
	ship1 = Ship(screen)
	
	done = False
	while not done:
		screen.fill(THECOLORS["black"])
		stars.update()
		ship1.draw()
		ship1.resetSprt()
		pygame.display.update()
		events = pygame.event.get()
		for e in events:
			if(e.type == QUIT):
				done = True
				break
			elif (e.type == KEYDOWN):
				if(e.key == K_ESCAPE):
					done = True
					break
				#Test for movement
				dx,dy = 0,0
				if(e.key == K_DOWN):
					dy += 1
				if(e.key == K_UP):
					dy -= 1
				if(e.key == K_LEFT):
					dx -= 1
				if(e.key == K_RIGHT):
					dx += 1
				ship1.move(dx,dy)
				#if(e.key == K_PLUS):
					#stars.set_speed((
	print "Exiting!"
	
	return
开发者ID:bcherry,项目名称:bcherry,代码行数:48,代码来源:space.py

示例2: __init__

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import move [as 别名]
class GateField:
    """Game field with logic"""
    def __init__(self, width, height, startpos, endpos, obstacles):
        self.width = width
        self.height = height
        self.field = Field(width, height, obstacles)
        self.ship = Ship(startpos)
        self.finish = endpos

    def _check_collision(self, coords):
        check_horiz = fabs(coords[0] - trunc(coords[0])) > 0.05
        check_vert = fabs(coords[1] - trunc(coords[1])) > 0.05
        if check_horiz:
            if check_vert:
                return self.field.get_at(floor(coords[0]), floor(coords[1])) or \
                       self.field.get_at(floor(coords[0]), ceil(coords[1])) or \
                       self.field.get_at(ceil(coords[0]), floor(coords[1])) or \
                       self.field.get_at(ceil(coords[0]), ceil(coords[1]))
            else:
                return self.field.get_at(floor(coords[0]), trunc(coords[1])) or \
                       self.field.get_at(ceil(coords[0]), trunc(coords[1]))
        else:
            if check_vert:
                return self.field.get_at(trunc(coords[0]), floor(coords[1])) or \
                       self.field.get_at(trunc(coords[0]), ceil(coords[1]))
            else:
                return self.field.get_at(trunc(coords[0]), trunc(coords[1]))

    def _sensors_state(self):
        circuit = {'s': False, 'w': False, 'n': False, 'e': False}
        current_cell = (trunc(self.ship.coords[0]), trunc(self.ship.coords[1]))
        circuit['s'] = self.field.get_at(current_cell[0], current_cell[1] + 1)
        circuit['w'] = self.field.get_at(current_cell[0] - 1, current_cell[1])
        circuit['n'] = self.field.get_at(current_cell[0], current_cell[1] - 1)
        circuit['e'] = self.field.get_at(current_cell[0] + 1, current_cell[1])
        return circuit

    def step(self):
        self.ship.move()
        if self._check_collision(self.ship.coords):
            self.ship.abort_move()

        self.ship.set_circuit(self._sensors_state())
        self.ship.process()
开发者ID:Shekeen,项目名称:PyGate,代码行数:46,代码来源:gatefield.py


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