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()
Sollten Sie nicht verwenden [Sprites] (http://www.pygame.org/docs/ref/sprite.html) aktualisieren? – ppperry
Wäre ich nicht das gleiche Problem, wenn ich Sprites benutze. – HALLOPEOPLE
Ich melde mich bei Ihnen, weil ich jede einzelne Frage, die ich ohne Grund hatte, abstimmen konnte. – HALLOPEOPLE