def run_game():
    pygame.init()
    screen = pygame.display.set_mode((setting.width, setting.height))
    pygame.display.set_caption("Alien Invasion")
    # 创建飞船
    ship = Ship(screen)
    while True:
        # 点击按键之后不动使飞机能够一直移动
        gf.check_events_keepMove(ship)
        ship.update()
        gf.update_screen(setting, screen, ship)
Exemple #2
0
 def prep_ships(self):
     self.ships = Group()
     for ship_number in range(self.stats.ships_left):
         ship = Ship(self.game)
         ship.rect.x = 10 + ship_number * ship.rect.width
         ship.rect.y = 10
         self.ships.add(ship)
 def pre_ship(self):
     self.ships = Group()
     for ship_num in range(self.states.ship_left):
         ship = Ship(self.screen)
         ship.rect.x = 10 + ship_num * ship.rect.width
         ship.rect.y = 10
         self.ships.add(ship)
Exemple #4
0
def initializePopulation(numShips, numAsteroids, drawNN = None):

	ships = []
	for i in range(numShips):
		asteroids = initAsteroids(numAsteroids)
		ship = Ship(np.asarray([int(GAME_AREA_WIDTH/2), int(HEIGHT/2)]), 0, GAME_AREA, asteroids, drawNN = drawNN,color=colors.YELLOW)
		ships.append(ship)
	return ships
Exemple #5
0
def initShips(numShips, asteroids):

	ships = []
	for i in range(numShips):
		ship = Ship(np.asarray([int(GAME_AREA_WIDTH/2), int(HEIGHT/2)]), 0, GAME_AREA, asteroids, color=colors.YELLOW)
		#ship.initilizeRandomPosition(GAME_AREA_WIDTH, HEIGHT)
		ships.append(ship)

	return ships
Exemple #6
0
def run_game():
    pygame.init()
    screen = pygame.display.set_mode((setting.width, setting.height))
    pygame.display.set_caption("Alien Invasion")
    # 创建飞船
    ship = Ship(screen)
    while True:
        gf.check_events(ship)
        gf.update_screen(setting, screen, ship)
Exemple #7
0
def run_game():
    #初始化游戏并创建屏幕对象
    pygame.init()
    setting = Setting()
    screen = pygame.display.set_mode(
        (setting.screen_width, setting.screen_height))
    pygame.display.set_caption("打飞机")

    #实例化飞机
    ship = Ship(screen)

    #储存子弹编组
    bullets = Group()

    #实例化外星人
    aliens = Group()
    gf.create_fleet(setting, screen, ship, aliens)

    #游戏状态
    states = GameStates(setting)

    #开始按钮
    play_bt = Button(screen, 'play')

    #记分板
    sb = ScoreBoard(setting, screen, states)
    #开始游戏主循环
    while True:
        #监视鼠标和键盘事件
        gf.check_events(setting, screen, ship, bullets, aliens, states,
                        play_bt, sb)
        if states.game_active:
            #更新飞机位置
            ship.update()
            #子弹更新
            gf.update_bullets(setting, screen, ship, aliens, bullets, states,
                              sb)
            #外星人更新
            gf.update_aliens(ship, aliens, bullets, setting, screen, states,
                             sb)
        #让最近的屏幕绘制可见
        gf.update_screen(setting, screen, ship, bullets, aliens, states,
                         play_bt, sb)
Exemple #8
0
def run(mode):
    # Initialize game and create a screen object
    pygame.init()
    ai_settings = Settings(mode)

    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))

    pygame.display.set_caption("Space Invasion")

    # Make the Play button.
    play_button = Button(ai_settings, screen, "Play")

    # Create an instance to store game statistics.
    stats = GameStats(ai_settings)

    # Make a ship
    ship = Ship(ai_settings, screen)

    # Make a group to store bullets in.
    bullets = Group()

    # Make a group of aliens.
    aliens = Group()

    # Create the fleet of aliens.
    gf.create_fleet(ai_settings, screen, ship, aliens)

    game_over = False

    # Start the main loop for the game
    while not game_over:
        # Watch for the keyboard and mouse events
        gf.check_events(ai_settings, screen, stats, play_button, ship, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets,
                             mode)

        gf.update_screen(ai_settings, screen, stats, ship, aliens, bullets,
                         play_button)
Exemple #9
0
def run_game():
    # Initialize background settings for pygame functionality
    pygame.init()

    # Initialize settings object
    settings = Settings()

    # Initialize screen object of 1200x800 and add caption
    screen = pygame.display.set_mode((settings.screen_w, settings.screen_h))
    pygame.display.set_caption("Alien Invasion")

    # Initialize ship
    ship = Ship(settings, screen)

    # Initialize alien and create fleet
    aliens = Group()
    gf.create_fleet(settings, screen, ship, aliens)

    # Create group for bullets
    bullets = Group()

    # Main loop for game
    # Surfaces are redrawn on every pass of our loop
    while True:

        # Check for events
        gf.check_events(screen, settings, ship, bullets)

        # Update ship
        ship.update(settings)

        # Update bullets
        bullets.update()

        # get rid of off-screen bullets
        gf.update_bullets(aliens, bullets)

        # Update aliens
        gf.update_aliens(settings, aliens)

        # Flip to new screen, ship position, etc.
        gf.update_screen(settings, screen, ship, bullets, aliens)
Exemple #10
0
def run_game():
    pygame.init()
    screen = pygame.display.set_mode((setting.width, setting.height))
    pygame.display.set_caption("Alien Invasion")
    # 在每次执行while 循环时都绘制一个空屏幕,并擦去旧屏幕
    bg_color = setting.backgroudColor
    # 创建飞船
    ship = Ship(screen)

    while True:
        # 设置背景颜色
        screen.fill(bg_color)
        ship.biltme()
        # 只要有交互时间时 , 就会执行以下的for循环。例如鼠标位置的变化
        for even in pygame.event.get():
            # 点击关闭按钮 pygame.QUIT
            if even.type == pygame.QUIT:
                print("Quit Process")
                # 游戏退出
                sys.exit()

            pygame.display.flip()
def run_game():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption('Inwazja OBCYCH!')

    play_button = Button(screen, ai_settings, 'Rozpocznij gre')

    stats = GameStats(ai_settings)
    ship = Ship(screen, ai_settings)
    bullets = Group()  # przechowywanie pociskow
    aliens = Group()

    gf.create_fleet(ai_settings, screen, ship, aliens)

    while True:
        gf.check_events(screen, ai_settings, stats, ship, aliens, bullets, play_button)
        gf.update_screen(screen, ai_settings, stats, ship, aliens, bullets, play_button)
        if stats.game_active:
            ship.update()
            gf.update_bullets(screen, ai_settings, ship, aliens, bullets)
            gf.update_aliens(screen, ai_settings, stats, ship, aliens, bullets)
Exemple #12
0
def run_game():
    #initialize game nad create a screen object
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    ship = Ship(screen, ai_settings)
    bullets = Group()
    aliens = Group()
    game_functions.create_fleet(ai_settings, screen, aliens)
    #start the main
    while True:
        game_functions.check_events(ai_settings, screen, ship, bullets)
        game_functions.update_bullets(bullets)
        game_functions.update_screen(screen, ai_settings, ship, bullets,
                                     aliens)
Exemple #13
0
#Simple turn based, 2 player game written in python 3
#Jaroslaw Glodowski
from classes.ship import Ship
from classes.attack import Attack
import os

os.system("cls")
p1 = input("Enter player 1's name: ")
p2 = input("Enter player 2's name: ")
os.system("cls")

m1 = Attack()
s1 = Ship(p1)
s2 = Ship(p2)

player = s1
ggame = True


def update_player(player):
    if player == s1:
        return s2
    else:
        return s1


def turn_move_light(ammo_type, plr):
    dmg = m1.attack(ammo_type)
    plr.sub_light_ammo()
    plr = update_player(plr)
    plr.sub_health(dmg)
Exemple #14
0
def select_ship():
    """Select type and color of the Ship"""
    global SCREEN, SCREEN_WIDTH, SCREEN_HEIGHT
    global m_ship

    back_text = text.render("Volver", 1, (255, 25, 255))
    test_ships = []
    preview_ship = m_ship

    back_button = pygame.Rect(250, 800, 200, 50)
    rect_blue = pygame.Rect(80, 500, 50, 50)
    rect_green = pygame.Rect(80 * 2, 500, 50, 50)
    rect_n_blue = pygame.Rect(80 * 3, 500, 50, 50)
    rect_orange = pygame.Rect(80 * 4, 500, 50, 50)
    rect_purple = pygame.Rect(80 * 5, 500, 50, 50)
    rect_red = pygame.Rect(80 * 6, 500, 50, 50)
    rect_yellow = pygame.Rect(80 * 7, 500, 50, 50)

    preview_ship.set_pos(250, 300)
    preview_ship.resize(2)
    for i in range(1, 7):
        test_ships.append(
            Ship("RED", str(i), SCREEN, SCREEN_WIDTH, SCREEN_HEIGHT, 90 * i,
                 600))

    click2 = False
    selecting = True
    while selecting:
        mx, my = pygame.mouse.get_pos()
        SCREEN.blit(Background, (0, 0))
        preview_ship.draw(SCREEN, SCREEN_HEIGHT, SCREEN_HEIGHT)
        pygame.draw.rect(SCREEN, (200, 200, 200), back_button)
        SCREEN.blit(back_text, (280, 810))

        i = 0
        for ships in test_ships:
            ships.draw(SCREEN, SCREEN_WIDTH, SCREEN_HEIGHT)
            if ships.get_hb_as_rect().collidepoint((mx, my)) and click2:
                m_ship.set_type(str(i + 1), m_ship.get_scale())
                preview_ship.set_type(str(i + 1), preview_ship.get_scale() * 2)
                print(preview_ship.get_color())
            i += 1

        pygame.draw.rect(SCREEN, (0, 0, 255), rect_blue)
        pygame.draw.rect(SCREEN, (0, 255, 0), rect_green)
        pygame.draw.rect(SCREEN, (35, 35, 142), rect_n_blue)
        pygame.draw.rect(SCREEN, (255, 165, 0), rect_orange)
        pygame.draw.rect(SCREEN, (255, 0, 255), rect_purple)
        pygame.draw.rect(SCREEN, (255, 0, 0), rect_red)
        pygame.draw.rect(SCREEN, (255, 255, 0), rect_yellow)

        #TEDIOUS PART!!!!!!!!!!!!!!!!!!!!!!!!
        if back_button.collidepoint((mx, my)) and click2:
            m_ship.set_color(preview_ship.get_color(), m_ship.get_scale())
            m_ship.set_type(preview_ship.get_type(), m_ship.get_scale())
            selecting = False
            click2 = False

        if rect_blue.collidepoint((mx, my)) and click2:
            preview_ship.set_color("BLUE", preview_ship.get_scale() * 2)

        if rect_green.collidepoint((mx, my)) and click2:
            preview_ship.set_color("GREEN", preview_ship.get_scale() * 2)

        if rect_n_blue.collidepoint((mx, my)) and click2:
            preview_ship.set_color("NAVY BLUE", preview_ship.get_scale() * 2)

        if rect_orange.collidepoint((mx, my)) and click2:
            preview_ship.set_color("ORANGE", preview_ship.get_scale() * 2)

        if rect_purple.collidepoint((mx, my)) and click2:
            preview_ship.set_color("PURPLE", preview_ship.get_scale() * 2)

        if rect_red.collidepoint((mx, my)) and click2:
            preview_ship.set_color("RED", preview_ship.get_scale() * 2)

        if rect_yellow.collidepoint((mx, my)) and click2:
            preview_ship.set_color("YELLOW", preview_ship.get_scale() * 2)

        click2 = False
        for event in pygame.event.get():
            if event.type == QUIT:
                quit()
            if event.type == MOUSEBUTTONDOWN:
                if event.button == 1:
                    click2 = True

        pygame.display.update()
Exemple #15
0
        if event.type == QUIT:
            quit()
        if event.type == MOUSEBUTTONDOWN:
            if event.button == 1:
                click = True


"""
MAIN LOOP - GAME LOOP

"""
diff = ""
main_loop = True
seeing_score = False
while main_loop:
    m_ship = Ship("NAVY BLUE", "1", SCREEN, SCREEN_WIDTH, SCREEN_HEIGHT)
    rect = Enemy(SCREEN, SCREEN_WIDTH, SCREEN_HEIGHT)
    global SCORE
    SCORE = 0

    #json_file = pen("scores.json", "r+", encoding="utf-8")
    #j_score = json.load(json_file)
    #BACKGROUND Sound
    mixer.music.load('src/sounds/Mercury.mp3')
    mixer.music.play(-1)
    """
    MENUS LOOP
    """
    menu_loop = True
    while menu_loop:
        main_menu()