This one, but the game 'Kissing booth' which is a game of click and hold throws the following error when I hold the button for the maximum time -
Code: Select all
I'm sorry, but an uncaught exception occurred.
While loading <renpy.display.im.Crop object at 0x00000000054ad0d0>:
File "game/script.rpy", line 304, in script
python:
File "game/script.rpy", line 309, in <module>
winner = ui.interact(suppress_overlay=True, suppress_window=True)
File "game/kissing_booth.rpy", line 55, in render
eileen = renpy.render( temp_meter, width, height, st, at)
error: subsurface rectangle outside surface area.
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 304, in script
python:
File "renpy-8.1.1-sdk\renpy\ast.py", line 1138, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "renpy-8.1.1-sdk\renpy\python.py", line 1122, in py_exec_bytecode
exec(bytecode, globals, locals)
File "game/script.rpy", line 309, in <module>
winner = ui.interact(suppress_overlay=True, suppress_window=True)
File "renpy-8.1.1-sdk\renpy\ui.py", line 299, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "renpy-8.1.1-sdk\renpy\display\core.py", line 3579, in interact
repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, pause_modal=pause_modal, **kwargs) # type: ignore
File "renpy-8.1.1-sdk\renpy\display\core.py", line 4172, in interact_core
self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
File "renpy-8.1.1-sdk\renpy\display\core.py", line 2779, in draw_screen
surftree = renpy.display.render.render_screen(
File "render.pyx", line 492, in renpy.display.render.render_screen
File "render.pyx", line 266, in renpy.display.render.render
File "renpy-8.1.1-sdk\renpy\display\layout.py", line 886, in render
surf = render(child, width, height, cst, cat)
File "render.pyx", line 170, in renpy.display.render.render
File "render.pyx", line 266, in renpy.display.render.render
File "renpy-8.1.1-sdk\renpy\display\layout.py", line 886, in render
surf = render(child, width, height, cst, cat)
File "render.pyx", line 170, in renpy.display.render.render
File "render.pyx", line 266, in renpy.display.render.render
File "renpy-8.1.1-sdk\renpy\display\layout.py", line 886, in render
surf = render(child, width, height, cst, cat)
File "render.pyx", line 170, in renpy.display.render.render
File "render.pyx", line 266, in renpy.display.render.render
File "game/kissing_booth.rpy", line 55, in render
eileen = renpy.render( temp_meter, width, height, st, at)
File "render.pyx", line 170, in renpy.display.render.render
File "render.pyx", line 266, in renpy.display.render.render
File "renpy-8.1.1-sdk\renpy\display\im.py", line 676, in render
return cache.get(self, render=True)
File "renpy-8.1.1-sdk\renpy\display\im.py", line 330, in get
surf = image.load()
File "renpy-8.1.1-sdk\renpy\display\im.py", line 1192, in load
return cache.get(self.image).subsurface((self.x*os, self.y*os,
File "src/pygame_sdl2/surface.pyx", line 642, in pygame_sdl2.surface.Surface.subsurface
error: subsurface rectangle outside surface area.
Windows-10-10.0.22000 AMD64
Ren'Py 8.1.1.23060707
Fall Fair 0.0
Wed Jul 12 16:21:40 2023
Code: Select all
init:
python:
import math
from vec2d import vec2d
class KissingBoothDisplayable(renpy.Displayable):
def __init__(self, time_limit, time_target):
renpy.Displayable.__init__(self)
self.time_limit = time_limit
self.time_target = time_target
# Some displayables we use.
self.panel = Image("images/panel.png")
self.meter = Image("images/meter.png")
self.arrow = Image("images/arrow.png")
self.ctb = Text("Click and Hold to start kissing.", size=36, drop_shadow=(2,2), drop_shadow_color="#C0C0C0")
# The sizes of some of the images.
self.METER_WIDTH = 50.0
self.METER_HEIGHT = 400.0
# Started.
self.started = False
# The time of the past render-frame.
self.oldst = None
self.time_passed = 0.0
def score(self):
return math.fabs(self.time_target-self.time_passed)
# draws the screen.
def render(self, width, height, st, at):
# Figure out the time elapsed since the previous frame.
if self.oldst is None and self.started:
self.oldst = st
if self.started:
self.time_passed = st - self.oldst
# The Render object we'll be drawing into.
r = renpy.Render(width, height)
pixel_height = self.METER_HEIGHT * (self.time_passed/self.time_limit)
target_height = self.METER_HEIGHT - (self.METER_HEIGHT * (float(self.time_target)/float(self.time_limit)))
eileen = renpy.render( self.panel, width, height, st, at)
ew, eh = eileen.get_size()
r.blit(eileen, (width*0.75 - ew / 2, height/2 - eh/ 2))
temp_meter = im.Crop(self.meter,0,self.METER_HEIGHT-pixel_height,self.METER_WIDTH,pixel_height)
eileen = renpy.render( temp_meter, width, height, st, at)
r.blit(eileen, (width*0.75 - self.METER_WIDTH / 2, height/2 + self.METER_HEIGHT/ 2-pixel_height))
meter = renpy.render( self.arrow, width, height, st, at)
ew, eh = meter.get_size()
r.blit(meter, (width*0.75 - self.METER_WIDTH / 2, (height/2) - (self.METER_HEIGHT/ 2) + target_height - (eh / 2)))
# Show the "Click to Begin" label.
if self.started == False:
ctb = renpy.render(self.ctb, 800, 600, st, at)
cw, ch = ctb.get_size()
r.blit(ctb, (width*0.5 - cw / 2, height*0.25 - ch/2))
# Ask that we be re-rendered ASAP, so we can show the next
# frame.
renpy.redraw(self, 0)
# Return the Render object.
return r
# Handles events.
def event(self, ev, x, y, st):
import pygame
# Mousebutton down == start the game by setting stuck to
# false.
if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
self.started = True
if ev.type == pygame.MOUSEBUTTONUP and ev.button == 1 and self.started:
return self.score()
if self.started:
if self.time_passed < self.time_limit:
raise renpy.IgnoreEvent()
else:
return self.score()
else:
raise renpy.IgnoreEvent()
Code: Select all
label kissing_booth:
scene bg gym full
$ customers = 0
$ booth_shifts += 1
label kb_customer:
if alignment > 0 and donations > 20 and booth_shifts == 2 and customers == 4:
hide customer
show robert normal behind table
mc "I didn't expect to see you here."
robert "Everyone needs to do their part for all the clubs."
"Robert leans in:"
robert "Plus, I suspect I will enjoy it."
scene robert_kiss
"..."
jump choose_game
elif alignment < 0 and experiences > 20 and booth_shifts == 2 and customers == 4:
hide customer
show kyle normal behind table
mc "This must be my lucky day!"
kyle "No. Actually I think it is mine."
scene kyle_kiss
"..."
jump choose_game
elif alignment == 0 and tickets > 50 and booth_shifts == 2 and customers == 4:
hide customer
show mark normal behind table
mc "What are you doing here?"
"Mark pushes his glasses up his nose."
mark "Just helping out for the sake of the Drama Club."
mc "For the sake of the Drama Club."
jump choose_game
else:
show customer
show table
python:
customers += 1
tips = 0
randfloat = renpy.random.random() * 2.0 + 0.5
ui.add(KissingBoothDisplayable(2.5,randfloat))
winner = ui.interact(suppress_overlay=True, suppress_window=True)
window show None
python:
if winner < 0.1:
tips = int((0.1 - winner) * 50)
tickets += tips
"You earned [tips] tickets in tips."
if customers < 5:
jump kb_customer
jump choose_game
I don't think there's any use of the vec2d, but here it is
Code: Select all
########################################################################
import operator
import math
class vec2d(object):
"""2d vector class, supports vector and scalar operators,
and also provides a bunch of high level functions
"""
__slots__ = ['x', 'y']
def __init__(self, x_or_pair, y = None):
if y == None:
self.x = x_or_pair[0]
self.y = x_or_pair[1]
else:
self.x = x_or_pair
self.y = y
def __len__(self):
return 2
def __getitem__(self, key):
if key == 0:
return self.x
elif key == 1:
return self.y
else:
raise IndexError("Invalid subscript "+str(key)+" to vec2d")
def __setitem__(self, key, value):
if key == 0:
self.x = value
elif key == 1:
self.y = value
else:
raise IndexError("Invalid subscript "+str(key)+" to vec2d")
# String representaion (for debugging)
def __repr__(self):
return 'vec2d(%s, %s)' % (self.x, self.y)
# Comparison
def __eq__(self, other):
if hasattr(other, "__getitem__") and len(other) == 2:
return self.x == other[0] and self.y == other[1]
else:
return False
def __ne__(self, other):
if hasattr(other, "__getitem__") and len(other) == 2:
return self.x != other[0] or self.y != other[1]
else:
return True
def __nonzero__(self):
return self.x or self.y
# Generic operator handlers
def _o2(self, other, f):
"Any two-operator operation where the left operand is a vec2d"
if isinstance(other, vec2d):
return vec2d(f(self.x, other.x),
f(self.y, other.y))
elif (hasattr(other, "__getitem__")):
return vec2d(f(self.x, other[0]),
f(self.y, other[1]))
else:
return vec2d(f(self.x, other),
f(self.y, other))
def _r_o2(self, other, f):
"Any two-operator operation where the right operand is a vec2d"
if (hasattr(other, "__getitem__")):
return vec2d(f(other[0], self.x),
f(other[1], self.y))
else:
return vec2d(f(other, self.x),
f(other, self.y))
def _io(self, other, f):
"inplace operator"
if (hasattr(other, "__getitem__")):
self.x = f(self.x, other[0])
self.y = f(self.y, other[1])
else:
self.x = f(self.x, other)
self.y = f(self.y, other)
return self
# Addition
def __add__(self, other):
if isinstance(other, vec2d):
return vec2d(self.x + other.x, self.y + other.y)
elif hasattr(other, "__getitem__"):
return vec2d(self.x + other[0], self.y + other[1])
else:
return vec2d(self.x + other, self.y + other)
__radd__ = __add__
def __iadd__(self, other):
if isinstance(other, vec2d):
self.x += other.x
self.y += other.y
elif hasattr(other, "__getitem__"):
self.x += other[0]
self.y += other[1]
else:
self.x += other
self.y += other
return self
# Subtraction
def __sub__(self, other):
if isinstance(other, vec2d):
return vec2d(self.x - other.x, self.y - other.y)
elif (hasattr(other, "__getitem__")):
return vec2d(self.x - other[0], self.y - other[1])
else:
return vec2d(self.x - other, self.y - other)
def __rsub__(self, other):
if isinstance(other, vec2d):
return vec2d(other.x - self.x, other.y - self.y)
if (hasattr(other, "__getitem__")):
return vec2d(other[0] - self.x, other[1] - self.y)
else:
return vec2d(other - self.x, other - self.y)
def __isub__(self, other):
if isinstance(other, vec2d):
self.x -= other.x
self.y -= other.y
elif (hasattr(other, "__getitem__")):
self.x -= other[0]
self.y -= other[1]
else:
self.x -= other
self.y -= other
return self
# Multiplication
def __mul__(self, other):
if isinstance(other, vec2d):
return vec2d(self.x*other.x, self.y*other.y)
if (hasattr(other, "__getitem__")):
return vec2d(self.x*other[0], self.y*other[1])
else:
return vec2d(self.x*other, self.y*other)
__rmul__ = __mul__
def __imul__(self, other):
if isinstance(other, vec2d):
self.x *= other.x
self.y *= other.y
elif (hasattr(other, "__getitem__")):
self.x *= other[0]
self.y *= other[1]
else:
self.x *= other
self.y *= other
return self
# Division
def __div__(self, other):
return self._o2(other, operator.div)
def __rdiv__(self, other):
return self._r_o2(other, operator.div)
def __idiv__(self, other):
return self._io(other, operator.div)
def __floordiv__(self, other):
return self._o2(other, operator.floordiv)
def __rfloordiv__(self, other):
return self._r_o2(other, operator.floordiv)
def __ifloordiv__(self, other):
return self._io(other, operator.floordiv)
def __truediv__(self, other):
return self._o2(other, operator.truediv)
def __rtruediv__(self, other):
return self._r_o2(other, operator.truediv)
def __itruediv__(self, other):
return self._io(other, operator.floordiv)
# Modulo
def __mod__(self, other):
return self._o2(other, operator.mod)
def __rmod__(self, other):
return self._r_o2(other, operator.mod)
def __divmod__(self, other):
return self._o2(other, operator.divmod)
def __rdivmod__(self, other):
return self._r_o2(other, operator.divmod)
# Exponentation
def __pow__(self, other):
return self._o2(other, operator.pow)
def __rpow__(self, other):
return self._r_o2(other, operator.pow)
# Bitwise operators
def __lshift__(self, other):
return self._o2(other, operator.lshift)
def __rlshift__(self, other):
return self._r_o2(other, operator.lshift)
def __rshift__(self, other):
return self._o2(other, operator.rshift)
def __rrshift__(self, other):
return self._r_o2(other, operator.rshift)
def __and__(self, other):
return self._o2(other, operator.and_)
__rand__ = __and__
def __or__(self, other):
return self._o2(other, operator.or_)
__ror__ = __or__
def __xor__(self, other):
return self._o2(other, operator.xor)
__rxor__ = __xor__
# Unary operations
def __neg__(self):
return vec2d(operator.neg(self.x), operator.neg(self.y))
def __pos__(self):
return vec2d(operator.pos(self.x), operator.pos(self.y))
def __abs__(self):
return vec2d(abs(self.x), abs(self.y))
def __invert__(self):
return vec2d(-self.x, -self.y)
# vectory functions
def get_length_sqrd(self):
return self.x**2 + self.y**2
def get_length(self):
return math.sqrt(self.x**2 + self.y**2)
def __setlength(self, value):
length = self.get_length()
self.x *= value/length
self.y *= value/length
length = property(get_length, __setlength, None, "gets or sets the magnitude of the vector")
def rotate(self, angle_degrees):
radians = math.radians(angle_degrees)
cos = math.cos(radians)
sin = math.sin(radians)
x = self.x*cos - self.y*sin
y = self.x*sin + self.y*cos
self.x = x
self.y = y
def rotated(self, angle_degrees):
radians = math.radians(angle_degrees)
cos = math.cos(radians)
sin = math.sin(radians)
x = self.x*cos - self.y*sin
y = self.x*sin + self.y*cos
return vec2d(x, y)
def get_angle(self):
if (self.get_length_sqrd() == 0):
return 0
return math.degrees(math.atan2(self.y, self.x))
def __setangle(self, angle_degrees):
self.x = self.length
self.y = 0
self.rotate(angle_degrees)
angle = property(get_angle, __setangle, None, "gets or sets the angle of a vector")
def get_angle_between(self, other):
cross = self.x*other[1] - self.y*other[0]
dot = self.x*other[0] + self.y*other[1]
return math.degrees(math.atan2(cross, dot))
def normalized(self):
length = self.length
if length != 0:
return self/length
return vec2d(self)
def normalize_return_length(self):
length = self.length
if length != 0:
self.x /= length
self.y /= length
return length
def perpendicular(self):
return vec2d(-self.y, self.x)
def perpendicular_normal(self):
length = self.length
if length != 0:
return vec2d(-self.y/length, self.x/length)
return vec2d(self)
def dot(self, other):
return float(self.x*other[0] + self.y*other[1])
def get_distance(self, other):
return math.sqrt((self.x - other[0])**2 + (self.y - other[1])**2)
def get_dist_sqrd(self, other):
return (self.x - other[0])**2 + (self.y - other[1])**2
def projection(self, other):
other_length_sqrd = other[0]*other[0] + other[1]*other[1]
projected_length_times_other_length = self.dot(other)
return other*(projected_length_times_other_length/other_length_sqrd)
def cross(self, other):
return self.x*other[1] - self.y*other[0]
def interpolate_to(self, other, range):
return vec2d(self.x + (other[0] - self.x)*range, self.y + (other[1] - self.y)*range)
def convert_to_basis(self, x_vector, y_vector):
return vec2d(self.dot(x_vector)/x_vector.get_length_sqrd(), self.dot(y_vector)/y_vector.get_length_sqrd())
def __getstate__(self):
return [self.x, self.y]
def __setstate__(self, dict):
self.x, self.y = dict