What I want to do : the same thing as vpunch/hpunch, except that the movement is not limited to being horizontal or vertical... it would shake all around. Think Phoenix Wright.
If possible, I'd like this to applicable to either the whole screen (explosions) or to a single sprite (someone freezing? :3). I suppose this means I'll need a transition for "with" and a function for "at".
I tried to make my own function by copying Revolve and the Revolver class. My only real problem so far is that I'd like the function to know where the object already is, ie. not having to give it a specific position.
For example :
Code: Select all
show something at MoveUp(50)
EDIT :
It's not perfect yet (it seems to shake mostly from top-left to bottom-right and it doesn't register anchors ;o;...) but if you want to put some "OBJECTION!" in your future games...
Code: Select all
init:
python:
import math
class Shaker(object):
anchors = {
'top' : 0.0,
'center' : 0.5,
'bottom' : 1.0,
'left' : 0.0,
'right' : 1.0,
}
def __init__(self, start, child, dist, freq):
self.start = [ self.anchors.get(i, i) for i in start ] # start position
self.dist = dist # how many pixels away from the start position it should go (maximum distance)
self.freq = freq # how many "rebounds" (going away and centering back)
self.child = child
def __call__(self, t, sizes=(None, None, None, None)):
xpos = self.start[0]
ypos = self.start[1]
d = 5 # friction
f = self.freq # fréquence de rebonds
# tc : valeur courante passée par la fonction "dampened harmonic"
tc = (d**(-t))*math.sin(t*math.pi*f)
nx = xpos + ((tc) * self.dist) * renpy.random.random()
ny = ypos + ((tc) * self.dist) * renpy.random.random()
return (int(nx), int(ny), 0, 0)
def Shake(start, time, child=None, dist=100.0, freq=25, **properties):
return Motion(Shaker(start, child, dist=dist, freq=freq),
time,
child,
add_sizes=False,
**properties)
#
$ sshake = Shake((0.5,0.5), 1.0, dist=50, freq=15)
#
Code: Select all
show girl with dissolve
cor "Didn't you hear something?"
show girl at Shake((0.5, 0.5), 1.0, dist=50)
with None
$ renpy.pause(2)
h "... Okay, stop shaking now!"
with sshake
h "Gguaah... I'm going to puke!"
Frequency (freq) is what will make it look either like an explosion, a Phoenix Wright shake or a dizzy-spell. 15 is good for a fullscreen explosion shake. 25 or more to emulate Phoenix Wright. Less to make it "woaah, dizzy".
Arg... except the "woah dizzy" doesn't work so well >.>... Will have to fix this ^^;