Esempio n. 1
0
    def text_input(self, key, val):

        if key == pygame.K_RETURN:
            self.input_active = False
            thehandler.get_game().set_text_input(None)
        elif key == pygame.K_LEFT:
            (self.char_offset, self.line_offset) = self._find_char_offsets(max(self.char_offset-1,0))
        elif key == pygame.K_RIGHT:
            (self.char_offset, self.line_offset) = self._find_char_offsets(min(self.char_offset+1,len(self.text)))
        elif key == pygame.K_BACKSPACE:
            if self.char_offset > 0:
                self.char_offset -= 1
                self.setText(self.text[0:self.char_offset]+self.text[self.char_offset+1:])
        else:
            if self.char_offset < self.maxlength:
                self.char_offset += 1
                self.setText(self.text[0:self.char_offset-1] + val + self.text[self.char_offset-1:])
        return True
Esempio n. 2
0
 def left_click(self, pos):
     (self.char_offset, self.line_offset) = self._find_pos_offsets(pos) 
     self.input_active = True
     thehandler.get_game().set_text_input(lambda key, val: self.text_input(key,val))
Esempio n. 3
0
 def fn(self, pos):
     thehandler.get_game().scene = NewGameScene(windowx, windowy)
Esempio n. 4
0
#!/usr/bin/env python
import pygame
from pygame.locals import *
import thehandler


game = thehandler.get_game()

clock = pygame.time.Clock()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit(0)
        if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
            exit(0)

        if event.type == pygame.MOUSEBUTTONUP:
            game.mouse_click(event.pos, event.button)
        if event.type == pygame.KEYDOWN:
            game.keyboard_action(event.key, event.mod, event.unicode, True)

    game.mouse_move(pygame.mouse.get_pos(), pygame.mouse.get_pressed()[0])
    game.render()

    clock.tick(60)