Exemplo n.º 1
0
def run():
    pygame.init()

    # load the game settings
    settings = Settings()

    # create the screen and add a title
    screen = pygame.display.set_mode(settings.screen_dimension)
    pygame.display.set_caption('BreakOut - Python')

    # create the game elements
    bar = Bar(screen, settings)
    chances = Chances(screen, settings)
    score = Score(screen, settings)
    ball = Ball(screen, bar, settings, chances, score)
    btn_start = Button(screen, 'press space to start')
    btn_game_over = Button(screen, 'Game Over')

    object_group = []
    function.dispose_objects(screen, object_group, score)

    while True:
        function.check_events(bar, settings, chances, score)
        function.update_screen(bar, screen, ball, settings, object_group,
                               btn_start, btn_game_over, chances, score)
Exemplo n.º 2
0
def game():
    pygame.init()
    game_settings = settings.Settings()
    screen = pygame.display.set_mode(
        (game_settings.width, game_settings.height))
    pygame.display.set_caption("Space Invaders")
    play_button = play.Button(settings, screen, "Play")
    stats = statistics.GameStats(game_settings)
    scoreboard = score.Score(game_settings, screen, stats)
    player_render = ship.Ship(screen, game_settings)
    bullets = pygame.sprite.Group()
    alien_group = pygame.sprite.Group()

    functions.alien_fleet(game_settings, screen, alien_group)

    while True:
        functions.check_events(game_settings, screen, player_render, bullets,
                               play_button, stats, alien_group, scoreboard)
        if stats.game_active:
            player_render.update()
            functions.update_bullets(alien_group, bullets, screen,
                                     game_settings, scoreboard, stats)
            functions.update_aliens(game_settings, stats, player_render,
                                    alien_group, screen, bullets, scoreboard)
        functions.update_screen(game_settings, screen, player_render,
                                alien_group, bullets, play_button, stats,
                                scoreboard)
Exemplo n.º 3
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("邓明星大战外星人!")

    bg_color = ai_settings.bg_color

    ship = Ship(ai_settings, screen)

    aliens = Group()

    bullets = Group()

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

    # 主循环开始
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)

        ship.update()

        gf.update_bullets(ai_settings, screen, ship, aliens, bullets)

        gf.update_aliens(ai_settings, aliens)

        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
Exemplo n.º 4
0
def run_game():
    pygame.init()
    ai_settings = Settings
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    alien = Alien(ai_settings, screen)
    pygame.display.set_caption("Invasion2.0")
    play_button = Button(ai_settings, screen, "Play")
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # main loop
    while True:
        gf.check_events(ai_settings, screen, stats, play_button, ship, aliens,
                        bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, ship, aliens, bullets,
                              stats)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
        gf.update_screen(ai_settings, screen, stats, ship, aliens, bullets,
                         play_button, sb)
Exemplo n.º 5
0
def run_game():
    # # Initialize pygame, settings, and screen object.
    # pygame.init()
    # screen = pygame.display.set_mode(
    #     (ai_settings.screen_width, ai_settings.screen_height))
    # pygame.display.set_caption("my game")
    #
    # # Make the Play button.
    # play_button = Button(ai_settings, screen, "Play")
    #
    # # Create an instance to store game statistics, and a 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)
    # bullets = Group()
    # aliens = Group()
    #
    # # Create the fleet of aliens.
    # gf.create_fleet(ai_settings, screen, ship, aliens)

    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))

    ship = Ship(screen)

    pygame.display.set_caption("One Hundred Fishing Nets")
    while True:
        fun.check_events(ship)
        ship.update_ship_position()
        fun.screen_update(screen, ship, settings)
Exemplo n.º 6
0
def run():
    #初始化窗口
    pygame.init

    #创建ai_settings存放Settings对象
    ai_settings = Settings()

    #设置窗口宽高
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))

    #设置窗口标题
    pygame.display.set_caption('yudi')

    #创建雨滴编组
    yudis = Group()

    #创建雨滴群
    f.create_yudis(ai_settings, screen, yudis)
    while True:
        #监听键盘事件
        f.check_events()
        #更新雨滴位置
        f.update_yudis(ai_settings, screen, yudis)
        #更新窗口
        f.update_screen(ai_settings, screen, yudis)
Exemplo n.º 7
0
def run_game():
    # Инициализирует игру и создает объект экрана.
    pygame.init()
    conf = Config()
    screen = pygame.display.set_mode((conf.width_screen, conf.height_screen))
    pygame.display.set_caption("Name Game")

    bg = pygame.image.load("images/bg.jpg")
    platform = Platform(screen, conf, 'images/platform.png')
    balls = Group()
    gf.create_balls(screen, ball_image, conf, balls, platform)
    # Запуск основного цикла игры.
    timer = pygame.time.Clock()
    while True:
        timer.tick(120)
        # Отслеживание событий клавиатуры и мыши.
        gf.check_events(screen, platform)

        screen.blit(bg, (0, 0))

        platform.update()
        platform.blitme()
        gf.update_balls(balls, conf, screen, ball_image, platform)
        balls.draw(screen)
        # Отображение последнего прорисованного экрана.
        pygame.display.flip()
Exemplo n.º 8
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("Alien Invasion")
    ship = Ship(ai_settings, screen)
    alien = Alien(ai_settings, screen)

    bullets = Group()
    aliens = Group()

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

    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        #bullets.update()
        gf.update_bullets(bullets)
        gf.update_aliens(ai_settings, aliens)

        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        #print(len(bullets))
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
Exemplo n.º 9
0
def run():
    pygame.init()
    game_settings = Settings()
    screen = pygame.display.set_mode(
        (game_settings.screen_width, game_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    play_button = Button(game_settings, screen, "Play")
    stats = GameStats(game_settings)
    sb = Scoreboard(game_settings, screen, stats)
    ship = Ship(game_settings, screen)
    bullets = Group()
    aliens = Group()
    f.create_fleet(game_settings, screen, ship, aliens)
    while True:
        f.check_events(game_settings, screen, stats, sb, play_button, ship,
                       aliens, bullets)
        if stats.game_active:
            ship.update()
            f.update_bullets(game_settings, screen, stats, sb, play_button,
                             ship, aliens, bullets)
            f.update_aliens(game_settings, stats, sb, screen, ship, aliens,
                            bullets)

        f.update_screen(game_settings, screen, stats, sb, ship, aliens,
                        bullets, play_button)
Exemplo n.º 10
0
def run_game():
    # initialize game and create screen object
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(settings.screen_res)
    pygame.display.set_caption("Alien Invasion")
    stats = Stats()
    ship = Ship(screen)
    bullets = Group()
    aliens = Group()
    play_button = Button(settings, screen, 'Play')
    scoreboard = Scoreboard(settings, screen, stats)
    fun.create_fleet(settings, screen, aliens, ship.rect.height, stats)

    # start the main loop for the game
    while True:
        fun.check_events(settings, screen, ship, bullets, stats, aliens, play_button, scoreboard)
        if stats.game_active:
            ship.update()
            bullets.update()
            aliens.update()
            fun.drop_aliens(aliens)
            fun.collide(ship, aliens, bullets, settings, stats)
            fun.delete_bullets(bullets)
        fun.update_screen(screen, settings, ship, bullets, aliens, stats, play_button, scoreboard)
Exemplo n.º 11
0
def run_game():
    pygame.init()
    ai_settings = settings.Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    #screen=pygame.display.set_mode((1200,800))
    #bg_color=(200,200,222)
    pygame.display.set_caption("alien invasion")
    ship = Ship(ai_settings, screen)
    play_button = Button(ai_settings, screen, "play")
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    #存储子弹
    bullets = Group()
    aliens = Group()

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

    #开始游戏的主循环
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        bullets, aliens)
        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)
Exemplo n.º 12
0
def run_game():
    ''' Inicjalizacja gry i utworzenie ekranu '''
    pygame.init()
    kk_settings = Settings()
    screen = pygame.display.set_mode(
        (kk_settings.screen_width, kk_settings.screen_height))
    pygame.display.set_caption('Kołko i krzyżyk')
    rectangles = Group()
    circles = Group()
    crosses = Group()

    # utworzenie menu gry
    functions.create_menu(screen, kk_settings)

    #utworzenie prostokatów planszy
    functions.create_rectangles(kk_settings, screen, rectangles)

    #rozpoczęcie pętli głównej gry
    while kk_settings.game_running:

        #sprawdzanie myszki i klawiatury
        functions.check_events(rectangles, screen, circles, kk_settings,
                               crosses)

        #odwiezenie ekranu po przejsciu kazdej iteracji
        functions.update_screen(kk_settings, screen, rectangles, circles,
                                crosses)
Exemplo n.º 13
0
 def play(self):
     while True:
         pygame.time.Clock().tick(1800)
         func.check_events(self.pacman, self.score_button, self.menu,
                           self.play_button, self, self.bportal,
                           self.oportal, self.screen, self.maze, self.audio)
         self.update_screen()
         if self.active:
             func.check_collisions(self.pacman, self.bricks, self.shields,
                                   self.powerpills, self.scoreboard,
                                   self.blinky, self.pinky, self.inky,
                                   self.clyde, self.qpills, self.fruit,
                                   self.audio)
             self.pacman.update(self.oportal, self.bportal, self.audio)
             if not self.pause:
                 self.fruit.update()
                 self.blinky.update(self.oportal, self.bportal)
                 self.inky.update(self.oportal, self.bportal)
                 self.pinky.update(self.oportal, self.bportal)
                 self.clyde.update(self.oportal, self.bportal)
                 self.scoreboard.update_score(self)
             if self.increase:
                 self.pacman.reset()
                 self.inky.reset()
                 self.clyde.reset()
                 self.pinky.reset()
                 self.fruit.reset()
                 self.blinky.reset()
                 self.maze.build()
                 self.increase = False
                 if self.scoreboard.lives == 0:
                     self.active = False
Exemplo n.º 14
0
def run_game ():
    #inicjalizacja gry i utworzenie obiektu ekranu
    pygame.init()
    dolphingame_settings=Settings()
    screen=pygame.display.set_mode((dolphingame_settings.screen_width, dolphingame_settings.screen_height))
    pygame.display.set_caption("Dolphin Game")
    play_button=Button(dolphingame_settings, screen,"Play")
    stats=GameStats(dolphingame_settings)
    dolphin_scores=Scoreboard(dolphingame_settings,screen,stats)
    #Utworzenie statku rybackiego
    dolphin=Dolphin(dolphingame_settings,screen)
    bubbles = Group()
    fishers=Group()

    #Utworzenie wielu statków
    functions.create_fishers(dolphingame_settings,screen,dolphin,fishers)

    #rozpocięcie pętli glownej gry
    while True:

        functions.check_events(dolphingame_settings,screen,stats, dolphin_scores, play_button,dolphin,fishers,bubbles)
        if stats.game_active:
            dolphin.update()
            functions.update_fishers(dolphingame_settings, screen, stats,dolphin_scores,dolphin, fishers, bubbles)
            functions.update_bubbles(dolphingame_settings,screen,stats, dolphin_scores, dolphin,fishers,bubbles)
        functions.update_screen(dolphingame_settings, screen, stats, dolphin_scores, dolphin, fishers, bubbles,play_button)
Exemplo n.º 15
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("Alien War")
    play_button = Button(ai_settings, screen, "Play")
    stats = GameStats(ai_settings)
    sb = ScoreBoard(ai_settings, screen, stats)
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    f.create_fleet(ai_settings, screen, ship, aliens)
    # Назначение цвета фона
    bg_color = (100, 100, 100)
    alien = Alien(ai_settings, screen)
    while True:
        f.check_events(ai_settings, screen, stats, sb, play_button, ship,
                       aliens, bullets)
        if stats.game_active:
            ship.update()
            f.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                             bullets)
            f.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                            bullets)
        f.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                        play_button)
Exemplo n.º 16
0
def run_program():
    pg.init()
    cn.mandelbrot.draw(cn.screen)
    pg.display.set_caption("Mandelbrot set")
    while True:
        fn.check_events()
        pg.display.update()
Exemplo n.º 17
0
def run_game():
    pygame.init()
    ai_setting = setting()
    scree = pygame.display.set_mode(
        (ai_setting.screen_width, ai_setting.screen_hight))
    aliens = Group()
    ship = Ship(scree, ai_setting)
    alien = Alien(ai_setting, scree)
    gf.create_fleet(ai_setting, scree, ship, aliens)
    bullets = Group()
    pygame.display.set_caption('New game')
    stats = GameStats(ai_setting)
    sb = Scoreboard(ai_setting, scree, stats)
    play_button = Button(ai_setting, scree, "Play")

    while True:
        gf.check_events(ship, ai_setting, scree, bullets, stats, play_button,
                        aliens)
        if stats.game_active:
            ship.update()
            gf.update_aliens(ai_setting, aliens, ship, stats, bullets, scree)
            gf.update_bullet(ai_setting, scree, ship, aliens, bullets, sb,
                             stats)
        gf.update_screen(ai_setting, scree, ship, bullets, aliens, play_button,
                         stats, sb)
Exemplo n.º 18
0
 def loop(self):
     functions.check_events(self.player, self.ball, self.go, self)
     settings.screen.fill(settings.background_color)
     self.player.update()
     self.ball.update(self.level, self.player)
     if self.go:
         self.go_button.blitme()
     functions.update_level(self.level)
     pygame.display.flip()
Exemplo n.º 19
0
Arquivo: wzq.py Projeto: belieffsy/wzq
def run_game():
    pygame.init()
    settings = Settings()
    # 创建存储棋子的编组
    pieces = Group()

    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height), 4, 0)
    chequer = Chequer(settings, screen, pieces)
    pygame.display.set_caption("五子棋")
    background = pygame.image.load("background3.jpg").convert()
    #按钮
    button_d = Button(screen, "悔棋", 30, (65, 49), (20, 20, 90, 55))
    button_d2 = Button(screen, "悔棋", 35, (65, 49), (18, 18, 95, 63))
    button_r = Button(screen, "重新開始", 30, (200, 49), (130, 20, 140, 58))
    button_r2 = Button(screen, "重新開始", 33, (200, 49), (128, 18, 145, 62))
    button_s = Button(screen, "設置", 30, (525, 49), (480, 20, 90, 55))
    button_s2 = Button(screen, "設置", 35, (525, 49), (478, 18, 95, 63))
    #弹框
    msg_box_reset = Msg_box(screen, "確定重新開始?", "確定", "取消")
    box_black_win = Msg_box(screen, "黑棋獲勝!", "重置", "退出游戲")
    box_white_win = Msg_box(screen, "白棋獲勝!", "重置", "退出游戲")
    box_get_draw = Msg_box(screen, '棋盤下滿了,平局!', "重置", "退出游戲")
    box_get_draw2 = Msg_box(screen, '時間到,此局平局!', "重置", "退出游戲")
    box_open_jinshou = Msg_box(screen, "開啓黑棋禁手?", "開啓", "禁手規則")
    box_close_jinshou = Msg_box(screen, "關閉黑棋禁手?", "關閉", "禁手規則")
    box_jinshou = Msg_box(screen, "黑棋禁手,不能落子", "確定", "禁手規則")
    #倒计时
    count_down = Count_down(screen)

    while True:
        f.check_events(settings, chequer, pieces, button_d2, button_r2,
                       button_s2, msg_box_reset, count_down)
        #screen.fill((settings.bg_color))
        screen.blit(background, (0, 0))
        chequer.lines()
        chequer.cirs()
        chequer.get_mouse_pos(pieces)
        for pos in settings.poslist_b:
            chequer.set_piece(pos, chequer.black)
        for pos in settings.poslist_w:
            chequer.set_piece(pos, chequer.white)

        ##绘制各种按钮————悔棋,重新开始,设置
        f.draw_button(button_d, button_d2)
        f.draw_button(button_r, button_r2)
        f.draw_button(button_s, button_s2)

        f.draw(settings, msg_box_reset, box_black_win, box_white_win,
               box_get_draw, box_get_draw2, box_open_jinshou,
               box_close_jinshou, box_jinshou)

        #f.tine_down(settings)
        f.prep_time(settings, count_down)
        count_down.draw()

        pygame.display.flip()
Exemplo n.º 20
0
def run_game():
    # Initialize game and create a screen object.
    pygame.init()
    bstats_settings = Settings()
    screen = pygame.display.set_mode(
        (bstats_settings.screen_width, bstats_settings.screen_height))
    pygame.display.set_caption("Basketball Scoring")

    # Create an instance to store game statistics.
    stats = ScoreStats(bstats_settings)

    # Create a scoreboard object
    sb = Scoreboard(bstats_settings, screen, stats)

    # Make the play button
    play_button = Button(bstats_settings, screen, "Play")

    playerdict = {}
    teams = []
    # Open Player List CSV, and get players from file in a dictionary
    csvfunc.read_playersCSV(bstats_settings, playerdict, teams)

    # List of team objects
    #    teams = [
    #        Team(bstats_settings, 'A', -1, 'Home'),
    #        Team(bstats_settings, 'B', -2, 'Away')
    #    ]

    # Populate teamlist of team object with correct player
    for team in teams:
        for player in playerdict.values():
            if player.team == team.team:
                team.teamlist.append(player)

    # bstats_settings.get_playerdict(playerdict)

    # Make the stats buttons for players and put it in a dictionary, buttons
    buttons = func.make_stats_buttons(bstats_settings, teams, screen)

    # Create player stats class object
    pstats = Playerstats(bstats_settings, screen, teams)

    # Create a running score class object
    runScore = RunningScore(bstats_settings, screen, teams)

    # Make a player
    # player = players.Player('Lorelei', 5)

    # Start the main loop for the game.
    while True:

        func.check_events(stats, buttons, playerdict, play_button,
                          bstats_settings, teams, runScore)

        func.update_screen(stats, bstats_settings, screen, play_button,
                           buttons, playerdict, sb, pstats, teams, runScore)
Exemplo n.º 21
0
def main():
    pygame.init()
    screen = pygame.display.set_mode((400, 300))
    pygame.display.set_caption("按键测试")

    message = Message(screen, 'Press a key...')

    while True:
        func.check_events(message)
        func.update_screen(screen, message)
Exemplo n.º 22
0
def program():
    #Pygame Initialize
    pygame.init()
    global angle

    # Set Class and pygame.sprite

    setting = ai_settings()
    arc = arc_main(0, 0)
    angle = arc.angle
    move = Line_move()


    #Set screen
    scr = pygame.display.set_mode((setting.scr_width, setting.scr_height),pygame.FULLSCREEN)
    scr.fill(setting.bg_color)
    pygame.display.set_caption("Display")
    width = int(setting.scr_width / 2)


    #Initial straight Dotted Line
    dr.dotted_line(scr,setting)

    img = image(scr, setting)
    dr.set_rect(scr,setting)
    pygame.display.update()
    #Check and run main codes
    while True:

        fn.check_events(move,scr,arc,setting)

        if move.mouse_movement == True:# and event.type == pygame.MOUSEMOTION:
            posi = pygame.mouse.get_pos()
            dr.draw_line(posi,scr, width, setting)
            #Dotted Line
            dr.dotted_line(scr,setting)

        if move.check == True:
            #Process movement and draw Pendulum
            lm.movement(arc.angle, scr, width, setting,move.time,move)
            move.time = move.time + 1
            # Limiting Time variable value as it increases to large value
            if setting.loop >= 10:
                move.time = 0
                setting.loop = 0
        lm.movement(arc.angle, scr, width, setting, move.time, move)
        dr.draw_arc(scr,width,setting)
        dr.draw_limiter(scr,arc,width,setting)

        #Show the display
        pygame.display.update(((setting.left+200,0),(setting.scr_width,setting.scr_height)))
        pygame.display.update(((0, setting.top+200), (setting.left+200, setting.scr_height)))
        scr.fill(setting.bg_color)
        #Slow the clock
        pygame.time.delay(10)
Exemplo n.º 23
0
def run_game():
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Game Character")
    game_char = Character(screen)

    while True:
        f.check_events()
        f.update_screen(settings, screen, game_char)
Exemplo n.º 24
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("Alien Invasion")
    ship = Ship(ai_settings,screen)

    while True:
        gf.check_events(ship)
        ship.update() 
        gf.update_screen(ai_settings,screen,ship)
Exemplo n.º 25
0
def run_game():
    pygame.init()
    settings = Settings()
    blue_bg = (130, 213, 255)
    settings.set_bg_color(blue_bg)
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Blue Sky")

    while True:
        f.update_screen_no_obj(settings, screen)
        f.check_events()
Exemplo n.º 26
0
def collect_data():
    # 初始化设置选项
    ai_settings = Settings()

    # 初始化小车
    car = Car(ai_settings)

    # 开始任务的主循环
    while True:
        func.check_events()
        func.update_collect_para()
        func.restore_data()
Exemplo n.º 27
0
def game():
    # Instantiate objects 1
    settings = Settings()
    # GUI display
    screen = pygame.display.set_mode(settings.size)
    pygame.display.set_caption("JumpUp!")
    # Instantiate objects 2
    player = Player(screen)
    plats = Group()
    score = Score(screen, settings)
    play_again = GameOver(screen, settings)
    clock = pygame.time.Clock()
    # create the first instance of a platform
    new_plat = JPlatform(screen, settings)
    plats.add(new_plat)
    new_plat.update()
    new_plat.draw_me()
    # update screen
    pygame.display.flip()
    # draw player on the top of the first platform.
    player.rect.centerx = new_plat.rect.centerx
    player.rect.bottom = new_plat.rect.top

    # [0] - x and [1] - y velocity
    velocity = [settings.x_speed, settings.jump_speed * (-1)]
    # [0] - negative x, [1] - positive x [2] - jumping
    movement = [False, False, False]
    # first image for animation
    image_no = [1]
    # create initial previous position
    #for not getting an error on the first frame
    prev_pos = [-30]

    while True:
        # check if the ball is still in game
        if f.still_playing(player, settings) == True:
            score.update_time()  # update score by the second
            score.check_highscore()  # check whether we beat the highscore
            delta_t = clock.tick(settings.fps) / 1000
            f.create_platform(player, screen, settings, clock, plats)
            f.check_events(player, movement)
            f.moving_the_ball(player, screen, settings, movement, plats,
                              velocity, delta_t, prev_pos)
            f.animate_the_ball(player, movement, image_no)
            f.update_screen(f.still_playing(player, settings), screen,
                            settings, player, play_again, plats, score)
        else:
            f.update_screen(f.still_playing(player, settings), screen,
                            settings, player, play_again, plats, score)
            score.save_highscore()  # save the current highscore
            if f.check_quit() == False:
                game()
Exemplo n.º 28
0
def run_game():
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Stars")
    star = Star(settings, screen)
    stars = Group()
    f.create_star_grid(settings, screen, stars, star)

    while True:
        f.update_screen_grid(settings, screen, stars)
        f.check_events()
Exemplo n.º 29
0
def run_game():
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Steady Rain")
    raindrop = Raindrop(settings, screen)
    raindrops = Group()
    f.create_raindrop_grid(settings, screen, raindrops, raindrop)

    while True: 
        f.update_screen_grid(settings, screen, raindrops)    
        f.update_steady_rain(settings, screen, raindrops, raindrop)
        f.check_events()
Exemplo n.º 30
0
def run_game():
    """Engine of the game"""
    # Initialize game and create a screen object.
    pygame.init()
    game_set = Settings()
    screen = pygame.display.set_mode(
        (game_set.screen_width, game_set.screen_height))
    # Setting caption
    pygame.display.set_caption("Alien Invasion")
    # An instance to store game statistics and create a scoreboard.
    stats = GameStats(game_set)
    sb = Scoreboard(game_set, screen, stats)
    # Make a ship, a group of bullets, and a group of aliens.
    ship = Ship(game_set, screen)
    flag = 0
    # Create the fleet of aliens.
    Timer(0.0, gf.create_alien, [game_set, screen]).start()
    Timer(8.0, gf.delete_alien, [game_set, screen, ship]).start()
    # Start the main loop for the game.
    while True:
        # Watch for keyboard events.
        flag = gf.check_events(game_set, screen, ship, stats, flag)
        # End game check
        if flag == 1:
            break
        # Update condition of bullets and ship
        ship.update()
        Bullet_Norm.bullets.update()
        Bullet_Wait.bullets.update()
        # Get rid of bullets that have disappeared.
        gf.update_bullets(game_set, screen, stats, sb, ship)
        gf.update_screen(game_set, screen, stats, sb, ship)
    print("Counter : " + (str)(stats.score))
    os._exit(0)
Exemplo n.º 31
0
def run_game():
    # Initialize pygame, settings, and screen object.
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Pong")

    play_button = Button(settings, screen, "Play")
    player = Player(settings, screen)
    ball = Ball(settings, screen)
    ai = Ai(settings, screen)
    audio = Audio()
    sb = Scorebord(settings, screen, audio)

    # Start the main loop for the game.
    while True:
        func.check_events(player, settings, ai, play_button, audio, ball)
        if settings.game_active:
            func.updates(player, ai, ball, settings)
        func.update_screen(settings, screen, player, ball, ai, sb, play_button, audio)
        pygame.time.Clock().tick(settings.game_speed)
Exemplo n.º 32
0
def run_game():
	#Initialize and create screen project
	pygame.init()
	game_settings = Settings()
#	screen = pygame.display.set_mode((1200,800))
	screen = pygame.display.set_mode(
		(game_settings.screen_width, game_settings.screen_height))
	pygame.display.set_caption("Rocket game")
	
	# make a rocket
	rocket = Rocket(game_settings, screen)
	# Make a group to store bullets in.
	bullets = Group()	
	aliens = Group()
	
	fn.create_fleet(game_settings, screen, rocket, aliens)
	# Main loop
	while True:
		# Watch for keyboard and mouse events
		fn.check_events(game_settings, screen, rocket, bullets)
		rocket.update()
		fn.update_bullets(bullets)				
		fn.update_screen(game_settings, screen, rocket, aliens, bullets)
Exemplo n.º 33
0
def run():
    # Initialize game, settings and create a screen object
    pygame.init()
    settings = Settings()
    screen_setup = display.build(settings)
    screen = screen_setup[0]
    pygame.display.set_caption("Fake It Til You Make It")

    # Change screen dims to match fullscreen dims
    settings.screen_width = screen_setup[1]
    settings.screen_height = screen_setup[2]

    # create variables for screen center
    scx = settings.screen_width / 2
    scy = settings.screen_height / 2

    # Make Main Menu
    buttons = []
    play_button = Button(settings, screen, "NEW GAME", scx - 100, 500, 300, 75, (0, 0, 0), None)
    quit_button = Button(settings, screen, "QUIT", scx - 100, 600, 300, 75, (0, 0, 0), None)
    buttons.append(play_button)
    buttons.append(quit_button)

    # Make Ingame Menu
    ig_buttons = []
    inv_button = Button(settings, screen, "INVENTORY", settings.screen_width * 0.2 - 100, 100, 300, 75, (0, 0, 0), None)
    craft_button = Button(settings, screen, "CRAFT", settings.screen_width * 0.35 - 100, 100, 300, 75, (0, 0, 0), None)
    build_button = Button(settings, screen, "BUILD", settings.screen_width / 2 - 100, 100, 300, 75, (0, 0, 0), None)
    character_button = Button(
        settings, screen, "CHARACTER", settings.screen_width * 0.65 - 100, 100, 300, 75, (0, 0, 0), None
    )
    menu_button = Button(settings, screen, "MENU", settings.screen_width * 0.8 - 100, 100, 300, 75, (0, 0, 0), None)
    ig_buttons.append(inv_button)
    ig_buttons.append(craft_button)
    ig_buttons.append(build_button)
    ig_buttons.append(character_button)
    ig_buttons.append(menu_button)

    # Make Loot PIP menu
    lp_buttons = []
    lp_title = Button(settings, screen, "", scx - 250, scy - 200, 500, 50, (0, 0, 0), None, 20)
    lptake_button = Button(settings, screen, "TAKE", scx + 25, scy - 125, 200, 50, (0, 0, 0), None, 20)
    lpdesc_button = Button(settings, screen, "", scx + 25, scy - 50, 200, 175, (0, 0, 0), None, 10)
    lp_window = Button(settings, screen, "", scx - 250, scy - 150, 500, 300, (100, 100, 100), None)
    lp_loot_window = Button(settings, screen, "", scx - 225, scy - 125, 200, 250, (180, 180, 180), None)
    lp_loot = Button(settings, screen, "", scx - 215, scy - 115, 180, 230, (250, 250, 250), None)
    lp_buttons.append(lp_title)
    lp_buttons.append(lp_window)
    lp_buttons.append(lptake_button)
    lp_buttons.append(lpdesc_button)
    lp_buttons.append(lp_loot_window)
    lp_buttons.append(lp_loot)

    # Create a stats instance
    stats = Stats(settings)

    # Create item groups
    player = Player(settings, screen)
    furniture = Group()
    items = Group()
    loots = Group()
    customers = Group()

    # Create clock to stabilize framerate
    clock = pygame.time.Clock()

    # Initialize Global Variables
    day = 1
    hour = 6
    minute = 0

    while True:
        clock.tick(100)
        gf.check_events(settings, screen, stats, buttons, ig_buttons, lp_buttons, loots)
        gf.update_screen(settings, screen, stats, buttons, ig_buttons, lp_buttons, player, loots)