Please improve the Ren'Py game code below to make the card in the player's hand less…
- User
Please improve the Ren'Py game code below to make the card in the player's hand less jumpy when the cursor is close the edges of the card.
# Player Hand vbox: align (0.5, 0.9) spacing 10 fixed: xsize 800 ysize 200 pos (0.5, 0) anchor (0.5, 1) $ sorted_hand = sorted(enumerate(player.hand), key=lambda x: 1 if x[0] == hovered_card_index else 0) $ card_count = len(player.hand) $ center_position = (card_count - 1) / 2.0 $ max_height_adjustment = min(20, 5 + card_count * 6) if card_count > 1 else 0 for i_card in sorted_hand: $ i, card = i_card $ base_angle = -20 + (40.0 / max(1, card_count - 1)) * i if card_count > 1 else 0 $ base_xpos = 250 - (card_count * 30) + (i * 120) if card_count > 1 else 250 if card_count <= 1: $ height_adjustment = 0 else: $ normalized_pos = (i - center_position) / max(1, center_position) $ height_adjustment = int(max_height_adjustment * (1 - (normalized_pos ** 4))) $ base_ypos = 150 - height_adjustment button: id "player_hand_card_{i}" xsize 180 ysize 252 pos (base_xpos, base_ypos) anchor (0.5, 1) at transform: rotate base_angle transform_anchor True on hover: linear 0.1 rotate 0 linear 0.1 ypos 150 linear 0.1 yoffset -30 on idle: linear 0.2 rotate base_angle linear 0.2 ypos base_ypos linear 0.2 yoffset 0 if selected_card == i: action [SetVariable("active_targeting_session", None), SetVariable("selected_card", None)] else: action [SetVariable("selected_card", i), Function(player.initiate_play_card, i), SetVariable("selected_creature", None),] hovered SetVariable("hovered_card_index", i) unhovered SetVariable("hovered_card_index", None) use card_preview(card, selected=(selected_card == i), playable=player.can_play_card(i), hoverable=(hovered_card_index == i), size=(180, 252))screen card_preview(card, selected=False, playable=False, size=(150, 210), hoverable=False, on_field=False, no_enlarge=False): default hover_state = [False] if on_field or no_enlarge: $ enlarged = None else: $ enlarged = selected or (hoverable and hover_state[0]) if selected and not hover_state[0]: $ zoom_factor = 1.2 if enlarged else 1.0 else: $ zoom_factor = 1.8 if enlarged else 1.0 $ actual_size = (int(size[0] * zoom_factor), int(size[1] * zoom_factor)) $ offset_x = -((actual_size[0] - size[0]) // 2) if enlarged else 0 $ offset_y = -((actual_size[1] - size[1]) // 0.74) if enlarged else 0 $ outline_thickness = max(3, int(size[0] * 0.02 * zoom_factor)) $ outline_color = "#00ff00aa" if playable else ("#ffff00aa" if selected else None) fixed: xysize actual_size xoffset offset_x yoffset offset_y if hoverable: mousearea: area (0, 0, actual_size[0], actual_size[1]) unhovered SetDict(hover_state, 0, False) hovered [SetDict(hover_state, 0, True), SetVariable("hovered_card", card)] if outline_color: add Solid(outline_color) xsize (actual_size[0] + outline_thickness*2) ysize (actual_size[1] + outline_thickness*2) xpos (-outline_thickness) ypos (-outline_thickness) # Card image if on_field and isinstance(card, CreatureCard): add "images/[card.card_id]-creature.png" xysize actual_size else: add "images/[card.card_id].png" xysize actual_size # Mana cost if not on_field: fixed: xpos int(size[0] * 0.02 * zoom_factor) ypos int(size[0] * 0.02 * zoom_factor) xsize int(size[0] * 0.25 * zoom_factor) ysize int(size[0] * 0.25 * zoom_factor) text "[card.mana]" size int(size[0] * 0.15 * zoom_factor) xalign 0.5 yalign 0.5 color "#FFFFFF" outlines [(int(outline_thickness/2), "#000000", 0, 0)] # Attack value if isinstance(card, CreatureCard): $ attack_color = "#FFFFFF" if hasattr(card, "original_attack"): if card.attack < card.original_attack: $ attack_color = "#FF4444" elif card.attack > card.original_attack: $ attack_color = "#44FF44" if on_field: fixed: xpos int(size[0] * 0.02 * zoom_factor) ypos actual_size[1] - int(size[1] * 0.25 * zoom_factor) xsize int(size[0] * 0.25 * zoom_factor) ysize int(size[0] * 0.25 * zoom_factor) text "[card.attack]" size int(size[0] * 0.20 * zoom_factor) xalign 0.5 yalign 0.5 color attack_color outlines [(int(outline_thickness/2), "#000000", 0, 0)] else: fixed: xpos int(size[0] * 0.0 * zoom_factor) ypos actual_size[1] - int(size[1] * 0.18 * zoom_factor) xsize int(size[0] * 0.25 * zoom_factor) ysize int(size[0] * 0.25 * zoom_factor) text "[card.attack]" size int(size[0] * 0.12 * zoom_factor) xalign 0.5 yalign 0.5 color attack_color outlines [(int(outline_thickness/2), "#000000", 0, 0)] # Health value if isinstance(card, CreatureCard): $ health_color = "#FFFFFF" if hasattr(card, "original_health"): if card.health < card.original_health: $ health_color = "#FF4444" elif card.health > card.original_health: $ health_color = "#44FF44" if on_field: fixed: xpos actual_size[0] - int(size[0] * 0.27 * zoom_factor) ypos actual_size[1] - int(size[1] * 0.25 * zoom_factor) xsize int(size[0] * 0.25 * zoom_factor) ysize int(size[0] * 0.25 * zoom_factor) text "[card.health]" size int(size[0] * 0.20 * zoom_factor) xalign 0.5 yalign 0.5 color health_color outlines [(int(outline_thickness/2), "#000000", 0, 0)] else: fixed: xpos actual_size[0] - int(size[0] * 0.21 * zoom_factor) ypos actual_size[1] - int(size[1] * 0.18 * zoom_factor) xsize int(size[0] * 0.25 * zoom_factor) ysize int(size[0] * 0.25 * zoom_factor) text "[card.health]" size int(size[0] * 0.12 * zoom_factor) xalign 0.5 yalign 0.5 color health_color outlines [(int(outline_thickness/2), "#000000", 0, 0)] - Assistant
To make the card in the player's hand less jumpy when the cursor is close to the edges of the card, you can adjust the hover and idle animations in the
buttontransform.Here's an updated version of the code:
button: id "player_hand_card_{i}" xsize 180 ysize 252 pos (base_xpos, base_ypos) anchor (0.5, 1) at transform: rotate base_angle transform_anchor True on hover: linear 0.2 rotate 0 linear 0.2 ypos 150 linear 0.2 yoffset -30 on idle: linear 0.4 rotate base_angle linear 0.4 ypos base_ypos linear 0.4 yoffset 0In this updated code, I've increased the duration of the
on idleanimation from0.2to0.4seconds. This will make the card return to its original position more slowly, reducing the jumpiness when the cursor is close to the edges of the card.You can adjust the duration of the animations to your liking, but keep in mind that longer durations may make the card feel less responsive to the player's actions.
Additionally, you can also consider adding a
on hoverandon idleanimation to thecard_previewscreen to make the card enlargement and rotation more smooth.For example:
screen card_preview(card, selected=False, playable=False, size=(150, 210), hoverable=False, on_field=False, no_enlarge=False): # ... fixed: xysize actual_size xoffset offset_x yoffset offset_y at transform: on hover: linear 0.2 zoom 1.8 on idle: linear 0.2 zoom 1.0This will make the card enlarge and rotate more smoothly when the player hovers over it. You can adjust the duration and zoom factor to your liking.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.