Page 1 of 1

Rotating an object with movement of the mouse

Posted: Sat Nov 02, 2019 3:55 am
by Per K Grok


Code of the completed script

Code: Select all

init python:
    import math

    def inCircle(pointX, pointY,gX,gY,distance):
        xDist = pointX-gX
        xDist=math.fabs(xDist)
        yDist = pointY-gY
        yDist=math.fabs(yDist)
        xyDist = (xDist*xDist)+(yDist*yDist)
        if distance >= math.sqrt(xyDist):
            return True
        else:
            return False

default mpos="Outside"
default mX = 0
default mY = 0
default turnDegree =0

image wheel w0="images/wheel00.png"
image wheel w1="images/wheel01.png"
image wheel w2="images/wheel02.png"
image wheel w3="images/wheel03.png"
image wheel w4="images/wheel04.png"
image wheel w5="images/wheel05.png"
image wheel w6="images/wheel06.png"
image wheel w7="images/wheel07.png"
image wheel w8="images/wheel08.png"
image wheel w9="images/wheel09.png"



screen checker():
    text str(mX) + ":" + str(mY)
    text mpos pos (156, 170)
    text str(int(turnDegree)) pos (156, 190)

# The game starts here.

label start:
    scene bg
    show screen checker

label rotater:
    $ mX, mY = renpy.get_mouse_pos()
    if inCircle(320, 240,mX,mY,100)==False:
        $ mpos="Outside"
    elif inCircle(320, 240,mX,mY,100)==True:
        if inCircle(320, 240,mX,mY,50)==False:
            $ mpos="In zone"
        else:
            $ mpos="To far in"

    $ turnDegree = - (math.degrees(math.atan2(mX-320, mY-240)) - 180)

    if mpos=="In zone":
        if turnDegree<36:
            show wheel w0:
                pos (270, 190)
        elif turnDegree<72:
            show wheel w1:
                pos (270, 190)
        elif turnDegree<108:
            show wheel w2:
                pos (270, 190)
        elif turnDegree<144:
            show wheel w3:
                pos (270, 190)
        elif turnDegree<180:
            show wheel w4:
                pos (270, 190)
        elif turnDegree<216:
            show wheel w5:
                pos (270, 190)
        elif turnDegree<252:
            show wheel w6:
                pos (270, 190)
        elif turnDegree<288:
            show wheel w7:
                pos (270, 190)
        elif turnDegree<324:
            show wheel w8:
                pos (270, 190)
        else:
            show wheel w9:
                pos (270, 190)

    else:
        show wheel w0:
            pos (270, 190)

    $renpy.pause (0.02, hard=True)
    jump rotater