Esempio n. 1
0
def main_game_loop():
    # create screen
    cfg = Settings()
    pygame.init()
    screen = create_screen(cfg)
    # create main objects of the game
    status = GameStatus(cfg)
    ship = Ship(screen, cfg)
    scoreboard = Scoreboard(screen, cfg, status)
    aliens = Group()
    bullets = Group()
    playBtn = PlayButton(screen, cfg)
    pauseBtn = PauseButton(screen, cfg)
    # setup game to start
    prepare_game(cfg, screen, status, bullets, aliens, ship)
    # main loop
    while True:
        # check user input
        check_events(cfg, screen, ship, bullets, playBtn, status)
        # update object states
        screen.fill(cfg.getBackgroundColor())
        update_objects_and_game(cfg, screen, ship, aliens, bullets, scoreboard,
                                status)
        # draw objects
        draw_objects(ship, aliens, bullets, scoreboard, playBtn, pauseBtn,
                     status)
        pygame.display.flip()
Esempio n. 2
0
def move(key):
    global brick, field, window
    window.clear()
    window.refresh()
    brick.control_brick(key, field)

    # check valid move or not
    valid = utils.check_valid(field, brick)
    if not valid:
        brick.revert()

    # check_get floor
    brick.control_brick(ord("s"), field)
    can_down = utils.check_valid(field, brick)
    brick.revert()
    if not can_down:
        field.add_brick(brick)
        brick.create_new_brick()

    # clear one row when full
    field.check_and_clear_rows()

    # render screen
    rendered = utils.create_screen(field, brick)
    window.addstr(0, 0, rendered)
Esempio n. 3
0
def auto_down():
    while True:
        time.sleep(cfg.TIME_SLEEP)
        global bricks, field, count
        bricks.control_brick(ord("s"))
        can_down = utils.check_valid(field, bricks)
        if not can_down:
            bricks.revert()
            field.add_bricks(bricks)
            bricks = go.Bricks()
            field.check_and_clear_rows()
        # render screen
        rendered = utils.create_screen(field, bricks)
        window.refresh()
        window.addstr(0, 0, rendered)
Esempio n. 4
0
 def create_kanji_page(self, level):
     self.page = KanjiViewer(self, level)
     create_screen("Kanji Viewer", self.page)
Esempio n. 5
0

Thread(target=auto_down).start()

while True:
    # get key
    key = window.getch()
    window.clear()
    window.refresh()
    bricks.control_brick(key)

    # check valid move or not
    valid = utils.check_valid(field, bricks)
    if not valid:
        bricks.revert()

    # check_get floor
    bricks.control_brick(ord("s"))
    can_down = utils.check_valid(field, bricks)
    bricks.revert()
    if not can_down:
        field.add_bricks(bricks)
        bricks = go.Bricks()

    # clear one row when full
    field.check_and_clear_rows()

    # render screen
    rendered = utils.create_screen(field, bricks)
    window.addstr(0, 0, rendered)