本文整理汇总了Python中enemy.Enemy.move方法的典型用法代码示例。如果您正苦于以下问题:Python Enemy.move方法的具体用法?Python Enemy.move怎么用?Python Enemy.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enemy.Enemy
的用法示例。
在下文中一共展示了Enemy.move方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import move [as 别名]
class MainWindow(window.Window):
def __init__(self, *args, **kwargs):
#Let all of the standard stuff pass through
window.Window.__init__(self, *args, **kwargs)
self.initGL()
self.bird = Bird()
self.world = World()
self.enemy = Enemy()
def initGL(self):
glClearColor(0.0, 0.0, 0.0, 0.0) # This Will Clear The Background Color To Black
glClearDepth(1.0) # Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS) # The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST) # Enables Depth Testing
glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading
glEnable(GL_TEXTURE_2D) # Enable Texture Mapping
glShadeModel(GL_SMOOTH) # Enable Smooth Shading
glClearColor(0.0, 0.0, 0.0, 0.5) # Black Background
glClearDepth(1.0) # Depth Buffer Setup
glEnable(GL_DEPTH_TEST) # Enables Depth Testing
glDepthFunc(GL_LEQUAL) # The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) # Really Nice Perspective Calculations
glLightfv(GL_LIGHT1, GL_AMBIENT, vec(*LightAmbient))
glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(*LightDiffuse))
glLightfv(GL_LIGHT1, GL_POSITION, vec(*LightPosition))
glEnable(GL_LIGHT1)
glColor4f(1.0,1.0,1.0,0.5)
glBlendFunc(GL_SRC_ALPHA,GL_ONE)
def rotate_world(self):
# know bird.roty is off of (1,0)
ref_angle = self.bird.roty
point1=0
if (ref_angle >= 0 and ref_angle<=90):
point1 = math.atan(ref_angle * math.pi/180.0)
elif (ref_angle >= 90 and ref_angle<=180):
point1 = math.atan((180-ref_angle) * math.pi/180.0)
elif (ref_angle >= 180 and ref_angle<=270):
point1 = -math.atan((ref_angle-180) * math.pi/180.0)
else:
point1 = math.atan((ref_angle) * math.pi/180.0)
point2=0
if (ref_angle >= 0 and ref_angle<=90):
point2 = math.atan((90-ref_angle) * math.pi/180.0)
elif (ref_angle >= 90 and ref_angle<=180):
point2 = math.atan((90.0-ref_angle) * math.pi/180.0)
elif (ref_angle >= 180 and ref_angle<=270):
point2 = math.atan((ref_angle-270) * math.pi/180.0)
else:
# between -90 and 0
point2 = math.atan((ref_angle+90) * math.pi/180.0)
self.world.rotate(1, point2, -point1)
def animate_bird(self, interval):
self.bird.flap()
self.rotate_world()
self.enemy.move(45)
def update(self):
pass
def draw(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glPushMatrix()
self.world.draw()
glPopMatrix()
glPushMatrix()
self.bird.draw()
glPopMatrix()
glPushMatrix()
self.enemy.draw()
glPopMatrix()
def main_loop(self):
clock.set_fps_limit(30)
clock.schedule_interval(self.animate_bird, 0.01)
while not self.has_exit:
self.dispatch_events()
self.clear()
self.update()
self.draw()
#Tick the clock
clock.tick()
self.flip()
#.........这里部分代码省略.........
示例2: TestEnemy
# 需要导入模块: from enemy import Enemy [as 别名]
# 或者: from enemy.Enemy import move [as 别名]
class TestEnemy(unittest.TestCase):
def setUp(self):
self.world = World("./assets/simple_map.txt", False)
self.enemy = Enemy([Vec2D(40, 64), Vec2D(41, 64),
Vec2D(40, 65), Vec2D(41, 65)])
def tearDown(self):
del self.world
del self.enemy
def test_create_bullet(self):
self.enemy.create_bullet()
self.assertIsInstance(self.enemy.bullet, Bullet)
self.assertEqual(self.enemy.bullet.owner, "enemy")
def test_must_be_still_alive(self):
for _ in range(2):
self.enemy.check_health()
self.assertTrue(self.enemy.alive)
def test_must_be_dead(self):
for _ in range(4):
self.enemy.check_health()
self.assertFalse(self.enemy.alive)
def test_check_direction(self):
s = Vec2D(23, 34)
result = self.enemy.check_direction(s, Vec2D(-1, 0), self.world.world)
self.assertTrue(result)
def test_detect_player_direction(self):
self.world.set_content('Y', [Vec2D(14, 34), Vec2D(15, 34)])
s = Vec2D(13, 34)
answer = self.enemy.check_for_player(s, Vec2D(1, 0), self.world.world)
self.assertTrue(answer)
def test_avoid_other_enemy_direction(self):
self.world.set_content('E', [Vec2D(14, 34), Vec2D(15, 34)])
s = Vec2D(13, 34)
answer = self.enemy.check_direction(s, Vec2D(1, 0), self.world.world)
self.assertFalse(answer)
def test_in_collision_with_player(self):
self.world.set_content('Y', [Vec2D(41, 64), Vec2D(42, 64),
Vec2D(41, 65), Vec2D(42, 65)])
answer = self.enemy.detect_collision(Vec2D(1, 0),
self.world.world)
self.assertTrue(answer)
def check_next_position_cell_by_cell(self):
self.assertTrue(self.world.check_by_cell(Vec2D(-1, 0)))
result = self.world.set_content('B', [Vec2D(38, 64), Vec2D(39, 64),
Vec2D(38, 65), Vec2D(39, 65)])
self.assertFalse(result)
def test_find_next_direction(self):
coords = [Vec2D(43, 64), Vec2D(44, 64), Vec2D(43, 65), Vec2D(44, 65)]
self.world.set_content('Y', coords)
self.world.set_energy('Y', coords)
self.world.spread(9, coords[0])
self.world.spread(9, coords[3])
self.world.spread(9, coords[-1])
self.world.spread(9, coords[-4])
self.world.clear_content(self.enemy.coords[0], 'E')
self.enemy.find_neighbours(self.enemy.coords[0], 2, self.world,
Vec2D(32, 34))
self.assertEqual(self.enemy.direction, Vec2D(1, 0))
def test_make_move(self):
coords = [Vec2D(36, 64), Vec2D(37, 64), Vec2D(36, 65), Vec2D(37, 65)]
self.world.clear_content(self.enemy.coords[0], 'E')
self.world.set_energy('Y', coords)
self.enemy.direction = Vec2D(-4, 0)
self.enemy.move(self.world)
self.assertEqual(self.enemy.coords, coords)
for x, y in coords:
self.assertEqual(self.world[x][y].energy, 5)
self.world.set_energy('E', self.enemy.coords)
for x, y in coords:
self.assertEqual(self.world[x][y].energy, 0)