python - Screen resizing pygame -
i trying resize game menu stuck. trying scale size of screen menu has when click on new game. have idea on how fix since cant find else.
import pygame import runpy import webbrowser, os game import * pygame.init() class option: hovered = false def __init__(self, text, pos): self.text = text self.pos = pos self.set_rect() self.draw() def draw(self): self.set_rend() screen.blit(self.rend, self.rect,) def set_rend(self): self.rend = menu_font.render(self.text, true, self.get_color()) def get_color(self): if self.hovered: return (255,255,255) else: return (100,100,100) def set_rect(self): self.set_rend() self.rect = self.rend.get_rect() self.rect.topleft = self.pos def onselect(self): if self.text == "quit": pygame.quit() quit() if self.text == "instructions": webbrowser.open_new("file://" + os.path.realpath("manual.pdf")) **if self.text == "new game": main()** class background(pygame.sprite.sprite): def __init__(self, image_file,): pygame.sprite.sprite.__init__(self) self.image = pygame.image.load(image_file) self.rect = self.image.get_rect() pygame.init() pygame.mixer.music.load('really slow motion - fjord keeper (epic intense uplifting).mp3') pygame.mixer.music.play(-1) background = background('bg.png') screen = pygame.display.set_mode((480, 320)) menu_font = pygame.font.font(none, 40) options = [option("new game", (2, 195)), option("instructions", (2, 245)), option("quit", (2, 295))] while true: pygame.event.pump() screen.fill((0, 0, 0)) screen.blit(background.image, background.rect) ev = pygame.event.get() event in ev: if event.type == pygame.quit: pygame.quit() option in options: if option.rect.collidepoint(pygame.mouse.get_pos()): option.hovered = true else: option.hovered = false if option.hovered: event in ev: if event.type == pygame.mousebuttondown: option.onselect() option.draw() pygame.display.update()
this menu far, i'm trying scale 1300x1000.
i'm on mobile , don't know how code thing i'll type out, k? k....
screen = pygame.display.set_mode((1300, 1300))
put want change. lets put f key. when press f should change screen res set_mode.
Comments
Post a Comment