def drawInterface(): text.message_display("Power:", 50, colors.RED1, init.gameSize["x"] + init.gameSize["width"] + 30, init.gameSize["y"] + 40) text.message_display("Angle:", 50, colors.RED1, init.gameSize["x"] + init.gameSize["width"] + 30, init.gameSize["y"] + 200) text.message_display("Firing Mode:", 50, colors.RED1, init.gameSize["x"] + init.gameSize["width"] + 70, init.gameSize["y"] + 450) text.button("Linear", init.gameSize["x"] + init.gameSize["width"] + 30, init.gameSize["y"] + 510, 100, 30, colors.BLACK, 30, colors.GRAY, colors.RED1, toLinear) text.button("Ballistic", init.gameSize["x"] + init.gameSize["width"] + 30, init.gameSize["y"] + 560, 100, 30, colors.BLACK, 30, colors.GRAY, colors.RED1, toBallistic) text.button("Guided", init.gameSize["x"] + init.gameSize["width"] + 30, init.gameSize["y"] + 610, 100, 30, colors.BLACK, 30, colors.GRAY, colors.RED1, toGuided) text.button("Crazy", init.gameSize["x"] + init.gameSize["width"] + 30, init.gameSize["y"] + 660, 100, 30, colors.BLACK, 30, colors.GRAY, colors.RED1, toCrazy) text.button("Save", init.gameSize["x"] + init.gameSize["width"] + 30, init.gameSize["y"] + 860, 100, 30, colors.BLACK, 30, colors.GRAY, colors.RED1, saveLoad.save)
def about(): run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_2 or event.key == pygame.K_ESCAPE: # til baka return var.gameDisplay.fill(var.light_grey) # Prenta texta á skjá text.message_to_screen("Um leikinn", var.green, -180, "medium") text.message_to_screen( "Sigmundur Davíð hefur nýverið verið svikinn um formannsembætti", var.black, -120, "small") text.message_to_screen( "flokksins. Hann er þó ekki af baki dottinn, en til þess að sigrast", var.black, -95, "small") text.message_to_screen( "á mótlætinu þarf hann að kljást við forna fjendur sem vilja aðeins eitt:", var.black, -70, "small") text.message_to_screen("fella kónginn.", var.red, -45, "small") text.message_to_screen( "Höfundar eru Friðrik Árni Halldórsson, Guðrún Snorra Þórsdóttir og", var.black, 20, "small") text.message_to_screen( "Sigrún Sayeh Valadbeygi. Leikurinn var hannaður og þróaður í", var.black, 45, "small") text.message_to_screen("áfanganum Þróun hugbúnaðar vorið 2018.", var.black, 70, "small") text.button("Spila leik", 40, 500, 120, 50, var.green, var.light_green, action="play") btn = text.button("Til baka", 640, 20, 120, 50, var.yellow, var.light_yellow, action="back") #text.button("Hætta", 650, 500, 100, 50, var.red, var.light_red, action="quit") if btn == "back": btn = "" return pygame.display.update() var.clock.tick(15)
def game_intro(): # Start menu Background background_image = pygame.image.load("startmenu_background.jpg").convert() background_x = 0 intro = True while intro: for event in pygame.event.get(): if event.type == pygame.QUIT: base.quitgame() break # Start Menu Background Image reset_x = background_x % background_image.get_rect().width base.gameDisplay.blit(background_image, (reset_x - background_image.get_rect().width, 0)) if reset_x < base.display_width: base.gameDisplay.blit(background_image, (reset_x, 0)) background_x -= 1 # Start Menu Buttons text.button(base.gameDisplay, "Start",300, 100, 200, 75, colours.lightgray, colours.gray, base.game_loop) text.button(base.gameDisplay, "Instructions", 300, 200, 200, 75, colours.lightgray, colours.gray, controls.instructions) text.button(base.gameDisplay, "Leaderboard", 300, 300, 200, 75, colours.lightgray, colours.gray, leaderboard.display_leaderboard) text.button(base.gameDisplay, "Quit", 300, 400, 200, 75, colours.lightgray, colours.gray, base.quitgame) pygame.display.update() base.clock.tick(45)
def mainView(self): run = True while run: # leyfa að loka glugga for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_1: # Klæðnaður pass #Level.levelOverview() elif event.key == pygame.K_2: # Upplýsingar pass elif event.key == pygame.K_3 or event.key == pygame.K_ESCAPE: # til baka return elif event.key == pygame.K_q: # hætta pygame.quit() quit() var.gameDisplay.fill(var.light_grey) text.message_to_screen("Leikmaður", var.green, -180, "medium") text.message_to_screen( "Velkomin/nn í leikmannahlutann. Hér getur þú valið fatnað á Sigmund,", var.black, -120, "small") text.message_to_screen( "auk þess sem þú getur skoðað helstu upplýsingar um stöðu þína í leiknum.", var.black, -95, "small") text.message_to_screen("Veldu að neðan hvað þú vilt gera.", var.black, 20, "small") text.button("Klæðnaður", 180, 420, 120, 50, var.green, var.light_green, "outfit") text.button("Upplýsingar", 340, 420, 130, 50, var.green, var.light_green, "info") btn = text.button("Til baka", 510, 420, 120, 50, var.yellow, var.light_yellow, "back") if btn == "back": btn = "" return pygame.display.update() var.clock.tick(15)
def instructions(): display = True box_height = 500 box_width = 400 instruct_image = pygame.image.load("instructions.png").convert() while display: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() break box = pygame.surface.Surface((box_width, box_height)) box.fill(colours.lightgray) # Controls title titleSurf, titleRect = text.text_objects("Instructions", text.smallText, colours.black) titleRect.center = ((box_width / 2), 50) box.blit(titleSurf, titleRect) # Instructions Text instructSurf, instructRect = text.text_objects( "Move your face to catch", text.smallText, colours.black) instructSurf2, instructRect2 = text.text_objects( "the falling apples for points!", text.smallText, colours.black) instructRect.center = ((box_width / 2), 125) instructRect2.center = ((box_width / 2), 175) box.blit(instructSurf, instructRect) box.blit(instructSurf2, instructRect2) # Instructions picture box.blit(instruct_image, (50, 250)) # Back button text.button(base.gameDisplay, "Back", 50, 500, 100, 50, colours.lightgray, colours.gray, startmenu.game_intro) pygame.draw.rect(box, colours.black, (0, 0, box_width, box_height), 3) base.gameDisplay.blit( box, text.center_box(box_width, box_height, base.display_width, base.display_height)) pygame.display.update() pygame.time.Clock().tick(15)
def info(self): run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_1: # Svartur btn = "black" c.changeImg(btn) elif event.key == pygame.K_2: # Rauður btn = "red" c.changeImg(btn) elif event.key == pygame.K_3: # Gulur btn = "yellow" c.changeImg(btn) elif event.key == pygame.K_4 or event.key == pygame.K_ESCAPE: # til baka return elif event.key == pygame.K_q: # hætta pygame.quit() quit() var.gameDisplay.fill(var.light_grey) text.message_to_screen("Upplýsingar", var.green, -180, "medium") text.message_to_screen( "Hér koma fram upplýsingar um stöðu leikmanns í leiknum.", var.black, -120, "small") text.message_to_screen("Þú heitir %s." % self.name, var.black, 0, "small") text.message_to_screen("Þú hefur safnað %d stigum." % self.points, var.black, 30, "small") text.message_to_screen("Þú átt %d líf eftir." % self.countLife, var.black, 60, "small") text.message_to_screen("Þú ert í %s jakka." % self.outfit, var.black, 90, "small") btn = text.button("Til baka", 640, 500, 120, 50, var.yellow, var.light_yellow, "back") if btn == "back": btn = "" return pygame.display.update() var.clock.tick(15)
def levelOverview(): #pygame.display.update() run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_1: # borð 1 Level.level1() if event.key == pygame.K_2: # borð 2 Level.level2() if event.key == pygame.K_3: # borð 3 Level.level3() if event.key == pygame.K_4: # borð 4 Level.level4() if event.key == pygame.K_ESCAPE: # til baka return elif event.key == pygame.K_0: # hætta pygame.quit() quit() var.gameDisplay.fill(var.light_grey) text.message_to_screen("Yfirlitssíða", var.green, -90, "large") text.message_to_screen("Hér getur þú valið um mismunandi borð.", var.black, -10, "small") text.button("Borð 1", 180, 420, 120, 50, var.green, var.light_green, "lvl1") text.button("Borð 2", 340, 420, 120, 50, var.green, var.light_green, "lvl2") text.button("Borð 3", 500, 420, 120, 50, var.green, var.light_green, "lvl3") btn = text.button("Til baka", 640, 20, 120, 50, var.yellow, var.light_yellow, "back") if btn == "back": btn = "" return pygame.display.update() var.clock.tick(15)
def mainView(): run = True while run: # leyfa að loka glugga for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_1: # spila leik Level.levelOverview() elif event.key == pygame.K_2: # leikmaður Level.char() elif event.key == pygame.K_3: # um leikinn Level.about() elif event.key == pygame.K_4 or event.key == pygame.K_ESCAPE: # hætta pygame.quit() quit() var.gameDisplay.fill(var.light_grey) var.gameDisplay.blit(var.mainView_bg, (0, 0)) text.message_to_screen("Velkomin/nn í leikinn", var.green, -250, "medium") text.message_to_screen("Aðförin", var.green, -190, "large") text.button("Spila leik", 40, 500, 120, 50, var.green, var.light_green, "play") text.button("Leikmaður", 240, 500, 120, 50, var.green, var.light_green, "character") text.button("Um leikinn", 440, 500, 120, 50, var.yellow, var.light_yellow, "about") text.button("Hætta", 640, 500, 120, 50, var.red, var.light_red, "quit") pygame.display.update() var.clock.tick(15)
def gameLoop(): pygame.mixer.music.load(path.join(var.snd_dir, var.city_noise)) pygame.mixer.music.set_volume(0.4) pygame.mixer.music.play(loops=-1) # Prepare bgWidth, bgHeight = var.lvl1_background.get_rect().size stageWidth = bgWidth * 3 stagePosX = 0 startScrollingPosX = var.display_width / 2 playerSize = 60 circlePosX = playerSize initialPosX = playerSize initialPosY = 260 gameOver = False isVictory = False count = 0 p = Player(initialPosX, initialPosY, circlePosX, playerSize) c = Cake() # main loop run = True while run: # Leik lokið skjár while gameOver == True: var.gameDisplay.fill(var.light_grey) text.message_to_screen("Leik lokið", var.red, -100, size="large") text.message_to_screen("Þú hlaust %d stig." % (count), var.black, -30) text.message_to_screen("Veldu C til að spila aftur eða Q til að hætta", var.black, 180,) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: pygame.mixer.music.stop() run = False gameOver = False elif event.key == pygame.K_c: return False elif event.key == pygame.K_r: return True while isVictory == True: pygame.mixer.music.stop() var.gameDisplay.fill(var.light_grey) text.message_to_screen("Til hamingju!", var.red, -100, size="large") text.message_to_screen("Göngutúrinn um miðbæ Reykavíkur hefur borið árangur og þú ert nú", var.black, -30,) text.message_to_screen("endurnærður og staðráðinn á ná þér niður á óvinum þínum. ", var.black, -5,) points = 0 text.message_to_screen("Þú hefur safnað %d stigum." % points, var.black, 65) text.button("Næsta borð", 240, 500, 120, 50, var.green, var.light_green, "lvl2") btn = text.button("Til baka", 440, 500, 120, 50, var.yellow, var.light_yellow, "back") if btn == "back": btn = "" return pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: gameExit = True gameOver = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: gameExit = True gameOver = False elif event.key == pygame.K_c: return False elif event.key == pygame.K_r: return True events() k = keys(p, c) p.do_jump() if k == True: k = False break p.posX += p.playerVelocityX c.update() if p.posX > stageWidth - playerSize: p.posX = stageWidth - playerSize if p.posX < 10: p.posX = 10 if p.posX < startScrollingPosX: p.circlePosX = p.posX elif p.posX > stageWidth - startScrollingPosX: p.circlePosX = p.posX - stageWidth + var.display_width else: p.circlePosX = startScrollingPosX stagePosX += -p.playerVelocityX # Draw / render var.gameDisplay.fill(var.black) rel_x = stagePosX % bgWidth var.gameDisplay.blit(var.lvl1_background, (rel_x - bgWidth, 0)) if rel_x < var.display_width: var.gameDisplay.blit(var.lvl1_background, (rel_x, 0)) if p.posX > stageWidth - 100: isVictory = True """if p.posX >= c.posX and p.posX <= c.posX + 30 and p.posY < c.posY: count += 1 print(c.posX)""" score(count) #print(cakeX) c.draw() p.draw() pygame.display.update() var.clock.tick(FPS) var.gameDisplay.fill(var.black)
def display_leaderboard(): display = True box_height = 500 box_width = 400 while display: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() break file = open('highscores.txt', 'r') lines = file.readlines()[1:] # lines is a list of lines of the file. scores = [] for line in lines: sep = line.index(',') name = line.strip()[:sep] score = line.strip()[(sep + 1):] scores.append((score, name)) file.close scores.sort(key=getkey, reverse=True) top_10 = scores[:10] box = pygame.surface.Surface((box_width, box_height)) box.fill(colours.lightgray) # Leaderboard title textSurf, textRect = text.text_objects("Leaderboard", text.smallText, colours.black) textRect.center = ((box_width / 2), 50) box.blit(textSurf, textRect) for i, entry in enumerate(top_10): # Position of names nameSurf, nameRect = text.text_objects(entry[1], text.smallText, colours.black) nameRect.left = 70 #CALCULATE THE SEPERATION LATER nameRect.centery = (30 * i + 100) box.blit(nameSurf, nameRect) # Position of scores scoreSurf, scoreRect = text.text_objects(entry[0], text.smallText, colours.black) scoreRect.right = (box_width - 70) scoreRect.centery = (30 * i + 100) box.blit(scoreSurf, scoreRect) text.button(base.gameDisplay, "Back", 50, 500, 100, 50, colours.lightgray, colours.gray, startmenu.game_intro) pygame.draw.rect(box, colours.black, (0, 0, box_width, box_height), 3) base.gameDisplay.blit( box, text.center_box(box_width, box_height, base.display_width, base.display_height)) pygame.display.update() pygame.time.Clock().tick(15)
def gameLoop(): # Load all game sounds pygame.mixer.music.load(var.space_music) pygame.mixer.music.set_volume(0.4) pygame.mixer.music.play(loops=-1) # Game loop running = True startScreen = True gameOver = False isVictory = False while running: if startScreen: game_intro() startScreen = False global all_sprites, mobs, bullets, powerups all_sprites = pygame.sprite.Group() mobs = pygame.sprite.Group() bullets = pygame.sprite.Group() powerups = pygame.sprite.Group() player = Player() all_sprites.add(player) for i in range(10): newmob() m = Mob() score = 0 while gameOver: pygame.mixer.music.stop() var.gameDisplay.fill(var.light_grey) text.message_to_screen("Ó nei!", var.red, -100, size="large") text.message_to_screen( "Fjendur Sigmundar hafa sigrast á Sigmundi og náð að bola honum", var.black, -30, ) text.message_to_screen( "endanlega í burtu. Réttlætið neyðist til þess að lúta í gras fyrir", var.black, -5, ) text.message_to_screen( "ranglætinu.", var.black, 20, ) pLife = 2 text.message_to_screen( "Þú missir eitt líf og átt nú %d líf eftir." % pLife, var.black, 70, ) text.message_to_screen("Þú hlaust %d stig." % (score), var.black, 95) text.button("Reyna aftur", 240, 500, 120, 50, var.green, var.light_green, "lvl3") btn = text.button("Til baka", 440, 500, 120, 50, var.yellow, var.light_yellow, "back") if btn == "back": btn = "" return pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: gameExit = True gameOver = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: pygame.quit() sys.exit() elif event.key == pygame.K_c: return False elif event.key == pygame.K_r: return True while isVictory == True: pygame.mixer.music.stop() var.gameDisplay.fill(var.light_grey) text.message_to_screen("Til hamingju!", var.red, -100, size="large") text.message_to_screen( "Þér hefur tekist að sigra hrægammana og knýja fram sigur á mótlætinu.", var.black, -30, ) life = 3 text.message_to_screen( "Forsætisráðherrastóllinn hefur verið endurheimtur og kominn til síns rétta", var.black, 15, ) text.message_to_screen( "eigenda. Aðförinni er lokið og framundan bjartir tímar fyrir land og þjóð.", var.black, 40, ) text.message_to_screen("Þú hefur safnað %d stigum." % (score + 10), var.black, 85) text.button("Ljúka leik", 240, 500, 120, 50, var.green, var.light_green, "quit") btn = text.button("Til baka", 440, 500, 120, 50, var.yellow, var.light_yellow, "back") if btn == "back": btn = "" return pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: gameExit = True gameOver = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: gameExit = True gameOver = False elif event.key == pygame.K_c: return False elif event.key == pygame.K_r: return True # keep loop running at the right speed var.clock.tick(FPS) # Process input (events) for event in pygame.event.get(): # check for closing window if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_q: pygame.quit() quit() elif event.key == pygame.K_ESCAPE: pygame.mixer.music.stop() return # Update all_sprites.update() # check to see if a bullet hit a mob hits = pygame.sprite.groupcollide(mobs, bullets, True, True) for hit in hits: score += 20 #- hit.radius random.choice(var.expl_sounds).play() expl = Explosion(hit.rect.center, 'lg') all_sprites.add(expl) if random.random() > 0.90: pow = Pow(hit.rect.center) all_sprites.add(pow) powerups.add(pow) newmob() # check if a mob hit the player hits = pygame.sprite.spritecollide(player, mobs, True, pygame.sprite.collide_circle) for hit in hits: player.shield -= hit.radius * 2 expl = Explosion(hit.rect.center, 'sm') all_sprites.add(expl) newmob() if player.shield <= 0: var.player_die_sound.play() death_explotion = Explosion(player.rect.center, "player") all_sprites.add(death_explotion) player.hide() player.lives -= 1 player.shield = 100 # if the player hit a powerup hits = pygame.sprite.spritecollide(player, powerups, True) for hit in hits: if hit.type == "shield": player.shield += 30 var.shield_sound.play() if player.shield >= 100: player.shield = 100 elif hit.type == "gun": player.powerup() var.power_sound.play() # if the player died and the explotion has finished playing if player.lives == 0 and not death_explotion.alive(): gameOver = True #l.changeLife(gameOver) if score == 1000: isVictory = True # Draw / render var.gameDisplay.fill(var.black) var.gameDisplay.blit(var.lvl2_background, var.lvl2_background_rect) all_sprites.draw(var.gameDisplay) draw_text(var.gameDisplay, str(score), 18, var.display_width / 2, 10) draw_shield_bar(var.gameDisplay, 5, 5, player.shield) draw_lives(var.gameDisplay, var.display_width - 100, 5, player.lives, var.lvl2_p_mini_img) # *after* drawing everything, flip the display pygame.display.flip() pygame.quit()
def gameLoop(): global direction direction = "right" gameExit = False gameOver = False isVictory = False # Upphafsstaðsetning lead_x = var.display_width / 4 lead_y = var.display_height / 2 # Upphafsbreyting lead_x_change = 10 lead_y_change = 0 snakeList = [] snakeLength = 1 randAppleX, randAppleY = randAppleGen() old_r = 0 currentImage = var.img_midfl1 life = 4 while not gameExit: # Leik lokið skjár while gameOver == True: var.gameDisplay.fill(var.light_grey) text.message_to_screen("Ó nei!", var.red, -100, size="large") text.message_to_screen( "Þú misstir stjórn á lestinni með þeim afleingum að hún fór út af sporinu.", var.black, -30, ) text.message_to_screen( "Þú missir eitt líf og átt nú %d líf eftir." % l.countLife, var.black, 15, ) text.message_to_screen("Þú hlaust %d stig." % (snakeLength - 1), var.black, 55) text.button("Reyna aftur", 240, 500, 120, 50, var.green, var.light_green, "lvl2") btn = text.button("Til baka", 440, 500, 120, 50, var.yellow, var.light_yellow, "back") if btn == "back": btn = "" return pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: gameExit = True gameOver = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: gameExit = True gameOver = False elif event.key == pygame.K_c: return False elif event.key == pygame.K_ESCAPE: return True while isVictory == True: var.gameDisplay.fill(var.light_grey) text.message_to_screen("Til hamingju!", var.red, -100, size="large") text.message_to_screen( "Miðflokkslestin er nú stútfull af nýjum og harðduglegum fylgjendum.", var.black, -30, ) life = 3 text.message_to_screen( "Nú er ekkert í vegi fyrir því að bjóða fram í næstu kosningum og leiðin", var.black, 15, ) text.message_to_screen( "að sjálfum forsætisráðherrastólnum greið.", var.black, 40, ) text.message_to_screen( "Þú hefur safnað %d stigum." % (snakeLength - 1), var.black, 95) text.button("Næsta borð", 240, 500, 120, 50, var.green, var.light_green, "lvl3") btn = text.button("Til baka", 440, 500, 120, 50, var.yellow, var.light_yellow, "back") if btn == "back": btn = "" return pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: gameExit = True gameOver = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: gameExit = True gameOver = False elif event.key == pygame.K_c: return False elif event.key == pygame.K_ESCAPE: return True for event in pygame.event.get(): if event.type == pygame.QUIT: gameExit = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: direction = "left" lead_x_change -= block_size lead_y_change = 0 elif event.key == pygame.K_RIGHT: direction = "right" lead_x_change += block_size lead_y_change = 0 elif event.key == pygame.K_UP: direction = "up" lead_y_change -= block_size lead_x_change = 0 elif event.key == pygame.K_DOWN: direction = "down" lead_y_change += block_size lead_x_change = 0 elif event.key == pygame.K_p or event.key == pygame.K_ESCAPE: pause(snakeLength) time.sleep(.5) if lead_x >= var.display_width or lead_x < -10 or lead_y >= var.display_height - border or lead_y < border: gameOver = True l.changeLife(gameOver) lead_x += lead_x_change lead_y += lead_y_change var.gameDisplay.fill(var.dark_grey) #posx, posy, width, height pygame.draw.rect( var.gameDisplay, var.light_grey, [0, border, var.display_width, var.display_height - (2 * border)]) var.gameDisplay.blit(currentImage, (randAppleX, randAppleY)) snakeHead = [] snakeHead.append(lead_x) snakeHead.append(lead_y) snakeList.append(snakeHead) if len(snakeList) > snakeLength: del snakeList[0] for eachSegment in snakeList[:-1]: if eachSegment == snakeHead: gameOver = True l.changeLife(gameOver) snake(block_size, snakeList) score(snakeLength - 1) pygame.display.update() if lead_x > randAppleX and lead_x < randAppleX + AppleThickness or lead_x + block_size > randAppleX and lead_x + block_size < randAppleX + AppleThickness: if lead_y > randAppleY and lead_y < randAppleY + AppleThickness + 10: randAppleX, randAppleY = randAppleGen() snakeLength += 1 currentImage = changeImg() var.snake_sound.play() elif lead_y + block_size > randAppleY and lead_y + block_size < randAppleY + AppleThickness + 10: randAppleX, randAppleY = randAppleGen() snakeLength += 1 currentImage = changeImg() var.snake_sound.play() if snakeLength - 1 == 10: isVictory = True pygame.display.update() var.clock.tick(FPS) pygame.quit() quit()
def setOutfit(self): run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_1: # Svartur btn = "black" c.changeOutfit(btn) elif event.key == pygame.K_2: # Rauður btn = "red" c.changeOutfit(btn) elif event.key == pygame.K_3: # Gulur btn = "yellow" c.changeOutfit(btn) elif event.key == pygame.K_4 or event.key == pygame.K_ESCAPE: # til baka return elif event.key == pygame.K_q: # hætta pygame.quit() quit() var.gameDisplay.fill(var.light_grey) img_big = pygame.transform.scale(c.image, (80, 217)).convert_alpha() var.gameDisplay.blit(img_big, (372, 240)) text.message_to_screen("Veldu klæðnað", var.green, -180, "medium") text.message_to_screen("Hér getur valið lit á jakka Sigmundar.", var.black, -120, "small") btn1 = text.button("Svartur", 180, 500, 120, 50, var.green, var.light_green, action="black") btn2 = text.button("Rauður", 340, 500, 120, 50, var.green, var.light_green, action="red") btn3 = text.button("Gulur", 500, 500, 120, 50, var.green, var.light_green, action="yellow") btn = text.button("Til baka", 640, 20, 120, 50, var.yellow, var.light_yellow, action="back") if btn == "back": btn = "" return elif btn1 == "black": c.changeOutfit(btn1) elif btn2 == "red": c.changeOutfit(btn2) elif btn3 == "yellow": c.changeOutfit(btn3) else: pass pygame.display.update() var.clock.tick(15)
# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ import text,init,colors,pygame,time clock = pygame.time.Clock() while True: init.surface.fill(colors.BLACK) text.button("Start Game" , 650 , 100 , 550 , 100, colors.BLACK , 80 , colors.GRAY , colors.RED1) text.button("Load Game" , 650 , 300 , 550 , 100 , colors.BLACK , 80 , colors.GRAY , colors.RED1) text.button("Leaderboards" , 650 , 500 , 550 , 100 , colors.BLACK , 80 , colors.GRAY , colors.RED1) text.button("Exit",650,700,550,100,colors.BLACK,80,colors.GRAY,colors.RED1) pygame.transform.scale(init.surface, (init.screen[0], init.screen[1])) init.gameDisplay.blit(init.surface, (0, 0)) pygame.display.update() clock.tick(60)