Пример #1
0
def run_game():
    """Initialise the 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("Catch")

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

    # Make a catcher and a ball and groups of both
    catcher = Catcher(ai_settings, screen)
    ball = Ball(ai_settings, screen)
    balls = Group()
    balls.add(ball)
    

    # Main game loop
    while True:
        gf.check_events(ai_settings, screen, catcher)

        if stats.game_active:
            catcher.update()
            gf.update_balls(ai_settings, stats, screen, catcher, balls)
        
        gf.update_screen(ai_settings, screen, catcher, balls)
Пример #2
0
def run_game():
    """Main game setup"""
    # 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("Ping Pong")
    stats = GameStats(ai_settings)
    play_button = Button(ai_settings, screen, "Play", stats)
    sb = Scoreboard(ai_settings, screen, stats)
    # Make a ball group
    balls = Group()
    # Make paddle objects
    left_paddle = LeftPaddle(ai_settings, screen)
    right_paddle = RightPaddle(ai_settings, screen)
    horizontal_paddle = HorizontalPaddle(ai_settings, screen)
    player_horizontal_paddle = PlayerHorizontalPaddle(ai_settings, screen)
    # Start the main loop for the game
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button,
                        left_paddle, player_horizontal_paddle, balls)
        if stats.game_active:
            left_paddle.update(ai_settings)
            player_horizontal_paddle.update(ai_settings)
            right_paddle.update(ai_settings)
            horizontal_paddle.update(ai_settings)
            gf.update_balls(ai_settings, stats, screen, sb, left_paddle,
                            player_horizontal_paddle, right_paddle,
                            horizontal_paddle, balls, play_button)
            gf.update_right_paddle(ai_settings, right_paddle)
            gf.update_horizontal_paddle(ai_settings, horizontal_paddle)
        gf.update_screen(ai_settings, screen, stats, sb, left_paddle,
                         player_horizontal_paddle, right_paddle,
                         horizontal_paddle, balls, play_button)
Пример #3
0
def run_game():
    # Initialize game and create a screen object.
    pygame.init()
    # start_game = False
    ai_settings = Settings()

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

    screen = pygame.display.set_mode((1200, 800))
    pygame.display.set_caption("Super Pong 64")

    start_game = False

    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats, "")
    title = Title(ai_settings, screen, "")

    # make the left paddle
    left_paddle = Left_Paddle(ai_settings, screen)
    right_paddle = Right_Paddle(ai_settings, screen)
    bottom_paddle = Bottom_Paddle(ai_settings, screen)
    top_paddle = Top_Paddle(ai_settings, screen)
    top_left = Top_Left(ai_settings, screen)
    center_line = Center_Line(ai_settings, screen)
    bottom_right = Bottom_Right(ai_settings, screen)
    balls = Group()

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

    # Start the main loop for the game
    while True:
        title.prep_title("")
        title.prep_rules("")
        gf.check_events(ai_settings, screen, stats, sb, play_button,
                        left_paddle, top_left, bottom_paddle, balls)

        if stats.game_active:

            left_paddle.update(ai_settings)
            right_paddle.update(ai_settings, balls)
            bottom_paddle.update(ai_settings)
            top_paddle.update(ai_settings, balls)
            bottom_right.update(ai_settings, balls)
            top_left.update(ai_settings)

            gf.update_balls(ai_settings, stats, screen, sb, left_paddle,
                            right_paddle, bottom_paddle, top_paddle, top_left,
                            bottom_right, balls)

            gf.update_top_paddle(ai_settings, top_paddle)
            gf.update_bottom_right(ai_settings, bottom_right)
            gf.update_right_paddle(ai_settings, right_paddle)

        gf.update_screen(ai_settings, screen, stats, sb, title, left_paddle,
                         right_paddle, bottom_paddle, center_line, top_paddle,
                         top_left, bottom_right, balls, play_button)
Пример #4
0
def run():
    pygame.init
    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
    receiver = Receiver(ai_settings, screen)
    ball = Ball(ai_settings,screen)
    
    
    while True:
        gf.check_events(receiver)
        if ball.game_active:
            gf.update_balls(ai_settings,screen,ball,receiver)
            receiver.update()
        gf.update_screen(ai_settings,screen,receiver,ball)
Пример #5
0
def run_game():
	# Initialize pygame, settings, and screen object.
	pygame.init()
	c_settings = Settings()
	screen = pygame.display.set_mode(
		(c_settings.screen_width, c_settings.screen_height))
	pygame.display.set_caption("Catch")

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

	# Make a catcher and a ball.
	# The ball will be kept track of inside a group,
	# so that we can use pygame collisions method on it.
	# In order for this to work, catcher must belong 
	# inside a group of as well (even though we never
	# replace it.)

	balls = Group()
	catchers = Group()

	# Create the initial ball
	ball = Ball(c_settings, screen)
	balls.add(ball)

	# and the catcher.
	catcher = Catcher(c_settings, screen)
	catchers.add(catcher)

	# Start the main loop for the game.
	while True:
		for catcher in catchers:
			gf.check_events(c_settings, screen, catcher)

		# just as bullet positions are updated, *then*
		# all collisions checked, inside a function call
		# before updating the screen, something similar 
		# should happen inside an 'update_bullets' call

		# pass update_catcher the group containing the
		# sole catcher, since update_catcher will cal
		# a function using groupcollisions()

		if stats.game_active:
			gf.update_catcher(c_settings, screen, catchers, balls)
			gf.update_balls(c_settings, stats, screen, balls)
		
		gf.update_screen(c_settings, screen, catchers, balls)
Пример #6
0
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("Catch")
    stats = GameStats(ai_settings)
    # 创建一个小人和一个球组
    person = Person(ai_settings, screen)
    balls = pygame.sprite.Group()
    # 创建球
    gf.create_ball(ai_settings, screen, person, balls)
    # 开始游戏主循环
    while True:
        gf.check_events(ai_settings, screen, person, balls)
        if stats.game_active:
            person.update()
            gf.update_balls(ai_settings, screen, person, balls, stats)
        gf.update_screen(ai_settings, screen, person, balls)
Пример #7
0
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("Catch Balls")
    # Создание корабля
    catcher = Catcher(ai_settings, screen)
    # catchers = Group()
    # catchers.add(catcher)
    # Создание группы пришельцев
    balls = Group()
    gf.create_ball(ai_settings, screen, balls)

    # Запуск основного цика игры
    while True:
        gf.check_events(catcher)
        catcher.update()
        gf.update_balls(ai_settings, screen, balls, catcher)
        gf.update_screen(ai_settings, screen, catcher, balls)
Пример #8
0
def run_game():
    pygame.init()
    catch_settings = Settings()
    screen = pygame.display.set_mode(
        (catch_settings.screen_width, catch_settings.screen_height))
    pygame.display.set_caption("Catch The Ball")

    play_button = Button(catch_settings, screen, "Start")
    stats = GameStats(catch_settings)
    sb = Scoreboard(catch_settings, screen, stats)
    base = Base(catch_settings, screen)
    balls = Group()
    gf.create_balls(catch_settings, screen, balls)

    while True:
        gf.check_events(catch_settings, screen, stats, sb, play_button, base,
                        balls)
        if stats.game_active:
            gf.update_base(base)
            gf.update_balls(catch_settings, stats, screen, sb, base, balls)
        gf.update_screen(catch_settings, screen, stats, sb, base, balls,
                         play_button)
Пример #9
0
def run_game():
    # Initialize game and create  screen object.
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Football game")

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

    # Make an attacker.
    attacker = Attacker(ai_settings, screen)

    # Make the initial ball
    initial_ball = Ball(ai_settings, screen, attacker)

    # Make a group of balls and a group of defender.
    balls = Group()
    defenders = Group()

    # Create the defense.
    gf.create_defense(ai_settings, screen, attacker, defenders)
    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, screen, stats, attacker, initial_ball,
                        balls)

        if stats.game_active:
            attacker.update()
            initial_ball.initial_update_ball(attacker)
            gf.update_balls(ai_settings, screen, stats, attacker, defenders,
                            balls)
            gf.update_defenders(ai_settings, stats, screen, attacker,
                                defenders, balls)

        gf.update_screen(ai_settings, screen, attacker, defenders,
                         initial_ball, balls)