Advertisement
Guest User

Renpy main menu parallax

a guest
Jan 24th, 2021
5,977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1.  
  2. init python:
  3. import pygame
  4. import math
  5.  
  6.  
  7. class TrackCursor(renpy.Displayable):
  8.  
  9. def __init__(self, child, paramod, **kwargs):
  10.  
  11. super(TrackCursor, self).__init__()
  12.  
  13. self.child = renpy.displayable(child)
  14. self.x = 0
  15. self.y = 0
  16. self.actual_x = 0
  17. self.actual_y = 0
  18.  
  19. self.paramod = paramod
  20. self.last_st = 0
  21.  
  22.  
  23.  
  24. def render(self, width, height, st, at):
  25.  
  26. rv = renpy.Render(width, height)
  27. minimum_speed = 0.5
  28. maximum_speed = 3
  29. speed = 1 + minimum_speed
  30. mouse_distance_x = min(maximum_speed, max(minimum_speed, (self.x - self.actual_x)))
  31. mouse_distance_y = (self.y - self.actual_y)
  32. if self.x is not None:
  33. st_change = st - self.last_st
  34.  
  35. self.last_st = st
  36. self.actual_x = math.floor(self.actual_x + ((self.x - self.actual_x) * speed * (st_change )) * self.paramod)
  37. self.actual_y = math.floor(self.actual_y + ((self.y - self.actual_y) * speed * (st_change)) * self.paramod)
  38.  
  39.  
  40. if mouse_distance_y <= minimum_speed:
  41. mouse_distance_y = minimum_speed
  42. elif mouse_distance_y >= maximum_speed:
  43. mouse_distance_y = maximum_speed
  44.  
  45. cr = renpy.render(self.child, width, height, st, at)
  46. cw, ch = cr.get_size()
  47. rv.blit(cr, (self.actual_x, self.actual_y))
  48.  
  49.  
  50.  
  51. renpy.redraw(self, 0)
  52. return rv
  53.  
  54. def event(self, ev, x, y, st):
  55. hover = ev.type == pygame.MOUSEMOTION
  56. click = ev.type == pygame.MOUSEBUTTONDOWN
  57. mousefocus = pygame.mouse.get_focused()
  58. if hover:
  59.  
  60. if (x != self.x) or (y != self.y) or click:
  61. self.x = -x /self.paramod
  62. self.y = -y /self.paramod
  63.  
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement