def Main(from_sett=True): if from_sett: G.cleanup(G.openf) else: p = psutil.Process() G.openf = p.open_files() # Creating the screen screen = P.display.set_mode(G.DEF_DIMENSIONS, 0, 32) #menu_items = ("Basic Typing","Quit") menu_items = ("Basic Typing", "Settings", "Falling Words", "TypeWars", "Type Type Revolution", "Type Vs Monster", "Quit") funcs = { "Basic Typing": BT.typing, "Settings": Settings, "Falling Words": SP.testingSpeed, "TypeWars": TW.type_war, "Type Type Revolution": TTR.typing, "Type Vs Monster": M.typing, "Quit": sys.exit } P.display.set_caption("Game Menu") gm = GameMenu(screen, menu_items, funcs, True, "TYPE TYPE GAMES") gm.run()
def main(self): # Object initialisation # Main Game self.game = Game(self.screen, self.bg_color) # Game Menu menu_items = ('Play Highscore', 'Help', 'Quit') self.gm = GameMenu(self.screen, menu_items, self.bg_color) gatekeeper = None # Start the show while True: if gatekeeper: choice == "Play Highscore" else: choice = self.gm.run() if choice == 'Play Highscore': lvl = lvl_test4 expl = self.game.display_explanation() if expl == 1: sim = self.game.run_simulation(lvl) if not sim: continue game = self.game.run_game(lvl) if not game: continue gatekeeper = self.game.display_score(lvl) else: pass elif choice == 'Help': pass else: sys.exit()
def Settings(): screen = P.display.set_mode(G.DEF_DIMENSIONS, 0, 32) menu_items = ("Set Difficulty", "Back to Main Menu", "Quit") funcs = { "Set Difficulty": Difficulty, "Back to Main Menu": Main, "Quit": sys.exit, } P.display.set_caption("Settings") gm = GameMenu(screen, menu_items, funcs, True, "SETTINGS") gm.run()
def start_menu(self): self.menu = StartMenu() self.menu.start_menu("./images/titulo.png") self.menu.startButton.bind(on_release=self.__removeStartMenu) self.menu.soundControl.bind(on_press=self.__soundOnOff) self.menu.exit.bind(on_press=self.__exit) self.add_widget(self.menu) self.gameMenu = GameMenu() self.gameMenu.startGameMenu() self.gameMenu.playPause.bind(on_press=self.__playPause) self.gameMenu.soundControl.bind(on_press=self.__soundOnOff) self.gameMenu.exit.bind(on_press=self.__exit) self.gameMenu.restart.bind(on_press=self.__restarCurrentLevelMenu) self.endGameMenu = EndGameMenu() self.endGameMenu.restart.bind(on_press=self.__restartCurrentLevel) self.gameOverMenu = GameOverMenu() self.gameOverMenu.restart.bind(on_press=self.__restartCurrentLevelOver)
def Difficulty(): screen = P.display.set_mode(G.DEF_DIMENSIONS, 0, 32) menu_items = ("Set Difficulty - EASY", "Set Difficulty - MEDIUM", "Set Difficulty - HARD", "Back", "Quit") funcs = { "Quit": sys.exit, "Set Difficulty - MEDIUM": G.set_difficulty_medium, "Set Difficulty - HARD": G.set_difficulty_hard, "Back": Settings, "Set Difficulty - EASY": G.set_difficulty_easy } P.display.set_caption("Difficulty") gm = GameMenu(screen, menu_items, funcs, True, "SET DIFFICULTY") gm.run()
class Main(object): def __init__(self, dimensions=DIMENSIONS, bg_color=BLACK, caption="Starburst"): self.dimensions = self.width, self.height = dimensions self.bg_color = bg_color self.caption = caption # Creating the screen self.screen = pygame.display.set_mode((self.width, self.height), 0, 32) pygame.display.set_caption(self.caption) self.clock = pygame.time.Clock() def main(self): # Object initialisation # Main Game self.game = Game(self.screen, self.bg_color) # Game Menu menu_items = ('Play Highscore', 'Help', 'Quit') self.gm = GameMenu(self.screen, menu_items, self.bg_color) gatekeeper = None # Start the show while True: if gatekeeper: choice == "Play Highscore" else: choice = self.gm.run() if choice == 'Play Highscore': lvl = lvl_test4 expl = self.game.display_explanation() if expl == 1: sim = self.game.run_simulation(lvl) if not sim: continue game = self.game.run_game(lvl) if not game: continue gatekeeper = self.game.display_score(lvl) else: pass elif choice == 'Help': pass else: sys.exit()
def testingSpeed(): mainLoop = True gameOver = False screen = P.display.set_mode((G.D_WIDTH, G.D_HEIGHT), 0, 32) gm = GameMenu(screen, [], G.SKY_BLUE) words = G.make_word_list('static/speedWords.txt') P.key.set_repeat(500, 50) #so people can hold a key down clock = P.time.Clock() P.time.set_timer(P.USEREVENT, 16) centerX = G.SCREEN_CENTER[0] centerY = G.TOP_CENTER[1] topY = 0 topLeft = (G.TOP_CENTER[0] - 225, G.TOP_CENTER[1] - 50) topLeft2 = (topLeft[0], topLeft[1] + 25) lanes = [ centerX - 200, centerX - 100, centerX, centerX + 100, centerX + 200 ] # testWord = Word.create_word("test").get_label() thingsToDraw = [] wordsOnScreen = [] # for x in lanes: # thingsToDraw.append((testWord,(x,centerY))) milliCounter = 0 if G.DIFFICULTY_LEVEL == 1: difficulty = 1.5 else: difficulty = G.DIFFICULTY_LEVEL score = 0.0 health = 5 multCount = 0 scoreWord = Word([], "Score: {}".format(score), G.RED, G.MONOSPACE_FONT, 25).get_label() healthWord = Word([], "Health: {}".format(health), G.RED, G.MONOSPACE_FONT, 25).get_label() userStats = [(scoreWord, topLeft), (healthWord, topLeft2)] thingsToDraw.append(userStats) gm.screen.fill(G.BLACK) P.display.flip() currently_typing = None current_word_idx = -1 curr_idx_in_drawlist = 0 first_letters = [] #P.mixer.init() # sound_hit_bottom = P.mixer.Sound("./static/HitsBottom.ogg") # sound_correct_word = P.mixer.Sound("./static/SpeedCorrectWord.ogg") #sound_wrong_letter = P.mixer.Sound("./static/SpeedWrongLetter.ogg") def updateScore(): userStats[0] = (Word([], "Score: {}".format(score), G.RED, G.MONOSPACE_FONT, 25).get_label(), topLeft) thingsToDraw[0] = userStats def updateHealth(): userStats[1] = (Word([], "Health: {}".format(health), G.RED, G.MONOSPACE_FONT, 25).get_label(), topLeft2) thingsToDraw[0] = userStats def drawList(thingsToDraw): scr, (tlx, tly) = thingsToDraw[0][0] hlt, (tlx2, tly2) = thingsToDraw[0][1] G.draw(gm, scr, (tlx, tly)) G.draw(gm, hlt, (tlx2, tly2)) for (letters, (x, y)) in thingsToDraw[1:]: G.draw_letter_list(gm, letters, (x, y)) def moveDown(things): newList = [] for i in range(len(things)): if i != 0: newList.append( (things[i][0], (things[i][1][0], things[i][1][1] + 0.20 * difficulty))) return [things[0]] + newList def checkDrawList( things, curr ): #checks for the word crossing bottom boundary (decrease score etc) for (letters, (x, y)) in things[1:]: if y > G.D_HEIGHT: P.mixer.Sound.play(sound_hit_bottom) if letters == curr: print "currently typing the word that died" currently_typing = None return things[2:] # removes the word from the screen return things def findWordByLetter(c, thingsToDraw): # find the first word in the list of words on screen that starts with given letter for idx, (letters, (x, y)) in enumerate(thingsToDraw): if idx != 0: if letters[0].letter == c: return (letters, idx) return (None, -1) while (mainLoop): for e in P.event.get(): gm.screen.fill(G.BLACK) if e.type == P.QUIT: mainLoop = False break if e.type == P.KEYDOWN: if e.key == P.K_ESCAPE: mainLoop = False break if e.key == P.K_BACKSPACE: if currently_typing is not None: currently_typing[current_word_idx].set_font_color( G.WHITE) current_word_idx -= 1 if current_word_idx < 0: currently_typing = None else: pass # remove the last typed in currently_typing # if it's empty, then set currently_typing to none if e.key == P.K_RETURN: #lets you stop typing a word and start another if currently_typing is not None: while current_word_idx >= 0: currently_typing[current_word_idx].set_font_color( G.WHITE) current_word_idx -= 1 currently_typing = None else: pass elif e.key in range(0, 255): key_name = P.key.name(e.key) if P.key.get_mods() in (1, 2) or P.key.get_mods() in ( 4097, 4098): #checks for left shift and right shift key_name = key_name.upper() if currently_typing is None: # find if there's a word on screen starting with this currently_typing, curr_idx_in_drawlist = findWordByLetter( key_name, thingsToDraw) if currently_typing is not None: # if this word is found, color the first letter green currently_typing[0].set_font_color(G.GREEN) current_word_idx = 0 # check if the word is already done being typed if current_word_idx == len(currently_typing) - 1: # play the sound for completing the word # P.mixer.Sound.play(sound_correct_word) # remove from draw list thingsToDraw.pop(curr_idx_in_drawlist) # remove its first letter from the first letters list first_letters.remove( currently_typing[0].letter) currently_typing = None # if there aren't other things to draw, set the counter to 0 so we spawn a new one if len(thingsToDraw) == 0: milliCounter = 0 score += 10 * difficulty updateScore() multCount += 1 if multCount % 5 == 0: difficulty += .25 pass else: if currently_typing[current_word_idx + 1].letter == key_name: # if the letter is the next in the word currently being typed, color it current_word_idx += 1 currently_typing[current_word_idx].set_font_color( G.GREEN) if current_word_idx == len(currently_typing) - 1: # play the sound for completing the word # P.mixer.Sound.play(sound_correct_word) # remove from draw list thingsToDraw.pop(curr_idx_in_drawlist) # remove its first letter from the first letters list first_letters.remove( currently_typing[0].letter) currently_typing = None if len(thingsToDraw) == 0: milliCounter = 0 score += 10 * difficulty updateScore() multCount += 1 if multCount % 10 == 0: difficulty += .5 # this was the last letter of the word. Remove the word from the list of things to draw else: #P.mixer.Sound.play(sound_wrong_letter) pass # check if this is the next letter in the words # if it is, update and color it # if it's not, don't do it else: pass if milliCounter % (300 / round(difficulty)) == 0 or len(thingsToDraw) == 1: new_word = G.get_random_no_dups(words, first_letters) new_word_obj = Word.create_word(new_word) thingsToDraw.append( (new_word_obj.letters, (G.getRandom(lanes), topY))) first_letters.append(new_word[0]) milliCounter = 0 milliCounter += 1 thingsToDraw = moveDown(thingsToDraw) #changing list size while going through causes error so do outside loop removeFirst = False for i in range(len(thingsToDraw)): if i != 0: (letters, (x, y)) = thingsToDraw[i] if y > G.D_HEIGHT: removeFirst = True # P.mixer.Sound.play(sound_hit_bottom) if letters == currently_typing: print "currently typing the word that died" currently_typing = None break if removeFirst: first_letters = first_letters[1:] thingsToDraw = [ thingsToDraw[0] ] + thingsToDraw[2:] # removes the word from the screen curr_idx_in_drawlist -= 1 removeFirst = False health -= 1 updateHealth() if health == 0: gameOver = True mainLoop = False thingsToDraw = checkDrawList(thingsToDraw, currently_typing) drawList(thingsToDraw) P.display.update() clock.tick(60) while gameOver: gm.screen.fill(G.BLACK) G.draw(gm, Word.create_word("GAME OVER").get_label(), (centerX, centerY)) G.draw(gm, Word.create_word('Press ESCAPE').get_label(), (centerX, centerY - 100)) G.draw(gm, Word.create_word('Final Score: {}'.format(score)).get_label(), (centerX, centerY + 100)) P.display.update() for e in P.event.get(): if e.type == P.QUIT: gameOver = False break if e.type == P.KEYDOWN: if e.key == P.K_ESCAPE: gameOver = False break else: pass
def typing(): loop = True startOver = True screen = P.display.set_mode((G.D_WIDTH, G.D_HEIGHT), 0, 32) gm = GameMenu(screen, [], G.BLACK) screenWord = Word([]) words = G.make_word_list() wordList = map(lambda listword: Word.create_word(listword), words) nextWord = 0 currentWordToType = wordList[nextWord] currentWordLabel = currentWordToType.get_label() currentLetterCount = 0 letterWidth = 0 P.key.set_repeat(500, 50) #so people can hold a key down BG_COLOR = G.BLACK LETTER_COLOR = G.DEF_LETTER_COLOR screenCenter = G.SCREEN_CENTER topCenter = G.TOP_CENTER topLeft = (topCenter[0] - 200, topCenter[1] - 50) topRight = (topCenter[0] + 200, topCenter[1] - 50) centerX = screenCenter[0] centerY = screenCenter[1] def draw_list(thingsToDraw): for (label, (x, y)) in thingsToDraw: G.draw(gm, label, (x, y)) thingsToDraw = [] lastLetter = None xDifferentials = [] P.time.set_timer(P.USEREVENT, 1000) # timer set for each second difficulty_setting = G.DIFFICULTY_LEVEL if difficulty_setting == 1: timeCount = 60 timeText = "1:00" elif difficulty_setting == 2: timeCount = 30 timeText = "0:30" else: timeCount = 15 timeText = "0:15" score = G.SCORE gm.screen.fill(BG_COLOR) # set initial background thingsToDraw.append((currentWordLabel, topCenter)) thingsToDraw.append((Word.create_word(timeText).get_label(), topRight)) thingsToDraw.append( (Word.create_word('Score: {}'.format(score)).get_label(), topLeft)) draw_list(thingsToDraw) P.display.flip() while loop: currentWordToType = wordList[nextWord] currentWordLabel = currentWordToType.get_label() thingsToDraw[0] = (currentWordLabel, topCenter) for e in P.event.get(): gm.screen.fill(BG_COLOR) if e.type == P.QUIT: # exit the loop if input is quit loop = False startOver = False break if e.type == P.USEREVENT: timeCount -= 1 if timeCount >= 10: timeText = "0:{}".format(timeCount) elif timeCount >= 0: timeText = "0:0{}".format(timeCount) else: gm.screen.fill(BG_COLOR) thingsToDraw = [] thingsToDraw.append( (Word.create_word('Game Over!').get_label(), screenCenter)) thingsToDraw.append((Word.create_word( 'Press Any Key To Continue').get_label(), (centerX, centerY - 100))) thingsToDraw.append((Word.create_word( 'Your Score was {}'.format(score)).get_label(), (centerX, centerY + 100))) draw_list(thingsToDraw) P.display.update() loop = False sleep(0.5) break timeWord = Word.create_word(timeText) thingsToDraw[1] = (timeWord.get_label(), topRight) draw_list(thingsToDraw) P.display.update() if e.type == P.KEYDOWN: # on keypress if e.key in G.SPECIAL_KEYS: # for special key presses if e.key == P.K_ESCAPE: # exit loop if escape loop = False startOver = False break if e.key == P.K_RETURN: # clear word typed so far if enter is pressed screenWord.clear() #label = screenWord.get_label() currentLetterCount = 0 xDifferentials = [] thingsToDraw = thingsToDraw[0:3] draw_list(thingsToDraw) P.display.update() if e.key == P.K_BACKSPACE: # remove letter from the word being typed if backspace #if currentLetterCount <= 0: # currentLetter = 0 score -= 10 thingsToDraw[2] = (Word.create_word( 'Score: {}'.format(score)).get_label(), topLeft) screenWord.remove_letter() #label = screenWord.get_label() offsetCenter = centerX + ( (letterWidth * (screenWord.length - 1)) / 2) if xDifferentials != []: xDifferentials = xDifferentials[:-1] if xDifferentials != []: letterWidth = xDifferentials[ len(xDifferentials) - 1] else: letterWidth = 0 xDifferentials = map(lambda x: x - letterWidth, xDifferentials) thingsToDraw = thingsToDraw[0:3] for pos, letter in enumerate( screenWord.get_letters()): thingsToDraw.append( (letter.get_label(), (offsetCenter - xDifferentials[pos], centerY - 25))) draw_list(thingsToDraw) P.display.update() else: thingsToDraw = thingsToDraw[0:3] for pos, letter in enumerate( screenWord.get_letters()): thingsToDraw.append( (letter.get_label(), (screenCenter - xDifferentials[pos], centerY - 25))) draw_list(thingsToDraw) P.display.update() currentLetterCount -= 1 if currentLetterCount < 0: currentLetterCount = 0 # if e.key == P.K_SPACE: # screenWord.add_letter(Letter(' ')) # currentLetter = screenWord.get_letters()[currentLetterCount] # letterWidth = currentLetter.get_width() # xDifferentials = map(lambda x: x + letterWidth,xDifferentials) # currentLetterCount += 1 # xDifferentials.append(0) # if (screenWord.equals(currentWordToType)): # nextWord += 1 # currentLetterCount = 0 # letterWidth = 0 # xDifferentials = [] # screenWord.clear() # if nextWord == len(wordList): # G.draw(gm,Word.create_word('You Win!').get_label(),screenCenter) # G.draw(gm,Word.create_word('Press Any Key To Continue').get_label(),(centerX,centerY-100)) # P.display.update() # loop = False # break # offsetCenter = centerX + ((letterWidth * (screenWord.length - 1)) / 2) # thingsToDraw = thingsToDraw[0:3] # for pos,letter in enumerate(screenWord.get_letters()): # thingsToDraw.append((letter.get_label(),(offsetCenter - xDifferentials[pos],centerY-25))) # thingsToDraw[0] = (wordList[nextWord].get_label(),topCenter) # draw_list(thingsToDraw) # P.display.update() else: pass elif e.key in range(0, 255): if currentLetterCount == len(currentWordToType.get_text()): screenWord.clear() xDifferentials = [] nextWord += 1 currentLetterCount = 0 letterWidth = 0 thingsToDraw = thingsToDraw[0:3] draw_list(thingsToDraw) P.display.update() else: keyName = P.key.name(e.key) if P.key.get_mods() in (1, 2) or P.key.get_mods() in ( 4097, 4098): #checks for left shift and right shift keyName = keyName.upper() if currentLetterCount < currentWordToType.length and \ keyName == wordList[nextWord].get_text()[currentLetterCount]: LETTER_COLOR = G.GREEN score += 10 thingsToDraw[2] = (Word.create_word( 'Score: {}'.format(score)).get_label(), topLeft) else: LETTER_COLOR = G.RED score -= 10 thingsToDraw[2] = (Word.create_word( 'Score: {}'.format(score)).get_label(), topLeft) screenWord.add_letter(Letter(keyName, LETTER_COLOR)) currentLetter = screenWord.get_letters( )[currentLetterCount] letterWidth = currentLetter.get_width() xDifferentials = map(lambda x: x + letterWidth, xDifferentials) currentLetterCount += 1 xDifferentials.append(0) if (screenWord.equals(currentWordToType)): score += 30 thingsToDraw[2] = (Word.create_word( 'Score: {}'.format(score)).get_label(), topLeft) nextWord += 1 currentLetterCount = 0 letterWidth = 0 xDifferentials = [] screenWord.clear() if nextWord == len(wordList): G.draw( gm, Word.create_word('You Win!').get_label(), screenCenter) G.draw( gm, Word.create_word( 'Press Any Key To Continue').get_label( ), (centerX, centerY - 100)) P.display.update() loop = False break offsetCenter = centerX + ( (letterWidth * (screenWord.length - 1)) / 2) thingsToDraw = thingsToDraw[0:3] for pos, letter in enumerate(screenWord.get_letters()): thingsToDraw.append( (letter.get_label(), (offsetCenter - xDifferentials[pos], centerY - 25))) thingsToDraw[0] = (wordList[nextWord].get_label(), topCenter) draw_list(thingsToDraw) P.display.update() while (startOver): sleep(0.5) for e in P.event.get(): if e.type == P.QUIT: # exit the loop if input is quit startOver = False if e.type == P.KEYDOWN: startOver = False
def typing(): global time_count, time_text, game_round, player1, player2, endGame, player, gameOver loop = True startOver = True screen = P.display.set_mode((G.D_WIDTH,G.D_HEIGHT),0,32) gm = GameMenu(screen,[],G.BLACK) screenWord = Word([]) words = G.make_word_list() #change to certain list based on difficulty level wordList = map(lambda listword: Word.create_word(listword),words) nextWord = 0 currentWordToType = wordList[nextWord] currentWordLabel = currentWordToType.get_label() currentLetterCount = 0 letterWidth = 0 P.key.set_repeat(500,50) #so people can hold a key down BG_COLOR = G.BLACK LETTER_COLOR = G.DEF_LETTER_COLOR screenCenter = G.SCREEN_CENTER topCenter = G.TOP_CENTER topLeft = (topCenter[0]-200,topCenter[1]-50) topRight = (topCenter[0]+200,topCenter[1]-50) centerX = screenCenter[0] centerY = screenCenter[1] def draw_list(thingsToDraw): for (label,(x,y)) in thingsToDraw: G.draw(gm,label,(x,y)) thingsToDraw = [] lastLetter = None xDifferentials = [] P.time.set_timer(P.USEREVENT, 1000) # timer set for each second set_time() gm.screen.fill(BG_COLOR) # set initial background thingsToDraw.append((currentWordLabel,topCenter)) thingsToDraw.append((Word.create_word(time_text).get_label(),topRight)) thingsToDraw.append((Word.create_word('Health: {}'.format(player.health)).get_label(),topLeft)) thingsToDraw.append((Word.create_word(player.label).get_label(),(topCenter[0]-200,topCenter[1]-80))) draw_list(thingsToDraw) P.display.flip() while loop: currentWordToType = wordList[nextWord] currentWordLabel = currentWordToType.get_label() thingsToDraw[0] = (currentWordLabel,topCenter) for e in P.event.get(): gm.screen.fill(BG_COLOR) if e.type == P.QUIT: # exit the loop if input is quit loop = False startOver = False endGame = True break if e.type == P.USEREVENT: time_count -= 1 if time_count >= 10: time_text = "0:{}".format(time_count) elif time_count >= 0: time_text = "0:0{}".format(time_count) else: gm.screen.fill(BG_COLOR) thingsToDraw2 = [] if (game_round % 2 == 0): thingsToDraw2.append((Word.create_word('Round {} Over!'.format(game_round/2)).get_label(),screenCenter)) else: thingsToDraw2.append((Word.create_word("Next Player's Turn!").get_label(),screenCenter)) thingsToDraw2.append((Word.create_word('Press Enter To Continue').get_label(),(centerX,centerY-100))) thingsToDraw2.append((Word.create_word('You typed {} words'.format(player.index)).get_label(),(centerX,centerY+150))) if (game_round % 2 == 0): diff1 = player1.index - player2.index diff2 = player2.index - player1.index if (diff1 > diff2): player2.modifyHealth(diff2) thingsToDraw2.append((Word.create_word('Player 1 won the round').get_label(),(centerX,centerY+30))) if (diff2 > diff1): player1.modifyHealth(diff1) thingsToDraw2.append((Word.create_word('Player 2 won the round').get_label(),(centerX,centerY+30))) player1.resetIndex() player2.resetIndex() thingsToDraw2.append((Word.create_word('Your Health is {}'.format(player.health)).get_label(),(centerX,centerY+100))) game_round += 1 if (game_round % 2 == 0): player = player2 else: player = player1 draw_list(thingsToDraw2) P.display.update() loop = False sleep(0.5) break timeWord = Word.create_word(time_text) thingsToDraw[1] = (timeWord.get_label(),topRight) draw_list(thingsToDraw) P.display.update() if e.type == P.KEYDOWN: # on keypress if e.key in G.SPECIAL_KEYS: # for special key presses if e.key == P.K_ESCAPE: # exit loop if escape loop = False startOver = False endGame = True break if e.key == P.K_RETURN: # clear word typed so far if enter is pressed screenWord.clear() #label = screenWord.get_label() currentLetterCount = 0 xDifferentials = [] thingsToDraw = thingsToDraw[0:4] draw_list(thingsToDraw) P.display.update() if e.key == P.K_BACKSPACE: # remove letter from the word being typed if backspace #if currentLetterCount <= 0: # currentLetter = 0 thingsToDraw[2] = (Word.create_word('Health: {}'.format(player.health)).get_label(),topLeft) screenWord.remove_letter() #label = screenWord.get_label() offsetCenter = centerX + ((letterWidth * (screenWord.length - 1)) / 2) if xDifferentials != []: xDifferentials = xDifferentials[:-1] if xDifferentials != []: letterWidth = xDifferentials[len(xDifferentials)-1] else: letterWidth = 0 xDifferentials = map(lambda x: x - letterWidth, xDifferentials) thingsToDraw = thingsToDraw[0:4] for pos,letter in enumerate(screenWord.get_letters()): thingsToDraw.append((letter.get_label(),(offsetCenter-xDifferentials[pos],centerY-25))) draw_list(thingsToDraw) P.display.update() else: thingsToDraw = thingsToDraw[0:4] for pos,letter in enumerate(screenWord.get_letters()): thingsToDraw.append((letter.get_label(),(screenCenter-xDifferentials[pos],centerY-25))) draw_list(thingsToDraw) P.display.update() currentLetterCount -= 1 if currentLetterCount < 0: currentLetterCount = 0 else: pass elif e.key in range(0,255): if currentLetterCount == len(currentWordToType.get_text()): screenWord.clear() xDifferentials = [] nextWord += 1 currentLetterCount = 0 letterWidth = 0 thingsToDraw = thingsToDraw[0:4] draw_list(thingsToDraw) P.display.update() else: keyName = P.key.name(e.key) if P.key.get_mods() in (1,2) or P.key.get_mods() in (4097,4098): #checks for left shift and right shift keyName = keyName.upper() if currentLetterCount < currentWordToType.length and \ keyName == wordList[nextWord].get_text()[currentLetterCount]: LETTER_COLOR = G.GREEN thingsToDraw[2] = (Word.create_word('Health: {}'.format(player.health)).get_label(),topLeft) else: LETTER_COLOR = G.RED player.modifyHealth(-5) thingsToDraw[2] = (Word.create_word('Health: {}'.format(player.health)).get_label(),topLeft) if (player.health == 0): gm.screen.fill(BG_COLOR) thingsToDraw3 = [] thingsToDraw3.append((Word.create_word('Game Over!').get_label(),screenCenter)) thingsToDraw3.append((Word.create_word('Press Enter To Continue').get_label(),(centerX,centerY-100))) thingsToDraw3.append((Word.create_word('Your Health is 0').get_label(),(centerX,centerY+100))) if (player.label == "Player 1"): thingsToDraw3.append((Word.create_word("Player 2 Won!").get_label(),(centerX,centerY+30))) else: thingsToDraw3.append((Word.create_word("Player 1 Won!").get_label(),(centerX,centerY+30))) draw_list(thingsToDraw3) P.display.update() loop = False endGame = True sleep(0.5) break screenWord.add_letter( Letter(keyName,LETTER_COLOR) ) currentLetter = screenWord.get_letters()[currentLetterCount] letterWidth = currentLetter.get_width() xDifferentials = map(lambda x: x + letterWidth,xDifferentials) currentLetterCount += 1 xDifferentials.append(0) if (screenWord.equals(currentWordToType)): player.modifyIndex(1) thingsToDraw[2] = (Word.create_word('Health: {}'.format(player.health)).get_label(),topLeft) nextWord += 1 currentLetterCount = 0 letterWidth = 0 xDifferentials = [] screenWord.clear() if nextWord == len(wordList): G.draw(gm,Word.create_word('You Win!').get_label(),screenCenter) G.draw(gm,Word.create_word('Press Enter Key To Continue').get_label(),(centerX,centerY-100)) P.display.update() loop = False endGame = True break offsetCenter = centerX + ((letterWidth * (screenWord.length - 1)) / 2) thingsToDraw = thingsToDraw[0:4] for pos,letter in enumerate(screenWord.get_letters()): thingsToDraw.append((letter.get_label(),(offsetCenter - xDifferentials[pos],centerY-25))) thingsToDraw[0] = (wordList[nextWord].get_label(),topCenter) draw_list(thingsToDraw) P.display.update() while(startOver): sleep(0.5) for e in P.event.get(): if e.type == P.QUIT: # exit the loop if input is quit startOver = False endGame = True if e.type == P.KEYDOWN: if e.key == P.K_RETURN: startOver = False if e.key == P.K_ESCAPE: # exit loop if escape endGame = True if (player1.health == 0): player = player1 gameOver = True if (player2.health == 0): player = player2 gameOver = True if gameOver: gm.screen.fill(BG_COLOR) thingsToDraw3 = [] thingsToDraw3.append((Word.create_word('Game Over!').get_label(),screenCenter)) thingsToDraw3.append((Word.create_word('Press Enter To Continue').get_label(),(centerX,centerY-100))) thingsToDraw3.append((Word.create_word('Your Health is 0').get_label(),(centerX,centerY+100))) if (player.label == "Player 1"): thingsToDraw3.append((Word.create_word("Player 2 Won!").get_label(),(centerX,centerY+30))) else: thingsToDraw3.append((Word.create_word("Player 1 Won!").get_label(),(centerX,centerY+30))) draw_list(thingsToDraw3) P.display.update() sleep(0.5)
def main(): menuTitle = GameMenu(0, ["My Gobang"]) menu = GameMenu(0, ["Human VS. AI", option1], ["Human VS. Human", option2], ["AI VS. AI", option3], ["AI VS. AI(200 Times)", option4], ["Self battle(200 Times)", option5], ["Settings", option6], ["Exit", option7]) # Title menuTitle.set_font(pygame.font.Font(None, 60)) menuTitle.center_at(270, 150) menuTitle.set_highlight_color((255, 255, 255)) # Menu settings menu.center_at(270, 320) menu.set_highlight_color((255, 255, 255)) menu.set_normal_color((200, 200, 255)) clock = pygame.time.Clock() while True: clock.tick(30) # Events events = pygame.event.get() # Update Menu menu.update(events) # Handle quit event for e in events: if e.type == pygame.QUIT: pygame.quit() return # Draw screen.blit(background, (0, 0)) menu.draw(screen) menuTitle.draw(screen) pygame.display.flip()
def settings(): # Settings Menu Text # Title for Option Menu menuTitle = GameMenu(0, ["AI LEVEL"]) menu = GameMenu(0 if search_depth == 1 else 1, ["Normal", level_option1], ["Hard", level_option2]) info = GameMenu(0, ["PRESS ESC TO RETURN"]) # Settings Title Font color, aligment, and font type menuTitle.set_font(pygame.font.Font(None, 60)) menuTitle.center_at(270, 150) menuTitle.set_highlight_color((255, 255, 255)) # Menu settings menu.center_at(270, 250) menu.set_highlight_color((255, 255, 255)) menu.set_normal_color((200, 200, 255)) # Settings info Font color, aligment, and font type info.center_at(270, 320) info.set_highlight_color((255, 255, 255)) info.set_normal_color((200, 200, 255)) clock = pygame.time.Clock() keepGoing = True while keepGoing: clock.tick(30) # Events events = pygame.event.get() # Update Menu menu.update(events) # Handle input for event in events: if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: keepGoing = False elif event.key == pygame.K_RETURN: keepGoing = False elif event.type == QUIT: keepGoing = False # Draw screen.blit(background, (0, 0)) menuTitle.draw(screen) menu.draw(screen) info.draw(screen) pygame.display.flip()
def gameOver(result, displayResult): # Game over screen menuTitle = GameMenu(0, ["GAME OVER"]) menuTitle.set_font(pygame.font.Font(None, 80)) menuTitle.center_at(270, 200) menuTitle.set_highlight_color((255, 255, 255)) # Game result if result == ChessboardState.BLACK: tips = "Winner is black" global black_win_count black_win_count += 1 elif result == ChessboardState.WHITE: tips = "Winner is white" global white_win_count white_win_count += 1 else: tips = "Tie" global tie_count tie_count += 1 resInfo = GameMenu(0, [tips]) resInfo.set_font(pygame.font.Font(None, 60)) resInfo.center_at(270, 270) resInfo.set_highlight_color((255, 0, 0)) info = GameMenu(0, ["Press ESC back to menu"]) info.set_font(pygame.font.Font(None, 40)) info.center_at(270, 320) info.set_highlight_color((255, 255, 255)) keepGoing = displayResult while keepGoing: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: keepGoing = False elif event.type == pygame.QUIT: keepGoing = False menuTitle.draw(screen) resInfo.draw(screen) info.draw(screen) pygame.display.flip()
class MyGame(Widget): menu = ObjectProperty(None) gameMenu = ObjectProperty(None) player = ObjectProperty(None) boss = ObjectProperty(None) endGameMenu = ObjectProperty(None) gameOverMenu = ObjectProperty(None) #Sons musicaTema = ObjectProperty(None) gameOverSound = ObjectProperty(None) gameWinSound = ObjectProperty(None) gamePause = True currentTime = NumericProperty(0) timeGame = NumericProperty(30) soundOn = True temaPlaying = False niveis = [] nivelCorrente = 0 if (android): android.init() android.accelerometer_enable(True) android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE) def start_menu(self): self.menu = StartMenu() self.menu.start_menu("./images/titulo.png") self.menu.startButton.bind(on_release=self.__removeStartMenu) self.menu.soundControl.bind(on_press=self.__soundOnOff) self.menu.exit.bind(on_press=self.__exit) self.add_widget(self.menu) self.gameMenu = GameMenu() self.gameMenu.startGameMenu() self.gameMenu.playPause.bind(on_press=self.__playPause) self.gameMenu.soundControl.bind(on_press=self.__soundOnOff) self.gameMenu.exit.bind(on_press=self.__exit) self.gameMenu.restart.bind(on_press=self.__restarCurrentLevelMenu) self.endGameMenu = EndGameMenu() self.endGameMenu.restart.bind(on_press=self.__restartCurrentLevel) self.gameOverMenu = GameOverMenu() self.gameOverMenu.restart.bind(on_press=self.__restartCurrentLevelOver) def __restartCurrentLevelOver(self, instance): if (self.gameOverSound.state == "play"): self.gameOverSound.stop() if (self.gameWinSound.state == "play"): self.gameWinSound.stop() self.player = Player() self.player.pos = [200, 10] self.lobo = Boss() self.niveis[self.nivelCorrente] = None self.niveis[self.nivelCorrente] = Nivel1( player=self.player, backgroundImage="./images/fundo.png", boss=self.lobo) self.niveis[0].soundOn = self.soundOn self.lobo.pos = [self.niveis[0].tamanhoFase / 3, 10] self.add_widget(self.niveis[0]) self.add_widget(self.player) self.add_widget(self.lobo) self.add_widget(self.gameMenu) self.remove_widget(self.gameOverMenu) self.gamePause = False def __restarCurrentLevelMenu(self, instance): self.remove_widget(self.niveis[self.nivelCorrente]) self.remove_widget(self.gameMenu) self.remove_widget(self.player) self.remove_widget(self.lobo) self.__restartCurrentLevel(instance) def __restartCurrentLevel(self, instance): if (self.gameOverSound.state == "play"): self.gameOverSound.stop() if (self.gameWinSound.state == "play"): self.gameWinSound.stop() self.player = Player() self.lobo = Boss() self.player.pos = [200, 10] self.niveis[self.nivelCorrente] = None self.niveis[self.nivelCorrente] = Nivel1( player=self.player, backgroundImage="./images/fundo.png", boss=self.lobo) self.niveis[0].soundOn = self.soundOn self.lobo.pos = [self.niveis[0].tamanhoFase / 3, 10] self.add_widget(self.niveis[0]) self.add_widget(self.player) self.add_widget(self.lobo) self.add_widget(self.gameMenu) self.remove_widget(self.endGameMenu) self.gamePause = False def __startNiveis(self): self.player = Player() self.lobo = Boss() self.player.pos = [200, 10] self.niveis.append( Nivel1(player=self.player, backgroundImage="./images/fundo.png", boss=self.lobo)) self.lobo.pos = [self.niveis[0].tamanhoFase / 3, 10] self.niveis[0].soundOn = self.soundOn self.add_widget(self.niveis[0]) self.add_widget(self.player) self.add_widget(self.lobo) def __removeStartMenu(self, instance): self.gamePause = False self.remove_widget(self.menu) self.__startNiveis() self.add_widget(self.gameMenu) def __addStartMenu(self, instance): self.add_widget(self.menu) def __playPause(self, instance): if (self.gamePause is True): self.gamePause = False self.gameMenu.playPause.background_normal = \ "./images/botoes/start0.png" else: self.gamePause = True self.gameMenu.playPause.background_normal = \ "./images/botoes/pause0.png" def __soundOnOff(self, instance): if (self.soundOn is True): self.soundOn = False self.gameMenu.soundControl.background_normal = \ "./images/botoes/mute.png" if (self.menu): self.menu.soundControl.background_normal = \ "./images/botoes/mute.png" else: self.soundOn = True self.gameMenu.soundControl.background_normal = \ "./images/botoes/sound.png" if (self.menu): self.menu.soundControl.background_normal = \ "./images/botoes/sound.png" def __exit(self, instance): import sys sys.exit() def on_touch_move(self, touch): if (touch.y < Window.height * 0.8 - 100): if (self.player): self.player.jump() def updateNivel(self, dt): self.niveis[self.nivelCorrente].soundOn = self.soundOn self.niveis[self.nivelCorrente].update() self.gameMenu.labelPonto.text = "Points: " + \ str(self.niveis[self.nivelCorrente].pontos) self.gameMenu.labelTime.text = "Time: " + \ str(self.niveis[self.nivelCorrente].timeGame) self.currentTime += 1 if (self.currentTime >= 60): self.currentTime = 0 self.niveis[self.nivelCorrente].timeGame -= 1 if (self.niveis[self.nivelCorrente].fimNivel): if (self.soundOn): self.gameWinSound.play() self.gamePause = True self.remove_widget(self.niveis[self.nivelCorrente]) self.remove_widget(self.gameMenu) self.remove_widget(self.player) self.remove_widget(self.lobo) self.endGameMenu.label.text = "Points: " \ + str(self.niveis[self.nivelCorrente].pontos) self.add_widget(self.endGameMenu) if (self.niveis[self.nivelCorrente].timeGame <= 0 or self.niveis[self.nivelCorrente].nivelPerdido is True): if (self.soundOn): self.gameOverSound.play() self.gamePause = True self.remove_widget(self.niveis[self.nivelCorrente]) self.remove_widget(self.gameMenu) self.remove_widget(self.player) self.remove_widget(self.lobo) self.gameOverMenu.label.text = "Points: " \ + str(self.niveis[self.nivelCorrente].pontos) self.add_widget(self.gameOverMenu) def __movingPlayerAndroid(self): if (android): accelerometer = android.accelerometer_reading() if (accelerometer[1] < -3 and self.player.jumping is False): self.player.velocity_x = -PLAYER_VX0 elif (accelerometer[1] > 3 and self.player.jumping is False): self.player.velocity_x = PLAYER_VX0 else: if (self.player.jumping is False): self.player.velocity_x = 0 def update(self, dt): if (android): if android.check_pause(): if (self.musicaTema.state == "play"): self.musicaTema.stop() android.wait_for_resume() if (self.soundOn is True): if (self.musicaTema.state == "stop"): self.musicaTema.play() self.musicaTema.volume = 0.3 else: if (self.musicaTema.state == "play"): self.musicaTema.stop() self.musicaTema.volume = 0.3 if (self.gamePause is not True): self.__movingPlayerAndroid() self.updateNivel(dt)
def enterTwoPlayerMode (self): self.gameMenu = GameMenu(self.programWindow, "Human", "Human", "") self.stop()
def typing(): line_color = G.WHITE P.mixer.music.load('static/sounds/The_Clubbing_of_Isaac.mp3') P.mixer.music.play(0) loop = True screen = P.display.set_mode((G.D_WIDTH, G.D_HEIGHT), 0, 32) gm = GameMenu(screen, [], G.BLACK) bkg = Background(BG_PATH, [0, 0]) topCenter = G.TOP_CENTER topLeft = (topCenter[0] - 200, topCenter[1] - 50) topRight = (topCenter[0] + 200, topCenter[1] - 50) BG_COLOR = G.BLACK LETTER_COLOR = G.WHITE score = G.SCORE # determine whether a given letter is within the desired band def draw_list(surfs): # is this at the correct level of indentation? for (label, (x, y)) in surfs: G.draw(gm, label, (x, y)) thingsToDraw = [] centerX = G.SCREEN_CENTER[0] centerY = G.TOP_CENTER[1] difficulty_setting = G.DIFFICULTY_LEVEL P.time.set_timer(P.USEREVENT, 1000) # timer set for each second #rounds are 60 seconds no matter what timeCount = 60 timeText = "1:00" gm.screen.fill(BG_COLOR) screen.blit(bkg.image, bkg.rect) thingsToDraw.append( (Word.create_word('Score: {}'.format(score)).get_label(), topLeft)) # display the current score in the top left thingsToDraw.append((Word.create_word(timeText).get_label(), topRight)) initial_letter = spawn_letter() current_letters = [initial_letter] thingsToDraw.append((initial_letter.get_label(), initial_letter.position)) draw_list(thingsToDraw) P.draw.line(screen, line_color, (0, band_pos), (G.D_WIDTH, band_pos), 4) P.display.flip() reset_velocity() thingsToDraw = [] counter = 0 line_counter = 0 spawn_letter_interval = 15 + 60 / G.DIFFICULTY_LEVEL # letters will spawn at a constant speed clock = P.time.Clock() while loop: clock.tick(FRAMERATE) gm.screen.fill(BG_COLOR) screen.blit(bkg.image, bkg.rect) thingsToDraw.append( (Word.create_word('Score: {}'.format(score)).get_label(), topLeft)) # display the current score in the top left thingsToDraw.append((Word.create_word(timeText).get_label(), topRight)) counter += 1 # this counter will be used to determine when to spawn a new letter line_counter += 1 # this counter will be used to determine when to revert the line color to white if (counter % spawn_letter_interval == 0 ): # when the interval between letter spawning has passed new_letter = spawn_letter() current_letters.append(new_letter) if (line_counter % (FRAMERATE / 4) == 0): line_color = G.WHITE #see if update time if (counter % FRAMERATE == 0): timeCount -= 1 if timeCount >= 10: timeText = "0:{}".format(timeCount) elif timeCount >= 0: timeText = "0:0{}".format(timeCount) else: thingsToDraw = [] thingsToDraw.append( (Word.create_word('Game Over!').get_label(), topCenter)) # thingsToDraw.append((Word.create_word('Press Any Key To Continue').get_label(),(centerX,centerY-100))) thingsToDraw.append((Word.create_word( 'Your Score was {}'.format(score)).get_label(), (centerX, centerY + 100))) draw_list(thingsToDraw) P.display.update() P.mixer.music.stop() loop = False #would like to figure out why sleep sleep(5.0) break for e in P.event.get(): if e.type == P.QUIT: P.mixer.music.stop() loop = False break # if e.type == P.USEREVENT: # code taken (and modified) from basic typing game if e.type == P.KEYDOWN: # if the user has pressed a key #user wants to leave this place if e.key == P.K_ESCAPE: P.mixer.music.stop() loop = False break #if ASCII, basically elif e.key in range(0, 255): keyName = P.key.name(e.key) #if we decide to throw in capital letters use this #if P.key.get_mods() in (1,2) or P.key.get_mods() in (4097,4098): #checks for left shift and right shift #keyName = keyName.upper() is_in_band = False for character in current_letters: if character.letter == keyName: if within_range(character): line_color = (0, 255, 0) # green line_counter = 0 current_letters.remove(character) score += 10 is_in_band = True break if not is_in_band: # deduct 5 points if there is no matching letter within the band line_color = (255, 0, 0) # red line_counter = 0 if score - 1 >= 0: score -= 1 else: score = 0 #special non-ESC character entered, deduct points for mistyping else: if score - 1 >= 0: score -= 1 else: score = 0 #deduct points for letters than have fallen below range for x in current_letters: if (x.pos_y > band_pos + band_range): if score >= 5: score -= 5 else: score = 0 #only consider letters that did not fall below band updated_list = [ x for x in current_letters if (x.pos_y <= band_pos + band_range) ] current_letters = updated_list #add all letters with updated positons to thingsToDraw for i in range(len(current_letters)): update_position(current_letters[i]) current_letters[i].set_label() thingsToDraw.append( (current_letters[i].get_label(), current_letters[i].position)) draw_list(thingsToDraw) P.draw.line(screen, line_color, (0, band_pos), (G.D_WIDTH, band_pos), 4) P.display.update() thingsToDraw = []
def typing(): bkg = Image(BG_PATH, [0, 0]) wand = Image(BG_WAND, [290, 180]) wand.scale(0.1) r = 200 polarWordPos = math.pi / 2.0 loop = True startOver = True screen = P.display.set_mode((G.D_WIDTH, G.D_HEIGHT), 0, 32) BG_COLOR = G.BLACK gm = GameMenu(screen, [], G.BLACK) #Initialize screenwords to eventually fill words into words = G.make_word_list() wordList = map(lambda listword: Word.create_word(listword), words) currentLetterCount = [] #Get 4 words at a time screenCenter = G.SCREEN_CENTER screenWord = Word([]) topCenter = G.TOP_CENTER topLeft = (topCenter[0] - 200, topCenter[1] - 50) topRight = (topCenter[0] + 200, topCenter[1] - 50) LETTER_COLOR = G.DEF_LETTER_COLOR fieldMsLabel = [] centerX = screenCenter[0] centerY = screenCenter[1] def draw_list(thingsToDraw): for (label, (x, y)) in thingsToDraw: G.draw(gm, label, (x, y)) thingsToDraw = [] lastLetter = None xDifferentials = [] P.time.set_timer(P.USEREVENT, 10) difficulty_setting = G.DIFFICULTY_LEVEL timeCount = 60.00 numMon = 1 << ((difficulty_setting + 1) / 2) fieldMsLabel = FieldMonsters(wordList, numMon) subtimeCount = 6.00 originaltimeCount = subtimeCount timeText = "1:00" score = G.SCORE gm.screen.fill(BG_COLOR) # set initial background #This will be our tracker to see which letter count that all our words are on # currentLetterCount[i] = 0 thingsToDraw.append((Word.create_word(timeText).get_label(), topRight)) thingsToDraw.append((Word.create_word('').get_label(), topRight)) monsters = [(i.word.get_label(), i.get_pos(r)) for i in fieldMsLabel.get_field()] draw_list(thingsToDraw + monsters) P.display.flip() scalar = 0 while loop: # P.display.update() for e in P.event.get(): if e.type == P.QUIT: # exit the loop if input is quit loop = False startOver = False break if e.type == P.USEREVENT: screen.blit(bkg.image, bkg.rect) screen.blit(wand.image, wand.rect) timeCount -= 0.01 subtimeCount -= 0.01 scalar += 1 monsters = [(i.word.get_label(), i.get_pos(r * subtimeCount / (originaltimeCount * i.rand_speed()))) for i in fieldMsLabel.get_field()] draw_list(thingsToDraw + monsters) P.display.update() if scalar % 100 == 0: timeWord = Word.create_word(timeText[:4]) thingsToDraw[0] = ((timeWord.get_label(), topRight)) draw_list(thingsToDraw + monsters) P.display.update() if timeCount >= 10: timeText = "0:{}".format(timeCount) elif timeCount >= 0: timeText = "0:0{}".format(timeCount) else: gm.screen.fill(BG_COLOR) screen.blit(bkg.image, bkg.rect) thingsToDraw = [] thingsToDraw.append( (Word.create_word('Game Over! You Win').get_label(), screenCenter)) thingsToDraw.append((Word.create_word( 'Press Escape To Continue').get_label(), (centerX, centerY - 100))) thingsToDraw.append((Word.create_word( 'Your Score was {}'.format(score)).get_label(), (centerX, centerY + 100))) draw_list(thingsToDraw) P.display.update() loop = False sleep(0.5) break if subtimeCount < 0.01: gm.screen.fill(BG_COLOR) screen.blit(bkg.image, bkg.rect) thingsToDraw = [] thingsToDraw.append( (Word.create_word('Game Over! You Lose').get_label(), screenCenter)) thingsToDraw.append((Word.create_word( 'Press Escape To Continue').get_label(), (centerX, centerY - 100))) thingsToDraw.append((Word.create_word( 'Your Score was {}'.format(score)).get_label(), (centerX, centerY + 100))) draw_list(thingsToDraw) P.display.update() loop = False sleep(0.5) break if e.type == P.KEYDOWN: if e.key in G.SPECIAL_KEYS: # for special key presses if e.key == P.K_ESCAPE: # exit loop if escape loop = False startOver = False break #IF PRESS KEY THAT IS NOT A SPECIAL KEY (AKA JUST A REGULAR KEY) elif e.key in range(0, 255): #CHECKS TO SEE IF THE LETTER COUNT OF THE WORD TYPED IN = THE LETTER COUNT OF THE WORD WE HAVE TO TYPE keyName = P.key.name(e.key) #Simply updates the key name to uppercase if shift + key is pressed if P.key.get_mods() in (1, 2) or P.key.get_mods() in ( 4097, 4098): #checks for left shift and right shift keyName = keyName.upper() LETTER_COLOR_CENTER = G.RED #Will check all monsters in fieldmonsters length = len(fieldMsLabel.get_field()) tried = fieldMsLabel.tryLetter(keyName) if tried: score += 10 LETTER_COLOR_CENTER = G.GREEN #Also, now that we have updated, we want to check if the len is 0. If it is 0, then we will +30 on the sore #And also detach the wordmonster from the list if len(fieldMsLabel.get_field()) < length: score += 30 monsters = [ (i.word.get_label(), i.get_pos(r * subtimeCount / (originaltimeCount * i.rand_speed()))) for i in fieldMsLabel.get_field() ] thingsToDraw[1] = ((Letter( keyName, LETTER_COLOR_CENTER).get_label(), (320, 240))) screen.blit(bkg.image, bkg.rect) screen.blit(wand.image, wand.rect) draw_list(thingsToDraw + monsters) P.display.update() if len(fieldMsLabel.fieldMs) == 0: subtimeCount = originaltimeCount del fieldMsLabel fieldMsLabel = FieldMonsters(wordList, numMon) random_speed = [ random.uniform(0.5, 1.00) for i in fieldMsLabel.get_field() ] while (startOver): sleep(0.5) for e in P.event.get(): if e.type == P.QUIT: # exit the loop if input is quit startOver = False if e.type == P.KEYDOWN and e.key == P.K_ESCAPE: startOver = False