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.


Topics - Mr Shiek

Pages: [1]
1
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.

2
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
      return
    else
      c_x = nc_x
      c_y = nc_y
    end
 
    return true

  end

  --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
      return
    else
      h_x = nh_x
      h_y = nh_y
      h_L = nh_L
    end

    if nh_dir == h_dir then
      return
    else
      h_dir = nh_dir
    end

    return true

  end

  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

    end

    return true

  end                                                  --End of get_cursor_direction()

  function game:on_started()

    local time = 100

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

    print(time)                                        --This print was to test if this segment executed...so far it hasn't printed.
  end
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]