Example #1
0
 def fire(self,x,y):
   tanX = abs(x - self.position[0]) / float(y)
   radian = math.atan(tanX)
   angle = radian * 180 / math.pi
   if x < WIN_WIDTH // 2:
     angle = -angle
   duration = abs(angle)/200.0
   self.do(actions.RotateTo(angle,duration) + actions.CallFunc(self._fire_net,x = x,y = y))
Example #2
0
def shake_back():
    """Predefined action that rotates to 0 degrees in 0.1 seconds"""
    return ac.RotateTo(0, 0.1)
Example #3
0
    def _load_path(self):
        """
        Dynamically finds the path for the enemies, by going through the
        gameGrid Matrix. Contains both the path for enemies and their health-
        bars, enemies rotate additionally to moving.
        """
        currentTile = copy.deepcopy(self.startTile)
        # move[0] for enemy with rotation and move[1] for healthbar
        move = [[], []]
        pos = self._get_position_from_grid(self.startTile)

        while(currentTile[0] != self.endTile[0] or
              currentTile[1] != self.endTile[1]):

            # Right
            if(self.gameGrid[currentTile[0]][currentTile[1] + 1] == 2):
                # Rotate right
                move[0].append(actions.RotateTo(0, 0))
                move[1].append([])
                # Move right
                for j in range(1, 11):
                    move[0].append((pos[0] + 6 * j, pos[1]))
                    move[1].append((6, 0))
                # Next position
                pos = (pos[0] + 60, pos[1])
                currentTile[1] += 1
                self.gameGrid[currentTile[0]][currentTile[1]] = 1

            # Up
            elif(self.gameGrid[currentTile[0] + 1][currentTile[1]] == 2):
                # Rotate up
                move[0].append(actions.RotateTo(270, 0))
                move[1].append([])
                # Move up
                for j in range(1, 11):
                    move[0].append((pos[0], pos[1] + 6 * j))
                    move[1].append((0, 6))
                # Next position
                pos = (pos[0], pos[1] + 60)
                currentTile[0] += 1
                self.gameGrid[currentTile[0]][currentTile[1]] = 1

            # Down
            elif(self.gameGrid[currentTile[0] - 1][currentTile[1]] == 2):
                # Rotate down
                move[0].append(actions.RotateTo(90, 0))
                move[1].append([])
                # Move down
                for j in range(1, 11):
                    move[0].append((pos[0], pos[1] - 6 * j))
                    move[1].append((0, -6))
                # Next position
                pos = (pos[0], pos[1] - 60)
                currentTile[0] -= 1
                self.gameGrid[currentTile[0]][currentTile[1]] = 1
            # Left
            elif(self.gameGrid[currentTile[0]][currentTile[1] - 1] == 2):
                # Rotate left
                move[0].append(actions.RotateTo(180, 0))  # RotateLeft
                move[1].append([])  # placeholder
                # Move left
                for j in range(1, 11):
                    move[0].append((pos[0] - 6 * j, pos[1]))
                    move[1].append((-6, 0))
                # Next position
                pos = (pos[0] - 60, pos[1])
                currentTile[1] -= 1
                self.gameGrid[currentTile[0]][currentTile[1]] = 1

            else:
                break
        self.gameGrid[self.startTile[0]][self.startTile[1]] = 1
        return move
Example #4
0
 def up(self, check=True):
     if self.rotation == 0:
         self.move(check)
     self.do(actions.RotateTo(0, self.rotTime))
Example #5
0
 def down(self):
     if self.rotation == 180:
         self.move()
     self.do(actions.RotateTo(-180, self.rotTime))
Example #6
0
 def left(self):
     if self.rotation == 270:
         self.move()
     self.do(actions.RotateTo(-90, self.rotTime))
Example #7
0
 def right(self):
     if self.rotation == 90:
         self.move()
     self.do(actions.RotateTo(90, self.rotTime))