I've been trying to make my turret rotate correctly, however, when I move my mouse (causing the rotation) the turret rotates above the tankbase, does anyone know an easy way to fix this? Help would be appreciated, please note this is my first attempt at pygame though
Code:
#Rotation
mousex,mousey = pygame.mouse.get_pos()
CalcHeight = cannonBase.y - mousey
CalcWidth = cannonBase.x - mousex
if CalcWidth == 0:
CalcWidth = 1
CalcRot = CalcHeight/float(CalcWidth)
rot = math.degrees(math.atan(CalcRot))
OldCenter = cannonBase.center
rot_image,rot_rect = rot_center(cannon_original, cannonBase, rot)
cannonBaseStretchedImage = rot_image
#Rot_center
def rot_center(image, rect, angle):
"""rotate an image while keeping its center"""
rot_image = pygame.transform.rotate(image, angle)
rot_rect = rot_image.get_rect(center=rect.center)
return rot_image,rot_rect
(my first time posting, please tell me if my post in anyway was hard to read or understand)
*Added pics
Thanks for the fast replys, here is 2 pics (Couldn't uploud via stackoverflow since I was to low of a grade)
http://imageshack.us/a/img266/606/prntscrnpygame.png http://imageshack.us/a/img507/3848/prntscrnpygame2.png
Note that I'm very aware the the rotation is somewhat off, I just wanted to fix the location first, hope we can fix this!