Esempio n. 1
0
            mouse_pos = PixelPos(pygame.mouse.get_pos()[0],
                                 pygame.mouse.get_pos()[1])
            corr_pos = CorrectPos(mouse_pos, HEROORIGIN)
            ball_angle_rad = math.atan2(float(corr_pos.y), float(corr_pos.x))
            ball_angle = math.degrees(ball_angle_rad)
            aimbulletx = 0.5 * (HEROSIZE.w + BULLETSIZE.w) * math.cos(
                math.radians(ball_angle))
            aimbullety = 0.5 * (HEROSIZE.w + BULLETSIZE.w) * math.sin(
                math.radians(ball_angle))
            aimbullet_pos = PixelPos((HEROORIGIN.x + aimbulletx),
                                     (HEROORIGIN.y - aimbullety))
        elif evtType == pygame.MOUSEBUTTONDOWN:
            mouse_pos = PixelPos(pygame.mouse.get_pos()[0],
                                 pygame.mouse.get_pos()[1])
            bulletmouse_pos = CorrectPos(mouse_pos, BULLETORIGIN)
            b = Bullet(ballBullet_scaled, aimbullet_pos, bulletmouse_pos)
            bullets.add(b)
            if len(bullets.sprites()) > 1:
                score += score_time * math.pow(len(bullets.sprites()),
                                               powerball)
            score_time = 0

    bullet_rect.center = (aimbullet_pos)

    ballHero = pygame.transform.rotate(ballHero_scaled, ball_angle)
    ballHero_rect = ballHero.get_rect()
    ballHero_rect.center = HEROORIGIN
    bullets.update(milliseconds)

    for b in bullets.sprites():
        sprite_pos = PixelPos(*b.pos)
Esempio n. 2
0
    def gameloop(self):
        Enemies = [Enemy(self.bg)]
        Bullets = []
        gameCounter = 1
        run = True
        Dificulty = 2
        while run:
            pygame.time.delay(50)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
            if self.b.bulletCount <= 10:
                if gameCounter % 50 == 0:
                    self.b.bulletCount += 1
            self.jet.move(self.b.bulletCount)
            if self.b.bulletCount >= 1 and self.jet.shoot:
                Bullets.append(Bullet(self.bg, self.jet))
                self.b.bulletCount -= 1
                self.jet.shoot = False
                self.playSound('Sounds\jet.mp3')
            self.bg.drawBg(self.b, self.Score)
            for bullet in Bullets:
                bullet.draw()
                if bullet.x_position > self.bg.Width:
                    Bullets.pop(Bullets.index(bullet))
            if len(Enemies) == 0:
                Enemies.append(Enemy(self.bg))
            for i, enemy in enumerate(Enemies):
                for bullet in Bullets:
                    if enemy.collide(bullet):
                        Enemies.pop(i)
                        Bullets.pop(Bullets.index(bullet))
                        self.Score += 100
                        self.playSound('Sounds\collision.mp3')
                if enemy.collide(self.jet):
                    self.playSound('Sounds\collision.mp3')
                    run = False
                    break
                if enemy.x_position < self.bg.Width - self.bg.Width // Dificulty and i == len(
                        Enemies) - 1:
                    Enemies.append(Enemy(self.bg))
                if enemy.x_position < 0 - enemy.Width:
                    Enemies.pop(i)
                enemy.draw()
            if gameCounter % 100 == 0:
                self.Score += 10
            self.jet.draw()
            gameCounter += 1

        run = True
        while run:
            pygame.time.delay(50)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                    run = False
            self.bg.drawBg(self.b, self.Score, Speed=0)
            for enemy in Enemies:
                enemy.draw()
            pygame.font.init()
            myfont = pygame.font.SysFont('Comic Sans MS', 70)
            textsurface = myfont.render("YOU LOST", False, (255, 255, 255))
            self.bg.Window.blit(textsurface, (150, 150))
            pygame.display.update()
            keys = pygame.key.get_pressed()
            if keys[pygame.K_r]:
                self.gameloop()
Esempio n. 3
0
 def __init__(self):
     self.bg = Background()
     self.jet = Jet(self.bg)
     self.b = Bullet(self.bg, self.jet)
     self.Score = 0
Esempio n. 4
0
def creat_Bullet( x , y ):
    global Bullets , Bullet_Count
    New_Bullet = Bullet(x + 30, y )
    Bullets.append(New_Bullet)
    game_world.add_object(New_Bullet, 1)
    Bullet_Count += 1
Esempio n. 5
0
 def ShootBullet(self, spaceShip_x):
     self.x = spaceShip_x
     self.listOfBullets.append(Bullet(self.x, self.y, 10, 10, 35))
     self.soundGun.play()
     self.soundGun.rewind()
Esempio n. 6
0
def fire_bullet(bullets, setting, screen, ship):
    if len(bullets) < setting.bullet_allowed:
        new_bullet = Bullet(setting, screen, ship)
        bullets.add(new_bullet)
Esempio n. 7
0
def fire_bullet(screen, ship, bullets, set):

    if len(bullets) <= set.bullets_allowed:
        new_bullet = Bullet(screen, ship,set)
        bullets.add(new_bullet)
Esempio n. 8
0
 def shoot(self, spaceShip_x):
     self.listOfBullets.append(Bullet(spaceShip_x, self.y, 10, 10, 40))
     self.soundGun.play()
     self.soundGun.rewind()