2016-04-11 35 views
0

Küçük bir oyun yapıyorum. Bir ana menüm var ve iki düğme var, birisi eğitim düğmesine bastığında ekran Black (Siyah) ve ekranda bir görüntü beliriyorsa. Bu görüntüyü taşımak istediğim halde klavye yönergelerine yerleştirmeme rağmen ne kadar hareket etmesi gerekiyorsa hareket etmiyor. Hi_image öğesini taşımayan resim.Görüntü hareket etmiyor mu?

# 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

sen [sprite] (http://www.pygame.org/docs/ref/sprite.html) kullanılarak olmamalı Gerçek menü konumunu güncellemeniz gerekir? – ppperry

+0

Eğer sprite kullansaydım aynı soruna sahip olmazdım. – HALLOPEOPLE

+0

Size hiçbir sebep göstermediğim her bir soruyu reddetmek için pufu bildiriyorum. – HALLOPEOPLE

cevap

0

menü konumunu, sadece x güncelleme değildir. Eğer

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

Çalışmadı .... – HALLOPEOPLE

+0

Tamam, olayları iki kez alıyorsunuz, ilk event.get'ten sonra kuyrukta hiçbir olay yok. Event.get satırını bu kısımdan kaldırın ve tekrar deneyin: 'eğer tutorial_white: screen.fill (BLACK) pygame.event.get():' içinde etkinlik için – marienbad