lo que sucede es que tengo un rectangulo que al presionar la tecla UP salta 360 grados, pero al llegar al suelo otro rectangulo debe colisionarlo, el asunto es que el empieza a empujarlo sin nisiquiera tocarlo, pero si no oprimo la tecla UP la colisión se hace correctamente. Les agradezco mucho pudieran ayudarme con respecto a esto, estoy aprendiendo sobre las rotaciones y como actualizar imagenes en la pantalla.
Este es el código
import pygame
NEGRO = (0, 0, 0)
BLANCO = (255, 255, 255)
YELLOW = (255, 255, 0)
RED = (255,0,0)
MORADO = (255,0,255)
pygame.init()
clock = pygame.time.Clock()
FPS = 60
pantalla = pygame.display.set_mode([800,600])
pygame.display.set_caption('')
personaje= pygame.Rect(50,470,50,50)
piso = pygame.Rect(0,520,800,20)
torre = pygame.Rect(300,440,100,80)
encimatorre = pygame.Rect(305,433,100,20)
estasaltando=False
rot = 0
rot_speed = 4
juego =True
veltorre=1
velxperso=1
salto=20
image_orig = pygame.Surface((50 , 50))
# for making transparent background while rotating an image
image_orig.set_colorkey(NEGRO)
# fill the rectangle / surface with green color
image_orig.fill(YELLOW)
# creating a copy of orignal image for smooth rotation
image = image_orig.copy()
image.set_colorkey(NEGRO)
# define rect for placing the rectangle at the desired position
rect = image.get_rect()
rect.center = (50,470)
while juego:
clock.tick(FPS)
pantalla.fill(NEGRO)
for evento in pygame.event.get():
if evento.type == pygame.QUIT:
juego=False
if evento.type == pygame.KEYDOWN:
if evento.key == pygame.K_SPACE:
estasaltando=True
if rect.colliderect(torre) and estasaltando==True:
estasaltando= False
if estasaltando:
if salto >= -20 :
old_center = rect.center
rot = (rot - rot_speed) % -360
new_image = pygame.transform.rotate(image_orig, rot)
rect = new_image.get_rect()
rect.center = old_center
rect.y -= salto
salto -=1
pantalla.blit(new_image , rect)
#pygame.display.update()
if rect.colliderect(encimatorre):
rect.bottom=torre.top
salto =20
estasaltando = False
else:
salto = 20
estasaltando = False
if rect.colliderect(torre):
rect.x -=2
torre.x -=veltorre
encimatorre.x-=veltorre
if torre.x==-100:
torre.x=700
encimatorre.x=705
pygame.draw.rect(pantalla,RED,torre)
if not rect.colliderect(encimatorre) and estasaltando == False:
rect.y += 40
if rect.colliderect(piso):
rect.y = 470
if estasaltando== False :
pantalla.blit(image_orig , rect)
pygame.draw.rect(pantalla,RED,encimatorre)
# pygame.draw.rect(pantalla,YELLOW,personaje)
pygame.draw.rect(pantalla,BLANCO,piso)
pygame.display.update()
pygame.display.flip()
pygame.quit()
Este es el pantallazo de la prueba que estoy realizando
Aqui se puede apreciar el rectangulo empuja al otro rectangulo sin ni siquiera tocarlo