2016-04-11 17 views
0

Ich machte ein kleines Spiel. Ich habe ein Hauptmenü und es gibt zwei Tasten, wenn jemand die Lerntaste drückt, wird der Bildschirm schwarz gefüllt und ein Bild erscheint auf dem Bildschirm. Ich möchte dieses Bild noch verschieben, obwohl ich in der Tastatur Anweisungen platziere und wie viel es bewegen soll bewegt es sich einfach nicht. Das Bild, das das hi_image nicht bewegt.Bild bewegt sich nicht?

# Import pygame 
import pygame 
# Colors 
RED = (255, 0, 0) 
GREEN = (0, 255, 0) 
BLUE = (0, 0, 255) 
PUPLE = (217, 0, 255) 
BROWN = (105, 84, 62) 
YELLOW = (255, 255, 0) 
ORANGE = (255, 115, 0) 
BLACK = (0, 0, 0) 
WHITE = (255, 255, 255) 
pygame.init() 
clock = pygame.time.Clock() 
# Screen Dynamics 
screen = pygame.display.set_mode([1000,700]) 
#Title of window 
pygame.display.set_caption("Space Victory") 

#Variables before main loop 
color_white = False 
tutorial_white = False 
x = 500 
speed = (5, 5) # Amount of pixels to move every frame (loop). 
moving_up = False 
moving_right = False 
moving_down = False 
moving_left = False 
#Positions of Graphics 
background_position = [0,0] 
start_position = [100,600] 
tutorial_position = [700, 600] 
hi_position = [x,x] 


#The graphics 
background_image = pygame.image.load("spacebackground.png").convert() 
start_image = pygame.image.load("start.png").convert() 
tutorial_image = pygame.image.load("tutorial.png").convert() 
hi_image = pygame.image.load("izzat.png").convert() 
hi_image.set_colorkey(BLACK) 
position = izzat_image.get_rect() 
# Sounds 


# Main loop ___________________________________________________________ 
done = False 

while not done: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      done = True 

    #The main menu 
      #The buttons and background image 
    screen.blit(background_image, background_position) 
    screen.blit(start_image, start_position) 
    screen.blit(tutorial_image,tutorial_position) 

      #If buttons get pressed screen does this. 
    mouse_pos = pygame.mouse.get_pos() 
    white_rect = pygame.Rect(100,600,177,44) 
    tutorial_rect = pygame.Rect(700,600,177,44) 
    if pygame.mouse.get_pressed()[0] and white_rect.collidepoint(mouse_pos): 
     color_white = True 
    if pygame.mouse.get_pressed()[2] and white_rect.collidepoint(mouse_pos): 
     color_white = False 
    if color_white: 
     screen.fill(WHITE) 
    if pygame.mouse.get_pressed()[0] and tutorial_rect.collidepoint(mouse_pos): 
     tutorial_white = True 
    if pygame.mouse.get_pressed()[2] and tutorial_rect.collidepoint(mouse_pos): 
     tutorial_white = False 
    if tutorial_white: 
     screen.fill(BLACK) 
     for event in pygame.event.get(): 
      if event.type == pygame.KEYDOWN: 
       if event.key == pygame.K_UP: 
        x -= 10 
       if event.key == pygame.K_DOWN: 
        x += 10 
       if event.key == pygame.K_RIGHT: 
        x += 10 
       if event.key == pygame.K_LEFT: 
        x -= 10 
     screen.blit(hi_image,hi_position) 

    #Flip the display  
    pygame.display.flip() 
    pygame.time.delay(100) 
    clock.tick(60) 
#Quitting the game 
pygame.quit() 
+0

Sollten Sie nicht verwenden [Sprites] (http://www.pygame.org/docs/ref/sprite.html) aktualisieren? – ppperry

+0

Wäre ich nicht das gleiche Problem, wenn ich Sprites benutze. – HALLOPEOPLE

+0

Ich melde mich bei Ihnen, weil ich jede einzelne Frage, die ich ohne Grund hatte, abstimmen konnte. – HALLOPEOPLE

Antwort

0

Sie aktualisieren nicht die Menüposition, nur x. benötigen Sie die aktuelle Menüposition

if event.type == pygame.KEYDOWN: 
     if event.key == pygame.K_UP: 
      hi_position[1] -= 10 
     if event.key == pygame.K_DOWN: 
      hi_position[1] += 10 
     if event.key == pygame.K_RIGHT: 
      hi_position[0] += 10 
     if event.key == pygame.K_LEFT: 
      hi_position[0] -= 10 
+0

Hat nicht funktioniert .... – HALLOPEOPLE

+0

OK, Sie erhalten die Ereignisse zweimal, nach dem ersten event.get gibt es keine Ereignisse in der Warteschlange. Entfernen Sie die Zeile event.get in diesem Teil und versuchen Sie es erneut: 'if tutorial_white: screen.fill (SCHWARZ) für das Ereignis in pygame.event.get():' – marienbad

Verwandte Themen