Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - MetalZelda

Pages: [1] 2 3 ... 33
1
Development / Re: Trouble porting a script
« on: June 25, 2017, 09:44:27 pm »
This kinda work, it is better than last time because now the cursor and item change.

However, this is messy, it only loops through 2 items, the distance system works but it only loops between 2 items, light be the command stuff but it looks ok ...

Code: Lua
  1. function submenu:set_cursor_position(command)
  2.   local width = sol.video.get_quest_size()
  3.   width = width / 2 - 160
  4.  
  5.   local current_x = self.cursor_position.x
  6.   local current_y = self.cursor_position.y
  7.        
  8.   -- Create default value for the closest item's distance
  9.   local closest_index = -1
  10.   local closest_distance = 9999999
  11.   local index = self:find_item(self:find_item_axis(current_x, current_y))
  12.        
  13.   -- Initialize variables for the weightings on the vertical and horizontal direction
  14.   local wv, wh = 0, 0
  15.        
  16.   -- The weightings for the secondary and primary axis relative to input
  17.   local w1, w2 = 1, 2
  18.        
  19.   -- Setup the weightings for each direction
  20.   if  (command == "down" or command == "up") then
  21.     wv, wh = w1, w2
  22.   elseif (command == "left" or command == "right") then
  23.         wv, wh = w2, w1
  24.   end
  25.  
  26.   for i, item in ipairs(self.items) do
  27.     local x = item.x
  28.         local y = item.y
  29.        
  30.         --  This isn't the old item or the opposite direction
  31.         if index ~= i or (command ~= "down" and y > current_y) or (command ~= "left" and x < current_x) or (command ~= "right" and x > current_x) or (command ~= "up" and y < current_y) then
  32.           -- Get the distance of the current item and the new one
  33.           local dist_h = math.abs(x - current_x)
  34.           local dist_v = math.abs(y - current_y)
  35.          
  36.           if (wh ~= w1 or w2 * dist_h > dist_v) and (wv ~= w1 or w2 * dist_v > dist_h) then
  37.             local dist = (dist_h * wh + dist_v * wv)
  38.                
  39.                 -- Set at closest item if appropriate
  40.             if (dist < closest_distance) then
  41.                   closest_distance = dist
  42.                   closest_index = i
  43.             end
  44.           end    
  45.         end
  46.   end
  47.  
  48.   local item = self.items[closest_index]
  49.   local x = item.x
  50.   local y = item.y - 5 
  51.        
  52.   self.cursor_position = {x = x, y = y + 5}
  53.   self.cursor_sprite_x = x + width
  54.   self.cursor_sprite_y = y
  55.   self.game:set_custom_command_effect("action", item.effect)
  56.  
  57.   local caption_item = item.item .. "_" .. self.game:get_item(item.item):get_variant()
  58.  
  59.   self:set_caption(self.caption_text_keys[caption_item])  
  60.   self.game:set_value(self.menu .. "_last_index", tostring(x) .. "," .. tostring(y + 5))
  61. end

index prints the right item index in the array so this is not the culprit there
Hmmm, that's the 1st time a ruby script port grinds my gears

2
Development / Trouble porting a script
« on: June 25, 2017, 04:40:28 pm »
Hello.

So, I am porting a RUBY script to lua.
This script will allow easier pause menu creation, replacing cursor position by user defined positions. Like so

Code: Lua
  1. local elements = {
  2.   config = {save = true},
  3.   {"rupee_bag", 68, 78, "info"},
  4.   {"bomb_bag", 68, 104, "info"},
  5.   {"quiver", 68, 130, "info"},
  6.   {"deku_nuts_bag", 68, 156, "info"},
  7.   {"bombchu_bag", 68, 182, "info"},
  8.   {"sword", 217, 84, "action"},
  9.   {"tunic", 209, 180, "action", variant = "_1"},
  10.   {"tunic", 233, 180, "action", variant = "_2"},
  11.   {"tunic", 257, 180, "action", variant = "_3"},
  12.   {"glove", 209, 132, "info"},
  13.   {"shield", 233, 132, "info"},
  14.   {"climb_ring", 257, 132, "info"},
  15.   {"sword_biggoron", 249, 84, "action"},
  16. }

The 2nd and 3rd index is used to place an item on the X and Y axis, as well as the cursor

This is the RUBY script I'm trying to port

Code: Ruby
  1. # Initialize variables for the weightings on the vertical and horizontal
  2.       # directions
  3.                         wv, wh = 0, 0
  4.       # The weightings for the secondary and primary axis relative to input
  5.                         w1, w2 = 1, 2
  6.       # Initialize a variable for the direction and get the direction
  7.       # pressed by the user
  8.       input_dir = 0
  9.       input_dir = 2 if Input.repeat?(Input::DOWN)
  10.       input_dir = 4 if Input.repeat?(Input::LEFT)
  11.       input_dir = 6 if Input.repeat?(Input::RIGHT)
  12.       input_dir = 8 if Input.repeat?(Input::UP)
  13.       # Do nothing if no button was pressed
  14.       return if input_dir == 0
  15.       #get the item
  16.       item = self.item
  17.       #if the item is left toggle and the input direction is left
  18.       if item == :left_toggle && input_dir == 4
  19.         #move to the left window
  20.         return $scene.move_window(6)
  21.       #elsif the item is right toggle and the input direction is right
  22.       elsif item == :right_toggle && input_dir == 6
  23.         #move to the right window
  24.         return $scene.move_window(4)
  25.       end
  26.       # Setup the weightings for each direction
  27.                         if  (input_dir == 2 or input_dir == 8)
  28.                                 wv, wh = w1, w2
  29.                         elsif (input_dir == 4 or input_dir == 6)
  30.                                 wv, wh = w2, w1
  31.                         end
  32.       # Get the xy position of the current item
  33.                         cxy = @xy_pos[@index]
  34.       # Create default value for the closest item's distance (absurdly large)
  35.       closest_index = -1
  36.                         closest_distance = 9999999
  37.       # Loop through every item
  38.                         for i in 0...@xy_pos.size
  39.                                 # Skip if it is the old item or is in the opposite direction
  40.                                 if @index == i or
  41.                                    (input_dir == 2 and @xy_pos[i][1] < cxy[1]) or
  42.                                    (input_dir == 4 and @xy_pos[i][0] > cxy[0]) or
  43.                                    (input_dir == 6 and @xy_pos[i][0] < cxy[0]) or
  44.                                    (input_dir == 8 and @xy_pos[i][1] > cxy[1])
  45.                                         next
  46.                                 end
  47.         # Get the distance from the last highlighted item to this tested one
  48.                                 dist_h = (@xy_pos[i][0] - cxy[0]).abs
  49.                                 dist_v = (@xy_pos[i][1] - cxy[1]).abs
  50.         # If it is really against the primary axis
  51.         if (wh == w1 and w2 * dist_h < dist_v) or
  52.             (wv == w1 and w2 * dist_v < dist_h)
  53.           next
  54.         end
  55.         # Get the distance multiplied with their weightings
  56.                                 dist = dist_h * wh + dist_v * wv
  57.         # Set at closest item if appropriate
  58.                                 if (dist < closest_distance)
  59.                                         closest_distance = dist
  60.                                         closest_index = i
  61.                                 end
  62.                         end
  63.       # Do nothing if nothing was selected
  64.       return if closest_index == -1
  65.       @index = closest_index
  66.       #move cursor
  67.       move_cursor

@xy_pos is already defined in the elements variable, @cxy is the current cursor position, they are already defined

The only problem, RUBY have a skip iterator whereas I can't find the closest thing for lua

This is my attempt in Lua, which still fails, the cursor will still highlight the current item forever

Code: Lua
  1. function submenu:set_cursor_position(command)
  2.   local width = sol.video.get_quest_size()
  3.   width = width / 2 - 160
  4.  
  5.   local current_x = self.cursor_position.x
  6.   local current_y = self.cursor_position.y
  7.        
  8.   -- Create default value for the closest item's distance
  9.   local closest_index = -1
  10.   local closest_distance = 320
  11.        
  12.   -- Initialize variables for the weightings on the vertical and horizontal direction
  13.   local wv, wh = 0, 0
  14.        
  15.   -- The weightings for the secondary and primary axis relative to input
  16.   local w1, w2 = 1, 2
  17.        
  18.   -- Setup the weightings for each direction
  19.   if (command == "down" or command == "up") then
  20.     wv, wh = w1, w2
  21.   elseif (command == "left" or command == "right") then
  22.         wv, wh = w2, w1
  23.   end
  24.  
  25.   for i = 1, #self.items do
  26.     local item = self.items[i]
  27.         local item_x = item.x
  28.         local item_y = item.y
  29.         local current_item_index = self:find_item(self:find_item_axis(self.cursor_position.x, self.cursor_position.y))
  30.        
  31.         --  Skip if it is the old item or is in the opposite direction
  32.         if current_item_index == i or (command == "down" and item_y < current_y) or (command == "left" and item_x > current_x) or (command == "right" and item_x < current_x) or (command == "up" and item_y > current_y) then
  33.           -- tried goto
  34.         end
  35.        
  36.         -- Get the distance of the current item and the new one
  37.         local dist_h = math.abs(item_x - current_x)
  38.         local dist_v = math.abs(item_y - current_y)
  39.                
  40.         if (wh == w1 and w2 * dist_h < dist_v) or (wv == w1 and w2 * dist_v < dist_h) then
  41.           goto matched
  42.         end
  43.        
  44.         ::matched::
  45.     -- # Get the distance multiplied with their weightings
  46.         local dist = (dist_h * wh + dist_v * wv)
  47.                  
  48.         -- # Set at closest item if appropriate
  49.         if (dist < closest_distance) then
  50.           closest_distance = dist
  51.           closest_index = i
  52.         end
  53.   end
  54.        
  55.   local item = self.items[closest_index]
  56.   local x = item.x
  57.   local y = item.y - 5 
  58.        
  59.   self.cursor_position = {x = x, y = y + 5}
  60.   self.cursor_sprite_x = x + width
  61.   self.cursor_sprite_y = y
  62.   self.game:set_custom_command_effect("action", item.effect)
  63.  
  64.   local caption_item = item.item .. "_" .. self.game:get_item(item.item):get_variant()
  65.   if item.item == "tunic" then
  66.     caption_item = "tunic_" .. self:get_tunic_variant()
  67.   end
  68.  
  69.   self:set_caption(self.caption_text_keys[caption_item])  
  70.   self.game:set_value("equipment_last_index", position)
  71. end
  72.  
  73.  

Is there a Lua equivalent of "next" ?

Next = https://www.tutorialspoint.com/ruby/ruby_loops.htm
Jumps to the next iteration of the most internal loop. Terminates execution of a block if called within a block (with yield or call returning nil).

3
Development / Re: Zelda Roth Reproduced Intro Help
« on: June 25, 2017, 01:03:35 pm »
In most case, if frescos returns nil, this is because your surface isn't created because the file has not been found

4
Your scripts / [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"

5
Development / Re: Item command held on item?
« on: June 21, 2017, 12:34:22 pm »
To make the hero controllable just call item:set_fiinished()

But, you might want to control the hero and having the item to work. I would link a menu to this item and control everrything from this menu, you will have access to on_command_pressed / released.

That's what I do for my bow, hookshot and other stuffs

6
Development / Re: [QUESTION] Traversable prickles?
« on: June 21, 2017, 12:31:48 pm »
Maybe using dynamic tiles metatable and apply bad ground if id = spikes

http://www.solarus-games.org/doc/latest/lua_api_dynamic_tile.html#lua_api_dynamic_tile_get_pattern_id

Since dynamic tiles are entities, you can redefine it's behavious on creation time

7
Development / Re: Simulating a command when the hero is frozen ?
« on: June 18, 2017, 11:46:44 pm »
Oh well, Haven't seen that the spin attack is canceled when the input is release, which is an event of an input press, this is fixed

8
Development / [FIXED] Simulating a command when the hero is frozen ?
« on: June 18, 2017, 11:42:51 pm »
Hello

I ran out with a problem

I am working on cutscenes, that imply the hero to be frozen AND execute basic actions when the cutscene is active
the problem is, you can't simulate a command when the hero is frozen, I've tried to unfreeze him before the action occurs but when loading a spin attack from simulated command and if the player mispress the attack button, the animation is cancelled and the hero can move on it's own depending on the rules given (hero:unfreeze before the action or handling the command)

If the attack command is not pressed then the animation will play fine

I've tried to start a dummy menu like so, I also tried using sol.main:on_key_pressed, same

In this event, your input should do nothing except if a dialog is active ...
Code: Lua
  1. function dummy:on_key_pressed(key)
  2.   return not game:is_dialog_active()
  3. end

But no matter what, even if I delete hero:freeze(), this prevent the hero from moving, but we can still cancel the simulated input, even if this rule (key_pressed) or on_command_pressed has been defined to prevent any input to interrupt the action

Anyone help ?

You can reproduce it simply

Code: Lua
  1. game:simulate_command_pressed("attack")
  2. sol.timer.start(1500, function()
  3.   game:simulate_command_released("attack")
  4. end)
  5.  

9
Development / Re: How to add an "opening" animation for chests?
« on: June 18, 2017, 03:31:18 pm »
To make this work you need to create a chest entity, not a custom entity, the script do the rest (delete the chest and create the custom entity).

You need to define the sprite, treasure and savegame variable from there, like this



But, it is very basic atm, the entity name could be used to store frame delays or other stuffs

10
Game art & music / Re: [Tool] Palette Swapping tool
« on: June 14, 2017, 01:01:40 pm »
I will update the links tonight, I don't have free time this june

11
It is already planned as pixel modification

12
Bugs & Feature requests / Re: "normal" video mode is at 2x
« on: June 04, 2017, 06:31:40 pm »
You are asking to have a wider view when resizing ? Not just a rescaling


https://github.com/solarus-games/solarus/issues/1027
 
You does already requested this

https://github.com/solarus-games/solarus/issues/1052

Something like this ?
https://www.youtube.com/watch?v=4617ygC6f88


13
Development / Re: Stop slide on ice?
« on: June 04, 2017, 12:16:36 am »
The workaround is to replace the movement that make the hookshot come back as "target" and set it to the hero. This will work.
You can't stop while sliding, maybe running could stop that but idk

14
Development / Re: Problem with timer
« on: May 29, 2017, 11:31:29 pm »
I don't really understand the on_update() usage there

what you can do is using map:get_entities("")
http://www.solarus-games.org/doc/latest/lua_api_map.html#lua_api_map_get_entities

This way, this should work

15
Bugs & Feature requests / Re: Universal Windows App
« on: May 22, 2017, 11:59:52 am »
Don't know how UWA works but yeah could be interesting

Pages: [1] 2 3 ... 33