def __init__(self, name): self.Game_Event_Load = False self.Text_Line = ["", "", "", "", "", "", "", "", ""] self.Text_Order = 1 self.Text_Action = ["", "", "", "", "", "", "", "", ""] self.Game_Event = [False, False, False, False, False, False] self.Game_Fight_Attack = [False, False] self.State = "" self.State_Inventory = False self.State_Fight = "" self.Player_Status = ["", "", "", "", "", "", "", "", "", "", ""] self.Leveling_UP = False self.textinput = pygame_textinput.TextInput() self.Line_x = 0 self.Minimal = 1 self.Maximal = 8 self.Variable_x = 0
def _build_form(self, screen): """ """ self._username = pygame_textinput.TextInput('tahoma', 30, True, self._text_color, self._text_color, 400, 35) self._password = pygame_textinput.TextInput('tahoma', 30, True, self._text_color, self._text_color, 400, 35) self._forename = pygame_textinput.TextInput('tahoma', 30, True, self._text_color, self._text_color, 400, 35) self._surname = pygame_textinput.TextInput('tahoma', 30, True, self._text_color, self._text_color, 400, 35) self._email = pygame_textinput.TextInput('tahoma', 30, True, self._text_color, self._text_color, 400, 35) self._confirm = pygame_textinput.TextInput('tahoma', 30, True, self._text_color, self._text_color, 400, 35) # now create a field object for each one and add it to the forms array self._form.append(Field("username", self._username, 429, 293)) self._form.append(Field("password", self._password, 429, 392)) self._form.append(Field("forename", self._forename, 429, 491)) self._form.append(Field("surname ", self._surname, 429, 590)) self._form.append(Field("email ", self._email, 429, 695)) self._form.append(Field("confirm ", self._confirm, 429, 797)) # now set the index of the form that should be input first self._form_index = 0 #if the mode is profile mode, then set text inputs with player 1 details. if self._profile_mode == True: self._form[0].textinput.set_text( self._dal.get_logged_user_player_1().forename) self._form[1].textinput.set_text( self._dal.get_logged_user_player_1().surname) self._form[2].textinput.set_text( self._dal.get_logged_user_player_1().username) self._form[3].textinput.set_text( self._dal.get_logged_user_player_1().email) self._form[4].textinput.set_text( self._dal.get_logged_user_player_1().password) # Blit its surface onto the screen for fld in self._form: fld.textinput.refresh_field_display()
def __init__(self, name): self.textinput = pygame_textinput.TextInput() self.Text_Line_Left = ["", "", "", "", "", "", "", ""] self.Text_Line_Right = ["", "", "", "", "", "", "", ""] self.Text_Order = 1 self.Cutscene = False self.Event = [False, False, False, False, False, False] self.Fight_Event = [False, False, False, False, False, False] self.State = "" self.Game_Progress = 1 self.Turn_Count = 0 self.Sound = False self.Background = "Cutscene" self.Player = ["", "", ""] self.Enemy = ["", "", ""] self.Player_Slot = [True, False, False] self.Enemy_Slot = [True, False, False]
def __init__(self): self._running = True self._display_surf = None self.size = self.width, self.height = 1280, 720 self.background = (255, 255, 255) self.font = pygame.font.Font(None, 32) self.prev_button = self.add_prev_button() self.next_button = self.add_next_button() self.input_box = pygame_textinput.TextInput() self.canvas = self.add_canvas() self.img_lib = self.make_library() self.lambda_array = [] self.alligator_surfs = {} self.lambda_index = -1 self.search_box = self.add_search_box() self.clock = pygame.time.Clock() self.fps = 60 self.next_button_color = (255, 0, 0) self.disabled_next_button_color = (255, 200, 200) self.prev_button_color = (0, 255, 0) self.disabled_prev_button_color = (200, 255, 200) self._running = True
def draw(self): textinput = pygame_textinput.TextInput() while self.active == True: events = pygame.event.get() for event in events: if event.type == pygame.QUIT: exit() pygame.draw.rect(screen, (80, 80, 80), (0, 0, display_width, 45)) # Feed it with events every frame textinput.update(events) # Blit its surface onto the screen screen.blit(textinput.get_surface(), (10, 10)) keys = pygame.key.get_pressed() if keys[pygame.K_RETURN]: self.cheat = textinput.get_text() self.active = False if self.cheat.lower() == "god": if self.god == True: self.god = False else: self.god = True if self.cheat.lower() == "1": game.room = 1 if self.cheat.lower() == "2": game.room = 2 if self.cheat.lower() == "3": game.room = 3 if self.cheat.lower() == "4": game.room = 4 if self.cheat.lower() == "5": game.room = 5 if self.cheat.lower() == "debug": if self.debug == True: self.debug = False else: self.debug = True if self.cheat.lower() == "addscore": player1.score += 200 pygame.display.flip()
def game_newgame(): run = True # n.send({'event': 1, 'player': (player-1)}) textinput = pygame_textinput.TextInput() # text_box = TextBox(600, 70, 110, 650, callback=callback) while run: events = pygame.event.get() for event in pygame.event.get(): # print(event) if event.type == pygame.QUIT: pygame.quit() quit() # elif event.type == pygame.KEYDOWN: # if button == 0 (玩家回合) # text_box.key_down(event) gameDisplay.fill(yellow) Map(gameDisplay) Title = largefont.render("Game Start!", True, gray) # 會改! Your Turn ~ gameDisplay.blit(Title, (270, 10)) # TextInputBox Create pygame.draw.rect(gameDisplay, black, (80, 600, 650, 150)) if textinput.update(events): print(textinput.get_text()) gameDisplay.blit(textinput.get_surface(), (100, 620)) SendBtn = button("GO", 770, 650, 150, 70, blue, light_blue, action="EndTurn") pygame.display.update() clock.tick(15)
def __init__(self, name): self.event = "" self.textinput = pygame_textinput.TextInput() self.Text_Line_Input = "" self.Text_File = open("0.0.0_None.txt", "r") self.Text_Line = "" self.Text_Line_Left = ["", "", "", "", "", "", "", "", ""] self.Text_Line_Right = ["", "", "", "", "", "", "", "", ""] self.Text_Order = 0 self.Order_Left = 0 self.Order_Right = 0 self.State = "" self.Menu = "" self.Event = [False, False, False, False, False, False] self.Fight_Event = [False, False, False, False, False, False] self.Win_Results = False self.Sound = False self.Music = False self.Background = "Cutscene" self.Text_Cutscene = False self.Zone_Progress = 1 self.Stage_Progress = 0 self.Turn_Count = 0 self.Player = ["", "", ""] self.Player_Slot = [False, False, False] self.Enemy = ["", "", ""] self.Enemy_Slot = [False, False, False] self.Enemy_Death = [False, False, False] self.Experience_Gain = 0 self.Gold_Gain = 0
def submitScore(): # Create TextInput-object textinput = pygame_textinput.TextInput() font = pygame.font.Font(None, 74) text = font.render("Input name", 1, Black) while True: screen.fill((225, 225, 225)) screen.blit(text, (275, 250)) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: exit() # Feed it with events every frame if textinput.update(events): uname = textinput.get_text() break # Blit its surface onto the screen screen.blit(textinput.get_surface(), (350, 350)) pygame.display.update() Sql.insert("test", uname, score)
def get_playername(screen): textinput = pygame_textinput.TextInput() textinput.text_color = (255, 255, 255) textinput.font_object = pygame.font.Font(None, 50) clock = pygame.time.Clock() active = True while active: events = pygame.event.get() for event in events: pressed_keys = pygame.key.get_pressed() if event.type == pygame.QUIT: exit() if pressed_keys[K_RETURN]: active = False # Feed it with events every frame textinput.update(events) # Blit its surface onto the screen screen.blit(textinput.get_surface(), (120, 30)) pygame.display.update() clock.tick(30) return textinput.get_text()
def __init__(self, screen, x, y, width, height, text="", size=30, hide=False): # constructor self.screen = screen self.x = x self.y = y self.width = width self.height = height self.text = text self.size = size self.activated = False self.textinput = pygame_textinput.TextInput(self.width, self.height, font_size=size, hide=hide) self.surface = pygame.Surface((1, 1)).set_alpha(0)
def Todo_menu(): global todo_more textinput = pygame_textinput.TextInput() clock = pygame.time.Clock() todoflag = True while todoflag: screen.fill((225, 225, 225)) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: exit() # Feed it with events every frame if textinput.update(events): todo_more = textinput.get_text() print(todo_more) todoflag = False # Blit its surface onto the screen screen.blit(textinput.get_surface(), (10, 10)) pygame.display.update() clock.tick(30)
def __get_name(self): input_name = pygame_textinput.TextInput(font_family=self.__font_style, font_size=self.__y_screen // 13, text_color=self.__text_colour, max_string_length=15) clock = pygame.time.Clock() is_input = True while is_input: self.__screen.fill(self.__background_colour) self.__text("PODAJ SWÓJ NICK:", self.__x_screen // 2, self.__y_screen // 4, font_size=self.__y_screen // 13) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: self.__kill() input_name.update(events) text_length = input_name.font_object.size(input_name.get_text())[0] self.__screen.blit( input_name.get_surface(), ((self.__x_screen - text_length) // 2, self.__y_screen // 2)) self.__update() clock.tick(30) for event in events: if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: self.__name = input_name.get_text() is_input = False break
def initials(self): saved_name = [] textinput = pygame_textinput.TextInput() keys = pygame.key.get_pressed() screen = pygame.display.set_mode((800, 600)) clock = pygame.time.Clock() name_been_saved = False initials_type = True while initials_type == True: screen.fill((225, 225, 225)) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: exit() # Feed it with events every frame textinput.update(events) # Blit its surface onto the screen screen.blit(textinput.get_surface(), (10, 10)) pygame.display.update() clock.tick(30) if textinput.update(events): print(textinput.get_text()) score_save = (repr(self.score)) name_save = (str(textinput.get_text()), score_save) saved_name.append(name_save) with open('snake_name_highscore.json', 'w') as snake: json.dump(saved_name, snake) print("Saved!") initials_type = False if initials_type == False: self.final_screen()
def run(self): mySprite = self.TestSprite(self.win_width, self.win_height) my_group = pygame.sprite.Group(mySprite) textinput = pygame_textinput.TextInput() while True: self.drawAllUI(my_group) #pygame.draw.rect(self.screen, (0,255,0), (self.leaderBoardContainer.left, self.leaderBoardContainer.bottom + 100 , 100, 50)) #pygame.draw.rect(self.screen, (255,255,0), (self.leaderBoardContainer.left, self.leaderBoardContainer.bottom + 100 , 100, 50)) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: if self.mySaveRect.collidepoint(pygame.mouse.get_pos()): assert textinput.get_text() != "" user = textinput.get_text() append_line = user + ", " + str(self.score) + ", " + str(self.level) self.write_to_file(self.leaderBoardFile, append_line) elif self.myTryAgainRect.collidepoint(pygame.mouse.get_pos()): return True if textinput.update(events): my_text = textinput.get_text() print(my_text) break self.screen.blit(textinput.get_surface(), (self.enterUserRect.left + 5, self.enterUserRect.top + 5)) pygame.display.update()
def Text_Input(events, f): if GameStateIG.textinput.update(events): # Input GameStateIG.Text_Line_Input = GameStateIG.textinput.get_text() GameStateIG.textinput = pygame_textinput.TextInput() # Read GameStateIG.Text_Line = f.readline().rstrip('\n').replace("%PlayerIG.name", ("%s" % GameStateIG.Player[0].name)) if "[L]" in GameStateIG.Text_Line: GameStateIG.Order_Left += 1 if GameStateIG.Order_Left == 7: Game_State_Reset("Left") GameStateIG.Text_Line_Left[GameStateIG.Order_Left] = GameStateIG.Text_Line.strip("[L]") GameStateIG.Text_Line_Left[GameStateIG.Order_Left+1] = "(-> Press Enter)" GameStateIG.Text_Line_Right[GameStateIG.Order_Right+1] = "" print(GameStateIG.Text_Line_Left[GameStateIG.Order_Left]) elif "[R]" in GameStateIG.Text_Line: GameStateIG.Order_Right += 1 if GameStateIG.Order_Right == 7: Game_State_Reset("Right") GameStateIG.Text_Line_Right[GameStateIG.Order_Right] = GameStateIG.Text_Line.strip("[R]") GameStateIG.Text_Line_Left[GameStateIG.Order_Left+1] = "" GameStateIG.Text_Line_Right[GameStateIG.Order_Right+1] = "(-> Press Enter)" print(GameStateIG.Text_Line_Right[GameStateIG.Order_Right]) GameStateIG.Text_Order += 1 # INTRO CHARACTER NAME if GameStateIG.State == "Character Name": pygame.draw.rect(gameDisplay, black, [295, 395, 210, 40]) pygame.draw.rect(gameDisplay, game_ui_color, [300, 400, 200, 30]) gameDisplay.blit(GameStateIG.textinput.get_surface(), (305, 405))
white = (255, 255, 255) red = (200, 0, 0) green = (0, 200, 0) dark_green = (0, 255, 0) dark_red = (255, 0, 0) n = 0 qlist = [] aliceBases = [] bobBases = [] bobBits = [] aliceBits = [] key = [] pygame.init() textinput = pygame_textinput.TextInput() display_width = 800 display_height = 600 gameDisplay = pygame.display.set_mode((display_width, display_height)) pygame.display.set_caption('Quantum Communication') clock = pygame.time.Clock() def text_objects(text, font): textSurface = font.render(text, True, black) return textSurface, textSurface.get_rect() def button(text, x, y, w, h, dark, light, action=None): mouse = pygame.mouse.get_pos() click = pygame.mouse.get_pressed()
except: with open(os.path.join(CWD, "scores.json"), "w") as scores_json: json.dump(scores_default, scores_json) scores_dict = json.dumps(scores_default) # input("\nPress Enter to continue...") # Pause the interface. # Initialise pygame pygame.init() # Create TextInput-object textinput = pygame_textinput.TextInput( font_family="", font_size=100, text_color=(98, 175, 57), cursor_color=(255, 255, 254), repeat_keys_initial_ms=400, repeat_keys_interval_ms=35, max_string_length=3, ) # Screen settings SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) # Hide mouse cursor pygame.mouse.set_visible(False) pygame.event.set_grab(True) # Background
(exchange_button_width, exchange_button_height)), (exchange_button_start_width, exchange_button_start_height)) if mouse_l_click(event): if len(second_put_group.sprites()) > 0 or len( third_put_group.sprites()) > 0: list2 = second_put_group.sprites() list3 = third_put_group.sprites() second_put_group.remove(list2) second_put_group.add(list3) third_put_group.remove(list3) third_put_group.add(list2) second_put_group.resize(-1) third_put_group.resize(-1) username_input = pygame_textinput.TextInput() username_input.max_string_length = 20 password_input = pygame_textinput.TextInput() password_input.max_string_length = 20 password_input.password = True logined = False input_password = False while True: if logined: for event in pygame.event.get(): # 退出游戏 if event.type == QUIT: print("bye!") exit()
import pygame import pygame_textinput import random clock = pygame.time.Clock() screen = pygame.display.set_mode((1000, 650), 0, 32) textinput = pygame_textinput.TextInput(text_color=(255, 255, 255)) class Shell(): def __init__(self, x, y, w, h): self.x = x self.y = -h self.des = y self.blone_up = False self.w = w self.h = h self.v_x = 1 self.v_y = -1 self.pic = pygame.image.load("../assets/Untitled.png") self.pic_small = pygame.transform.scale(self.pic, (self.w, self.h)) self.pic_small.set_colorkey((255, 255, 255)) self.boom_pic = pygame.image.load("../assets/boom.jpg") self.boom_pic_small = pygame.transform.scale( self.boom_pic, (self.w + 100, self.h + 100)) self.hitbox = pygame.Rect(self.x, self.y, w, h) def update(self, screen): if self.blone_up: screen.blit(self.boom_pic_small, (self.hitbox.x, self.hitbox.y)) else: if self.hitbox.y < self.des:
# drawing foundation pygame.draw.rect(screen, WHITE, (470, 450, 100, 50)) # drawing hanger stand pygame.draw.rect(screen, WHITE, (510, 150, 20, 300)) # drawing hor bulk pygame.draw.rect(screen, WHITE, (320, 150, 210, 15)) pygame.draw.line(screen, WHITE, (460, 155), (520, 190), 5) # drawing rope pygame.draw.rect(screen, WHITE, (340, 150, 2, 40)) pygame.display.flip() draw_hanger() while not is_end: text_input = pygame_textinput.TextInput(initial_string='Welcome') events = pygame.event.get() for event in events: if event.type == pygame.QUIT: exit() if event.type == pygame.KEYDOWN: print('got = ', pygame.key.name(event.key)) text_input.update(events) # Blit its surface onto the screen if text_input.update(events): print(text_input.get_text()) screen.blit(text_input.get_surface(), (10, 10))
def camstream(): pygame.init() pygame.display.set_caption("อ่าน BARCODE & QRCODE จาก กล้องเว็บแคม USB") display = pygame.display.set_mode(SIZE0, 0, 24) f01 = pygame.font.Font("Garuda-Bold.ttf", 12) textinput = pygame_textinput.TextInput(font_family='', font_size=25, text_color=xcolor[0], cursor_color=xcolor[0]) pygame.camera.init() camera = pygame.camera.Camera(DEVICE0, SIZECAM) camera.start() surfcam = pygame.surface.Surface(SIZECAM, depth=24) FPS = 25 clock = pygame.time.Clock() running = True while running: camera.get_image(surfcam) display.blit(surfcam, (0, 0)) xrect1 = pygame.Rect(0, CAMH, CAMW, 20) pygame.draw.rect(display, xcolor[0], xrect1) msgcam = "คลิกซ้าย..อ่าน BARCODE คลิกขวา..อ่าน QRCODE" display.blit(f01.render(msgcam, True, xcolor[1]), (10, CAMH)) events = pygame.event.get() for event in events: #event quit if event.type == QUIT: running = False elif event.type == KEYDOWN and event.key == K_q: running = False #gen qrcode image elif event.type == KEYDOWN and event.key == K_F1: xqrtext = textinput.get_text() ximgfile = genqrcodefile(xqrtext) imgqr = pygame.image.load(ximgfile) imgqr = pygame.transform.scale(imgqr, (CAMW, CAMH)) display.blit(imgqr, (CAMW, CAMH + 20)) elif event.type == pygame.MOUSEBUTTONDOWN: #[1=Lclick 3=Rclick 2=Mclick 4=ScrUp 5=ScrDN] if (event.button == 1): #event zbar ximgndarray = getimg_ndarray(surfcam) xrtns = convzbar(ximgndarray) if (event.button == 3): #event zbarlight xfile = 'filecam.png' pygame.image.save(surfcam, xfile) xrtns = convzbarlight(xfile) display.blit(surfcam, (CAMW, 0)) xrect2 = pygame.Rect(CAMW, CAMH, CAMW, 20) pygame.draw.rect(display, xcolor[2], xrect2) msgzbar = xrtns[0] display.blit(f01.render(msgzbar, True, xcolor[0]), (CAMW + 10, CAMH)) #input QRcode textin xrect2 = pygame.Rect(0, CAMH + 20, CAMW, 20) pygame.draw.rect(display, xcolor[1], xrect2) textinput.update(events) display.blit(textinput.get_surface(), (0, CAMH + 20)) pygame.display.flip() clock.tick(FPS) camera.stop() pygame.quit() return
GREEN_D = (0, 120, 0) YELLOW = (255, 255, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) GREEN = (0, 200, 0) MAROON = (200, 0, 200) blockWidth = 100 # g_ClickCount = -1 g_TotalSecond = 0 g_TotalPieNums = 4 g_USERNAME = "******" textinput = pygame_textinput.TextInput(initial_string=g_USERNAME, font_size=24, text_color=WHITE, font_family="simhei") curSurface = pygame.display.set_mode((630, 560), 0, 32) pygame.display.set_caption("汉诺塔游戏") # fontObj = pygame.font.Font('simsunb.ttf', 32) numberFontObj = pygame.font.SysFont("simhei", 36) resultFontObj = pygame.font.SysFont("simhei", 22) fontObj = pygame.font.SysFont("simhei", 50) headTextObj = fontObj.render("汉诺塔游戏", True, WHITE, NAVYBLUE) headRectObj = headTextObj.get_rect() headRectObj.center = (300, 50) infoFontObj = pygame.font.SysFont("simhei", 16)
def draw_game(): screen_info = pygame.display.Info() w, h = screen_info.current_w, screen_info.current_h if game.state == 0: game.textinput = pygame_textinput.TextInput() pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(0, 0, w, h)) pygame.draw.rect(screen, (30, 30, 30), pygame.Rect(w // 2 - 40, h // 2 - 20, 80, 40)) screen.blit(myfont.render("MENU", 1, (255, 255, 255)), (381, 291)) elif game.state == 0.5: map = game.world_map # World_map object ts = map.tile_size # size of an individual tile in pixels screen.fill((255, 255, 255)) for x in range(map.width): for y in range(map.height): pygame.draw.rect(screen, map.tiles[x][y][1], pygame.Rect(x * ts, y * ts, ts, ts)) for road in map.roads: pygame.draw.line( screen, (181, 103, 36), (road.P1[0] * ts + ts / 2, road.P1[1] * ts + ts / 2), (road.P2[0] * ts + ts / 2, road.P2[1] * ts + ts / 2), 5) pygame.draw.line( screen, (209, 147, 54), (road.P1[0] * ts + ts / 2, road.P1[1] * ts + ts / 2), (road.P2[0] * ts + ts / 2, road.P2[1] * ts + ts / 2), 3) for city in map.cities: pygame.draw.circle( screen, city.col, (city.pos[0] * ts + ts // 2, city.pos[1] * ts + ts // 2), city.size, 0) pygame.draw.circle( screen, (city.col[0] - 50, city.col[1] - 50, city.col[2] - 50), (city.pos[0] * ts + ts // 2, city.pos[1] * ts + ts // 2), city.size - 2, 0) elif game.state == 1: p_pos = game.player.pos # position of player map = game.world_map # World_map object ts = map.tile_size # size of an individual tile in pixels dims = game.game_dim # game_dim[0],game_dim[1] = game view size in tiles lB = 0 #leftBoundary rB = 0 #rightBoundary tB = 0 #topBoundary bB = 0 #bottomBoundary if int(p_pos.x) // ts - dims[0] // 2 < 0: lB = dims[0] // 2 - int(p_pos.x) // ts if int(p_pos.x) // ts + dims[0] // 2 > map.width: rB = int(p_pos.x) // ts + dims[0] // 2 - map.width if int(p_pos.y) // ts - dims[1] // 2 < 0: tB = dims[1] // 2 - int(p_pos.y) // ts if int(p_pos.y) // ts + dims[1] // 2 > map.height: bB = int(p_pos.y) // ts + dims[1] // 2 - map.height screen.fill((100, 100, 100)) for x in range( int(p_pos.x) // ts - dims[0] // 2 + lB, int(p_pos.x) // ts + dims[0] // 2 - rB): for y in range( int(p_pos.y) // ts - dims[1] // 2 + tB, int(p_pos.y) // ts + dims[1] // 2 - bB): pygame.draw.rect(screen, map.tiles[x][y][1], pygame.Rect(x * ts, y * ts, ts, ts)) for road in map.roads: P1, P2 = road.P1, road.P2 roadlen = dist(P1, P2) PMid = ((P1[0] + P2[0]) / 2, (P1[1] + P2[1]) / 2) if dist(PMid, (p_pos[0] // ts, p_pos[1] // ts)) < sqrt((dims[0] // 2)**2 + (dims[1] // 2)**2) + roadlen / 2: pygame.draw.line( screen, (181, 103, 36), (road.P1[0] * ts + ts / 2, road.P1[1] * ts + ts / 2), (road.P2[0] * ts + ts / 2, road.P2[1] * ts + ts / 2), 5) pygame.draw.line( screen, (209, 147, 54), (road.P1[0] * ts + ts / 2, road.P1[1] * ts + ts / 2), (road.P2[0] * ts + ts / 2, road.P2[1] * ts + ts / 2), 3) for city in map.cities: if sqrt(((city.pos[0] - p_pos[0] // ts)**2) + ((city.pos[1] - p_pos[1] // ts)**2)) < sqrt( (dims[0] // 2)**2 + (dims[1] // 2)) + city.size: pygame.draw.circle( screen, city.col, (city.pos[0] * ts + ts // 2, city.pos[1] * ts + ts // 2), city.size, 0) pygame.draw.circle( screen, (city.col[0] - 50, city.col[1] - 50, city.col[2] - 50), (city.pos[0] * ts + ts // 2, city.pos[1] * ts + ts // 2), city.size - 2, 0) pygame.draw.circle(screen, (255, 0, 0), (int(p_pos.x), int(p_pos.y)), game.world_map.tile_size, 0) """ pygame.draw.polygon(screen, (255, 255, 255), game.Ship_pointlist(), 1) if game.thrust_counter > 9: game.thrust_counter = 0 if 0 <= game.thrust_counter <= 5 and game.thrust: pygame.draw.polygon(screen, (255, 255, 255), game.Ship_thrust_pointlist(), 1) game.thrust_counter += 1 """ """ if len(game.astr) > 0: for i in range(len(game.astr)): pygame.draw.circle(screen, (255, 255, 255), (int(game.astr[i].x), int(game.astr[i].y)), game.astr[i].size * 10, 2) if len(game.pjct) > 0: for i in range(len(game.pjct)): pygame.draw.circle(screen, (255, 255, 255), (int(game.pjct[i].x), int(game.pjct[i].y)), 2, 0) """ """ screen.blit(myfont.render("Points: {}".format(game.points), 1, (255, 255, 0)), (20, 20)) screen.blit(myfont.render("Shield: {}".format(game.shield), 1, (255, 255, 0)), (20, 35)) screen.blit(myfont.render("Stage: {}".format(game.stage), 1, (255, 255, 0)), (20, 50)) """ elif game.state == 2: pygame.draw.rect(screen, (30, 30, 30), pygame.Rect(w // 2 - 40, h // 2 - 20, 80, 40)) screen.blit(myfont.render("PAUSE", 1, (255, 255, 255)), (377, 291)) if game.state == 2 or game.state == 0: """ pygame.draw.rect(screen, (30, 30, 30), pygame.Rect(570, 10, 210, 40 + 15 * len(game.scores))) screen.blit(myfont.render("Highscores:", 1, (255, 255, 0)), (590, 20)) for i, j in enumerate(game.scores): screen.blit(myfont.render(str(j['Name']) + ': ' + str(j['Score']) + ' at ' + str(j['Stage']), 1, (255, 255, 0)), (590, 35 + i * 15)) """ """ pygame.draw.rect(screen, (30, 30, 30), pygame.Rect(260, 400, 300, 120)) screen.blit(myfont.render("Controls:", 1, (255, 255, 255)), (270, 405)) screen.blit(myfont.render("Thrust: Up Arrow", 1, (255, 255, 255)), (280, 420)) screen.blit(myfont.render("Turn: Left and Right Arrows", 1, (255, 255, 255)), (280, 435)) screen.blit(myfont.render("Shoot: Spacebar", 1, (255, 255, 255)), (280, 450)) screen.blit(myfont.render("Pause: p", 1, (255, 255, 255)), (280, 465)) screen.blit(myfont.render("Exit Game/New Game: ESC", 1, (255, 255, 255)), (280, 480)) screen.blit(myfont.render("Sumbmit Score: Enter", 1, (255, 255, 255)), (280, 495)) """ """ pygame.draw.rect(screen, (30, 30, 30), pygame.Rect(570, 400, 210, 30 + 15 * len(game.localScores))) screen.blit(myfont.render("Local Highscores:", 1, (255, 255, 0)), (590, 405)) for i, j in enumerate(game.localScores): screen.blit(myfont.render(str(j['Name']) + ': ' + str(j['Score']) + ' at ' + str(j['Stage']), 1, (255, 255, 0)), (590, 420 + i * 15)) """ elif game.state == 3: """
def main(): # Main menu of the application # Set global variables to be used by other loops, this to allow them # to be declared in one loop and used in the others global filename, kinematic_data textinput = pygame_textinput.TextInput( ) # Generate editable text line object screen = pygame.display.set_mode( screen_size) # Set display mode for window clock = pygame.time.Clock() # Get current time title = "INME 4998 Research Project" instructions = """ This application takes in two sets of information from a six degree of freedom IMU unit and process the data to produce an animation in a 3-D space created with Open GL for an easy to interpret visualization of the sensor data. Data must adhere to the following guidelines so that the limitations of the program do not become an issue. -- Data for the sensors must be of similar length and should not exceed values of 50 -- Data may only include movements that are not to rash and a calibration time of at least 5 seconds should be allowed to permit for noise removal algorithm to work appropriately -- If data should contain pauses in movement (zero velocity instances) then a reasonable window of at least 4.5 seconds should be allowed for the program to register such an event """ options_1 = """Enter file name here and press Enter:""" options_2 = """Press Esc to exit""" typing = False while True: # Main menu loop screen.fill(black) events = pygame.event.get() for event in events: # Check for quit action if event.type == pygame.QUIT: exit() if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: exit() # Display text paragraphs to screen blit_text(screen, title, (20, 20), title_font) blit_text(screen, instructions, (20, 40), general_font) blit_text(screen, options_1, (20, 300), general_font) blit_text(screen, options_2, (930, 20), general_font) # Get mouse position data mouse_pos = pygame.mouse.get_pos() xpos = mouse_pos[0] ypos = mouse_pos[1] # Check if mouse is over the text box and if it has been clicked if xpos > 20 and (xpos < 20 + 500) and ypos > 320 and (ypos < 320 + 25) \ and event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: # Clear previous text input set typing to True textinput.clear_text() typing = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: # Check if Enter was pressed to store entered filename and call data processing module # Set typing to Flase filename = textinput.get_text() kinematic_data = np.array( SensorDataProcessingModule.process_data(filename)) typing = False if typing: # If typing display text box with editable line textinput.update(events) pygame.draw.lines(screen, light_gray, True, [[20, 320], [520, 320], [520, 345], [20, 345]]) screen.blit(textinput.get_surface(), (25, 325)) if not typing: # If not typing draw a lighter color box pygame.draw.lines(screen, white, True, [[20, 320], [520, 320], [520, 345], [20, 345]]) if xpos > 150 and (xpos < 150 + 200) and ypos > 400 and (ypos < 400 + 50): # If mouse is over graphing menu button darken the color pygame.draw.rect(screen, dark_gray, (150, 400, 200, 50)) if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: # If the button has been clicked, call the graphing_menu loop graphing_menu() screen = pygame.display.set_mode(screen_size) pygame.display.update() clock.tick(30) else: # If not over the graphing menu box, draw a lighter colored button pygame.draw.rect(screen, light_gray, (150, 400, 200, 50)) # Generate text for graphing menu button, render, center and display textSurf, textRect = text_objects("To Graphing Module", general_font) textRect.center = ((150 + (200 / 2)), (400 + (50 / 2))) screen.blit(textSurf, textRect) if xpos > 730 and (xpos < 730 + 200) and ypos > 400 and (ypos < 400 + 50): # If mouse is over animation menu button darken the color pygame.draw.rect(screen, dark_gray, (730, 400, 200, 50)) if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: # If the button has been clicked, call the animation_menu loop animation_menu() else: # If not over the animation menu box, draw a lighter colored button pygame.draw.rect(screen, light_gray, (730, 400, 200, 50)) # Generate text for animation menu button, render, center and display textSurf, textRect = text_objects("To Animation Module", general_font) textRect.center = ((730 + (200 / 2)), (400 + (50 / 2))) screen.blit(textSurf, textRect) # Update screen to show events, set time in milliseconds for updates pygame.display.update() clock.tick(30)
import pygame import pygame_textinput import random import clipboard # VARIABLES AND LISTS font = pygame.font.SysFont('comicsans', 35) width, height = 760, 650 text_input = pygame_textinput.TextInput(' ') win = pygame.display.set_mode((width, height)) pygame.display.set_caption('Password Generator') clock = pygame.time.Clock() password = [] symbols = ['@', '#', '$', '%', '&', '*', '-', '_', '=', '+', '!'] numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] lowercase = [ 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'ç', 'z', 'x', 'c', 'v', 'b', 'n', 'm' ] uppercase = [ 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Ç', 'Z', 'X', 'C', 'V', 'B', 'N', 'M' ] ambiguous_characters = [ '[', ']', '{', '}', '(', ')', '/', '\\', '"', '\'', '~', '<', '>' ] run = True error = False right_length = False
def __init__(self, name): self.Order_Text = 1 self.Line_x = 1 self.textinput = pygame_textinput.TextInput() self.Minimal = 1 self.Maximal = 8
def main(): # auto correction # data processing data = os.path.join('auto', 'shakespeare.txt') word_l = process_data(data) vocab = set(word_l) word_count_dict = get_count(word_l) probs = get_probs(word_count_dict) # Initialize variables font = pygame.font.Font('freesansbold.ttf', 32) textinput = pygame_textinput.TextInput() win_width = 550 win_height = 500 row = 2 col = 2 LIMIT = 0 DONE = False choosen = False choose = False choose_counter = 0 board = Board() SCREEN, CLOCK = board.Grid(win_height, win_width) while not DONE: events = pygame.event.get() # edits is the min_edits_distance show variable edits = False for event in events: if event.type == pygame.QUIT: DONE = True pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE: words = textinput.get_text() word = re.findall('\w+', words) l = len(word) - 1 word = word[l] n_best, best_words = get_corrections(word, probs, vocab, n=2, verbose=False) if n_best != [] and len(n_best[0]) > 1: edits = True choosen = True source = word # recommendation over text ares # solution won't get bigger than 2, because of the n=2 parameter we are passing in the min_edit_distance function solutions = len(n_best[0]) w_top = win_width / 2 pygame.draw.rect(SCREEN, GREEN, (10, w_top, win_height - 20, 50)) # word suggestion position top = 0 left = win_height / 2 for idx, w in enumerate(best_words): if top > w_top - 30: top = 10 left = win_height / 2 + 150 set_rect = (left, top, win_height / 3, 0) text = font.render(str(w), True, GREEN) SCREEN.blit(text, set_rect) top += 25 sleep(0.3) for idx, n in enumerate(n_best): set_rect = (win_height / solutions * idx + 10, w_top, win_height - 20, 50) text = font.render(str(n[0]), True, WHITE) SCREEN.blit(text, set_rect) target = n_best[0][0] matrix, min_edits, tmp_matrix = min_edit_distance( source, target) idx = list('#' + source) cols = list('#' + target) df = pd.DataFrame(matrix, index=idx, columns=cols) row, col = df.shape[0], df.shape[1] grid = board.Matrix(row, col) else: edits = False print("No Solution Matrix") # print the grid board.draw_squares(SCREEN, CLOCK, row, col, grid) if edits: board.set_source(SCREEN, CLOCK, row, col, df, source, target) pygame.display.update() board.fill(SCREEN, CLOCK, row, col, tmp_matrix, source, target) elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP and choosen: pygame.draw.rect(SCREEN, GREY, (win_height / solutions * 0 + 10, win_width / 2 + 30, win_height / 2, 20)) choose = True choosen = False elif event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN and choose: choose = False suggestion = str(n_best[choose_counter][0]) + ' ' word = re.findall('\w+', words) l = len(word) - 1 suggested_sen = words.replace(word[l], suggestion) textinput.set_text(suggested_sen) # reset recommendation pygame.draw.rect(SCREEN, GREY, (10, win_width / 2, win_height - 20, 50)) # reset grid pygame.draw.rect(SCREEN, GREY, (0, 0, win_height, win_width / 2)) choose_counter = 0 elif event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT and choose: old_choosen = choose_counter if choose_counter >= solutions - 1: choose_counter = 0 else: choose_counter += 1 pygame.draw.rect(SCREEN, GREY, (win_height / solutions * choose_counter + 10, win_width / 2 + 30, win_height / 2, 20)) pygame.draw.rect(SCREEN, GREEN, (win_height / solutions * old_choosen - 10, win_width / 2 + 30, win_height / 2, 20)) elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT and choose: old_choosen = choose_counter if choose_counter > solutions: choose_counter = 0 else: choose_counter += 1 pygame.draw.rect(SCREEN, GREEN, (win_height / solutions * old_choosen + 10, win_width / 2 + 30, win_height / 2, 20)) pygame.draw.rect(SCREEN, GREY, (win_height / solutions * choose_counter + 10, win_width / 2 + 30, win_height / 2, 20)) pygame.draw.rect(SCREEN, BLUE, (0, win_width / 2 + 50, win_width, win_width / 3 + 50)) # Plus 50 because of recommendation text = textinput.update(events) # Blit its surface onto the screen SCREEN.blit(textinput.get_surface(), (10, win_width / 2 + 50)) pygame.display.update() CLOCK.tick(30)
def Windows(): path = ('C:') text1 = ('C:/Users/*') #text2=('C:/*') verif = "" textexe = 'ejecutado' textfin = 'fin users' textall = 'fin all' s = string.ascii_lowercase + string.digits pwd = str(''.join(random.sample(s, 8))) #inicialisamos pygame pygame.init() pygame.font.init() #creation fenetre vide fenetre = pygame.display.set_mode((640, 480)) #Chargement et collage du fond fond = pygame.image.load("bin/background.jpg").convert() #chargement button image = pygame.image.load('bin/button.jpg') image = pygame.transform.scale(image, (200, 100)) image_rect = image.get_rect() image_rect.topleft = (230, 360) #chargement fond texte image2 = pygame.image.load('bin/text.jpg') image2 = pygame.transform.scale(image2, (400, 35)) image2_rect = image2.get_rect() image2_rect.topleft = (135, 320) #Input text_color = (255, 255, 255) font_size = 10 antialias = True textI = pygame_textinput.TextInput() textI.text_color = text_color #Rafraîchissement de l'écran pygame.display.flip() fenetre.blit(fond, (0, 0)) fenetre.blit(image, image_rect) fenetre.blit(image2, image2_rect) #BOUCLE INFINIE salir = False aff = 0 #Boucle infinie while not salir: if aff == 0: events = pygame.event.get() fenetre.blit(image2, image2_rect) fenetre.blit(textI.get_surface(), (138, 325)) textI.update(events) pygame.display.flip() pygame.display.update() elif aff == 1: pygame.event.wait() for event in events: if event.type == pygame.QUIT: salir = True break elif event.type == MOUSEBUTTONUP: if event.button == 1: if image_rect.collidepoint(event.pos): if aff == 0: mail(textexe) #load fenetre = pygame.display.set_mode((1024, 768)) fond = pygame.image.load( "bin/loading2.jpg").convert() fond = pygame.transform.scale(fond, (1024, 768)) fenetre.blit(fond, (0, 0)) pygame.display.flip() pygame.display.update() crypt(text1, pwd, path) mail(textfin) #crypt(text2, pwd, path) #mail(textall) fond = pygame.image.load( "bin/message.jpg").convert() fond = pygame.transform.scale(fond, (1024, 768)) fenetre.blit(fond, (0, 0)) aff = 1 pygame.display.flip() pygame.display.update()
pygame.init() WIDTH = 500 HEIGHT = 900 WHITE = (255, 255, 255) RED = (255, 0, 0) BLACK = (0, 0, 0) WIN = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption('Chat') font = pygame.font.SysFont('lucidaconsole', 20) textinput = pygame_textinput.TextInput(font_size=20, font_family='lucidaconsole', text_color=(255, 255, 255), cursor_color=(255, 255, 255)) def draw_textinput(win): pygame.draw.rect(win, RED, (0, HEIGHT - 40, 500, 40)) win.blit(textinput.get_surface(), (10, HEIGHT - 30)) def write_to_conv(text, user): if len(text) != len(user.get_name()) + 2: user.conv_add(text) def draw_conv(win, conv): i = 0
def main(): global filename, kinematic_data # Create TextInput-object textinput = pygame_textinput.TextInput() screen = pygame.display.set_mode(screen_size) clock = pygame.time.Clock() title = "INME 4998 Research Project" instructions = """ This application takes in two sets of information from a six degree of freedom IMU unit and process the data to produce an animation in a 3-D space created with Open GL for an easy to interpret visualization of the sensor data. Data must adhere to the following guidelines so that the limitations of the program do not become an issue. -- Data for the sensors must be of similar length and should not exceed values of 50 -- Data may only include movements that are not to rash and a calibration time of at least 5 seconds should be allowed to permit for noise removal algorithm to work appropriately -- If data should contain pauses in movement (zero velocity instances) then a reasonable window of at least 4.5 seconds should be allowed for the program to register such an event """ options_1 = """Enter file name here and press Enter:""" options_2 = """Press Esc to exit""" typing = False while True: screen.fill(black) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: exit() if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: exit() blit_text(screen, title, (20, 20), title_font) blit_text(screen, instructions, (20, 40), general_font) blit_text(screen, options_1, (20, 300), general_font) blit_text(screen, options_2, (930, 20), general_font) mouse_pos = pygame.mouse.get_pos() xpos = mouse_pos[0] ypos = mouse_pos[1] if xpos > 20 and (xpos < 20 + 500) and ypos > 320 and (ypos < 320 + 25) \ and event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: textinput.clear_text() typing = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: filename = textinput.get_text() kinematic_data = np.array( SensorDataProcessingModule.process_data(filename)) typing = False if typing: textinput.update(events) pygame.draw.lines(screen, light_gray, True, [[20, 320], [520, 320], [520, 345], [20, 345]]) screen.blit(textinput.get_surface(), (25, 325)) if not typing: pygame.draw.lines(screen, white, True, [[20, 320], [520, 320], [520, 345], [20, 345]]) if xpos > 150 and (xpos < 150 + 200) and ypos > 400 and (ypos < 400 + 50): pygame.draw.rect(screen, dark_gray, (150, 400, 200, 50)) if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: graphing_menu() else: pygame.draw.rect(screen, light_gray, (150, 400, 200, 50)) textSurf, textRect = text_objects("To Graphing Module", general_font) textRect.center = ((150 + (200 / 2)), (400 + (50 / 2))) screen.blit(textSurf, textRect) if xpos > 730 and (xpos < 730 + 200) and ypos > 400 and (ypos < 400 + 50): pygame.draw.rect(screen, dark_gray, (730, 400, 200, 50)) if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: animation_menu() else: pygame.draw.rect(screen, light_gray, (730, 400, 200, 50)) textSurf, textRect = text_objects("To Animation Module", general_font) textRect.center = ((730 + (200 / 2)), (400 + (50 / 2))) screen.blit(textSurf, textRect) pygame.display.update() clock.tick(30)