コード例 #1
0
 def facing(self, enemy, other):
     front = enemy.front
     right = enemy.right
     vec = [(other.pos[0] - enemy.pos[0])/Auxiliars.dist(enemy.pos, other.pos), (other.pos[1] - enemy.pos[1])/Auxiliars.dist(enemy.pos, other.pos)]
     enemy.angle_front, enemy.angle_right = (math.acos(front[0]*vec[0] + front[1]*vec[1])*180.0/math.pi, math.acos(right[0]*vec[0] + right[1]*vec[1])*180.0/math.pi)
     if enemy.angle_front <= enemy.values["ang_rang"]:
         return True
コード例 #2
0
 def enemy_ai(self, player):
     enemy_copy = self.enemy_group.copy()
     for enemy in enemy_copy:
         if self.facing(enemy, player) and Auxiliars.dist(enemy.pos, player.pos) > enemy.values["min_dist"]:
             enemy.thrust(True)
             print("thrust")
         elif self.facing(enemy, player) and Auxiliars.dist(enemy.pos, player.pos) < enemy.values["min_dist"]:
             enemy.thrust()
             enemy.shoot()
             print("not thrust")
         if self.facing(enemy, player): #and np.random.random_sample()<math.exp(-(enemy.values["V"])/enemy.values["T"]):
             enemy.key(0.0, True)
         elif not self.facing(enemy, player) and 0.0 <= enemy.angle_right < 90.0:
             enemy.key(enemy.values["ang_acc"])
         elif not self.facing(enemy, player) and 90.0 <= enemy.angle_right <= 180.0:
             enemy.key(-enemy.values["ang_acc"])
         elif self.facing(enemy, player) and Auxiliars.dist(enemy.pos, player.pos) <= enemy.values["min_dist"]:
             enemy.shoot()
             print("Shoot")
     self.enemy_group = enemy_copy.copy()
コード例 #3
0
ファイル: game.py プロジェクト: leguiart/Python
 def rock_spawner(self):
     x=0
     for s in self.rock_group:
         x+=1
     rock_pos=[random.randrange(0, self.globals_dict["WIDTH"]-44),random.randrange(0, self.globals_dict["HEIGHT"]-44)]
     if self.globals_dict["score"]>0 and self.globals_dict["score"]%5==0:
         self.explosion_group=set()
         self.globals_dict["sc_dif"]+=.2
     rock_vel=[random.randrange(-1,3) * random.random() * self.globals_dict["sc_dif"], random.randrange(-1,3) * random.random() * self.globals_dict["sc_dif"]]
     if self.globals_dict["started"] and x<12 and Auxiliars.dist(rock_pos, self.pars["my_ship"].get_pos())> (self.pars["ship_info"].get_radius() + self.pars["asteroid_info"].get_radius())*1.2:
         a_rock = Sprite(rock_pos ,rock_vel, random.random(), 0.10471976, self.pars["asteroid_image"], \
             self.pars["asteroid_info"], self.globals_dict["WIDTH"], self.globals_dict["HEIGHT"])
         self.rock_group.add(a_rock)
コード例 #4
0
ファイル: ship.py プロジェクト: leguiart/PTSG
 def facing(self, other_pos):
     front = Ship.get_front(self)
     right = Ship.get_right(self)
     self.d_player = Auxiliars.dist(Ship.get_pos(self), other_pos)
     vec = [(other_pos[0] - Ship.get_pos(self)[0]) / self.d_player,
            (other_pos[1] - Ship.get_pos(self)[1]) / self.d_player]
     phi = math.atan2(vec[1], vec[0])
     # self.angle_front, self.angle_right = (math.acos(front[0]*vec[0] + front[1]*vec[1])*180.0/math.pi, math.acos(right[0]*vec[0] + right[1]*vec[1])*180.0/math.pi)
     front = Ship.get_front(self)
     self.angle_front = (
         (phi - math.atan2(front[1], front[0])) * 180.0 / math.pi) / 360.0
     self.d_player = self.d_player / 1000
     if self.angle_front <= self.pars[
             "ang_rang"] / 360.0 and self.angle_front >= -self.pars[
                 "ang_rang"] / 360.0:
         self.delay += 1
         if self.delay >= 5:
             Ship.shoot(self)
             self.delay = 0
コード例 #5
0
 def collide(self, other):
     if Auxiliars.dist(self.kinematic_dict["pos"], other.get_physics_component().get_pos()) <= self.radius + other.get_physics_component().get_radius():
         return True
     else:
         return False
コード例 #6
0
 def collide(self, other_object):
     if Auxiliars.dist(other_object.get_pos(), self.get_pos()
                       ) <= other_object.get_radius() + self.get_radius():
         return True
     else:
         return False