Nyaatrap

アダルト百合ゲー開発ブログ。一部記事は18歳未満閲覧禁止です。

Home どれぱら デーモンマスタークリス 商用ゲーム フリーゲーム

スポンサーサイト

上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

Ren'py の SnowBlossom を改良


Uploaded with ImageShack.us

ren'py の標準機能である SnowBlossom には左右に揺れる機能がないので、揺れ落ちる木の葉や舞い上がる光球を表現できるように機能を追加した SnowBlossom2 を作りました。コードの98%は標準のものを流用しています。

追加命令は fluttering と flutteringspeed。 前者は左右の揺れ幅をピクセル数で指定、後者はその周期速度です。それ以外の使い方は標準と一緒。コードは続きから。

##############################################
# Particle sprites

init python:

import random, math

class SnowBlossomFactory2(renpy.python.NoRollback):

rotate = False

def __setstate__(self, state):
self.start = 0
vars(self).update(state)
self.init()

def __init__(self, image, count, xspeed, yspeed, border, start, fluttering, flutteringspeed, fast, rotate=False):
self.image = renpy.easy.displayable(image)
self.count = count
self.xspeed = xspeed
self.yspeed = yspeed
self.border = border
self.start = start
self.fluttering = fluttering
self.flutteringspeed = flutteringspeed
self.fast = fast
self.rotate = rotate
self.init()

def init(self):
self.starts = [ random.uniform(0, self.start) for _i in xrange(0, self.count) ] # W0201
self.starts.append(self.start)
self.starts.sort()

def create(self, particles, st):

def ranged(n):
if isinstance(n, tuple):
return random.uniform(n[0], n[1])
else:
return n

if not particles and self.fast:
rv = [ ]

for _i in xrange(0, self.count):
rv.append(SnowBlossomParticle(self.image,
ranged(self.xspeed),
ranged(self.yspeed),
self.border,
st,
self.fluttering,
self.flutteringspeed,
random.uniform(0, 100),
fast=True,
rotate=self.rotate))
return rv


if particles is None or len(particles) < self.count:

# Check to see if we have a particle ready to start. If not,
# don't start it.
if particles and st < self.starts[len(particles)]:
return None

return [ SnowBlossomParticle2(self.image,
ranged(self.xspeed),
ranged(self.yspeed),
self.border,
st,
self.fluttering,
self.flutteringspeed,
random.uniform(0, 100),
fast=False,
rotate=self.rotate) ]

def predict(self):
return [ self.image ]


class SnowBlossomParticle2(renpy.python.NoRollback):

def __init__(self, image, xspeed, yspeed, border, start, fluttering, flutteringspeed, offset, fast, rotate):

# safety.
if yspeed == 0:
yspeed = 1

self.image = image
self.xspeed = xspeed
self.yspeed = yspeed
self.border = border
self.start = start
self.fluttering = fluttering
self.flutteringspeed = flutteringspeed
self.offset = offset
self.rotate = rotate
self.angle = 0


if not rotate:
sh = renpy.config.screen_height
sw = renpy.config.screen_width
else:
sw = renpy.config.screen_height
sh = renpy.config.screen_width


if self.yspeed > 0:
self.ystart = -border
else:
self.ystart = sh + border


travel_time = (2.0 * border + sh) / abs(yspeed)

xdist = xspeed * travel_time

x0 = min(-xdist, 0)
x1 = max(sw + xdist, sw)

self.xstart = random.uniform(x0, x1)

if fast:
self.ystart = random.uniform(-border, sh + border)
self.xstart = random.uniform(0, sw)

def update(self, st):
to = st - self.start
self.angle += self.flutteringspeed

xpos = self.xstart + to * self.xspeed + math.sin(self.angle)*self.fluttering
ypos = self.ystart + to * self.yspeed

if not self.rotate:
sh = renpy.config.screen_height
else:
sh = renpy.config.screen_width

if ypos > sh + self.border:
return None

if ypos < -self.border:
return None

if not self.rotate:
return int(xpos), int(ypos), to + self.offset, self.image
else:
return int(ypos), int(xpos), to + self.offset, self.image

def SnowBlossom2(d,
count=10,
border=50,
xspeed=(20, 50),
yspeed=(100, 200),
start=0,
fluttering=10,
flutteringspeed=0.01,
fast=False,
horizontal=False):

"""
:doc: sprites_extra

The snowblossom effect moves multiple instances of a sprite up,
down, left or right on the screen. When a sprite leaves the screen, it
is returned to the start.

`d`
The displayable to use for the sprites.

`border`
The size of the border of the screen. The sprite is considered to be
on the screen until it clears the border, ensuring that sprites do
not disappear abruptly.

`xspeed`, `yspeed`
The speed at which the sprites move, in the horizontal and vertical
directions, respectively. These can be a single number or a tuple of
two numbers. In the latter case, each particle is assigned a random
speed between the two numbers. The speeds can be positive or negative,
as long as the second number in a tuple is larger than the first.

`start`
The delay, in seconds, before each particle is added. This can be
allows the particles to start at the top of the screen, while not
looking like a "wave" effect.

'fluttering'
The width of fluttering in pixel.

'flutteringspeed'
The speed of fluttering.

`fast`
If true, particles start in the center of the screen, rather than
only at the edges.

`horizontal`
If true, particles appear on the left or right side of the screen,
rather than the top or bottom.
"""

# If going horizontal, swap the xspeed and the yspeed.
if horizontal:
xspeed, yspeed = yspeed, xspeed

return Particles(SnowBlossomFactory2(image=d,
count=count,
border=border,
xspeed=xspeed,
yspeed=yspeed,
start=start,
fluttering=fluttering,
flutteringspeed=flutteringspeed,
fast=fast,
rotate=horizontal))

コメント

コメントの投稿


管理者にだけ表示を許可する

上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。