Beispiel #1
0
    def update(self, dt):
        super().update(dt)
        if self.rotating:
            self.angle += Ship.WSPEED * dt
            self.image = rot_center(self.base_image, self.angle)
        self.ax = -Ship.BASE_ACC * sin(rad(self.angle))
        self.ay = -Ship.BASE_ACC * cos(rad(self.angle))
        check_collision = self.collision_cirlce.update(
            self.x + Ship.ship_iwidth // 2 + 4 * sin(rad(self.angle)) - 9,
            self.y + Ship.ship_iheight // 2 + 4 * cos(rad(self.angle)) - 9)
        if check_collision['v']:
            if not self.colliding['v']:
                self.colliding['v'] = True
                self.vx_C = self.vx
            if not (self.ax * self.vx_C < 0 and self.vx_C * self.vx < 0):
                self.vx = 0
        else:
            self.colliding['v'] = False
            self.vx_C = 0

        if check_collision['h']:
            if not self.colliding['h']:
                self.colliding['h'] = True
                self.vy_C = self.vy
            if not (self.ay * self.vy_C < 0 and self.vy_C * self.vy < 0):
                self.vy = 0
        else:
            self.colliding['h'] = False
            self.vy_C = 0

        if check_collision['b']:
            self.shot()
Beispiel #2
0
 def set_active(self, x, y, angle):
     self.x = x
     self.y = y
     self.angle = angle
     self.vx = Pilot.BASE_SPEED * sin(rad(self.angle))
     self.vy = Pilot.BASE_SPEED * cos(rad(self.angle))
     self.image = rot_center(self.base_image, angle)
     self.active = True
     self.add(pilot_sprites)
Beispiel #3
0
    def show(self, window):

        # pygame.gfxdraw.aacircle(window, self.x, self.y, self.r, color)
        # pygame.gfxdraw.filled_circle(window, self.x, self.y, self.r, color)
        if self.Blink:
            window.blit(
                utils.rot_center(self.blinkFrames[self.seq[self.frame]],
                                 self.angle),
                (self.x - self.r, self.y - self.r))
            self.frame += self.animdir
            if self.frame >= len(self.seq) or self.frame <= 0:
                self.frame = 0
                self.Blink = False
        else:
            window.blit(utils.rot_center(self.texture, self.angle),
                        (self.x - self.r, self.y - self.r))
        window.blit(self.number,
                    (self.x - self.size[0] / 2, self.y - self.size[1] / 2))
        self.angle -= 5
 def draw(self):
     GameEngine.game_display.fill((0, 0, 0))
     GameEngine.game_display.blit(utils.rot_center(self.ship.image, self.ship.angle),
                                  (self.ship.rect.x, self.ship.rect.y))
     for bullet in self.ship.bullets:
         GameEngine.game_display.blit(bullet.image, (bullet.rect.x, bullet.rect.y))
     for asteroid in self.asteroids:
         GameEngine.game_display.blit(
             pygame.transform.scale(asteroid.image, (25 * asteroid.size, 25 * asteroid.size)),
             (asteroid.rect.x, asteroid.rect.y))
     GameEngine.display_data(100, 20, self.score, GameEngine.font, (255, 255, 255))
     super().draw()
Beispiel #5
0
 def revive(self):
     x, y = self.player.pilot.x, self.player.pilot.y
     angle = self.player.pilot.angle
     self.angle = angle
     self.image = rot_center(self.base_image, angle)
     self.vx = self.vy = 1
     self.x = x
     self.y = y
     self.add(ships_sprites)
     self.collision_cirlce = CollisionCircle(
         self.x + (Ship.ship_iwidth - 18) / 2, self.y + 10, 9, self)
     self.active = True
     self.player.pilot.killed()
Beispiel #6
0
    def __init__(self, group, path, x, y, v, a, angle):
        super().__init__(group)

        self.angle = angle  # угол от вертикали (0 - вверх), против часовой, деги на калькуляторе!
        self.base_image = load_image(f'{path}')
        self.image = rot_center(self.base_image, angle)
        self.rect = self.image.get_rect()
        self.x = x
        self.y = y
        self.rect.x = x
        self.rect.y = y
        self.vx = -v * sin(rad(angle))
        self.vy = -v * cos(rad(angle))
        self.ax = -a * sin(rad(angle))
        self.ay = -a * cos(rad(angle))