Some pygame issues

Marcos Eimil Pardo marcos at nordesia.org
Mon Dec 22 09:37:04 CET 2003


 >
 >class dot:
 >	x = 317.5
 >	y = 207.5
 >	width = 15
 >	height = 15
 >	#dir = +1
 >
# You can uncoment
     dir = 1
# *or* add a variable called speed so it has clearer meaning
     speed = 1

 >
 >	#Collision detection
 >	if leftpadd.y > 430:
 >		leftpadd.y = 430
 >		
 >	if rightpadd.y > 430:
 >		rightpadd.y = 430
 >			
 >	if leftpadd.y < 0:
 >		leftpadd.y = 0
 >		
 >	if rightpadd.y < 0:
 >		rightpadd.y = 0
 >	
 >	#Dot Motion
 >	dot.x = dot.x+1
 >
# Replace the previous line with, so dot will move along direction
           dot.x = dot.x + dot.dir
# or with the variable speed
           dot.x = dot.x + dot.speed

 >
 >	#Dot collision HAVING ISSUES HERE!
 >	if dot.x + dot.width > rightpadd.x:
 >		dot.x = dot.x-1

#Think that dot is not allways colliding pad so you can't do this, when dot 
collides it should change the sign of it's velocity:
         dot.dir = -dot.dir
# Or
         dot.speed = -dot.speed
		
 >	if dot.x + dot.width < leftpadd.x:
 >		dot.x = dot.x+1
 >	
# The same for the left pad
         dot.dir = -dot.dir
# Or
         dot.speed = -dot.speed

		
 >	#Refresh the screen and pump the event qeue.
 >	pygame.display.flip()
 >	pygame.event.pump()
 >

I see you haven't take in account the y-axis movement, it works the same way but 
you should have a 2-component speed, so, the class dot will look like that:
class dot:
	x = 317.5
	y = 207.5
	width = 15
	height = 15
	speedx = +1
	speedy = +1


Greets, Marcos.

(And merry xmas :)






More information about the Python-list mailing list