Disable diagonal movement

Started by CopperKatana, July 21, 2019, 03:18:35 AM

Previous topic - Next topic
Hello, I've been working on a Solarus recreation of Golden Axe Warrior from the Sega Master System. In that game, you can only move in four directions, just like in Zelda 1. I don't know of any way to disable diagonal movement or lock movement to four directions natively, so I wrote a script which does it for me.


require("scripts/multi_events")


local game_meta = sol.main.get_metatable("game")

function game_meta:on_command_pressed(command)
  if command == "right" then
    if self:is_command_pressed("up") then
      self:simulate_command_released("up")

    end   
    if self:is_command_pressed("down") then
      self:simulate_command_released("down")   
    end   
  end
 
  if command == "left" then
    if self:is_command_pressed("up") then
      self:simulate_command_released("up")   
    end   
    if self:is_command_pressed("down") then
      self:simulate_command_released("down")   
    end   
  end

  if command == "up" then
    if self:is_command_pressed("left") then
      self:simulate_command_released("left")   
    end   
    if self:is_command_pressed("right") then
      self:simulate_command_released("right")   
    end   
  end
  if command == "down" then
      if self:is_command_pressed("left") then
      self:simulate_command_released("left")   
    end   
    if self:is_command_pressed("right") then
      self:simulate_command_released("right")   
    end   
  end
 
  --Optionally, this disables the spin attack (or anything which would come after a normal attack)
  if command == "attack" then
    self:simulate_command_released("attack")
  end
end


It's not pretty or elegant, but it has held up to my tests thus far and results in a game that plays much more similarly to Zelda 1.