How to make an image move diagonally in pygame
<p>I've been taught how to move an image in pygame left, right, up and down. Our next task is to make the image move diagonally, but I don't understand how. This is my code so far: (sorry for the weird names)
Oh and also, I have two images in my code. I was wondering if there was a way that I could move both images without one disappearing on the screen? For example, I can move one image using the arrow keys, but the other image will disappear. I can also move the other image using WASD, but the first image will disappear. Thank you so much!</p>

<pre><code>import pygame

#set up the initial pygame window
pygame.init()
screen = pygame.display.set_mode([900,600])

#set background color
background = pygame.Surface(screen.get_size())
background.fill([204,255,229])
screen.blit(background, (0,0))

#Pull in the image to the program
my_image = pygame.image.load("google_logo.png")
person = pygame.image.load("google_logo2.png")

#copy the image pixels to the screen
left_side = 50
height = 50
diagonal = 100
down_diagonal = 100
screen.blit(my_image, [left_side, height])
screen.blit (person, [diagonal, down_diagonal])

#Display changes
pygame.display.flip()

#set up pygame event loop
running = True
while running:
for event in pygame.event.get():
    print event
    if event.type == pygame.QUIT:
            running = False
    elif event.type == pygame.KEYDOWN:
        if event.key == pygame.K_q:
            print "QUITTING NOW..."
            pygame.time.delay(2000)
            running = False
        if event.key == pygame.K_h:
            print "HELLO!"
            pygame.time.delay(2500)
            running = False
        if event.key == pygame.K_c:
            print "To move the original Google logo, use the arrow keys. To move the second logo, use the WASD keys."
        elif event.key == pygame.K_RIGHT:
            screen.blit(background, (0,0))
            left_side = left_side + 10
            screen.blit(my_image, [left_side, height])
            pygame.display.flip()
        elif event.key == pygame.K_LEFT:
            screen.blit(background, (0,0))
            left_side = left_side - 10
            screen.blit(my_image, [left_side, height])
            pygame.display.flip()
        elif event.key == pygame.K_UP:
            screen.blit(background, (0,0))
            height = height - 10
            screen.blit(my_image, [left_side, height])
            pygame.display.flip()
        elif event.key == pygame.K_DOWN:
            screen.blit(background, (0,0))
            height = height + 10
            screen.blit(my_image, [left_side, height])
            pygame.display.flip()
        elif event.key == pygame.K_w:
            screen.blit(background, (0,0))
            down_diagonal = down_diagonal - 10
            screen.blit(person, [diagonal, down_diagonal])
            pygame.display.flip()
        elif event.key == pygame.K_a:
            screen.blit(background, (0,0))
            diagonal = diagonal - 10
            screen.blit(person, [diagonal, down_diagonal])
            pygame.display.flip()
        elif event.key == pygame.K_s:
            screen.blit(background, (0,0))
            down_diagonal = down_diagonal + 10
            screen.blit(person, [diagonal, down_diagonal])
            pygame.display.flip()
        elif event.key == pygame.K_d:
            screen.blit(background, (0,0))
            diagonal = diagonal + 10
            screen.blit(person, [diagonal, down_diagonal])
            pygame.display.flip()

pygame.quit()
</code></pre>

<p>EDIT: I've revised my code like you said, but it's still not quite working for me. (I apologize again for these questions as I am very new to Python) I would be eternally grateful for help.</p>

<pre><code>import pygame

#set up the initial pygame window
pygame.init()
screen = pygame.display.set_mode([900,600])

#set background color
background = pygame.Surface(screen.get_size())
background.fill([204,255,229])
screen.blit(background, (0,0))

#Pull in the image to the program
my_image = pygame.image.load("google_logo.png")

#copy the image pixels to the screen
screen.blit(my_image, [x, y])

#Display changes
pygame.display.flip()

keys = {'right':False, 'up':False, 'left':False, 'down':False}

#set up pygame event loop
running = True
while running:
for event in pygame.event.get():
    print event
    if event.type == pygame.QUIT:
            running = False
    elif event.type == pygame.KEYDOWN:
        if event.key == pygame.K_q:
            print "QUITTING NOW..."
            pygame.time.delay(2000)
            running = False
        if event.key == pygame.K_h:
            print "HELLO!"
            pygame.time.delay(2500)
            running = False
        if event.key == pygame.K_c:
            print "To move the original Google logo, use the arrow keys. To move the second logo, use the WASD keys."
        if event.key == pygame.K_RIGHT:
            keys['right'] = True
        if event.key == pygame.K_UP:
            keys['up'] = True
        if event.key == pygame.K_DOWN:
            keys['down'] = True
        if event.key == pygame.K_RIGHT:
            keys['right'] = True
        if event.key == pygame.K_LEFT:
            keys['left'] = True
    elif event.type == pygame.KEYUP:
        if event.key == pygame.K_RIGHT:
            keys['right'] = False
        if event.key == pygame.K_UP:
            keys['up'] = False
        if event.key == pygame.K_DOWN:
            keys['down'] = False
        if event.key == pygame.K_LEFT:
            keys['left'] = False

    x = 0
    y = 0

    if keys['right']:
        x += 10
    if keys['up']:
        y += 10
    if keys['down']:
        y -=10
    if keys['left']:
        x -=10

pygame.quit()
</code></pre>

<p>I think you should monitor key down and key up and then do the maths.</p>

<p>First set this :</p>

<pre><code>keys = {'right':False, 'up':False, 'left':False, 'down':False}
</code></pre>

<p>Then on event <code>KEYDOWN</code> set your <code>dict[key]</code> to <code>True</code> :</p>

<pre><code>if event.key == pygame.K_RIGHT:
    keys['right'] = True
if event.key == pygame.K_UP:
    keys['up'] = True
...
</code></pre>

<p>And on event type <code>KEYUP</code> do the same thing but set <code>keys[key]</code> to <code>False</code>.</p>

<p>Then in your event loop :</p>

<pre><code>x = 0
y = 0

if keys['right']:
   x += 10

if keys['up']:
   y += 10

....
</code></pre>

<p>And then move your object using <code>x</code> and <code>y</code>.</p>

<pre><code>screen.blit(my_image, [x, y])
</code></pre>

<p>Now you can keep key pressed, and your image will be moving, and when you release your keys, it'll stop (no need to repeatedly tap keys to move)</p>

<p><strong>EDIT :</strong></p>

<pre><code>import pygame

#set up the initial pygame window
pygame.init()
screen = pygame.display.set_mode([900,600])

#set background color
background = pygame.Surface(screen.get_size())
background.fill([204,255,229])
screen.blit(background, (0,0))

#Pull in the image to the program
my_image = pygame.image.load("google_logo.png")

#copy the image pixels to the screen
screen.blit(my_image, [x, y])

#Display changes
pygame.display.flip()

keys = {'right':False, 'up':False, 'left':False, 'down':False}
x = 0
y = 0
#set up pygame event loop
running = True
while running:
    screen.blit(my_image, [x, y])
    pygame.display.flip()
    for event in pygame.event.get():
        print event
        if event.type == pygame.QUIT:
                running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_q:
                print "QUITTING NOW..."
                pygame.time.delay(2000)
                running = False
            if event.key == pygame.K_h:
                print "HELLO!"
                pygame.time.delay(2500)
                running = False
            if event.key == pygame.K_c:
                print "To move the original Google logo, use the arrow keys. To move the second logo, use the WASD keys."
            if event.key == pygame.K_RIGHT:
                keys['right'] = True
            if event.key == pygame.K_UP:
                keys['up'] = True
            if event.key == pygame.K_DOWN:
                keys['down'] = True
            if event.key == pygame.K_LEFT:
                keys['left'] = True
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT:
                keys['right'] = False
            if event.key == pygame.K_UP:
                keys['up'] = False
            if event.key == pygame.K_DOWN:
                keys['down'] = False
            if event.key == pygame.K_LEFT:
                keys['left'] = False

        x = 0
        y = 0

        if keys['right']:
            x += 10
        if keys['up']:
            y += 10
        if keys['down']:
            y -=10
        if keys['left']:
            x -=10

pygame.quit()
</code></pre>

python image move