0

I´ve written a programm code in python using pygame and i dont know why it doesn´t work. I want the program to show the menu and i can switch through the Buttons using "w" and "s". But it doesn´t work. Can anyone help me please? I already tried everything.

import pygame
pygame.init()


WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BLUE = (0, 26, 219)

w = 1280
h = 800
screen = pygame.display.set_mode((w,h),pygame.FULLSCREEN)
clock = pygame.time.Clock()
done = False
marked = 1
while not done:
    start = pygame.font.Font(None, 100)
    option = pygame.font.Font(None, 100)
    help = pygame.font.Font(None, 100)
    end = pygame.font.Font(None, 100)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                done = True
            if event.key == pygame.K_w:
                marked -= 1
            elif event.key == pygame.K_a:
                marked += 1
    if(marked == 0):
        marked = 1
        start = pygame.font.Font(None, 125)
    if(marked == 1):
        start = pygame.font.Font(None, 125)
    if(marked == 2):
        option = pygame.font.Font(None, 125)
    if(marked == 3):
        help = pygame.font.Font(None, 125)
    if(marked == 4):
        end = pygame.font.Font(None, 125)
    if(marked == 5):
        marked = 4
        end = pygame.font.Font(None, 125)

    starttext = start.render("Start the Game",True,BLACK)
    optiontext = option.render("Options",True,BLACK)
    helptext = help.render("Help",True,BLACK)
    endtext = end.render("End the Game",True,BLACK)

    screen.fill(WHITE)
    screen.blit(starttext, [400,200])
    screen.blit(optiontext, [400,300])
    screen.blit(helptext, [400,400])
    screen.blit(endtext, [400,500])
    pygame.display.flip()
    clock.tick(30)

Thanks for answer!

4
  • 2
    Just a note: you're detecting keypresses of a and w, not s and w. Commented Mar 25, 2014 at 18:40
  • You should look to specify which area's aren't working and what you want the code to do. Also if there are any errors then tell us what they are. Commented Mar 25, 2014 at 18:40
  • Thanks thats it Bill. :D Beginner's mistake! Commented Mar 25, 2014 at 18:44
  • 1
    Note: You are re-creating all the Font objects, and rerendering every frame. Commented Mar 26, 2014 at 0:45

1 Answer 1

1

Since you haven't really given a great description of what the errors are I'll just try my best to help. I think the reason your code doesn't do what you intend is because you are looking for K_a as opposed to K_s. Change that up and it should be fine :)

Sign up to request clarification or add additional context in comments.

1 Comment

@user3393830 Oops sorry :) Note to self: Read comments before answering!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.