1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  magnitude = 0
  vx = 0
  vy = 0

  if joy1_axisDir1 ~= 0 then
     vx = joy1_axisDir1
  end
  if joy1_axisDir2 ~= 0 then
     vy = joy1_axisDir2
  end

  magnitude = math.sqrt(vx*vx + vy*vy)
  
  if magnitude ~= 0 then
    vx = math.abs(joy1_axisDir1) * vx/magnitude;
    vy = math.abs(joy1_axisDir2) * vy/magnitude;
    
    player.x = player.x + player.move_speed * dt * vx
    player.y = player.y + player.move_speed * dt * vy
  end