예제 #1
0
def run_game():
	pygame.init()
	ai_setting = Setting()
	screen = pygame.display.set_mode((ai_setting.screen_width, ai_setting.screen_height))
	pygame.display.set_caption('alien invasion')

	bg_color = ai_setting.bg_color

	ship = Ship(screen,ai_setting)
	bullets = Group()

	allion = Alion(ai_setting, screen)
	allions = Group()
	gf.create_fleet(ai_setting, screen, allions, ship)

	stats = gs(ai_setting)

	play_btn = Button(ai_setting, screen, 'Play')

	sb = Scoreboard(ai_setting, screen, stats)

# def update_bullet(bullets, allions, ai_setting, screen, ship):
	while 1:
		# def check_events(ai_setting, screen, ship, bullets, stats, play_button, allions):
		gf.check_events(ai_setting, screen, ship, bullets, stats, play_btn, allions)
		if stats.game_active:
			ship.update()
			bullets.update()
			gf.update_aliens(ai_setting, allions, ship, screen, stats, bullets)
			gf.update_bullet(bullets, allions, ai_setting, screen, ship, stats, sb)
		else :
			print('game is done')
		gf.update_screen(ai_setting, screen, ship, bullets, allions, stats, play_btn, sb)
예제 #2
0
def run_game():

    pygame.init()
    ai_settings = Settings()

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

    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

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

    pygame.display.set_caption("Alien Invasion")

    play_button = Button(ai_settings, screen, "Play")

    stats = GameStats(ai_settings)

    sb = Scoreboard(ai_settings, screen, stats)

    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets)
        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         play_button)
예제 #3
0
def run_game():
    # Инициализирует игру и создает объект экрана
    pygame.init()
    ai_settings = Settings(bg_url)
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height),
        pygame.FULLSCREEN)
    pygame.display.set_caption("Alien Invasion")
    # Создание кнопки Play
    play_button = Button(ai_settings, screen, "Play")
    # Создание корабля
    ship = Ship(ai_settings, screen, spaceraft_url)
    # создание экземпляра для хранение игровой статистик
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats, life_ship_url)
    # Создание группы для хранения пуль
    bullets = Group()
    aliens = Group()
    # Создание флота пришельцев
    gf.create_fleet(ai_settings, screen, ship, aliens, alien_url)
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets, life_ship_url, alien_url)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets, life_ship_url, alien_url)
        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         play_button)
예제 #4
0
def run_game():
    # initialize pygame ,settings and screen object
    pygame.init()
    ai_settings = Settings()
    ai_settings.default_settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    # make ship
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    # Create the fleet of aliens
    gf.create_fleet(ai_settings, screen, ship, aliens)
    # start the main loop for the game
    #stats = GameStats(ai_settings)
    stats = GameStats(ai_settings)
    play_button = Button(ai_settings, screen, "Play")
    sb = Scoreboard(ai_settings, screen, stats)

    while True:
        # watch for the keyword and mouse events
        gf.get_events(ai_settings, screen, stats, sb, play_button, ship,
                      bullets)
        if stats.game_active:
            pygame.mouse.set_visible(False)
            ship.update()
            gf.update_bullets(ai_settings, screen, ship, stats, sb, aliens,
                              bullets)
            gf.update_aliens(ai_settings, stats, screen, sb, ship, aliens,
                             bullets)
        gf.update_screen(ai_settings, screen, stats, ship, aliens, sb, bullets,
                         play_button)
예제 #5
0
    def __init__(self):
        """Inicjalizacja gry i utworzenie jej zasoboów"""
        pygame.init()  # wyswietlanie tła
        self.settings = Settings()

        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        # self.screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN)# krotka definiujaca fullscrena
        # self.settings.screen_width = self.screen.get_rect().width
        # self.settings.screen_height = self.screen.get_rect().height

        pygame.display.set_caption("Inwazja obcych")

        #utworzenie egzemplarza do przechowywania danych
        #dane statystyczne w grze
        self.stats = GameStats(self)
        self.sb = Scoreboard(self)

        self.ship = Ship(
            self
        )  # utworzenie egemplrza klasy SHIP, wymaga przekazania obiektu klasy alieninvasion
        self.bullets = pygame.sprite.Group()
        self.aliens = pygame.sprite.Group()

        self._create_fleet()

        #utworzenie przycisku
        self.play_button = Button(self, msg="Graj")
예제 #6
0
def run_game():
    # Initialize game and 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")
    # Make the Play button.
    play_button = Button(ai_settings, screen, "Play")
    # Create an instance to store game statistics and create scoreboard.
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    # Make a ship, a group of bullets, and a group of aliens.
    ship = Ship(ai_settings, screen)
    # Make a group to store bullets in.
    bullets = Group()
    aliens = Group()
    # Create the fleet of aliens.
    gf.create_fleet(ai_settings, screen, ship, aliens)
    # Make an alien.
    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets)
        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         play_button)
예제 #7
0
def run_game():
    """初始化游戏并创建屏幕对象"""
    pygame.init()
    ai_setting = settings.Settings()
    screen = pygame.display.set_mode((ai_setting.screen_width, ai_setting.screen_height))
    pygame.display.set_caption("Alien Invasion")
    play_button = Button(ai_setting, screen, "Play")

    # 创建一艘飞船
    ship = Ship(ai_setting, screen)

    # 创建一个用于存储子弹的编组
    bullets = Group()

    # 创建外星人编组
    aliens = Group()
    game_functions.create_fleet(ai_setting, screen, aliens, ship)

    # 创建游戏数据
    game_status = GameStatus(ai_setting)
    scoreboard = Scoreboard(ai_setting, screen, game_status)

    # 游戏主循环
    while True:
        game_functions.check_events(ai_setting, screen, aliens, ship, bullets, game_status, play_button, scoreboard)

        if game_status.game_active:
            ship.update()
            game_functions.update_bullet(aliens, bullets, ai_setting, screen, ship, game_status, scoreboard)
            game_functions.update_aliens(aliens, ai_setting, ship, game_status, screen, bullets, scoreboard)

        game_functions.update_screen(ai_setting, screen, ship, aliens, bullets, game_status, play_button, scoreboard)
예제 #8
0
    def __init__(self):
        """initialize the game, and create game resources"""
        pygame.init()
        self.settings = Settings()

        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("YAKS! in Space")

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

        self.ship = Ship(self)
        self.bullets = pygame.sprite.Group()
        self.boomerangs = pygame.sprite.Group()
        self.aliens = pygame.sprite.Group()

        self._create_fleet()

        # set the background color
        self.bg_color = self.settings.bg_color

        # Make the Play Button
        self.play_button = Button(self, "Play")

        # Create an instance to store game statistics and create a scoreboard.
        self.stats = GameStats(self)
        self.sb = Scoreboard(self)
예제 #9
0
    def __init__(self):
        self._screen = None

        self.settings = Settings()
        self.stats = GameStats(self.settings)
        self.play_button = Button(self.settings, self.screen, 'Play')
        self.scoreboard = Scoreboard(self.settings, self.screen, self.stats)
        self.ship = Ship(self.settings, self.screen)
        self.bullets = Group()
        self.aliens = Group()
def run_game():

    pygame.init()  # Initializes background settings for Pygame to work
    ai_settings = Settings()
    # we call pygame.display.set_mode to create a display window(screen), arguments are access  to file Settings
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    play_button = Button(ai_settings, screen, "Play")

    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    #make a shipSC

    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    gf.create_fleet(ai_settings, screen, ship, aliens)

    while True:  #the game is controlled by a this loop. It contains event loop and code that manages screen updates
        gf.check_events(
            ai_settings, screen, stats, sb, play_button, ship, aliens, bullets
        )  #everything is in game_functions kur yra event loop called check_events
        #tikrinam paspaudimus nors zaidimas neveikia, gali paspausti quit pvz

        if stats.game_active:  #ijungti tik kai True
            ship.update()
            #pirma tikrina kulkas, tada ateivius
            #nes tikrinsim ar kulkos paliete ateivius
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets)

    #referuoja i skilti apie bullets in game_functions imported as gf
        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         play_button)
        ship.blitme()

        pygame.display.flip()  # Make the most recently drawn screen visible
    def __init__(self):
        ''' Start the game'''

        pygame.init()
        self.settings = Settings()

        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("Alien Invasion")

        #instance to store game stats
        self.stats = GameStats(self)
        self.sb = Scoreboard(self)
        self.ship = Ship(self)
        self.bullets = pygame.sprite.Group()
        self.aliens = pygame.sprite.Group()
        self.alien_bullet = pygame.sprite.Group()

        self._create_fleet()

        self.play_button = Button(self, 'Start')
예제 #12
0
def run_game():
    # Initialize pygame, settings and screen object.
    pygame.init()
    ai_settings = settings()
    screen = pygame.display.set_mode((ai_settings.width, ai_settings.height))
    pygame.display.set_caption("Alien Invasion")
    play_button = Button(ai_settings, screen, "Play")

    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    bg = pygame.image.load('images\space.bmp')
    bg_image = pygame.transform.scale(bg, (1280, 720))

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

    #make group to store bullets
    bullets = Group()
    aliens = Group()
    alien = Alien(ai_settings, screen)

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

    # Start the main loop for the game.
    while True:
        screen.blit(bg_image, (0, 0))
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets)

        if stats.game_active:

            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets)

        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         play_button)
예제 #13
0
def run_game():
    """
    Initialize a game screen
    """
    # Game screen setup
    pygame.init()
    game_settings = Settings()
    screen = pygame.display.set_mode(
        (game_settings.screen_width, game_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    # Create a object to store game stats
    stats = GameStats(game_settings)

    # Create a button and score board
    play_button = Button(game_settings, screen, "Play")
    score = Scoreboard(game_settings, screen, stats)

    # Create a ship, alien and bullet
    ship = Ship(game_settings, screen)
    bullets = Group()
    aliens = Group()

    # Create a group of alien
    g_func.create_fleet(game_settings, screen, ship, aliens)

    # Start the game main loop: check keyboard and mouse event, update ship, update bullet and screen
    while True:
        g_func.check_events(game_settings, stats, score, screen, play_button,
                            ship, aliens, bullets)
        if stats.game_active:
            ship.update()
            g_func.update_bullets(game_settings, stats, score, screen, ship,
                                  aliens, bullets)
            g_func.update_aliens(game_settings, stats, score, screen, ship,
                                 aliens, bullets)
        g_func.update_screen(game_settings, stats, score, screen, play_button,
                             ship, aliens, bullets)
예제 #14
0
def run_game():
    # initialize a game window
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    # create Play button
    play_button = Button(ai_settings, screen, "Play")

    # create initial data object
    stats = GameStats(ai_settings)

    # create a ship
    ship = Ship(ai_settings, screen)
    # create bullet's group
    bullets = Group()
    # create an alien guoup
    aliens = Group()

    # create a group alien
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # create statistic instance and score board
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    # start game main loop
    while True:
        # verify keyboard and mouse event
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets)

        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
예제 #15
0
def run_game():
    #初始化游戏并创建一个屏幕对象
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    # caption :标题
    pygame.display.set_caption("Alien chou")
    # 创建按钮
    play_button = Button(ai_settings, screen, 'Play')

    ship = Ship(ai_settings, screen)
    # 创建外星人的空编组
    aliens = Group()
    # 创建一个用于存储子弹的编组
    # Group类 类似于列表,但提供了有助于开发游戏的额外功能,了解即可class 'pygame.sprite.Group
    bullets = Group()
    # 创建外星人群
    gf.create_fleet(ai_settings, screen, aliens, ship)
    # 创建一个用于存储游戏统计信息的实例
    history_highest_score = gf.GetHistoryHighestScore(ai_settings)
    stats = GameStats(ai_settings, history_highest_score)
    sb = Scoreboard(ai_settings, screen, stats)
    #开始游戏的 主循环
    while True:
        #监视键盘和鼠标事件
        gf.check_events(ai_settings, screen, ship, bullets, stats, play_button,
                        aliens, sb)
        if stats.game_active:
            ship.update()

            gf.update_bullets(ai_settings, aliens, bullets, screen, ship,
                              stats, sb)
            gf.update_aliens(ai_settings, aliens, ship, stats, screen, bullets,
                             sb)
        gf.update_screen(ai_settings, screen, ship, bullets, aliens, stats,
                         play_button, sb)
예제 #16
0
def run_game():
    # 初始化游戏并创建一个屏幕对象
    pygame.init()

    # 将设置赋给ai_settings
    ai_settings = Settings()
    # (没有settings版本)screen = pygame.display.set_mode((1200,800))
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("外星人入侵")

    # 创建Play按钮实例
    play_button = Button(ai_settings, screen, "Play")

    # 设置背景色
    # (没有settings版本)bg_color = (230,230,230)

    # 创建飞船实例
    ship = Ship(ai_settings, screen)
    # 创建一个用于存储游戏统计信息的实例,并创建记分牌
    stats = GameStats(ai_settings)
    score_board = Scoreboard(ai_settings, screen, stats)
    '''不再创建
    # 创建外星人实例
    alien = Alien(ai_settings,screen)
    '''

    # 创建一个用于存储子弹的编组
    bullets = Group()
    # 创建一个用于存储外星人的编组
    aliens = Group()

    # 创建外星人群
    gf.creat_fleet(ai_settings, screen, ship, aliens)

    # 开始游戏的主循环
    while True:
        """
        #监视键盘和鼠标事件
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        """
        # 上面可简化为 ↓
        gf.check_events(ai_settings, screen, stats, score_board, play_button,
                        ship, aliens, bullets)

        if stats.game_active:
            # 在每次循环时都调用飞船移动标志的判断
            ship.update()

            # 子弹
            # bullets.update()

            # 删除已消失的子弹
            '''
            ######重构至game_functions中的update_bullets()######
            for bullet in bullets.copy():
                if bullet.rect.bottom <= 0:
                    bullets.remove(bullet)
            #下面这个语句是检验当子弹到达顶部后是否将子弹从bullets中删除
            #print(len(bullets))
            '''
            gf.update_bullets(ai_settings, screen, stats, score_board, ship,
                              aliens, bullets)

            # 外星人位置
            gf.update_aliens(ai_settings, stats, score_board, screen, ship,
                             aliens, bullets)
        """
        #每次循环都重绘屏幕
        #(没有settings版本)screen.fill(bg_color)
        screen.fill(ai_settings.bg_color)
        #显示飞船
        ship.blitme()

        #让最近绘制的屏幕可见
        pygame.display.flip()
        """
        # 上面代码可简化为 ↓
        gf.update_screen(ai_settings, screen, stats, score_board, ship, aliens,
                         bullets, play_button)
예제 #17
0
difference = 2
timer_game_difficulty_increase = time.time()
difference_to_increase_difficulty = 25
number_bullets = 2
number_ships_left_to_increase_diff = 18

# Enemy ships movement control variables
index_movement = 0
enemy_movement = [10, 10, -10, -10,
                  -10, -10, 10, 10]  # The enemy ships can only move left (- negative values) or right (positive values)
# by the following values

# player lives
lives = 3
points = 0
score = Scoreboard(lives, points)

game_is_on = True
while game_is_on:
    time.sleep(0.02)
    game_screen.update()
    player_ship_x_position = player_ship.xcor()

    # check if player bullet reach end of screen and delete them if so
    for bullet in player_bullets:
        if bullet.ycor() >= Y_WALL:
            player_bullets.remove(bullet)
        else:
            bullet.bullet_moving()

    # shoot enemy bullets and move the ships
예제 #18
0
from turtle import Screen
from snake import Snake
from food import Food
from score_board import Scoreboard
import time

screen = Screen()
screen.setup(width=600, height=600)
screen.bgcolor("black")
screen.title("My Snake Game")
screen.tracer(0)

snake = Snake()
food = Food()
scoreboard = Scoreboard()
screen.listen()
screen.onkey(snake.up, "Up")
screen.onkey(snake.down, "Down")
screen.onkey(snake.left, "Left")
screen.onkey(snake.right, "Right")

game_is_on = True
while game_is_on:
    screen.update()
    time.sleep(0.1)

    snake.move()

    if snake.head.distance(food) < 15:
        food.refresh()
        snake.extend()
예제 #19
0
high_score_button = Button(
    screen, "HIGHSCORES",
    (ai_settings.screen_width / 2, ai_settings.screen_height - 300),
    (255, 255, 255), (0, 0, 0))

score_table = HighScoreTable(screen)
# used to control fps
clock = pygame.time.Clock()

# max fps
MAX_PFS = 30

# game intro object
intro = GameIntro(screen, play_button, high_score_button, ai_settings)

score_board = Scoreboard(ai_settings, screen, stats, score_table)

fruit = Fruit(0, 0, 19, 19, pac.maze, screen, stats, pac)

portal = Portal(screen, pac, pac.rect.x, pac.rect.y, 32, 32,
                os.getcwd() + '/images/invis_portal.png')

fire = False


def gameloop():
    # temporary fix for variables will create classes and clean the code
    global fire
    while not stats.game_exit:
        # debugging
        # print(str(pac.rect.x) + ", " + str(pac.rect.y))
예제 #20
0
from turtle import Screen
from snake import Snake
from food import Food
from score_board import Scoreboard
import time

screen = Screen()
screen.setup(width=600, height=600)
screen.bgcolor('black')
screen.title("Snake Game")
screen.tracer(0)

snake = Snake()
food = Food()
score = Scoreboard()

screen.listen()
screen.onkey(snake.up, "Up")
screen.onkey(snake.down, "Down")
screen.onkey(snake.left, "Left")
screen.onkey(snake.right, "Right")

game_is_on = True
while game_is_on:
    screen.update()
    time.sleep(0.1)

    snake.move()
    # collision with food
    if snake.head.distance(food) < 13:
        food.refresh()
예제 #21
0
from snake import Snake
from food import Food
from score_board import Scoreboard
import time

screen = Screen()

screen.setup(width=600, height=600)
screen.title("snakeGame")
screen.bgcolor("black")

screen.tracer(0)

snake = Snake()
food = Food()
sco = Scoreboard()

screen.listen()
screen.onkey(snake.up, "Up")
screen.onkey(snake.down, "Down")
screen.onkey(snake.right, "Right")
screen.onkey(snake.left, "Left")

game_is_on = True
while game_is_on:
    screen.update()
    time.sleep(0.1)

    snake.move()
    if snake.head.distance(food) < 15:
        food.refresh()