Rotating an object with movement of the mouse

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Rotating an object with movement of the mouse

#1 Post 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


Post Reply

Who is online

Users browsing this forum: No registered users