background_image_filename = 'sushiplate.jpg'
sprice_image_filename = 'fugu.png'

import pygame
from pygame.locals import *
from sys import exit

pygame.init()

screen = pygame.display.set_mode((640, 480), 0, 32)

background = pygame.image.load(background_image_filename).convert()
sprite = pygame.image.load(sprice_image_filename)

# our clock object
clock = pygame.time.Clock()

x1 = 0.
x2 = 0.

# speed in pixels per second
speed = 250.

frame_no = 0

while True:
    
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()
            
    screen.blit(background, (0, 0))
    screen.blit(sprite, (x1, 50))
    screen.blit(sprite, (x2, 250))
    
    time_passed = clock.tick(30)
    time_passed_seconds = time_passed / 1000.0
    
    distance_moved = time_passed_seconds * speed
    x1 += distance_moved
    
    if (frame_no % 5) == 0:
        distance_moved = time_passed_seconds * speed
        x2 += distance_moved * 5
        
    # if the image goes of the end of the screen, move it back
    if x1 > 640.:
        x1 -= 640.
    if x2 > 640.:
        x2 -= 640.
        
    pygame.display.update()
    frame_no += 1

Could someone please explain to me what going on in the if statement. I don't understand why there is a duplicate line of code in the if statement that was also just a few lines back. The variable frame_no is also getting me. It's already 0 so the remainder of 0 \ 5 is always going to be 0. Thanks for any and all replies.

The if statements are no repeated, theres one if for each sprite.

The if of line 42 moves the second sprite (x2) every 5 frames, or being said every 5 movements of the first sprite (x1)

The frame counter is incremented on line 52.

Cheers and Happy coding

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.