Python Forum
[PyGame] how to make objects move at a precise amount of time?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] how to make objects move at a precise amount of time?
#1
Hi everybody. I'm quite a beginner in programming. I wrote a code that produces an image moving left and right until it hits the walls and change direction. After each collision to the wall, I want it to move at a different speed and this time should be exact in my work. So for my project, I need it to hit the walls 6 times with inter collision times being 500ms, 500ms, 1000ms, 750ms, and 250ms. My code doesn't produce exact times. What should I do to have these precise timings between collisions?
Here is my code:

import pygame 
pygame.init()
screen=pygame.display.set_mode((800,600)) 

pygame.display.set_caption('visual rhythm')
icon=pygame.image.load("song.png")
pygame.display.set_icon(icon)

playerImg=pygame.image.load('spaceship.png')
playerX=370
playerY=400
def player(x,y):
    screen.blit(playerImg,(int(x),int(y)))

acceleration=[0.5, -0.5 , 1 , -0.7 , 0.3]
count=0
count2=0
while count2<len(acceleration):
    screen.fill((0,255,0))
    playerX+=acceleration[count]
    player(playerX,playerY)
    pygame.display.update()
    if playerX>=746 or playerX<1:
        count+=1
        count2+=1
Reply


Messages In This Thread
how to make objects move at a precise amount of time? - by Zhaleh - Aug-02-2020, 11:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to make an image move in relation to another in PYGAME CompleteNewb 1 2,387 Nov-10-2021, 03:38 PM
Last Post: metulburr
  How can I make all of the background move as opposed to just one platform? HelpMEE 6 3,066 Dec-28-2019, 11:04 PM
Last Post: HelpMEE
  How to make a walljump + move between rooms ? dMn420 1 2,624 Jul-17-2019, 08:49 PM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020