Author Topic: [Cursor] Majora's Mask / Project Zelda Engine cursor  (Read 93 times)

MetalZelda

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
[Cursor] Majora's Mask / Project Zelda Engine cursor
« on: June 25, 2017, 12:59:44 pm »
This is a straight port of a RUBY script. Made by MaximusMaxy, from Project Zelda Engine
This script allow to have an animated cursor for your pause menu, like Majora's Mask, of course, it can be adapted for other stuffs

This is an alternative solution for avoiding a spriteset creation (frame by frame cursor animation), this script calculate the animation for you.

You need:

-> a cursor png (1 part or 4 sides) which you should save in /sprites/menus/src/pause_submenus/cursor.png (You can change the file bellow
-> using 4 side cursor ? Just set use_rotation to false
-> Using 1 part cursor ? Set use_rotation to true

What can you do ?

-> You can modify the radius of the circle (minimum, maximum)
-> You can modify the speed of the animation (speed, where 1 = super slow and 9 = 1 lightyear per sanic)
-> Disable the rotation system and only keep the offset system
-> Disable the fading animation that occurs when the animation is drawn

Code: Lua
  1. function submenu:create_cursor()
  2.   -- Set the minimum and maximum radius of the rotation
  3.   local minimum, maximum = 10, 12
  4.  
  5.   -- Speed of the animation (1 = slow, 9 = fast)
  6.   local speed = 5
  7.  
  8.   -- Use the rotation system or just the zoom ? (true = use the rotation, false = just the zoom)
  9.   local use_rotation = true
  10.  
  11.   -- Use the fading option
  12.   local use_fade = true
  13.  
  14.   -- Cursor file
  15.   local cursor = sol.surface.create("menus/src/pause_submenus/cursor.png")
  16.   local cursor_width, cursor_height = cursor:get_size()
  17.  
  18.   -- Determine the region parts depending on use_rotation state
  19.   if not use_rotation then
  20.     cursor_width = cursor_width / 2
  21.     cursor_height = cursor_height / 2
  22.   end
  23.  
  24.   -- Don't touch this
  25.   local count = 0
  26.  
  27.   function submenu:draw_cursor(dst_surface, x, y)
  28.     -- Increment the rotation
  29.     count = (count + speed) % 360
  30.  
  31.     -- Compute the sin and cos of the rotation
  32.     local sin = math.sin(count * math.pi / 180)
  33.     local cos = math.cos(count * math.pi / 180)
  34.  
  35.     -- Compute the zoom scaling
  36.     local offset = minimum + (maximum - minimum) / 2 + (maximum - minimum) / 2 * sin
  37.        
  38.         -- Update the cursor opacity
  39.         if use_fade then
  40.           cursor:set_opacity(205 - (0.5 + sin) * 100)
  41.         end
  42.        
  43.         -- Not using the rotation system, no rotation
  44.         if not use_rotation then
  45.           cos, sin = 1, 1
  46.         end
  47.        
  48.         local rotation_w = use_rotation and 0 or cursor_width
  49.         local rotation_h = use_rotation and 0 or cursor_height
  50.  
  51.         -- Draw the cursors
  52.         -- Upper Right
  53.     cursor:draw_region(rotation_w, 0, cursor_width, cursor_height, dst_surface, x + (sin * offset), y + (cos * -offset))
  54.        
  55.         -- Lower Left
  56.     cursor:draw_region(0, rotation_h, cursor_width, cursor_height, dst_surface, x + (sin * -offset), y + (cos * offset))
  57.        
  58.         -- Lower Right
  59.     cursor:draw_region(rotation_w, rotation_h, cursor_width, cursor_height, dst_surface, x + (cos * offset), y + (sin * offset))
  60.        
  61.         -- Upper Left
  62.     cursor:draw_region(0, 0, cursor_width, cursor_height, dst_surface, x + (cos * -offset), y + (sin * -offset))
  63.   end
  64. end
  65. submenu:create_cursor()

This is plug and play, at least if you use the MoS submenu system, you just have to call submenu:draw_cursor(dst_surface, x, y) in yout submenu script

You can also delete the rotation system for a zooming cursor, all you need to zoom is the local "offset"
« Last Edit: June 25, 2017, 02:07:24 pm by MetalZelda »