예제 #1
0
def get_params():
    width = 500
    height = 400

    DISPLAYSURF = pygame.display.set_mode((width, height))
    DISPLAYSURF.fill((255, 255, 255))

    score = 0
    lives = 1

    return {
        'FPS': 30,
        'width': width,
        'height': height,
        'DISPLAYSURF': DISPLAYSURF,
        'fps_clock': pygame.time.Clock(),
        'score': score,
        'lives': lives,
        'bullets': [],
        'rocks': [],
        'bullet_group': pygame.sprite.Group(),
        'rock_group': pygame.sprite.Group(),
        'ship': Ship((width / 2, height - 50), 0.5),
        'rock_generator': RockGenerator(width, height),
        'game_info': GameInfo(score, lives),
        'audio': AudioEffects()
    }
예제 #2
0
    def __init__(self, name, width, height):
        super().__init__(name, width, height)

        self.ship = Ship()  # None  # TODO: should create a Ship object here
        # TODO: should create asteroids
        self.asteroids = []
        # TODO: should create stars
        self.stars = []
        self.bullets = []
예제 #3
0
 def __init__(self, name, width, height):
     super().__init__( name, width, height )
     self.ship = Ship()  # Creates a ship
     self.asteroids=[]   # A list of all asteroids
     for i in range(4):                  # Change for different amount of Asteroids
         self.asteroids.append(Asteroid(random.randrange(0, 1280, 5),random.randrange(0, 720, 5)))
     self.stars=[]       # A list of all background stars
     for i in range(50):                # Change for different amount of background Stars
         self.stars.append(Star())
     self.bullets = []   # A list of all bullets
예제 #4
0
 def create_enemy(self):
     ship = Ship()
     ship.set_part('body', self.items_factory.create_body())
     ship.set_part('leftwing', self.items_factory.create_left_wing())
     ship.set_part('rightwing', self.items_factory.create_right_wing())
     ship.set_part('leftrearwing',
                   self.items_factory.create_left_rear_wing())
     ship.set_part('rightrearwing',
                   self.items_factory.create_right_rear_wing())
     ship.set_part('weapon', self.items_factory.create_weapon())
     return ship
예제 #5
0
 def __init__(self, name, width, height):
     super().__init__(name, width, height)
     # TODO: should create a Ship object here
     self.ship = Ship()  # None
     # TODO: should create asteroids
     self.asteroids = []
     for i in range(8):  # Change for different amount of Asteroids
         self.asteroids.append(Asteroid())
     self.stars = []
     for i in range(250):  # Change for different amount of background Stars
         self.stars.append(Star())
     # TODO: should create bullets
     self.bullets = []
예제 #6
0
 def __init__(self, name, width, height):
     super().__init__(name, width, height)
     self.width = width
     self.height = height
     self.ship = Ship()  # Creates a ship
     self.asteroids = []  # A list of all asteroids
     for i in range(5):  # Change for different amount of Asteroids
         self.asteroids.append(
             Asteroid(random.randrange(0, width, 5),
                      random.randrange(0, height, 5)))
     self.stars = []  # A list of all background stars
     for i in range(25):  # Change for different amount of background Stars
         self.stars.append(Star())
     self.bullets = []  # A list of all bullets
     self.score = 0  # Possible score variable
예제 #7
0
def main():
    """Set up main loop for game"""
    pygame.init()
    clock = pygame.time.Clock()
    settings = Settings()
    screen = settings.screen
    ship = Ship(screen)
    aliens = create_aliens(screen)
    projectiles = pygame.sprite.Group()
    barriers = pygame.sprite.Group(Barrier(screen, 1), Barrier(screen, 2),
                                   Barrier(screen, 3), Barrier(screen, 4))
    score = Score()

    while True:
        check_events(screen, ship, projectiles)
        update_objects(ship, projectiles, barriers, aliens, score)
        update_screen(settings, ship, barriers, projectiles, aliens, score)
        clock.tick(60)
예제 #8
0
def restart_game(text, color):
    global ship_enemies, ship, bullets
    font = pygame.font.SysFont('comicsans', 100)
    text = font.render(text, True, (255, 255, 255))
    window.blit(text, (screen_width/2-text.get_width()/2, screen_height/2))
    font = pygame.font.SysFont('comicsans', 50)
    text = font.render('Naciśnij dowolny klawisz, aby rozpocząć nową grę...', True, color)
    window.blit(text, (screen_width/2-text.get_width()/2, screen_height/2+100))
    pygame.display.update()
    pause = True
    while pause:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pause = False
                pygame.quit()
            if event.type == pygame.KEYDOWN:
                pause = False
                bullets = []
                ship_enemies = [[Ship(x*100+100, i*60, 64, 64, 15, enemy_image) for x in range(8)] for i in range(4)]
                ship.x = screen_width/2-ship.width/2
예제 #9
0
 def __init__(self, ship=None):
     if ship is None:
         self.ship = Ship()
     else:
         # Rebuild object if ship is set
         self.ship = ship
예제 #10
0
 def create_enemy(self):
     ship = Ship()
     ship.set_part('body', self.items_factory.create_body())
     return ship
예제 #11
0
import pygame
from objects import Ship, Bullet
import random

pygame.init()

run = True
clock = pygame.time.Clock()
screen_width, screen_height = (1000, 600)
window = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('Space Invaders')
background_image = pygame.image.load('background.png')
ship_image = pygame.transform.scale(pygame.image.load('ship.png'), (64, 64))
enemy_image = pygame.transform.scale(pygame.image.load('enemy.png'), (64, 48))
ship = Ship(screen_width/2-32, screen_height-64, 64, 64, 5, ship_image)
bullet_image_up = pygame.image.load('bullet.png')
bullet_image_down = pygame.transform.rotate(bullet_image_up, 180)
bullets = []
pygame.time.set_timer(pygame.USEREVENT+1, random.randrange(1000, 2000))
ship_enemies = None
bullet_time = 0
enemy_move_time = 0
enemy_direction = 1
enemies_go_down = False


def redraw_window():
    window.blit(background_image, (0, 0))
    
def restart_game(text, color):
    global ship_enemies, ship, bullets