I just made a space-invadish game, where things fall to the ground and you have to avoid crashing, etc.
I succeeded in creating 2 objects falling down simultaneously but I cannot make them doing this with different speed.
This the first object's attributes.
thing_startx = random.randrange(0, display_width-100)
thing_starty = -700
thing_speed = 4
Now it falls by
thing_starty += thing_speed
in each while loop iteration.
For the next object I just added random numbers to the original X and Y coordinates so it gets it different position. (cf function below to create two rect objects if mult == True)
def things_mult(thingx, thingy, thingw, thingh, color, mult, xopt, yopt, wopt, col2):
if mult == False:
pygame.draw.rect(gameDisplay, color, [thingx, thingy, thingw, thingh])
else:
pygame.draw.rect(gameDisplay, color, [thingx, thingy, thingw , thingh])
pygame.draw.rect(gameDisplay, col2, [thingx + xopt, thingy + yopt, thingw + wopt, thingh])
Now, I assume I just need to define
thingy_new = thing_starty + thing_yopt
thingy_new = thingy_new + thing_speed* someconstant #(to make it faster or slower)
Unfortunately, it does not work out like that. Can someone please explain to me why I am somehow shortcoming that simple logic?