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 - Kamigousu

Pages: [1]
This is crazy that I find this thread because I was just thinking about this problem a little while back and something like solution #2 is what I figured would work best.

I'm trying to work on an ARPG mix of Dark Souls and ALttP and I had planned on having interchangeable weapons and armour. I don't know for certain that this would work on a large scale, but my thought was that you would layer the armour/weapon sprites on top of/underneath the hero sprite and synchronise them. It is a bit of work to make all the sprite sheets but it's not all that terrible. As a proof of concept, I used a custom enemy sprite and overlaid the weapon (a broken straight sword) in his hand.

I copied the soldier.lua from the ALttp_1.6 resource pack and changed a few things and named it hollow.lua. This function:

Code: [Select]
function enemy:order_sprites(main_sprite,sword_sprite)
    local direction4 = enemy:get_direction4_to(enemy:get_facing_position())
      if direction4 == 1 or direction4 == 2 then
        print("sword in back")
        print("sword in front")
    return true

is what I used to change the sprite overlay depending on the direction of the entity. It is called in the hollow.lua here:

Code: [Select]
function enemy:check_hero()

    local _, _, layer = enemy:get_position()
    local _, _, hero_layer = hero:get_position()
    local near_hero = layer == hero_layer
        and enemy:get_distance(hero) < 500
        and enemy:is_in_same_region(hero)

    if near_hero and not going_hero then
      if properties.play_hero_seen_sound then"hero_seen")
    elseif not near_hero and going_hero then
    sol.timer.start(enemy, 50, function() enemy:order_sprites(main_sprite, sword_sprite) end)   --timer to ensure weapon sprite is in front/
                                                                                                --behind the enemy when necessary
    sol.timer.start(self, 100, function() enemy:check_hero() end)

I call it every 50ms because it doesn't perform well above that (weapon sprites pop through after the hero has changed direction). I also haven't tested this with any other circumstance aside from this single enemy on the Kakariko Village map from the resource pack, so I have no clue if it would work with 10 or more enemies on the same map. I had planned to use this for the hero clue if that would work too, but that is for a little bit later on.

Comments and feedback are appreciated.

As llamazing suggested, the tostring and tonumber option worked out perfectly. I had tried that but I put them in the wrong place to get the expected results. Thank you for the helpful tip, llamazing.

@Diarandor: I ended up setting it up to calculate the value whenever you call it but it still saves the value (for now) because I'm not sure if there will items that directly affect the multiplier (without affecting Endurance). So a little of both solutions helped here.

I appreciate this community for being so helpful; this post wasn't even about getting help but you helped me reconfigure my scripts to work properly. Do either of you know, by chance, why it is that game values are truncated? That was my main reason for posting. I wasn't sure if anyone knew.

You're saying to just use the function to calculate the number anytime it is needed? I suppose I could, I just thought it would be better to save it; not sure why.

The function mentioned is one I defined however it doesn’t have anything in it that would truncate the decimal.

I think what you have posted may just work. I was trying tostring and tonumber but I don’t think I was placing them correctly for the desired effect. I will try it the way you have said and see if it helps.

It beats my original plan: change everything over to hero_meta functions. That way, my get/set_value becomes get/set_property which doesn’t work as expected ( although I suspect I haven’t properly changed al of my scripts to match the new hero_meta versus the old game_meta setup).

I’ll post back tomorrow and hopefully will have some successful results.

Sorry, I will try to explain better. There are a few scripts that work with this so I will post them if this post doesn't get across what I'm talking about.

I'm working on an RPG that is supposed to be a mix of Dark Souls 3 and ALttP. It has lots of parameters like Strength, Endurance, and Vigor and some of these parameters are added or multiplied together to define other parameters.

My current issue lies in determining my hero's vitality level. Vitality level depends on three factors: Endurance level, Strength level, and Vigor level.

(strength * 2) + (vigor * endurance multiplier) = vitality

So the parameters (Strength, Vigor, Endurance) all have min and max values (1 - 99). For Strength and Vigor, all I need are the levels; so if my Strength level is 45, I use it in the first part as (45 * 2). However, the Endurance Multiplier is calculated using the Endurance level and its min and max values are 1.01 up to 1.9999999; so if my Endurance level is 25 then my Endurance Multiplier would be 1.340.

This is where the problem lies. I have functions to get,set,add,remove,and calculate all these values but when I call the functions, like game:get_end_mult() (to get my endurance multiplier, obviously), the decimals are removed from the value leaving it as 1 or 2 depending on how large the decimal portion was. I'm currently working on trying the same thing but with the hero metatable instead of the game_metatable. My first test seemed to work; the value printed was the full decimal value that I had typed in.

I was just hoping to be able to integrate all the stats and params into the game table...I suppose its not really necessary for anything besides health, stamina, and magic. I made this post mostly because I am curious as to what the reason is for the game table truncating values.

Was working on stats for a new game and noticed that some of the resources like health and stamina were not coming out to their expected value, but rather they were rounded up or down depending on the following decimal. 100.1 becomes 100, 89.97 becomes 90.

I found that other values I printed were coming out with all decimal places intact though these values weren't called through any 'game' function. It mostly hasn't been a problem until I needed to use a multiplier that scales between 1.01 and 1.9999999. Calling the multiplier through the 'game' function I made for it truncates and rounds the number to either 1 or 2. It's causing a little bit of a problem with a few things but nothing game breaking.

Any one know of a work around or a way to get 'game' functions to print out full number values? I have tried a few things but nothing has worked out yet.

Development / Re: Is it possible to make the hero face the cursor?
« on: August 18, 2018, 07:55:57 am »
I really appreciate the help. I have been working with it for a while now and, while it shows no errors, it doesn't work as intended. By no means do I want nor expect you to do the work for me; as you said, it defeats the purpose of the learning process. I will just have to continue to expand my Lua knowledge until I can understand better where I am making the mistake. Looking forward to learning more Lua and Solarus.

Many thanks, again!

Development / Re: Is it possible to make the hero face the cursor?
« on: August 17, 2018, 05:09:19 pm »
I really appreciate the fast replies!

@Diarandor: your code make it look so easy...clearly I have much to learn. I’ll try implementing that later today, after work. Am I missing a call for this script somewhere though? Because I feel like it isn’t being called properly.

@llamazing: I’ll definitely keep those functions in mind. Once I can get a proof of concept working for myself, I’d like to add more to it so that it functions properly in a game, and it looks like what you mentioned is going to be extremely helpful. The game I’m working on is going to be styled like a two stick shooter; essentially the wasd would control the hero movement direction and the mouse would control hero facing direction. So I do want the hero to constantly face the cursor, unless it is directly on top of the hero, in which case he should simply look North.

Really hoping I can get this done with your help  because my next task is to add a stamina resource to the game, alongside life and magic. I’ve been trying to use the anger bar from OLB as a reference but I can’t figure out how to add the resource to the game just yet. I’m assuming it has to do with meta tables so I suppose I’ll need to get to that point in the book before really understanding how to do that. I feel bad for asking for help on here when I haven’t learned wverything I can on my own but I’m glad I wasn’t met with negativity. Thanks again and I’ll post back whether or not  I get it working tonight!

Development / Is it possible to make the hero face the cursor?
« on: August 16, 2018, 11:22:25 pm »
Hello, Solarus World.

    I have been learning Solarus through the online tutorial series by Christopho. It has been incredibly helpful. However, there are many things in my current project that are not covered in any of the tutorial videos and I've not been able to find any info on them online. The API has also been incredibly helpful but I admit I lack a complete understanding of Lua and so I may not fully understand everything as written in the API (for instance, I had trouble with the drawable:draw_region()...the two sets of coordinates confused me, but I figured out through practice what they meant). I am very new to using it but I have been quickly picking things up and reading through previously posted links on this forum for Lua learning resources.

    The problem I am facing right now is my face_cursor script. I wanted to allow the player to change their character's facing direction by moving the mouse around on the screen (and add support for joysticks as well). Essentially, I'm looking to make it behave similar to a two stick shooter game. Is this possible in the engine as it stands? I will attach my script, which is just supposed to be a proof of concept, for your scrutiny..

Code: [Select]
local function init_cursor_info(game)        --Local Function encapsulating lesser functions and pulling 'game'.

  local map = game:get_map()
  local hero = game:get_hero()
  local h_x, h_y, h_L = hero:get_position()
  local h_dir = hero:get_direction()
  local c_x, c_y = sol.input.get_mouse_position()
  local c_dir

  --The following function should update cursor coordinates continuously.
  function game:cursor_update()
    local nc_x, nc_y = sol.input.get_mouse_position()

    if nc_x == c_x and nc_y == c_y then
      c_x = nc_x
      c_y = nc_y
    return true


  --The following function should update hero coordinates and direction continuously.
  function game:hero_update()
    local nh_x, nh_y, nh_L = hero:get_position()
    local nh_dir = hero:get_direction()

    if nh_x == h_x and nh_y == h_y then
      h_x = nh_x
      h_y = nh_y
      h_L = nh_L

    if nh_dir == h_dir then
      h_dir = nh_dir

    return true


  function game:get_cursor_direction()

    local x_chg
    local y_chg

    x_chg = cursor_x - hero_x
    y_chg = cursor_y - hero_y

    if x_chg > 0 and y_chg > 0 then     --Face Hero South-East.
      cur_dir = 7
    elseif x_chg == 0 and y_chg > 0 then --Face Hero South.
      cur_dir = 6
    elseif x_chg < 0 and y_chg > 0 then --Face Hero South-West.
      cur_dir = 5
    elseif x_chg < 0 and y_chg == 0 then --Face Hero West.
      cur_dir = 4
    elseif x_chg < 0 and y_chg < 0 then
      cur_dir = 3
    elseif x_chg == 0 and y_chg < 0 then
      cur_dir = 2
    elseif x_chg > 0 and y_chg < 0 then
      cur_dir = 1
    elseif x_chg > 0 and y_chg == 0 then
      cur_dir = 0
    else if x_chg == 0 and y_chg == 0 then
      cur_dir = 2


    return true

  end                                                  --End of get_cursor_direction()

  function game:on_started()

    local time = 100

    sol.timer.start(game, time, cursor_update())
    sol.timer.start(game, time, hero_update())
    sol.timer.start(game, time, get_cursor_direction())

    print(time)                                        --This print was to test if this segment far it hasn't printed.
end                                                    --Not sure why I needed two ends here...I was getting an error with only one.
end                                                    --End Local Function init_cursor_info(game)

--The following code was taken from OniLinkBegins. My understanding is that this works as is but I am unsure.
-- Set up face_cursor features on any game that starts.
local game_meta = sol.main.get_metatable("game")
game_meta:register_event("on_started", init_cursor_info)

return true

..I'm sure I am making some rookie mistake, but as I said I'm learning still so any advice is appreciated.

Pages: [1]