コード例 #1
0
 def initialize(self, world):
     for i in range(-5, 6):
         world.addObstacle(
             Circle(r=15,
                    pos=[
                        world.width / 2 + i * world.width / 13,
                        0.36 * world.height
                    ]))
         world.addObstacle(
             Circle(r=15,
                    pos=[
                        world.width / 2 + i * world.width / 13,
                        0.2 * world.height
                    ]))
     for i in range(-5, 5):
         world.addObstacle(
             Circle(r=15,
                    pos=[
                        world.width / 2 + world.width / 39 +
                        i * world.width / 13, 0.28 * world.height
                    ]))
         world.addObstacle(
             Circle(r=15,
                    pos=[
                        world.width / 2 + world.width / 39 +
                        i * world.width / 13, 0.44 * world.height
                    ]))
     world.canon = Canon(r=75,
                         pos=[world.width / 2, world.height],
                         theta=-np.pi / 2)
     world.target = TargetArea(pos=(world.width / 2, world.height * 0.05),
                               width=world.width * 0.05,
                               height=world.height * 0.05)
コード例 #2
0
 def initialize(self, world):
     world.addObstacle(
         Circle(world.height * 0.25,
                (world.width * 0.5, world.height * 0.5), 1.0))
     world.canon = Canon(r=75,
                         pos=[world.width / 2, world.height],
                         theta=-np.pi / 2)
     world.canon.shotQuantity = 6
     world.showTrajectories = True
コード例 #3
0
 def __init__(self, width=400, height=400):
     self.width, self.height = width, height
     self.target = TargetArea()
     self.canon = Canon()
     self.missiles = []
     self.obstacles = []
     self.holes = []
     self.trajectoryDict = TrajectoryDict()
     self.showTrajectories = False
     self.interaction = False
     self.nt = 1
     self.dt = 1.
コード例 #4
0
 def __init__(self):
     self.change_scene('scene')
     print(self.N)
     try:
         self.canon = Canon()
         self.canon.setup_preview()
     except Exception as e:
         print(e)
         print('Failed to connect to camera!')
         self.canon = None
     self.alpha = 0.70
     self.frame_rate = 12
     self.check_before_delete = True
コード例 #5
0
 def initialize(self, world):
     world.addObstacle(
         Rectangle(world.width * 0.625, world.height * 0.33,
                   world.width * 0.75, 50, 0))
     world.addObstacle(
         Rectangle(world.width * 0.375, world.height * 0.66,
                   world.width * 0.75, 50, 0))
     world.target = TargetArea(pos=(world.width * 0.85,
                                    world.height * 0.15),
                               width=world.width * 0.2,
                               height=world.height * 0.2)
     world.canon = Canon(r=75,
                         pos=[world.width * 0.5, world.height],
                         theta=-np.pi / 2)
コード例 #6
0
 def initialize(self, world):
     world.addObstacle(
         Circle(r=150, pos=[world.width / 2, world.height / 2]))
     world.addObstacle(
         Circle(r=world.height,
                pos=[-world.height * np.sqrt(3) / 2, world.height / 2]))
     world.addObstacle(
         Circle(r=world.height,
                pos=[
                    world.width + world.height * np.sqrt(3) / 2,
                    world.height / 2
                ]))
     world.canon = Canon(r=75,
                         pos=[world.width / 2, world.height],
                         theta=-np.pi / 2)
     world.target = TargetArea(pos=(world.width / 2, world.height * 0.21),
                               width=world.height * 0.04,
                               height=world.height * 0.04)
コード例 #7
0
 def initialize(self, world):
     world.addObstacle(
         Line(world.width * 0.75, world.height / 2, world.width * 0.3,
              np.pi * 0.5))
     world.addObstacle(
         Line(world.width * 0.6, world.height / 4, world.width * 0.3, 0))
     world.addObstacle(
         Rectangle(world.width * 0.2, world.height * 0.42,
                   world.width * 0.45, 30, 0))
     world.addObstacle(
         Rectangle(world.width * 0.2, world.height * 0.58,
                   world.width * 0.5, 35, 0))
     world.addObstacle(
         Circle(r=20, pos=[world.width * 0.43, world.height * 0.42]))
     world.addObstacle(
         Circle(r=55, pos=[world.width * 0.46, world.height * 0.58]))
     world.canon = Canon(r=75,
                         pos=[world.width / 2, world.height],
                         theta=-np.pi / 2)
     world.target = TargetArea(pos=(world.width * 0.35, world.height * 0.5),
                               width=world.height * 0.1,
                               height=world.height * 0.1)
コード例 #8
0
    def _checkCollision(self, paddleobj, ballobj, cannonobj):
        if (self._x + self._xvel >= paddleobj._x and
                paddleobj._y <= self._y < paddleobj._y + paddleobj._ylength):
            self._x = paddleobj._x - 1 - self._xvel
            # print(self._type,self._x,self._y)
            if (self._type == "E"):
                paddleobj.powerups[self._type].append(POWERUPTIME)
                paddleobj._ylength += EXPANDSIZE
            elif (self._type == "S"):
                paddleobj.powerups[self._type].append(POWERUPTIME)
                if (paddleobj._ylength != 3):
                    paddleobj._ylength -= SHRINKSIZE
            elif (self._type == "M"):
                newballs = []
                for ball in ballobj:
                    nball = Ball(ball._x, ball._y, ball._xlength,
                                 ball._ylength, -1 * ball._xvel,
                                 -1 * ball._yvel)
                    nball.isCollidedWithPaddle = False
                    newballs.append(nball)
                for i in newballs:
                    ballobj.append(i)
                paddleobj.powerups[self._type].append(-1)
            elif (self._type == "F"):
                paddleobj.powerups[self._type].append(POWERUPTIME)
                for ball in ballobj:
                    ball._xvel = ball._xvel + self.ballvel(
                        ball._xvel) * INCREASEBALLXSPEED
                    ball._yvel = ball._yvel + self.ballvel(
                        ball._yvel) * INCREASEBALLYSPEED
            elif (self._type == "T"):
                paddleobj.powerups[self._type].append(POWERUPTIME)
                for ball in ballobj:
                    ball.isThrough = True
            elif (self._type == "G"):
                paddleobj.powerups[self._type].append(POWERUPTIME)
            elif (self._type == "B"):
                paddleobj.powerups[self._type].append(40)
                cannonobj.append(
                    Canon(paddleobj._x - 1, paddleobj._y, 1, 1, 0, 0, 0))
                cannonobj.append(
                    Canon(paddleobj._x - 1,
                          paddleobj._y + paddleobj._ylength - 1, 1, 1, 0, 0,
                          1))
            elif (self._type == "@"):
                rIndex = []
                for i in ballobj:
                    rIndex.append(i)
                for i in rIndex:
                    ballobj.remove(i)
            elif (self._type == "A"):
                paddleobj.powerups[self._type].append(POWERUPTIME)
                for ball in ballobj:
                    ball.isFire = True

            self.isCollided = True
        if (self._x + self._xvel >= config.FRAMEHEIGHT):
            self._x = 0
            self.isCollided = True
        elif (self._x + self._xvel <= 0):
            self._x = 0 - self._xvel
            self._xvel = -1 * self._xvel
        if (self._y + self._yvel >= config.FRAMEWIDTH):
            self._y = config.FRAMEWIDTH - self._yvel - 1
            self._yvel = -1 * self._yvel
        elif (self._y + self._yvel <= 0):
            self._y = 0 - self._yvel
            self._yvel = -1 * self._yvel
コード例 #9
0
 def initialize(self, world):
     world.canon = Canon(r=75,
                         pos=[world.width / 2, world.height],
                         theta=-np.pi / 2)
     world.canon.shotQuantity = 6
     world.showTrajectories = True
コード例 #10
0
def fire_canon(ai_settings,screen,ship,bullets):
    # Limit number of shots fired to the number declared in the settings file
    if len(bullets) < ai_settings.nr_bullets:
        bullet = Canon(ai_settings,screen,ship)
        bullets.add(bullet)