Beispiel #1
0
def name(display_text):
    screen = pygame.display.set_mode((700, 400))
    clock = pygame.time.Clock()
    pygame.init()
    text=textinput.TextInput(initial_string=display_text)
    while True:
        screen.fill((225, 225, 225))

        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                exit()
            if event.type==pygame.KEYDOWN:
                if event.key == 13:
                    return(text.input_string)

        # Feed it with events every frame
        text.update(events)
        # Blit its surface onto the screen
        screen.blit(text.get_surface(), (10, 10))
        pygame.display.update()
        clock.tick(30)
Beispiel #2
0
    def __init__(self):
        self.white = (255, 255, 255)
        self.black = (0, 0, 0)
        self.red = (255, 0, 0)
        self.blue = (0, 0, 255)
        self.green = (0, 255, 0)

        self.background = pygame.image.load("assets/images/home_bg.png")
        self.apple_image = pygame.image.load("assets/images/apple.png")
        self.original_snake_head_image = pygame.image.load(
            "assets/images/snake_head.png")
        self.snake_body_image = pygame.image.load(
            "assets/images/snake_body.png")
        self.original_snake_tail = pygame.image.load(
            "assets/images/snake_tail.png")
        self.snake_tail = self.original_snake_tail
        self.snake_head_image = self.original_snake_head_image

        self.apple_sound = pygame.mixer.Sound("assets/sounds/apple_sound.wav")

        self.direction = "up"

        self.SCREEN_WIDTH = 800
        self.SCREEN_HEIGHT = 500

        self.screen = pygame.display.set_mode(
            [self.SCREEN_WIDTH, self.SCREEN_HEIGHT])

        self.running = True
        self.paused = False
        self.agreed = False

        self.snake_block = 25
        self.apple_block = 25

        self.snake_x = 0
        self.snake_y = 0
        self.apple_x = 0
        self.apple_y = 0

        self.center = (self.SCREEN_WIDTH // 2, self.SCREEN_HEIGHT // 2)

        self.width_grid = 0
        self.height_grid = 0

        self.snake_x_change = 0
        self.snake_y_change = 0

        self.snake_list = list()
        self.snake_head = list()
        self.snake_length = 2

        self.score = 0
        self.show_score_page = False
        with open('scores.json') as f:
            self.scores = json.load(f)
        self.name = ""

        self.clock = pygame.time.Clock()

        self.velocity = 400

        self.text_input = textinput.TextInput()
Beispiel #3
0
                CLOCK.tick(FPS)
                pygame.display.flip()
            CLOCK.tick(FPS)
            frame_display_ghost(W, H)
            CAMERA.start_preview()
        # Erase the last frame.
        elif pressed == {4}:
            frame_erase_last()
            frame_display_ghost(W, H)
        # Take picture.
        elif pressed == {5}:
            frame_capture()
            frame_display_ghost(W, H)
        # Make and save movie.
        elif pressed == {6}:
            text_input = textinput.TextInput(antialias=False)
            while True:
                SCREEN.fill((225, 225, 225))
                events = pygame.event.get()
                SCREEN.blit(text_input.get_surface(), (10, 10))
                if text_input.update(events):
                    movie_name = text_input.get_text()
                    break
                pygame.display.update()
                CLOCK.tick(FPS)
            movie_make(movie_name, FPS_MOVIE)
            frame_display_ghost(W, H)
        # Exit program.
        elif pressed == {13}:
            quit(CAMERA)
Beispiel #4
0
    def __init__(
            self,
            win,
            expHandler,
            mydir,
            subjectnr,
            sessionnr,
            triggerlen,
            ntrials,  # number of Trials
            nfr_on2onisi_upper,  # upper bound of isis in frames
            nfr_on2onisi_lower,  # lower bound of isis in frames
            nFrStim,  # length of stimulus presentation in frames
            pdeviants,  # probability of deviants
            maxNConsecStan,  # the array that determines whether a stimulus is a deviant or a standard is divided 
            # in pairs, each containing a deviant in first place and a standard or deviant in second place
            # max(diffPairsIndeces) > int((maxNConsecStan)/2) the list of pairs will be reshuffled
        verticesPixStim,  # the vertices of the shape in pixls
            trackFrIntervals=True,  # whether to track the frame intervals
            dataSaveClock=None,  # a clock for which we'll query for the timing of every trial stored alongside the data
            stopIndxForInstr=-1,
            seed=None):

        np.random.seed(seed=seed)  # if seed is not None, the calls to
        # np.random will not be (pseudo-)random but produce a reproducible sequence

        self.win = win
        self.thisExp = expHandler
        self.nFrStim = nFrStim
        self.triggerlen = triggerlen
        self.trackFrIntervals = trackFrIntervals

        # check the framerate
        framerate = win.getActualFrameRate()
        logging.warn('The framerate is: %d' % framerate)
        assertWarningTxt = 'The length you set for the presentation of the'\
            ' stimulus is less than the length for which you send a trigger. '\
            'This is not possible.'
        assert self.triggerlen <= self.nFrStim * 1 / framerate, assertWarningTxt

        stims = self._stimsList(ntrials, pdeviants, maxNConsecStan)
        self.isi_list = self._isiList(nfr_on2onisi_lower, nfr_on2onisi_upper,
                                      nFrStim, ntrials)

        # initialize stimuli
        myOris = [0.0, 45.0]  # one of the stimuli will be turned by 45 degrees
        np.random.shuffle(myOris)  # returns None!
        self.deviant = visual.ShapeStim(win,
                                        units='pix',
                                        vertices=verticesPixStim,
                                        lineWidth=5,
                                        ori=myOris[0],
                                        name='oddball_deviant')
        self.standard = visual.ShapeStim(win,
                                         units='pix',
                                         vertices=verticesPixStim,
                                         lineWidth=5,
                                         ori=myOris[1],
                                         name='oddball_standard')

        # create a list of dicts with isi and stimtype for every trial
        trialList = []
        for i, j in zip(stims, self.isi_list):
            trialList.append(dict(standard=i, isi=j))
        # initialize a TrialHandler object
        self.trialHandler = data.TrialHandler(
            trialList=trialList,
            nReps=1,
            method='sequential',
            extraInfo={'deviant_ori':
                       self.deviant.ori},  # store which shape was the deviant
            name='trialhandler_oddball')
        self.thisExp.addLoop(self.trialHandler)

        # Initialise a port
        self.parallel_port_exists = False  # initialized with False, so that if the parallel port
        #   cannot be initialised, I later query this variable and avoid running code that would through error without a parallel port
        if parallel_imported:
            try:
                self.port = parallel.ParallelPort(address=0x0378)
                self.parallel_port_exists = True
            except Exception:
                logging.warn(
                    'Es konnte kein parallel port initialisiert werden! Es werden keine Trigger gesendet.'
                )

        # the text for instruction
        instrString = 'Im Folgenden werden Ihnen in schneller Reihenfolge in '\
            'zwei Blöcken je 150 Formen hintereinander auf dem Bildschirm präsentiert. '\
            'Sie sollen zählen, wie oft Ihnen die Form, die Sie unten '\
            'links sehen, präsentiert wird. Die Form, die Sie unten '\
            'rechts sehen, sollen sie nicht beachten.\n'\
            '\nDrücken Sie die Leertaste, um die ersten {} Formen '\
            'zu sehen.'.format(len(trialList) if stopIndxForInstr is -1 else stopIndxForInstr)
        self.instructionTxt = visual.TextStim(win,
                                              height=.08,
                                              units='norm',
                                              pos=(0, 0.5),
                                              wrapWidth=1.5,
                                              text=instrString,
                                              name='instruction_oddball')

        # an object to run a routine which allows entering numbers
        # without a dlg gui, but directly on screen
        self.textInput = textinput.TextInput(self.win)

        # clocks for timing and a mouse to hide the mouse during the trial
        self.trialClock = core.Clock(
        )  # this clock is for the timing of triggers
        self.dataSaveClock = core.Clock(
        ) if dataSaveClock is None else dataSaveClock  # this clock is for storing the time of each trial
        self.mouse = event.Mouse(win=self.win)
def run_game(screenmode=0):
    # Initialize pygame, settings, and screen object.
    pygame.init()
    ai_settings = Settings()

    if screenmode:
        #fullscreen speeds up game, but cannot see terminal output for debugging
        screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        ai_settings.screen_width = screen.get_rect().width
        ai_settings.screen_height = screen.get_rect().height
        print(screenmode)
    else:
        screen = pygame.display.set_mode(
            (ai_settings.screen_width, ai_settings.screen_height))
        print('windowed mode')

    pygame.display.set_caption("Alien Invasion - Press p to exit")

    # Creat instances of several class objects.
    play_button = Button(ai_settings, screen, "Play")
    stats = GameStats(ai_settings)
    ship = Ship(ai_settings, screen, 1)
    ship2 = Ship(ai_settings, screen, 2)
    bullets = Group()
    alien_bullets = Group()
    aliens = Group()
    leaderboard = Leaderboard(stats, screen, ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    textinput = ti.TextInput()

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

    # Start the main loop for the game.
    while ai_settings.quitflag:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets, ship2)
        if stats.game_active:
            gf.update_ships(ai_settings, screen, stats, sb, ship, aliens,
                            bullets, alien_bullets, ship2, leaderboard,
                            textinput)
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets, alien_bullets, ship2, leaderboard,
                              textinput)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets, alien_bullets, ship2, leaderboard,
                             textinput)
        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         play_button, alien_bullets, ship2)

    leaderboard.read_high_score(stats)
    if stats.score > leaderboard.previous_high_score:
        leaderboard.new_high_score(ai_settings, screen, textinput, stats)

    ai_settings.quitflag = 1
    while ai_settings.quitflag:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets, ship2)
        leaderboard.display(ai_settings, screen)

    pygame.display.quit()
    pygame.quit()
    exit()