hi all. This might be more of a math problem then anything, but i'll give it a shot. I have an idea for a game i am working on, in which the player must advanced thru a level my the means of propelling a cube in the air (across the level and around barriers). The way this is done, is the player clicks on anywhere on the screen, and the cube is propelled in the direction of the angle between the player and the mouse position. here's a picture that attempts to explain it. So pretty much, i have a function return_cube_slope(mpos,obj_pos), that returns the slope for the cube:
def dist(p1,p2): # returns the distance (length of the line) return math.sqrt( (p2-p1)**2+(p2-p1)**2 ) def return_cube_slope(mpos,obj_pos): # velocity for how fast the cube will move velocity = 3 l1 = dist(obj_pos,mpos) # hypotenus l2 = dist(mpos,[mpos,obj_pos]) # adjacent # radians radians = math.asin( l2/l1 ) # angle angle = math.degrees(radians) print angle # actual slope move_x = math.sin(radians)*-velocity move_y = math.cos(radians)*-velocity # return the slope return [move_x,move_y]
Look at it this way: this can only return a value from 0 to 90. how would I go about re-writing my function to have it support angles 0 thru 360?