Beispiel #1
0
 def post(self):
     food = self.request.get('food')
     amount = self.request.get('amount')
     name = self.request.get('name')
     WhatPeopleEat(person=name, food=food, amount=int(amount)).put()
     text = 'Awesome people eat ' + food
     render.text(text, self.response)
Beispiel #2
0
 def post(self):
   food = self.request.get('food')
   amount = self.request.get('amount')
   name = self.request.get('name')
   WhatPeopleEat(person=name, food=food, amount=int(amount)).put()
   text = 'Awesome people eat ' + food
   render.text(text, self.response)
Beispiel #3
0
def high_scores(screen, game_score):
    with open('./high_scores.json') as f:
        scores = json.load(f, object_pairs_hook=OrderedDict)

    center = screen.get_rect().center

    text_surfs = []
    text_rects = []
    i = 0
    for name, score in scores.iteritems():
        this_surf, this_rect = render.text("name" + ": " + str(score), 18,
                                           center)
        this_rect.top = 40 + (i * 20)
        text_surfs.append(this_surf)
        text_rects.append(this_rect)
        if i == 10:
            break
        i += 1

    high_score_surf, high_score_rect = render.text("HIGH SCORES", 20, center)
    high_score_rect.top = 20
    prompt = "Enter your name: "
    init_len = len(prompt)
    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
            if event.type == pygame.KEYDOWN and event.key == pygame.K_ENTER:
                done = True
            elif event.type == pygame.KEYDOWN and event.key <= 127:
                prompt.append(chr(event.key))
            elif event.key == K_BACKSPACE:
                if len(prompt) > 17:
                    prompt = prompt[0:-1]

        prompt_surf, prompt_rect = render.text(prompt, 20, center)
        prompt_rect.top = center[1] + 100

        screen.fill((0, 0, 0))
        i = 0
        for surf in text_surfs:
            screen.blit(surf, text_rects[i])
            i += 1

        screen.blit(prompt_surf, prompt_rect)
        screen.blit(high_score_surf, high_score_rect)

        pygame.display.flip()
        clock.tick(60)

    scores[prompt[init_len + 1:]] = game_score
    scores = OrderedDict(sorted(scores.iteritems(), key=lambda x: x[1]))
    json.dump(scores, f)
Beispiel #4
0
def mimg_prompts(screen):
    screen_rect = screen.get_rect()

    text1, text_rect1 = render.text(
        "Think about moving wildly, loud noises, etc.", 20, screen_rect.center)
    text2, text_rect2 = render.text("Think normally", 20, screen_rect.center)
    text3, text_rect3 = render.text("Think about nothing, clear your mind", 20,
                                    screen_rect.center)

    text_surfs = cycle([text1, text2, text3])
    text_surf = next(text_surfs)
    text_rects = cycle([text_rect1, text_rect2, text_rect3])
    text_rect = next(text_rects)
    return text_surfs, text_surf, text_rects, text_rect
Beispiel #5
0
def ssvep_prompts(screen):
    screen_rect = screen.get_rect()

    text1, text_rect1 = render.text("Look at the left flashing light", 20,
                                    screen_rect.center)
    text2, text_rect2 = render.text("Look at the center of the screen", 20,
                                    screen_rect.center)
    text3, text_rect3 = render.text("Look at the right flashing light", 20,
                                    screen_rect.center)

    text_surfs = cycle([text1, text2, text3])
    text_surf = next(text_surfs)
    text_rects = cycle([text_rect1, text_rect2, text_rect3])
    text_rect = next(text_rects)
    return text_surfs, text_surf, text_rects, text_rect
Beispiel #6
0
def main():
    SCREEN_HEIGHT = 700
    SCREEN_WIDTH  = 1024
    clock  = pygame.time.Clock()
    screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
    screen_rect = screen.get_rect()
    x = screen_rect.centerx
    y = screen_rect.centery

    pygame.init()
    pygame.display.set_caption('Think-Blast')

    title_unscale = pygame.image.load('../assets/title.png')
    title         = pygame.transform.scale(title_unscale, (500, 200))
    title_rect    = title.get_rect(center = (SCREEN_WIDTH/2, 150))

    done = False
    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True

        pressed = pygame.key.get_pressed()
        if pressed[pygame.K_q]:
            done = True
        if pressed[pygame.K_p]:
            game.gameplay(screen, clock)
        if pressed[pygame.K_c]:
            calibrate.calibrate(screen, clock)

        play, play_rect = render.text("Press p to Play", 30, (x,y))
        play_rect.top += 0
        cal, cal_rect   = render.text("Press c to Calibrate", 30, (x,y))
        cal_rect.left = play_rect.left
        cal_rect.top += 40
        quit, quit_rect = render.text("Press q to Quit", 30, (x,y))
        quit_rect.left = play_rect.left
        quit_rect.top += 80

        screen.fill((0, 0, 0))
        screen.blit(title, title_rect)
        screen.blit(play, play_rect)
        screen.blit(cal, cal_rect)
        screen.blit(quit, quit_rect)
       
        pygame.display.flip() 
        clock.tick(60)
Beispiel #7
0
def gameplay(screen, clock):
    all_sprites = pygame.sprite.Group()
    enemies = pygame.sprite.Group()
    bullets = pygame.sprite.Group()
    ship1 = ship()
    all_sprites.add(ship1)

    clf = interface.get_classifier("./cal_ssvep.csv")
    print "Classifier generated!"
    f = interface.trial_to_feat(x)
    clf.classify_buf()

    SPAWN = pygame.USEREVENT + 0
    SPAWN_TIME = 2000
    pygame.time.set_timer(SPAWN, SPAWN_TIME)

    SSVEP1, ssvep_surfs1, ssvep_surf1, ssvep_rect1 = render.ssvep(1, 8.0)
    SSVEP2, ssvep_surfs2, ssvep_surf2, ssvep_rect2 = render.ssvep(2, 22.0)

    game_theme = pygame.mixer.music.load("../assets/game-theme-temp.mp3")
    pygame.mixer.music.play(-1, 0)

    CLASSIFY = pygame.USEREVENT + 3
    pygame.time.set_timer(CLASSIFY, 1000)

    screen_rect = screen.get_rect()
    score = 0
    score_frames = 0
    score_surf, score_rect = render.text("Score: %d" % score, 20,
                                         screen_rect.center)
    score_rect.top = SCREEN_HEIGHT - 40

    inlet = interface.init_lsl(0)

    i = 0
    sample_buf = numpy.empty(60)
    done = False
    pygame.key.set_repeat()
    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
            if event.type == SPAWN:
                e = enemy()
                enemies.add(e)
                all_sprites.add(e)
            if event.type == SSVEP1:
                ssvep_surf1 = next(ssvep_surfs1)
            if event.type == SSVEP2:
                ssvep_surf2 = next(ssvep_surfs2)
            if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
                b = bullet(ship1.angle)
                b.rect.x = ship1.rect.centerx
                b.rect.y = ship1.rect.centery
                all_sprites.add(b)
                bullets.add(b)

        all_sprites.update()
        player_hits = pygame.sprite.spritecollide(
            ship1, enemies, False, pygame.sprite.collide_circle_ratio(0.7))
        if player_hits:
            high_scores(score)
            done = True
        bullet_hits = pygame.sprite.groupcollide(
            enemies, bullets, True, True,
            pygame.sprite.collide_circle_ratio(0.7))
        score += len(bullet_hits) * 100

        ssvep_rect1.top = ship1.rect.top
        ssvep_rect1.left = ship1.rect.left - 160
        ssvep_rect2.top = ship1.rect.top
        ssvep_rect2.left = ship1.rect.left + 175

        screen.fill((0, 0, 0))
        screen.blit(ssvep_surf1, ssvep_rect1)
        screen.blit(ssvep_surf2, ssvep_rect2)
        if score_frames == 60:
            score += 1
            score_frames = 0
        else:
            score_frames += 1
        score_surf, _ = render.text("Score: %d" % score, 20, (0, 0))
        screen.blit(score_surf, score_rect)
        all_sprites.draw(screen)

        pygame.display.flip()

        times, samples = interface.read_lsl(inlet)
        for s in samples:
            sample_buf[i] = numpy_asarray(sample[0:8])
            i += 1
        if i >= 245:
            ssvep_result, _ = classify_buf(clf, sample_buf)
            if ssvep_result == 0:
                ship1.rotate_ccw()
            if ssvep_result == 2:
                ship1.rotate_cw()
            i = 0
            sample_buf = numpy.empty([250, 8])

        clock.tick(60)