GlovePIE:Double Dragon 2

From WiiLi

Jump to: navigation, search

This script uses Dead Zones and Pulsing. Last updated 10:12, 3 March 2007 (EST)

[edit] Script

/*************************************************************
Double Dragon 2 - Two Player Pulse Script 1.2
by almostconnected (almost#technodookie,com)

This script uses the default Nestopia control scheme. Nunchuk
is optional, but recommended!

With Nunchuk:
NES        -> Wiimote
D-Pad      -> Analog Stick
Select     -> -
Start      -> +
B          -> Z or Punch with Nunchuk
A          -> B or Punch with Wiimote
Jump (A+B) -> A

Without Nunchuk:
NES        -> Wiimote
D-Pad      -> D-Pad
Select     -> -
Start      -> +
B          -> 1
A          -> 2
*************************************************************/

// init
if not var.Inited
   var.LowBattery  = 10
   var.RemindWait  = 30 seconds
   var.SwingThresh = 300.0
   var.SwingTime   = 5 ms
   var.DeadZone    = 0.15
   var.LiveZone    = 1.0 - var.DeadZone
   var.Inited      = true
end

// LEDs
Wiimote1.Leds = 1
Wiimote2.Leds = 2

// report low batteries
if Wiimote.Count >= 1 and Wiimote1.Battery <= var.LowBattery
   say "wiimote 1 batteries are low."
   wait var.RemindWait
end
if Wiimote.Count >= 2 and Wiimote2.Battery <= var.LowBattery
   say "wiimote 2 batteries are low."
   wait var.RemindWait
end
      
// wiimote 1
if Wiimote1.HasNunchuk

   // attack left
   var.Swing = Wiimote1.Nunchuk.RelAccX*Wiimote1.Nunchuk.RelAccX + Wiimote1.Nunchuk.RelAccY*Wiimote1.Nunchuk.RelAccY + Wiimote1.Nunchuk.RelAccZ*Wiimote1.Nunchuk.RelAccZ

   if var.Swing > var.SwingThresh
      Key.Comma = true
      wait var.SwingTime
   else
      Key.Comma = false
   end

   // attack right
   var.Swing = Wiimote1.RelAccX*Wiimote1.RelAccX + Wiimote1.RelAccY*Wiimote1.RelAccY + Wiimote1.RelAccZ*Wiimote1.RelAccZ

   if var.Swing > var.SwingThresh
      Key.Dot = true
      wait var.SwingTime
   else
      Key.Dot = false
   end

   // use wiimote 1
   var.JoyX = Wiimote1.Nunchuk.JoyX
   var.JoyY = Wiimote1.Nunchuk.JoyY

   // apply deadzone to X axis
   if var.JoyX < -var.DeadZone
      var.JoyX = (var.JoyX + var.DeadZone) / var.LiveZone
   else if var.JoyX > var.DeadZone
      var.JoyX = (var.JoyX - var.DeadZone) / var.LiveZone
   else
      var.JoyX = 0
   end

   // apply deadzone to Y axis
   if var.JoyY < -var.DeadZone
      var.JoyY = (var.JoyY + var.DeadZone) / var.LiveZone
   else if var.JoyY > var.DeadZone
      var.JoyY = (var.JoyY - var.DeadZone) / var.LiveZone
   else
      var.JoyY = 0
   end

   // pulse X axis
   var.PulseX1 = var.PulseX1 + Abs(var.JoyX)
   if var.PulseX1 >= 1.0 // pulse!
      Key.Left    = var.JoyX < 0
      Key.Right   = var.JoyX > 0
      var.PulseX1 = var.PulseX1 - 1.0
   else
      Key.Left    = false
      Key.Right   = false
   end

   // pulse Y axis
   var.PulseY1 = var.PulseY1 + Abs(var.JoyY)
   if var.PulseY1 >= 1.0 // pulse!
      Key.Up      = var.JoyY < 0
      Key.Down    = var.JoyY > 0
      var.PulseY1 = var.PulseY1 - 1.0
   else
      Key.Up      = false
      Key.Down    = false
   end

   // buttons
   Key.Comma = Key.Comma or Wiimote1.Nunchuk.ZButton or Wiimote1.A  // B
   Key.Dot   = Key.Dot   or Wiimote1.B               or Wiimote1.A  // A
   Key.RightShift = Wiimote1.Minus // Select
   Key.Enter      = Wiimote1.Plus  // Start

else

   Key.Left       = Wiimote1.Up    // left
   Key.Up         = Wiimote1.Right // up
   Key.Right      = Wiimote1.Down  // right
   Key.Down       = Wiimote1.Left  // down
   Key.Comma      = Wiimote1.One   // B
   Key.Dot        = Wiimote1.Two   // A
   Key.RightShift = Wiimote1.Minus // Select
   Key.Enter      = Wiimote1.Plus  // Start

end

// wiimote 2
if Wiimote2.HasNunchuk

   // attack left
   var.Swing = Wiimote2.Nunchuk.RelAccX*Wiimote2.Nunchuk.RelAccX + Wiimote2.Nunchuk.RelAccY*Wiimote2.Nunchuk.RelAccY + Wiimote2.Nunchuk.RelAccZ*Wiimote2.Nunchuk.RelAccZ

   if var.Swing > var.SwingThresh
      Key.Z = true
      wait var.SwingTime
   else
      Key.Z = false
   end

   // attack right
   var.Swing = Wiimote2.RelAccX*Wiimote2.RelAccX + Wiimote2.RelAccY*Wiimote2.RelAccY + Wiimote2.RelAccZ*Wiimote2.RelAccZ

   if var.Swing > var.SwingThresh
      Key.X = true
      wait var.SwingTime
   else
      Key.X = false
   end

   // use wiimote 2
   var.JoyX = Wiimote2.Nunchuk.JoyX
   var.JoyY = Wiimote2.Nunchuk.JoyY

   // apply deadzone to X axis
   if var.JoyX < -var.DeadZone
      var.JoyX = (var.JoyX + var.DeadZone) / var.LiveZone
   else if var.JoyX > var.DeadZone
      var.JoyX = (var.JoyX - var.DeadZone) / var.LiveZone
   else
      var.JoyX = 0
   end

   // apply deadzone to Y axis
   if var.JoyY < -var.DeadZone
      var.JoyY = (var.JoyY + var.DeadZone) / var.LiveZone
   else if var.JoyY > var.DeadZone
      var.JoyY = (var.JoyY - var.DeadZone) / var.LiveZone
   else
      var.JoyY = 0
   end

   // pulse X axis
   var.PulseX2 = var.PulseX2 + Abs(var.JoyX)
   if var.PulseX2 >= 1.0 // pulse!
      Key.C       = var.JoyX < 0
      Key.B       = var.JoyX > 0
      var.PulseX2 = var.PulseX2 - 1.0
   else
      Key.C       = false
      Key.B       = false
   end

   // pulse Y axis
   var.PulseY2 = var.PulseY2 + Abs(var.JoyY)
   if var.PulseY2 >= 1.0 // pulse!
      Key.F       = var.JoyY < 0
      Key.V       = var.JoyY > 0
      var.PulseY2 = var.PulseY2 - 1.0
   else
      Key.F       = false
      Key.V       = false
   end

   // buttons
   Key.Z = Key.Z or Wiimote2.Nunchuk.ZButton or Wiimote2.A  // B
   Key.X = Key.X or Wiimote2.B or Wiimote2.A                // A
   Key.A = Wiimote2.Minus // Select
   Key.S = Wiimote2.Plus  // Start

else

   Key.C = Wiimote2.Up    // left
   Key.F = Wiimote2.Right // up
   Key.B = Wiimote2.Down  // right
   Key.V = Wiimote2.Left  // down
   Key.Z = Wiimote2.One   // B
   Key.X = Wiimote2.Two   // A
   Key.A = Wiimote2.Minus // Select
   Key.S = Wiimote2.Plus  // Start

end

[edit] External Links

Personal tools