I'm designing a side scrolling computer game for my class, that needs to be handed in soon, however, there is a section of the code that I am struggling with.
I have created an almost Artificial level, where there is a "villain" throwing object at the user, however, I want these objects to be able to follow an angle so that when the sprite moves, a new angle is created to follow, so that the object being thrown essentially "follows" the sprites movement.
This is the code I have so far but I am not sure how to announce the direction the object moves in. I have created the calculation to find the required angle, but do not know how create the line of code needed in order to make the object follow the direction of travel. Not sure if this is relevant, but the object and screen both need to move from right to left.
if player_y < 268: #if the sprite is positioned above the x coordinate where the obstacle is initialised
opposite = player_y - 268
angle = (math.atan(opposite/adjacent))#Inverse tan using the opposite and adjacent angles
o_rect = screen.blit(obstacle,(angle)) #blit obstacle on screen
obstacle_x -= obstacle_speed #allows the obstacle to constantly move to the left
if obstacle_x<-50: #allows net regeneration
obstacle_x = 400 #obstacle regenerated at a x position 400
if player_y > 268: #if the sprite is positioned below the x coordinate where the obstacle is initialised
opposite = 268 - player_y
angle = (math.atan(opposite/adjacent))#Inverse tan using the opposite and adjacent angles
o_rect = screen.blit(obstacle,(angle)) #blit obstacle on screen
obstacle_x -= obstacle_speed #allows the obstacle to constantly move to the left
if obstacle_x<-50: #allows net regeneration
obstacle_x = 400 #obstacle regenerated at a x position 400
if player_y == 268: #if the sprite is positioned directly on the x coordinate
angle = 0
o_rect = screen.blit(obstacle,(angle)) #blit obstacle on screen
obstacle_x -= obstacle_speed #allows the obstacle to constantly move to the left
if obstacle_x<-50: #allows net regeneration
obstacle_x = 400 #obstacle regenerated at a x position 400